[5/6] imagehlp: Recalculate PE checksum after file modification
Alexandre Julliard
julliard at winehq.org
Thu Dec 3 04:44:08 CST 2009
Owen Rudge <orudge at codeweavers.com> writes:
> +static BOOL IMAGEHLP_RecalculateChecksum(HANDLE handle)
> +{
> + IMAGE_DOS_HEADER dos_hdr;
> + IMAGE_NT_HEADERS nt_hdr;
> + HANDLE hMapping;
> + LPVOID BaseAddress;
> + DWORD FileLength, count, HeaderSum, CheckSum = 0;
> + BOOL r;
> +
> + TRACE("handle %p\n", handle);
> +
> + /* read the DOS header */
> + count = SetFilePointer(handle, 0, NULL, FILE_BEGIN);
> +
> + if (count == INVALID_SET_FILE_POINTER)
> + return FALSE;
> +
> + count = 0;
> +
> + r = ReadFile(handle, &dos_hdr, sizeof dos_hdr, &count, NULL);
> +
> + if (!r)
> + return FALSE;
> +
> + if (count != sizeof dos_hdr)
> + return FALSE;
> +
> + /* verify magic number of 'MZ' */
> + if (dos_hdr.e_magic != 0x5A4D)
> + return FALSE;
> +
> + /* read the PE header */
> + count = SetFilePointer(handle, dos_hdr.e_lfanew, NULL, FILE_BEGIN);
> +
> + if (count == INVALID_SET_FILE_POINTER)
> + return FALSE;
> +
> + count = 0;
> + r = ReadFile(handle, &nt_hdr, sizeof nt_hdr, &count, NULL);
> +
> + if (!r)
> + return FALSE;
> +
> + if (count != sizeof nt_hdr)
> + return FALSE;
> +
> + /* verify NT signature */
> + if (nt_hdr.Signature != IMAGE_NT_SIGNATURE)
> + return FALSE;
Please write a helper for this, we don't need 3 implementations of the
same thing.
--
Alexandre Julliard
julliard at winehq.org
More information about the wine-devel
mailing list