EXE file structure and read method

Source: Internet
Author: User

First, EXE file concept

EXE file English full name executable file. Translated executable file, portable (PE) file format file, it can be loaded into memory. and is run by operating system loader, it is a running program which can be located in the operating system storage space. such as Notepad program notepad.exe, can be used to edit the document, such as: Test. txt Double-click Open Notepad.exe Notepad program for editing processing.

Second, EXE file structure

EXE file is divided into two parts: exe file header and program ontology. EXE files are more complex and belong to a multi-segment structure. is one of the most successful and complicated designs of DOS. Each EXE file includes a file header and an image of a relocatable program. The file header includes MS-DOS information for loading the program, such as the size of the program and the initial value of the register. The header also points to a relocation table that includes a list of pointers to relocatable segment addresses in the program image.

MS-DOS then adjusts the relocatable segment address described in the location table by copying the image directly from the file to the memory loading EXE program. A positional table is an array of reposition pointers.  Each one points to the relocatable segment address in the program image. To predict the specific principle and structure, please click on the EXE file structure and principle

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqveglhb2zlbmdjyw55dwv4ag==/font/5a6l5l2t/fontsize/400/fill/ I0jbqkfcma==/dissolve/70/gravity/southeast ">

The above table is the exe file header

Three, exe file open method

Because EXE file is more special, open way is also a bit special. To specify the format, see the following code:

#include <iostream> #include <string> #include <fstream> #include <ios>using namespace std; const int buffer_size=1024;void update (ifstream& in) {if (!in) {return;} Std::streamsize Length;char Buffer[buffer_size];while (!in.eof ()) {in.read (buffer, buffer_size); length = In.gcount (); if (length > 0) {printf ("%s", buffer);}} In.close ();} int main () {Update (Ifstream ("1.exe", Ios_base::binary)); return 0;}

among them. Ios_base is a class in the C + + standard library, defined in the <ios> header file.

The Ios_base class encapsulates basic information about the types of data in stream input and output in the C + + standard that are not dependent on read and write, such as formatting information, exception states, event callback functions, and so on.

About PE head, can refer to PE file description.



EXE file structure and read method

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.