LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-13-2012, 01:22 PM   #1
lee_can
Member
 
Registered: Mar 2011
Posts: 118

Rep: Reputation: 1
Changing the byte in an Executable file in Delphi


Hi,

I am working on a program who will find an address in a executable file, then read the byte and replace it.

For example,
File name is Test.exe (size 10.6 kb), I want to change the byte FA located at 5000 to 05.

I search on the net about SetFilePointer, and i try to do this:
Code:
var
  h,      : HFILE;
  buf     : array[0..4095] of Byte;
  Read, p : DWORD;
  m, nac  : DWORD;

begin

  m := 1;
  nac := 5000;
  h := CreateFileA('C:\TEST\test.exe', GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, NIL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  
if h <> INVALID_HANDLE_VALUE then
  begin
    p := SetFilePointer(h, nac, @m, FILE_BEGIN);
    if p <> 0 then
      ReadFile(h, Buf, SizeOf(Buf), Read, NIL);
  end;

 edit1.Text := InTtoStr(m);
 edit2.Text := InTtoStr(nac);
 edit3.Text := InTtoStr(p);
Can anyone advice please how can I rearrange the above code?

Regards
 
Old 11-13-2012, 04:03 PM   #2
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
This is a Linux forum...

Furthermore: you should assume that an executable file cannot be altered by whoever-you-are, and further that if you did, the operating system would no longer consent to run it (since it was digitally signed).

Last edited by sundialsvcs; 11-13-2012 at 04:04 PM.
 
Old 11-13-2012, 04:36 PM   #3
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
It's been to long since I (briefly) used Delphi, so I can't help you with your code problem.

I should note that almost all ELF object files (i.e., compiled executable files) on Linux systems contain a section, .gnu.hash, that must match the hash code of the object file before it will be executed, so simply changing a byte in an executable will, almost always, kill the file. (Among other things, this prevents a bad drive from making your file do catastrophic things to your system.)

So, even if you get your code to work, the result may not work.

Oh, if this is not just a Delphi programming exercise, you can install the hexedit package and make you change "by hand."

Last edited by PTrenholme; 11-13-2012 at 04:37 PM.
 
1 members found this post helpful.
Old 11-13-2012, 08:56 PM   #4
lee_can
Member
 
Registered: Mar 2011
Posts: 118

Original Poster
Rep: Reputation: 1
Sorry Guys
I must put this thread in a Delphi Forum.

Regards
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] memcpy fails to copy data, but byte by byte assignment work venu_s Programming 7 07-08-2011 03:29 AM
problem in changing the name of executable file a.out way2bhanu Linux - Newbie 5 01-19-2011 02:14 AM
Changing executable file extension acwbrat Programming 25 10-19-2007 10:19 PM
Changing the default open action for an executable file nitrambass LinuxQuestions.org Member Intro 1 06-22-2004 03:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration