kernel32/tests: Add a PE test image that resembles format of some of 8k demos.

Signed-off-by: Dmitry Timoshkov <dmitry@baikal.ru>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Dmitry Timoshkov 2020-05-06 15:16:01 +08:00 committed by Alexandre Julliard
parent 360820fb58
commit 1a7dd7cdbe
1 changed files with 38 additions and 2 deletions

View File

@ -228,7 +228,7 @@ static DWORD create_test_dll( const IMAGE_DOS_HEADER *dos_header, UINT dos_size,
{ {
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
ret = WriteFile(hfile, &nt_header->OptionalHeader, ret = WriteFile(hfile, &nt_header->OptionalHeader,
min(nt_header->FileHeader.SizeOfOptionalHeader, sizeof(IMAGE_OPTIONAL_HEADER)), sizeof(IMAGE_OPTIONAL_HEADER),
&dummy, NULL); &dummy, NULL);
ok(ret, "WriteFile error %d\n", GetLastError()); ok(ret, "WriteFile error %d\n", GetLastError());
if (nt_header->FileHeader.SizeOfOptionalHeader > sizeof(IMAGE_OPTIONAL_HEADER)) if (nt_header->FileHeader.SizeOfOptionalHeader > sizeof(IMAGE_OPTIONAL_HEADER))
@ -244,6 +244,8 @@ static DWORD create_test_dll( const IMAGE_DOS_HEADER *dos_header, UINT dos_size,
assert(nt_header->FileHeader.NumberOfSections <= 1); assert(nt_header->FileHeader.NumberOfSections <= 1);
if (nt_header->FileHeader.NumberOfSections) if (nt_header->FileHeader.NumberOfSections)
{ {
SetFilePointer(hfile, dos_size + sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER) + nt_header->FileHeader.SizeOfOptionalHeader, NULL, FILE_BEGIN);
section.SizeOfRawData = 10; section.SizeOfRawData = 10;
if (nt_header->OptionalHeader.SectionAlignment >= page_size) if (nt_header->OptionalHeader.SectionAlignment >= page_size)
@ -268,6 +270,17 @@ static DWORD create_test_dll( const IMAGE_DOS_HEADER *dos_header, UINT dos_size,
ret = WriteFile(hfile, section_data, sizeof(section_data), &dummy, NULL); ret = WriteFile(hfile, section_data, sizeof(section_data), &dummy, NULL);
ok(ret, "WriteFile error %d\n", GetLastError()); ok(ret, "WriteFile error %d\n", GetLastError());
} }
/* Minimal PE image that Windows7+ is able to load: 268 bytes */
size = GetFileSize(hfile, NULL);
if (size < 268)
{
file_align = 268 - size;
SetLastError(0xdeadbeef);
ret = WriteFile(hfile, filler, file_align, &dummy, NULL);
ok(ret, "WriteFile error %d\n", GetLastError());
}
size = GetFileSize(hfile, NULL); size = GetFileSize(hfile, NULL);
CloseHandle(hfile); CloseHandle(hfile);
return size; return size;
@ -417,7 +430,8 @@ static BOOL query_image_section( int id, const char *dll_name, const IMAGE_NT_HE
ok( image.LoaderFlags == (cor_header != NULL), "%u: LoaderFlags wrong %08x\n", id, image.LoaderFlags ); ok( image.LoaderFlags == (cor_header != NULL), "%u: LoaderFlags wrong %08x\n", id, image.LoaderFlags );
ok( image.ImageFileSize == file_size || broken(!image.ImageFileSize), /* winxpsp1 */ ok( image.ImageFileSize == file_size || broken(!image.ImageFileSize), /* winxpsp1 */
"%u: ImageFileSize wrong %08x / %08x\n", id, image.ImageFileSize, file_size ); "%u: ImageFileSize wrong %08x / %08x\n", id, image.ImageFileSize, file_size );
ok( image.CheckSum == nt_header->OptionalHeader.CheckSum, "%u: CheckSum wrong %08x / %08x\n", id, ok( image.CheckSum == nt_header->OptionalHeader.CheckSum || broken(truncated),
"%u: CheckSum wrong %08x / %08x\n", id,
image.CheckSum, nt_header->OptionalHeader.CheckSum ); image.CheckSum, nt_header->OptionalHeader.CheckSum );
if (nt_header->OptionalHeader.SizeOfCode || nt_header->OptionalHeader.AddressOfEntryPoint) if (nt_header->OptionalHeader.SizeOfCode || nt_header->OptionalHeader.AddressOfEntryPoint)
@ -768,6 +782,7 @@ static void test_Loader(void)
/* Mandatory are all fields up to SizeOfHeaders, everything else /* Mandatory are all fields up to SizeOfHeaders, everything else
* is really optional (at least that's true for XP). * is really optional (at least that's true for XP).
*/ */
#if 0 /* 32-bit Windows 8 crashes inside of LoadLibrary */
{ sizeof(dos_header), { sizeof(dos_header),
1, FIELD_OFFSET(IMAGE_OPTIONAL_HEADER, CheckSum), 0x200, 0x200, 1, FIELD_OFFSET(IMAGE_OPTIONAL_HEADER, CheckSum), 0x200, 0x200,
sizeof(dos_header) + sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER) + FIELD_OFFSET(IMAGE_OPTIONAL_HEADER, CheckSum) + sizeof(IMAGE_SECTION_HEADER) + 0x10, sizeof(dos_header) + sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER) + FIELD_OFFSET(IMAGE_OPTIONAL_HEADER, CheckSum) + sizeof(IMAGE_SECTION_HEADER) + 0x10,
@ -775,6 +790,7 @@ static void test_Loader(void)
{ ERROR_SUCCESS, ERROR_BAD_EXE_FORMAT, ERROR_INVALID_ADDRESS, { ERROR_SUCCESS, ERROR_BAD_EXE_FORMAT, ERROR_INVALID_ADDRESS,
ERROR_NOACCESS } ERROR_NOACCESS }
}, },
#endif
{ sizeof(dos_header), { sizeof(dos_header),
0, FIELD_OFFSET(IMAGE_OPTIONAL_HEADER, CheckSum), 0x200, 0x200, 0, FIELD_OFFSET(IMAGE_OPTIONAL_HEADER, CheckSum), 0x200, 0x200,
0xd0, /* beyond of the end of file */ 0xd0, /* beyond of the end of file */
@ -843,6 +859,14 @@ static void test_Loader(void)
0x40, /* minimal image size that Windows7 accepts */ 0x40, /* minimal image size that Windows7 accepts */
0, 0,
{ ERROR_SUCCESS } { ERROR_SUCCESS }
},
/* the following data mimics the PE image which 8k demos have */
{ 0x04,
0, 0x08,
0x04 /* also serves as e_lfanew in the truncated MZ header */, 0x04,
0x200000,
0x40,
{ ERROR_SUCCESS }
} }
}; };
int i; int i;
@ -1077,6 +1101,18 @@ static void test_Loader(void)
ok(ret, "FreeLibrary error %d\n", GetLastError()); ok(ret, "FreeLibrary error %d\n", GetLastError());
} }
SetLastError(0xdeadbeef);
ret = DeleteFileA(dll_name);
ok(ret, "DeleteFile error %d\n", GetLastError());
nt_header.OptionalHeader.AddressOfEntryPoint = 0x12345678;
file_size = create_test_dll( &dos_header, td[i].size_of_dos_header, &nt_header, dll_name );
if (!file_size)
{
ok(0, "could not create %s\n", dll_name);
break;
}
query_image_section( i, dll_name, &nt_header, NULL ); query_image_section( i, dll_name, &nt_header, NULL );
} }
else else