【发布时间】:2020-10-20 19:29:31
【问题描述】:
int main() {
HANDLE source = CreateFile(L"D:\\msgbox.exe", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
LARGE_INTEGER size;
GetFileSizeEx(source, &size);
char* buff = new char[size.QuadPart];
DWORD dwBytesRead;
ReadFile(source, buff, sizeof(buff), &dwBytesRead, NULL);
void* buffer = (void*)buff;
IMAGE_DOS_HEADER* DOSHeader = PIMAGE_DOS_HEADER(buffer);
PIMAGE_NT_HEADERS nt = PIMAGE_NT_HEADERS((char*)(buffer)+DOSHeader->e_lfanew);
//using other method it is correct (0x40000), using winapi will fail.
cout << hex << nt->OptionalHeader.ImageBase << endl;
return 0;
}
当我使用其他技术读取文件时,例如 fstream。或使用 c stdio。它通过输出二进制文件的 ImageBase 完美地工作,但是它不能使用 winapi 的 ReadFile() 工作。文件大小已经正确。
【问题讨论】: