?
Solved

Editing hex codes in exe files.

Posted on 1998-10-25
9
Medium Priority
?
274 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
Independent Software Vendors: 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 100 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

840 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