What can we really do with RAIL?
n//Create the RAssemblyDef representation of the Teste3.exe assembly
nRAssemblyDef rAssembly = RAssemblyDef.LoadAssembly("Teste3.exe");
n//Get the RTypeDef object for the type where the method is declared
nRTypeDef rtd = (RTypeDef)rAssembly.RModuleDef.GetType("FooBar");
n//Get the RTypeDef of the object to create with the create new instruction
nRTypeDef rtd2 = (RTypeDef)rAssembly.RModuleDef.GetType("ReferencedClass");
n//Get the constructor method where to apply the changes
nRConstructorDef rcd = (RConstructorDef)rtd.GetConstructor(new RType[0]);
n//Get to raplacement method
nRMethod rmGet = rtd.GetMethod("GetVal",rtd2,new RParameter[0]);
n//Create a code transformer object
nCodeTransformer cc = new CodeTransformer();
n//Set the transformation to make in the code
ncc.ReplaceNew(rtd2,rmGet);
n//Aplly the changes
nrcd.Accept(cc);
n//Save the new assembly
nrAssembly. RunAndSaveAssembly("Teste3.exe");
Replace create new instructions with a static method
Create, Run and Save assemblies