Editing hex codes in exe files.

How do i do if i want to edit a hexcode in a file?
I know the offset - just need to change 4 bytes...
t0m3kAsked:
Who is Participating?
 
elkiorsConnect With a Mentor Commented:
try this: there's no error checking or anything but it illustrates the idea.

procedure TForm1.Button1Click(Sender: TObject);
type
  hfile=RECORD
    hexitem:BYTE;
  END;

var
  hexfile:FILE OF hfile;
  hdata:hfile;
  distance:INTEGER;
  I:INTEGER;

begin
  distance:=152; {or whatever your offset is}
  ASSIGNFILE(hexfile,'C:\Test.Txt'); {or any other file}
  RESET(hexfile);
  SEEK(hexfile,distance);
  for I:=$2A TO $32 do {I've only done this to create data to populate hexitem}
  begin
    hdata.hexitem:=I;
    WRITE(hexfile,hdata);
  end;
  CLOSEFILE(hexfile);
end;

Hope this helps.

If you need anymore help let me know.

Beware changeing the bytes in an EXE file will probably kill it but I suppose you have your reasons.

0
 
elkiorsCommented:
Open the file using type byte, then use SEEK to position the record pointer to your offset, then WRITE to the file whatever you want, then CLOSE the file ... and that's it in a nutshell. If you want me to produce full code snippet for you, let me know.

Darren
0
 
t0m3kAuthor Commented:
it would be great if u could give me a tiny example.

/t0m3k
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
elkiorsCommented:
Okay bear with me a while and I'll see what I can come up with

Darren

0
 
t0m3kAuthor Commented:
I've noticed that the offset must be in decimal format - not hexadecimal.
How do I convert, for example 0005:EA89 to decimal?
0
 
viktornetCommented:
in decimal that would be... 60121.. Hope this helps :-)

Segment:Offset

0005:EA89

Hex = Offset * 10h + Offset

Hex = 0005 * 10h + EA89
Hex = EAD9
HexToDec = 60121

Cheers,
Viktor
0
 
elkiorsCommented:
Why do you need to do any hex to dec conversion ? the standard integer can take decimal as well as hex numbers, just prefix the number with $ to designate it as base16, just as I have done in the example code for example,

Distance:=$5EA89;

would assign the decimal value 60121 to Distance.

Hope this helps

Darren

0
 
viktornetCommented:
The hex value would be Distance := $EAD9; not Distance := $5EA89;

Cheers,
Viktor
0
 
elkiorsCommented:
Oh yes, sorry

Any luck with evaluating the answer yet?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.