Force an external function to be at a specified address on MSVC

70 views Asked by At

My plan is to patch an xbox 360 game, at first by simply overwriting the function's bytes. With ghidra I decompiled a simple function that I can recompile to the exact same assembly (using cl.exe /c /Fa <file>.c).

My code is looking like this:

void Function_820C5110();

void func_8025AABC()
{
    // some code
    Function_820C5110();
}

The assembly looks the same, but the machine code in the .obj file doesn't. The original call to the function is 4B FF F6 75 but I get 4B FF FF D5, is there a way to tell the compiler the address of the function (and probably the address of func_8025AABC too) so the jump can have the correct relative offset?

Everything I find talks about the linker which obviously I never call. I did try to see if there was a way to "link" an obj file without generating an executable (just update the jumps) but that doesn't seem possible.

I can't either call the address directly since ((void(*)())0x820C5110)() doesn't generate a bl instruction but lis, ori, mtctr, bctrl.

Is there a simpler solution than generate an executable (with a stub Function_820C5110) then extract my function's machine code?

thanks

0

There are 0 answers