How to read the content of an EXE file. Delphi/Windows SDK/API
Http://www.delphi2007.net/DelphiAPI/html/delphi_20061123125818182.html
When I append some data to the end of the EXE file and want to read the data during the EXE operation, Delphi cannot open itself. How can I remember it?
Will youProgramThe same is true if you call other programs.
ShellExecute
Use shellapi
Http://www.delphibox.com/article.asp? ArticleID = 422
Take a look at the windows PE file format.
You can modify \
Eventually, all files are mapped to hard disks.
Learned
Use a file stream
It is easy to read. The master Delphi7 has a demo.
Procedure tform1.formcreate (Sender: tobject );
VaR
Nsize: integer;
Hfile: thandle;
Strsize: string;
Begin
Hfile: = createfile (pchar (paramstr (0 )),
0, file_cmd_read, nil, open_existing, 0, 0 );
Nsize: = getfilesize (hfile, nil );
Closehandle (hfile );
Setlength (strsize, 20 );
STR (nsize, strsize );
Caption: = 'size = '+ strsize;
End;
Open createfile and then read it. But writing it into the EXE file requires some tips.
Top ~~~ Vividw (vividw )~~~
Deliberately pass by without comments or comments. :)
Ranye
Procedure tform1.button1click (Sender: tobject );
VaR
FS: tfilestream;
Strbuf: array [0 .. 501] of char;
Begin
FS: = tfilestream. Create (application. exename, fmopenread); // create a file stream object
Try
FS. Position: = 1000; // point the object pointer to the position of 1000.
FS. readbuffer (strbuf, 500); // read this section of content with a length of 500
Showmessage (strbuf );
Finally
FS. Free;
End;
End;
This is the main idea. You can rebuild it on your own.
Share
I wrote this one just a few days ago .. but I am not like this .. it's too easy to write data .. reading is copying itself to the temp directory .. text read again .. pointing to the end .. read 100 reverse and then centercat (string, 'start: ',': end ')..
You can use tfilestream to open it. Mode: fmopenread + fmsharedenynone