Skip to content

Instantly share code, notes, and snippets.

@Zetrith
Last active February 23, 2019 17:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zetrith/d86b1d84e993c8117983c09f1a5dcdcd to your computer and use it in GitHub Desktop.
Save Zetrith/d86b1d84e993c8117983c09f1a5dcdcd to your computer and use it in GitHub Desktop.
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