Commit 602ff38c authored by Vijay Kiran Kamuju's avatar Vijay Kiran Kamuju Committed by Alexandre Julliard

imagehlp/tests: Add initial tests for CheckSumMappedFile.

Based on a patch by Michael Müller. Signed-off-by: 's avatarVijay Kiran Kamuju <infyquest@gmail.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 8236c7a8
......@@ -89,40 +89,19 @@ PIMAGE_NT_HEADERS WINAPI CheckSumMappedFile(
LPVOID BaseAddress, DWORD FileLength,
LPDWORD HeaderSum, LPDWORD CheckSum)
{
IMAGE_DOS_HEADER *dos = (IMAGE_DOS_HEADER *) BaseAddress;
PIMAGE_NT_HEADERS32 Header32;
PIMAGE_NT_HEADERS64 Header64;
DWORD *ChecksumFile;
PIMAGE_NT_HEADERS header;
DWORD CalcSum;
DWORD HdrSum;
TRACE("(%p, %d, %p, %p)\n",
BaseAddress, FileLength, HeaderSum, CheckSum
);
CalcSum = (DWORD)CalcCheckSum(0,
BaseAddress,
(FileLength + 1) / sizeof(WORD));
TRACE("(%p, %d, %p, %p)\n", BaseAddress, FileLength, HeaderSum, CheckSum);
if (dos->e_magic != IMAGE_DOS_SIGNATURE)
return NULL;
CalcSum = CalcCheckSum(0, BaseAddress, (FileLength + 1) / sizeof(WORD));
header = RtlImageNtHeader(BaseAddress);
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
if (!header)
return NULL;
HdrSum = *ChecksumFile;
*HeaderSum = HdrSum = header->OptionalHeader.CheckSum;
/* Subtract image checksum from calculated checksum. */
/* fix low word of checksum */
......@@ -149,9 +128,8 @@ PIMAGE_NT_HEADERS WINAPI CheckSumMappedFile(
CalcSum += FileLength;
*CheckSum = CalcSum;
*HeaderSum = *ChecksumFile;
return (PIMAGE_NT_HEADERS) Header32;
return header;
}
/***********************************************************************
......
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