private IntPtr CreateAsmFunction(string[] function) { var result = _assembler.Assemble(function); var address = _memory.Allocate(result.Length); _memory.WriteRaw(address, result); return(address); }
/* Building functions to hook. */ private void BuildAdd() { string[] addFunction = new string[] { $"{_use32}", $"push {_ebp}", $"mov {_ebp}, {_esp}", $"mov {_eax}, {_edx}", // Right Parameter $"add {_eax}, {_ecx}", // Left Parameter $"pop {_ebp}", $"ret" }; var result = _assembler.Assemble(addFunction); Add = _memory.Allocate(result.Length); _memory.WriteRaw(Add, result); }
private void BuildAdd() { string[] addFunction = new string[] { $"use64", $"lea eax, [rcx+rdx]", $"ret", }; var result = _assembler.Assemble(addFunction); Add = _memory.Allocate(result.Length); _memory.WriteRaw(Add, result); }
private void BuildAdd() { string[] addFunction = new string[] { $"use32", $"mov eax, [esp+8]", // Right Parameter $"add eax, [esp+4]", // Left Parameter $"ret 8", }; var result = _assembler.Assemble(addFunction); Add = _memory.Allocate(result.Length); _memory.WriteRaw(Add, result); }
private void BuildNativeFunction() { int wordSize = IntPtr.Size; string[] addFunction = new string[] { $"{_use32}", $"push {_ebp}", $"mov {_ebp}, {_esp}", $"mov {_eax}, [{_ebp} + {wordSize * 2}]", // Left Parameter $"mov {_ecx}, [{_ebp} + {wordSize * 3}]", // Right Parameter $"add {_eax}, {_ecx}", $"pop {_ebp}", $"ret" }; var result = _assembler.Assemble(addFunction); var func = _memory.Allocate(result.Length); _memory.WriteRaw(func, result); _nativeFunctions.Add(func); }