Last active
February 23, 2019 17:30
-
-
Save Zetrith/d86b1d84e993c8117983c09f1a5dcdcd to your computer and use it in GitHub Desktop.
This file contains 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
private static void RewriteAssembly(string assemblyPath) | |
{ | |
ModuleDef assembly = ModuleDefMD.Load(assemblyPath); | |
foreach (TypeDef type in assembly.Types.SelectMany(t => t.NestedTypes.Concat(t))) | |
{ | |
type.Attributes &= ~TypeAttributes.VisibilityMask; | |
if (type.IsNested) | |
{ | |
type.Attributes |= TypeAttributes.NestedPublic; | |
} | |
else | |
{ | |
type.Attributes |= TypeAttributes.Public; | |
} | |
foreach (MethodDef method in type.Methods) | |
{ | |
method.Attributes &= ~MethodAttributes.MemberAccessMask; | |
method.Attributes |= MethodAttributes.Public; | |
} | |
foreach (FieldDef field in type.Fields) | |
{ | |
field.Attributes &= ~FieldAttributes.FieldAccessMask; | |
field.Attributes |= FieldAttributes.Public; | |
} | |
} | |
assembly.Write($"{Path.ChangeExtension(assemblyPath, null)}_public.dll"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment