Repository navigation
fix: obfuscated assemblies crash on .NET 9+ with resources/constants/compressor (#101) - #104
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #101
Problem
Obfuscating an assembly with the
resourcesprotection produced a binary that crashed at startup on .NET 9 and later:The runtime no longer accepts types nested directly under the module type
<Module>(see dotnet/runtime#111164). ConfuserEx relied on that previously-tolerated layout for its injected helper types, so any assembly using the affected protections became unloadable on modern .NET.Root cause
Two separate sources of
<Module>-nested types:resources,constants, andcompressorprotections each add a FieldRVA-backedValueTypeas a nested type of the global type.InjectHelper.Inject(runtimeType, GlobalType, module)copies a runtime helper's members into<Module>. When that helper itself contains nested types (the LZMA decompressorConfuser.Runtime.Lzmahas six), those nested types are recreated nested under<Module>. This path is shared by resources, constants, and the packer, and is the reason a data-type-only fix is insufficient.Fix
InjectHelper: when injecting into the global type, promote directly-nested helper types to top-level module types (with adjusted visibility). This centrally covers every protection that injects runtime helpers.resources/constants/compressor: create the dataValueTypeas a top-level type (NotPublic) instead of nested under<Module>.RickRoller(renamer easter-egg): same defect, same fix — its trap type is now top-level.Confuser.Runtime.Resource: also hookResourceResolveand match manifest resource names, soGetManifestResourceStreamworks after obfuscation. This mirrors the already-presentResource_Packerruntime.All changes keep the output compatible with every target framework (net2.0 through net10).
Test
Adds
Console_Net10_ResourceProtection, the first cross-framework test that obfuscates and runs a modern-.NET app: it embeds a manifest resource, appliesresources, executes the obfuscatednet10.0assembly, and asserts it exits42with the resource read back correctly. Without the fix this test reproduces the exactBadImageFormatExceptionfrom the report.TestBasegains support for passing non-assembly external files (e.g.runtimeconfig.json) through to the output without treating them as modules.Verification
Credit
Root cause originally reported by @jeremy-visionaid, who also provided an initial draft and regression-test scaffold.