Skip to content

Instantly share code, notes, and snippets.

@guillaC
Created February 29, 2024 19:32
Show Gist options
  • Save guillaC/faaf5d7172229301552b4aad94f5f542 to your computer and use it in GitHub Desktop.
Save guillaC/faaf5d7172229301552b4aad94f5f542 to your computer and use it in GitHub Desktop.
static string SelfDecompile()
{
string result = string.Empty;
string assemblyFilePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
AssemblyDefinition assembly = AssemblyDefinition.ReadAssembly(assemblyFilePath);
// Trouver la classe Program
TypeDefinition programType = null;
foreach (TypeDefinition type in assembly.MainModule.Types)
{
if (type.Name == "Program")
{
programType = type;
break;
}
}
if (programType != null)
{
foreach (MethodDefinition method in programType.Methods)
{
result = $"{result}Method: {method.Name}{Environment.NewLine}";
foreach (Instruction instruction in method.Body.Instructions)
{
result = $"{result}{instruction.OpCode} {instruction.Operand}{Environment.NewLine}";
}
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment