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;
}
When I read file using other technique, e.g fstream. or using c stdio. it works perfectly by outputting the ImageBase of the binary, however it won't work using winapi's ReadFile(). The file size is already correct.
 
     
     
    