EXE file structure and reading Method

Source: Internet
Author: User

1. EXE file Concept

EXE file: executable file, which is an executable file. It can be transplanted into the memory and executed by the operating system, it is an executable program that can be floating in the operating system storage space. For example, the notepad.exe program can be used to edit documents. For example, test. txt double-hitting the notepad.exe Notepad program for editing.

Ii. EXE file structure

The EXE file is divided into two parts: the EXE file header and the program body. The EXE file is complex and belongs to a multi-segment structure. It is one of the most successful and complex dos designs. Each EXE file contains a file header and an image of the relocated program. The file header contains information for the MS-DOS to load the program, such as the program size and initial register values. The file header also points to a relocation table, which contains a linked list of pointers pointing to the relocated segment addresses in the program image. The MS-DOS loads the EXE program by copying the image directly from the file to the memory, and then adjusts the relocated segment address described in the positioning table. The positioning table is a relocation pointer array, each pointing to the relocated segment address in the program image. For details about the principle and structure, click the structure and principle of the EXE file.

The preceding figure shows the EXE file header.

Iii. Open EXE files

Because the EXE file is special, the open method is also a bit special, you need 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;}

Ios_base is a class in the C ++ standard library and is defined in the header file <IOS>. The ios_base class encapsulates basic information about data types that do not depend on read/write in the Stream Input and Output in the C ++ standard, such as formatting information, exception status, and Event Callback functions.



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.