不知何故,以下代码输出“部分数:57344”,这显然是不正确的。谁能给我一个提示我做错了什么?
#include <windows.h>
#include <iostream>
#include <vector>
#include <sstream>
#include <fstream>
#include <iterator>
#include <algorithm>
int main() {
std::string file_path = "C:\\foo.exe";
if(!file_path.size()) {
cout << "No file was selected" << endl;
return 1;
}
std::ifstream input( file_path.c_str(), std::ios::binary );
std::vector<unsigned char> buffer((
std::istream_iterator<unsigned char>(input)),
(std::istream_iterator<unsigned char>()));
if(!buffer.size()) {
cout << "Error reading file" << endl;
return 1;
}
char * BinFile = (char*)&buffer[0];
IMAGE_DOS_HEADER* DOSHeader = (IMAGE_DOS_HEADER*)BinFile;
IMAGE_NT_HEADERS* NTHeader = (IMAGE_NT_HEADERS*)(BinFile + DOSHeader->e_lfanew);
cout << "Number of sections: " << NTHeader->FileHeader.NumberOfSections << endl;
return 0;
}