[Snippet] Write bytes to memory
Made this little function because WriteProcessMemory was getting detected in a game hack I was making
// Write Bytes to Address Method
Function WriteIt(pAddress: Pointer; Bytes: Array of Byte): Boolean;
var
OldProtect, DummyProtect: DWord;
begin
if VirtualProtect(pAddress, SizeOf(Bytes), PAGE_EXECUTE_READWRITE, @OldProtect) then
begin
Move(Bytes, pAddress^, Length(Bytes));
VirtualProtect(pAddress, SizeOf(Bytes), OldProtect, @DummyProtect);
Result := True
end
else
Result := False;
end;
Great for when you Dll is injected into a process, you can use it like this... Example]Const
//NoReLoad
AddressReload = $374B1826;
PatchReload : Array[0..7] of byte = ($90,$90,$90,$90,$90,$90,$90,$90);
OriginalReload : Array[0..7] of byte = ($81,$44,$24,$04,$1C,$00,$00,$00);
.......
//Apply new bytes
WriteIt(ptr(AddressReload),PatchReload);
//Restore Old bytes
//WriteIt(ptr(AddressReload),OriginalReload);[/delphi]
by Departure
Write exact value to address
Hello there i'v been researching game hacking in delphi for a while now, I'v gotten to the point were i can inject and change a value yet when using the function above i try set example $821 it comes with a different value? how to resolve this issue & i change the bytes to a UInt64 value.