In Cheatengine I can use a code injection template to change a function in a running process, how can I do that in ahk?
[Mod edit: Removed img tags from around inline attached image tags. The img tags are only for URLs to an online image.]
Code Injection
Re: Code Injection
Replacing a function might be possible - it involves detour and trampoline functions - @malcev includes that in this example at
MinHook - API Hooking Library.
Related, see WriteProcessMemory Not working, AhkHook: API hooking with AutoHotkey and Memory Process reading/Writing & Pattern Scans (Array of bytes).
MinHook - API Hooking Library.
Related, see WriteProcessMemory Not working, AhkHook: API hooking with AutoHotkey and Memory Process reading/Writing & Pattern Scans (Array of bytes).
![Arrow :arrow:](./images/smilies/icon_arrow.gif)
Re: Code Injection
I found out how to do it!
but I dont know how to convert ASM to hex as I mentioned in my newest post
Code: Select all
replace_instruction(hProcess, address, new_opcode) {
new_opcode := StrSplit(new_opcode, " ")
for index, hex_value in new_opcode
new_opcode[index] := "0x" . hex_value
VarSetCapacity(opcode, new_opcode.MaxIndex(), 0)
Loop % new_opcode.MaxIndex()
NumPut(new_opcode[A_Index], opcode, A_Index - 1, "UChar")
if !DllCall("WriteProcessMemory", "Ptr", hProcess, "Ptr", address, "Ptr", &opcode, "UInt", new_opcode.MaxIndex(), "Ptr", 0) {
MsgBox, Failed to replace instruction.
return
}
return
}
Re: Code Injection
The ASM code has to be assembled to machine code, would the Auto Assembler help there? Check types for 64 bit if compiling for that. It all then has to go into a custom DLL, see here, and here for the mcode bit.
![Arrow :arrow:](./images/smilies/icon_arrow.gif)