Commit ba5a86e3 authored by Owen Rudge's avatar Owen Rudge Committed by Alexandre Julliard

imagehlp: Check for 64-bit PE files in CheckSumMappedFile.

parent b2770127
......@@ -89,11 +89,14 @@ PIMAGE_NT_HEADERS WINAPI CheckSumMappedFile(
LPVOID BaseAddress, DWORD FileLength,
LPDWORD HeaderSum, LPDWORD CheckSum)
{
PIMAGE_NT_HEADERS Header;
IMAGE_DOS_HEADER *dos = (IMAGE_DOS_HEADER *) BaseAddress;
PIMAGE_NT_HEADERS32 Header32;
PIMAGE_NT_HEADERS64 Header64;
DWORD *ChecksumFile;
DWORD CalcSum;
DWORD HdrSum;
FIXME("(%p, %d, %p, %p): stub\n",
TRACE("(%p, %d, %p, %p)\n",
BaseAddress, FileLength, HeaderSum, CheckSum
);
......@@ -101,8 +104,25 @@ PIMAGE_NT_HEADERS WINAPI CheckSumMappedFile(
BaseAddress,
(FileLength + 1) / sizeof(WORD));
Header = RtlImageNtHeader(BaseAddress);
HdrSum = Header->OptionalHeader.CheckSum;
if (dos->e_magic != IMAGE_DOS_SIGNATURE)
return NULL;
Header32 = (IMAGE_NT_HEADERS32 *)((char *)dos + dos->e_lfanew);
if (Header32->Signature != IMAGE_NT_SIGNATURE)
return NULL;
if (Header32->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC)
ChecksumFile = &Header32->OptionalHeader.CheckSum;
else if (Header32->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
{
Header64 = (IMAGE_NT_HEADERS64 *)Header32;
ChecksumFile = &Header64->OptionalHeader.CheckSum;
}
else
return NULL;
HdrSum = *ChecksumFile;
/* Subtract image checksum from calculated checksum. */
/* fix low word of checksum */
......@@ -129,9 +149,9 @@ PIMAGE_NT_HEADERS WINAPI CheckSumMappedFile(
CalcSum += FileLength;
*CheckSum = CalcSum;
*HeaderSum = Header->OptionalHeader.CheckSum;
*HeaderSum = *ChecksumFile;
return Header;
return (PIMAGE_NT_HEADERS) Header32;
}
/***********************************************************************
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment