jbevain / cecil

Cecil is a library to inspect, modify and create .NET programs and libraries.
MIT License
2.76k stars 627 forks source link

Fix WriteCompressedInt32 logic by using the same code as in System.Reflection.Metadata #958

Closed simonferquel closed 3 months ago

simonferquel commented 3 months ago

Note: the implementation in SRM uses methods that are not available in netfx 4.0. To make the code work with all platforms supported by Mono.Cecil, I extracted the required methods.

While working on a Unity codebase, we found out a case where Mono.Cecil would generate invalid sequence points. After digging, it seems the root issue is in the implementation of WriteCompressedInt32. The provided test fails with the original implementation, while it succeeds with the SRM implementation in this PR.