Solved

Editing hex codes in exe files.

Posted on 1998-10-25
9
263 Views
Last Modified: 2010-04-06
How do i do if i want to edit a hexcode in a file?
I know the offset - just need to change 4 bytes...
0
Comment
Question by:t0m3k
  • 5
  • 2
  • 2
9 Comments
 

Expert Comment

by:elkiors
ID: 1344224
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
 

Author Comment

by:t0m3k
ID: 1344225
it would be great if u could give me a tiny example.

/t0m3k
0
 

Expert Comment

by:elkiors
ID: 1344226
Okay bear with me a while and I'll see what I can come up with

Darren

0
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

Accepted Solution

by:
elkiors earned 50 total points
ID: 1344227
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
 

Author Comment

by:t0m3k
ID: 1344228
I've noticed that the offset must be in decimal format - not hexadecimal.
How do I convert, for example 0005:EA89 to decimal?
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1344229
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
 

Expert Comment

by:elkiors
ID: 1344230
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
 
LVL 10

Expert Comment

by:viktornet
ID: 1344231
The hex value would be Distance := $EAD9; not Distance := $5EA89;

Cheers,
Viktor
0
 

Expert Comment

by:elkiors
ID: 1344232
Oh yes, sorry

Any luck with evaluating the answer yet?
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Tembedded WB animatid gifs not animated on some pcs 2 84
Base1 Encode/Decode 3 82
Multi-layered image in FireMonkey 9 49
How to Get Images From Server using App Tethering 11 39
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question