mezzo Cheater
Reputation: 1
Joined: 08 Sep 2010 Posts: 28
|
Posted: Sun Jan 01, 2012 8:01 pm Post subject: |
|
|
For some weird reason I kept getting bogus return values from GetProcAddress under freepascal. But I figured it out through some code I found online.
This is what I made of it:
| Code: |
function writepatch:boolean;stdcall;
begin
AddressFunc := Cardinal(@hunger);
JMP[0] := $E8; JMP[1] := 0; JMP[2] := 0; JMP[3] := 0; JMP[4] := 0;JMP[5] := $90;
searchforstuff; // find patch location, put address in cAddress global
Calculation := ((AddressFunc-cAddress)-5);
Move(Calculation, JMP[1], 4);
//writeln('Patch should be written to: ' +IntToHex(cAddress,8));
//writeln('I would jump to: ' +IntToHex(AddressFunc,8));
//writeln('patch: '+inttohex(JMP[0],2)+inttohex(JMP[1],2)+inttohex(JMP[2],2)+inttohex(JMP[3],2)+inttohex(JMP[4],2)+inttohex(JMP[5],2));
//writeln('Unprotecting...');
if not VirtualProtect(Pointer(cAddress), 6, PAGE_EXECUTE_READWRITE, @oldprotect) then
RaiseLastWin32Error;
//writeln('Virtualprotect done, starting to patch...');
WriteByte(cAddress, JMP[0]);
WriteByte(cAddress+1, JMP[1]);
WriteByte(cAddress+2, JMP[2]);
WriteByte(cAddress+3, JMP[3]);
WriteByte(cAddress+4, JMP[4]);
WriteByte(cAddress+5, JMP[5]);
writeln('Reprotecting: ');
if not VirtualProtect(Pointer(cAddress), 6, oldprotect^, nil) then
RaiseLastWin32Error;
Result := true;
end;
|
Probably not the most elegant way but it seems to be working for what I need..
|
|