Jump to content
Tuts 4 You

Making Generic Patcher with Delphi


Eleos

Recommended Posts

  • 2 weeks later...
  • 2 weeks later...
  • 4 weeks later...

I will provide you an example as soon as i can (too late right now):

1) CreateFile();

- If you wanna write a saved buffer (e.g: cracked .exe) use CREATE_ALWAYS flag to empty the file to ZERO-BYTE length.

- If you want to go to offsets and patch some bytes or words, etc... then OPEN_EXISTSING

1.5) SetFilePointer(); (To go to a specific offset if needed)

2) WriteFile(); on the handle CreateFile returned. (very similiar to WPM)

3) CloseHandle(); on the handle CreateFile returned.

Link to comment
I can'nt wait to see your example Rot1 :)

No problem, here you go:

NOTE: All the ... stuff you see must be filled manually according to your needs, check out MSDN for details.

const
buffer: Array[0..1] of byte = ($90, $90);
var
hFile: THandle; //or Cardinal
beign
hFile := (... , GENERIC_WRITE , ... , OPEN_EXISTING, ... );
SetFilePointer( hFile, $XXXXX, ... , FILE_BEGIN ); //Sets position offset @ address ($offset in hex)
WriteFile( hFile, buffer, sizeof(buffer), ... );
CloseHandle( hFile );
end;

study this code carefully.

Link to comment

ah okay i thought this was to be a search and replace example, I will defently look into SetFilePointer API but from what you have wrote you need to know the offset address to patch? or am i missing something here? anyway I will check out the SetFilePointer API, it seems to just point an offset address therefore it seems at first glance nothing to do with Search and replace byte patterns.

//Edit

Okay i had a quick look on msdn site at SetFilePointer, I see what you mean now

Quote Msdn:"You can also use the SetFilePointer function to query the current file pointer position. To do this, specify a move method of FILE_CURRENT and a distance of zero (0)."

Im guessing this means we can loop through the file checking the byte at current position. I still need to look into to this but thanks for the tip.

Edited by Departure
Link to comment
ah okay i thought this was to be a search and replace example, I will defently look into SetFilePointer API but from what you have wrote you need to know the offset address to patch? or am i missing something here? anyway I will check out the SetFilePointer API, it seems to just point an offset address therefore it seems at first glance nothing to do with Search and replace byte patterns.

//Edit

Okay i had a quick look on msdn site at SetFilePointer, I see what you mean now

Quote Msdn:"You can also use the SetFilePointer function to query the current file pointer position. To do this, specify a move method of FILE_CURRENT and a distance of zero (0)."

Im guessing this means we can loop through the file checking the byte at current position. I still need to look into to this but thanks for the tip.

What SetFilePointer does is setting a different position in a file (offset), for example you open the binary file with a HEX Editor and you see the dumped result, the current offset (FILE_BEGIN) will be 0x00 (0), move 1 byte will be 0x01 (1), get me ?

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...