Relax a bit PE consistency checks.

Return BINARY_DOS type if extended header was not recognized.
This commit is contained in:
Dmitry Timoshkov 2002-08-27 00:34:41 +00:00 committed by Alexandre Julliard
parent 155710ce62
commit 1467bbd5a4
2 changed files with 11 additions and 7 deletions

View File

@ -635,15 +635,14 @@ enum binary_type MODULE_GetBinaryType( HANDLE hfile )
*/
if (!memcmp( magic, "PE\0\0", 4 ))
{
IMAGE_NT_HEADERS nt;
IMAGE_FILE_HEADER FileHeader;
if (SetFilePointer( hfile, header.mz.e_lfanew, NULL, SEEK_SET ) != -1 &&
ReadFile( hfile, &nt, sizeof(nt), &len, NULL ) && len == sizeof(nt))
if (ReadFile( hfile, &FileHeader, sizeof(FileHeader), &len, NULL ) && len == sizeof(FileHeader))
{
if (nt.FileHeader.Characteristics & IMAGE_FILE_DLL) return BINARY_PE_DLL;
if (FileHeader.Characteristics & IMAGE_FILE_DLL) return BINARY_PE_DLL;
return BINARY_PE_EXE;
}
return BINARY_UNKNOWN;
return BINARY_DOS;
}
if (!memcmp( magic, "NE", 2 ))
@ -666,7 +665,7 @@ enum binary_type MODULE_GetBinaryType( HANDLE hfile )
}
}
/* Couldn't read header, so abort. */
return BINARY_UNKNOWN;
return BINARY_DOS;
}
/* Unknown extended header, but this file is nonetheless DOS-executable. */

View File

@ -211,8 +211,13 @@ static int get_image_params( struct mapping *mapping )
if (read( fd, &dos, sizeof(dos) ) != sizeof(dos)) goto error;
if (dos.e_magic != IMAGE_DOS_SIGNATURE) goto error;
if (lseek( fd, dos.e_lfanew, SEEK_SET ) == -1) goto error;
if (read( fd, &nt, sizeof(nt) ) != sizeof(nt)) goto error;
if (read( fd, &nt.Signature, sizeof(nt.Signature) ) != sizeof(nt.Signature)) goto error;
if (nt.Signature != IMAGE_NT_SIGNATURE) goto error;
if (read( fd, &nt.FileHeader, sizeof(nt.FileHeader) ) != sizeof(nt.FileHeader)) goto error;
/* zero out Optional header in the case it's not present or partial */
memset(&nt.OptionalHeader, 0, sizeof(nt.OptionalHeader));
if (read( fd, &nt.OptionalHeader, nt.FileHeader.SizeOfOptionalHeader) != nt.FileHeader.SizeOfOptionalHeader) goto error;
/* load the section headers */