public void InjectAndExecute(String[] asm)
{
//write asm
Memory.Asm.Clear();
foreach (string tempLineAsm in asm)
{
Memory.Asm.AddLine(tempLineAsm);
}
//allocate
uint injected_code = Memory.AllocateMemory(Memory.Asm.Assemble().Length, Magic.MemoryAllocType.MEM_COMMIT, Magic.MemoryProtectType.PAGE_EXECUTE_READWRITE);
///inject
Memory.Asm.Inject(injected_code);
//Execute
IntPtr th = Memory.CreateRemoteThread(injected_code, 0);
SThread.WaitForSingleObject(th);
//free memory
Memory.FreeMemory(injected_code);
SThread.TerminateThread(th, 0);
}
public void Lua_Dostring(String command)
{
//allocate for command
uint DoStringArg_Codecave = Memory.AllocateMemory(Encoding.UTF8.GetBytes(command).Length + 1);
//write command
Memory.WriteBytes(DoStringArg_Codecave, Encoding.UTF8.GetBytes(command));
String[] asm = new String[]
{
"mov eax, " + DoStringArg_Codecave,
"push 0",
"push eax",
"push eax",
"mov eax, " + (uint)Offsets.Fonctions.Lua_Dostring, // Lua_DoString
"call eax",
"add esp, 0xC",
"retn",
};
InjectAndExecute(asm);
Memory.FreeMemory(DoStringArg_Codecave);
}