Solved

Editing hex codes in exe files.

Posted on 1998-10-25
9
264 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

740 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