How to read the content of an EXE file.

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.