Guest User

Untitled

a guest
Jun 25th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. int InjectHelperMethod(String^ path)
  2. {
  3. AssemblyDefinition^ asmDef = AssemblyDefinition::ReadAssembly(path);
  4.  
  5. MethodDefinition^ mDef = gcnew MethodDefinition("_Main", (MethodAttributes::ReuseSlot | MethodAttributes::Static), asmDef->MainModule->Import(int::typeid));
  6. mDef->Parameters->Add(gcnew ParameterDefinition("arg", ParameterAttributes::None, asmDef->MainModule->Import(String::typeid)));
  7.  
  8. ILProcessor^ ilProc = mDef->Body->GetILProcessor();
  9.  
  10. ilProc->Append(ilProc->Create(OpCodes::Call, (MethodReference^)asmDef->EntryPoint));
  11. ilProc->Append(ilProc->Create(OpCodes::Ldc_I4, 1));
  12. ilProc->Append(ilProc->Create(OpCodes::Ret));
  13.  
  14. asmDef->EntryPoint->DeclaringType->Methods->Add(mDef);
  15.  
  16. path = path->Replace(".exe", "_.exe");
  17.  
  18. asmDef->Write(path);
  19.  
  20. return 1;
  21. }
Add Comment
Please, Sign In to add comment