ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.