Question

How do i resolve the RVA of the method i have injected without reloading the entire module?
I am always getting 0 as the RVA of the added method. Is there anyway to retrieve the RVA without writing and reloading the assembly? Thanks!

AssemblyDefinition asm = AssemblyDefinition.ReadAssembly("hello.exe"); 
ModuleDefinition mod = asm.MainModule;
TypeDefinition modType= mod.GetType("PrintClass"); //get class found in hello.exe
MethodDefinition MethodToInject= new MethodDefinition("PrintMethod", ..., ...); //filled
modType.Methods.Add(MethodToInject);

int InjectedRVA = MethodToInject.RVA; //Always get 0
InjectedRVA = modType.Methods.FirstOrDefault(mtd => mtd.Name == "PrintMethod").RVA; //Also get 0

asm.MainModule.Write("output.exe"); //write output
Was it helpful?

Solution

The newly method RVA is computed at write time, but the model is not updated. I guess we can consider this is a bug.

For now you'll have to analyze the generated assembly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top