小编Dsd*_*dsd的帖子

如何使用 c++ 和 Window.h 解析 EXE 文件并从 IMAGE_DOS_HEADER 结构中获取数据?

我正在尝试解析 Windows 中的 PE 文件并从此结构中获取数据

IMAGE_DOS_HEADER

我写了这段代码,它从 exe 文件中读取字节。

 #include <Windows.h>
    
    int main()
    {
        // open the file for binary reading
        std::ifstream file;
            file.open("D:/SomeProgram.exe", ios_base::binary);
    
        if (!file.is_open())
            return 1;
    
        // get the length of the file
        file.seekg(0, ios::end);
        size_t fileSize = file.tellg();
        file.seekg(0, ios::beg);
    
        // create a vector to hold all the bytes in the file
        std::vector<byte> data(fileSize, 0);
    
        // read the file
        file.read(reinterpret_cast<char*>(&data[0]), fileSize);
Run Code Online (Sandbox Code Playgroud)

我不知道如何获取数据,其中包含e_magic, e_cbip, e_cp.... 和最重要的e_ifanew. 我知道,这个结构 IMAGE_DOS_HEADER 存储在 Windows.h 中,但我不知道如何使用它从任何 exe …

c++ parsing portable-executable

5
推荐指数
1
解决办法
4102
查看次数

标签 统计

c++ ×1

parsing ×1

portable-executable ×1