I am trying to inject a jump instruction into another process (External injection), although the injection operation has been completed the address was not correct.
For example:
Code:
unsigned int addr = 0x0048DA03;
unsigned int jumpToAddr = 0x0048D9B2;
unsigned char command[] = { 0xEA };
VirtualProtectEx(hProcess, (void*)addr, 20, PAGE_READWRITE, &oldProtect);
WriteProcessMemory(hProcess, (void*)addr, (void*)command, sizeof(command), NULL); // this line for jmp
WriteProcessMemory(hProcess, (void*)addr, (void*)jumpToAddr, sizeof(jumpToAddr), NULL); // this line for the address
VirtualProtectEx(hProcess, (void*)addr, 20, oldProtect, &oldProtect);
The result:
As you see, after executing that code, the jump address is wrong.
Also, the same problem occurs with the following code:
Code:
void* reservedMemAddress = VirtualAllocEx(hProcess, NULL, 100, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
if (reservedMemAddress) {
WriteProcessMemory(hProcess, (void*)addr, (void*)command, sizeof(command), NULL);
WriteProcessMemory(hProcess, (void*)addr, (void*)reservedMemAddress, sizeof(reservedMemAddress), NULL);
}
- How can I write the address correctly?
- How can I merge the two WriteProcessMemory lines into one to write the entire instruction ex: JMP 0x0048D9B2?
-