2006-12-28 11:57:43 +01:00
|
|
|
/*
|
2010-01-23 16:46:09 +01:00
|
|
|
* Unit test suite for resource functions.
|
2006-12-28 11:57:43 +01:00
|
|
|
*
|
|
|
|
* Copyright 2006 Mike McCormack
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
|
|
|
static const char filename[] = "test_.exe";
|
2018-07-26 08:49:14 +02:00
|
|
|
static const WCHAR filenameW[] = {'t','e','s','t','_','.','e','x','e',0};
|
2007-04-26 10:08:10 +02:00
|
|
|
static DWORD GLE;
|
2006-12-28 11:57:43 +01:00
|
|
|
|
2010-10-01 13:36:35 +02:00
|
|
|
enum constants {
|
2010-07-21 15:57:37 +02:00
|
|
|
page_size = 0x1000,
|
|
|
|
rva_rsrc_start = page_size * 3,
|
|
|
|
max_sections = 3
|
2010-10-01 13:36:35 +02:00
|
|
|
};
|
2010-07-21 15:57:37 +02:00
|
|
|
|
|
|
|
/* rodata @ [0x1000-0x3000) */
|
|
|
|
static const IMAGE_SECTION_HEADER sh_rodata_1 =
|
|
|
|
{
|
|
|
|
".rodata", {2*page_size}, page_size, 2*page_size, page_size, 0, 0, 0, 0,
|
|
|
|
IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ
|
|
|
|
};
|
|
|
|
|
|
|
|
/* rodata @ [0x1000-0x2000) */
|
2014-12-03 23:54:27 +01:00
|
|
|
static const IMAGE_SECTION_HEADER sh_rodata_2 =
|
2010-07-21 15:57:37 +02:00
|
|
|
{
|
|
|
|
".rodata", {page_size}, page_size, page_size, page_size, 0, 0, 0, 0,
|
|
|
|
IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ
|
|
|
|
};
|
|
|
|
|
|
|
|
/* rsrc @ [0x3000-0x4000) */
|
|
|
|
static const IMAGE_SECTION_HEADER sh_rsrc_1 =
|
|
|
|
{
|
|
|
|
".rsrc\0\0", {page_size}, rva_rsrc_start, page_size, rva_rsrc_start, 0, 0, 0, 0,
|
|
|
|
IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ
|
|
|
|
};
|
|
|
|
|
|
|
|
/* rsrc @ [0x2000-0x4000) */
|
2014-12-03 23:54:27 +01:00
|
|
|
static const IMAGE_SECTION_HEADER sh_rsrc_2 =
|
2010-07-21 15:57:37 +02:00
|
|
|
{
|
|
|
|
".rsrc\0\0", {2*page_size}, rva_rsrc_start-page_size, 2*page_size, rva_rsrc_start-page_size, 0, 0, 0, 0,
|
|
|
|
IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ
|
|
|
|
};
|
|
|
|
|
|
|
|
/* rsrc @ [0x2000-0x3000) */
|
2014-12-03 23:54:27 +01:00
|
|
|
static const IMAGE_SECTION_HEADER sh_rsrc_3 =
|
2010-07-21 15:57:37 +02:00
|
|
|
{
|
|
|
|
".rsrc\0\0", {page_size}, rva_rsrc_start-page_size, page_size, rva_rsrc_start-page_size, 0, 0, 0, 0,
|
|
|
|
IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ
|
|
|
|
};
|
|
|
|
|
|
|
|
/* rsrc @ [0x3000-0x6000) */
|
2014-12-03 23:54:27 +01:00
|
|
|
static const IMAGE_SECTION_HEADER sh_rsrc_4 =
|
2010-07-21 15:57:37 +02:00
|
|
|
{
|
|
|
|
".rsrc\0\0", {3*page_size}, rva_rsrc_start, 3*page_size, rva_rsrc_start, 0, 0, 0, 0,
|
|
|
|
IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ
|
|
|
|
};
|
|
|
|
|
|
|
|
/* rsrc @ [0x2000-0x5000) */
|
2014-12-03 23:54:27 +01:00
|
|
|
static const IMAGE_SECTION_HEADER sh_rsrc_5 =
|
2010-07-21 15:57:37 +02:00
|
|
|
{
|
|
|
|
".rsrc\0\0", {3*page_size}, 2*page_size, 3*page_size, 2*page_size, 0, 0, 0, 0,
|
|
|
|
IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ
|
|
|
|
};
|
|
|
|
|
|
|
|
/* rsrc @ [0x3000-0x4000), small SizeOfRawData */
|
2014-12-03 23:54:27 +01:00
|
|
|
static const IMAGE_SECTION_HEADER sh_rsrc_6 =
|
2010-07-21 15:57:37 +02:00
|
|
|
{
|
|
|
|
".rsrc\0\0", {page_size}, rva_rsrc_start, 8, rva_rsrc_start, 0, 0, 0, 0,
|
|
|
|
IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ
|
|
|
|
};
|
|
|
|
|
|
|
|
/* reloc @ [0x4000-0x5000) */
|
|
|
|
static const IMAGE_SECTION_HEADER sh_junk =
|
|
|
|
{
|
|
|
|
".reloc\0", {page_size}, 4*page_size, page_size, 4*page_size, 0, 0, 0, 0,
|
|
|
|
IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ
|
|
|
|
};
|
|
|
|
|
|
|
|
/* reloc @ [0x6000-0x7000) */
|
|
|
|
static const IMAGE_SECTION_HEADER sh_junk_2 =
|
|
|
|
{
|
|
|
|
".reloc\0", {page_size}, 6*page_size, page_size, 6*page_size, 0, 0, 0, 0,
|
|
|
|
IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _sec_build
|
|
|
|
{
|
|
|
|
const IMAGE_SECTION_HEADER *sect_in[max_sections];
|
|
|
|
} sec_build;
|
|
|
|
|
|
|
|
typedef struct _sec_verify
|
|
|
|
{
|
|
|
|
const IMAGE_SECTION_HEADER *sect_out[max_sections];
|
|
|
|
DWORD length;
|
|
|
|
int rsrc_section;
|
|
|
|
DWORD NumberOfNamedEntries, NumberOfIdEntries;
|
|
|
|
} sec_verify;
|
|
|
|
|
|
|
|
static const struct _sec_variants
|
|
|
|
{
|
|
|
|
sec_build build;
|
|
|
|
sec_verify chk_none, chk_delete, chk_version, chk_bigdata;
|
|
|
|
} sec_variants[] =
|
|
|
|
{
|
|
|
|
/* .rsrc is the last section, data directory entry points to whole section */
|
|
|
|
{
|
|
|
|
{{&sh_rodata_1, &sh_rsrc_1, NULL}},
|
|
|
|
{{&sh_rodata_1, &sh_rsrc_1, NULL}, 4*page_size, 1, 0, 0},
|
|
|
|
{{&sh_rodata_1, &sh_rsrc_1, NULL}, 4*page_size, 1, 0, 0},
|
|
|
|
{{&sh_rodata_1, &sh_rsrc_1, NULL}, 4*page_size, 1, 0, 1},
|
2014-12-03 23:54:27 +01:00
|
|
|
{{&sh_rodata_1, &sh_rsrc_4, NULL}, 6*page_size, 1, 0, 1}
|
2010-07-21 15:57:37 +02:00
|
|
|
},
|
|
|
|
/* .rsrc is the last section, data directory entry points to section end */
|
|
|
|
/* Vista+ - resources are moved to section start (trashing data that could be there), and section is trimmed */
|
|
|
|
/* NT4/2000/2003 - resources are moved to section start (trashing data that could be there); section isn't trimmed */
|
|
|
|
{
|
2014-12-03 23:54:27 +01:00
|
|
|
{{&sh_rodata_2, &sh_rsrc_2, NULL}},
|
|
|
|
{{&sh_rodata_2, &sh_rsrc_3, NULL}, 3*page_size, 1, 0, 0},
|
|
|
|
{{&sh_rodata_2, &sh_rsrc_3, NULL}, 3*page_size, 1, 0, 0},
|
|
|
|
{{&sh_rodata_2, &sh_rsrc_3, NULL}, 3*page_size, 1, 0, 1},
|
|
|
|
{{&sh_rodata_2, &sh_rsrc_5, NULL}, 5*page_size, 1, 0, 1}
|
2010-07-21 15:57:37 +02:00
|
|
|
},
|
|
|
|
/* .rsrc is not the last section */
|
|
|
|
/* section is reused; sections after .rsrc are shifted to give space to rsrc (in-image offset and RVA!) */
|
|
|
|
{
|
|
|
|
{{&sh_rodata_1, &sh_rsrc_1, &sh_junk}},
|
|
|
|
{{&sh_rodata_1, &sh_rsrc_1, &sh_junk}, 5*page_size, 1, 0, 0},
|
|
|
|
{{&sh_rodata_1, &sh_rsrc_1, &sh_junk}, 5*page_size, 1, 0, 0},
|
|
|
|
{{&sh_rodata_1, &sh_rsrc_1, &sh_junk}, 5*page_size, 1, 0, 1},
|
2014-12-03 23:54:27 +01:00
|
|
|
{{&sh_rodata_1, &sh_rsrc_4, &sh_junk_2}, 7*page_size, 1, 0, 1}
|
2010-07-21 15:57:37 +02:00
|
|
|
},
|
|
|
|
/* .rsrc is the last section, data directory entry points to whole section, file size is not aligned on FileAlign */
|
|
|
|
{
|
2014-12-03 23:54:27 +01:00
|
|
|
{{&sh_rodata_1, &sh_rsrc_6, NULL}},
|
2010-07-21 15:57:37 +02:00
|
|
|
{{&sh_rodata_1, &sh_rsrc_1, NULL}, 4*page_size, 1, 0, 0},
|
|
|
|
{{&sh_rodata_1, &sh_rsrc_1, NULL}, 4*page_size, 1, 0, 0},
|
|
|
|
{{&sh_rodata_1, &sh_rsrc_1, NULL}, 4*page_size, 1, 0, 1},
|
2014-12-03 23:54:27 +01:00
|
|
|
{{&sh_rodata_1, &sh_rsrc_4, NULL}, 6*page_size, 1, 0, 1}
|
2010-07-21 15:57:37 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static int build_exe( const sec_build* sec_descr )
|
2006-12-28 11:57:43 +01:00
|
|
|
{
|
|
|
|
IMAGE_DOS_HEADER *dos;
|
|
|
|
IMAGE_NT_HEADERS *nt;
|
|
|
|
IMAGE_SECTION_HEADER *sec;
|
|
|
|
IMAGE_OPTIONAL_HEADER *opt;
|
|
|
|
HANDLE file;
|
2010-07-21 15:57:37 +02:00
|
|
|
DWORD written, i, file_size;
|
|
|
|
BYTE page[page_size];
|
2006-12-28 11:57:43 +01:00
|
|
|
|
|
|
|
memset( page, 0, sizeof page );
|
|
|
|
|
|
|
|
dos = (void*) page;
|
|
|
|
dos->e_magic = IMAGE_DOS_SIGNATURE;
|
|
|
|
dos->e_lfanew = sizeof *dos;
|
|
|
|
|
|
|
|
nt = (void*) &dos[1];
|
|
|
|
|
|
|
|
nt->Signature = IMAGE_NT_SIGNATURE;
|
|
|
|
nt->FileHeader.Machine = IMAGE_FILE_MACHINE_I386;
|
2010-07-21 15:57:37 +02:00
|
|
|
nt->FileHeader.NumberOfSections = 0;
|
2006-12-28 11:57:43 +01:00
|
|
|
nt->FileHeader.SizeOfOptionalHeader = sizeof nt->OptionalHeader;
|
|
|
|
nt->FileHeader.Characteristics = IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_DLL;
|
|
|
|
|
|
|
|
opt = &nt->OptionalHeader;
|
|
|
|
|
|
|
|
opt->Magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
|
|
|
|
opt->MajorLinkerVersion = 1;
|
|
|
|
opt->BaseOfCode = 0x10;
|
|
|
|
opt->ImageBase = 0x10000000;
|
|
|
|
opt->MajorOperatingSystemVersion = 4;
|
|
|
|
opt->MajorImageVersion = 1;
|
|
|
|
opt->MajorSubsystemVersion = 4;
|
|
|
|
opt->SizeOfHeaders = sizeof *dos + sizeof *nt + sizeof *sec * 2;
|
2010-07-21 15:57:37 +02:00
|
|
|
opt->SizeOfImage = page_size;
|
2006-12-28 11:57:43 +01:00
|
|
|
opt->Subsystem = IMAGE_SUBSYSTEM_WINDOWS_CUI;
|
|
|
|
|
|
|
|
/* if SectionAlignment and File alignment are not specified */
|
|
|
|
/* UpdateResource fails trying to create a huge temporary file */
|
|
|
|
opt->SectionAlignment = page_size;
|
|
|
|
opt->FileAlignment = page_size;
|
|
|
|
|
2010-07-21 15:57:37 +02:00
|
|
|
opt->DataDirectory[IMAGE_FILE_RESOURCE_DIRECTORY].VirtualAddress = rva_rsrc_start;
|
|
|
|
opt->DataDirectory[IMAGE_FILE_RESOURCE_DIRECTORY].Size = page_size;
|
2006-12-28 11:57:43 +01:00
|
|
|
|
2010-07-21 15:57:37 +02:00
|
|
|
sec = (void*) &nt[1];
|
2006-12-28 11:57:43 +01:00
|
|
|
|
2010-07-21 15:57:37 +02:00
|
|
|
file_size = 0;
|
|
|
|
for ( i = 0; i < max_sections; i++ )
|
|
|
|
if ( sec_descr->sect_in[i] )
|
|
|
|
{
|
|
|
|
DWORD virt_end_of_section = sec_descr->sect_in[i]->Misc.VirtualSize +
|
|
|
|
sec_descr->sect_in[i]->VirtualAddress;
|
|
|
|
DWORD phys_end_of_section = sec_descr->sect_in[i]->SizeOfRawData +
|
|
|
|
sec_descr->sect_in[i]->PointerToRawData;
|
|
|
|
memcpy( sec + nt->FileHeader.NumberOfSections, sec_descr->sect_in[i],
|
|
|
|
sizeof(sec[0]) );
|
|
|
|
nt->FileHeader.NumberOfSections++;
|
|
|
|
if ( opt->SizeOfImage < virt_end_of_section )
|
|
|
|
opt->SizeOfImage = virt_end_of_section;
|
|
|
|
if ( file_size < phys_end_of_section )
|
|
|
|
file_size = phys_end_of_section;
|
|
|
|
}
|
2006-12-28 11:57:43 +01:00
|
|
|
|
2013-10-21 10:02:31 +02:00
|
|
|
file = CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
|
2006-12-28 11:57:43 +01:00
|
|
|
ok (file != INVALID_HANDLE_VALUE, "failed to create file\n");
|
|
|
|
|
|
|
|
/* write out the header */
|
|
|
|
WriteFile( file, page, sizeof page, &written, NULL );
|
|
|
|
|
2010-07-21 15:57:37 +02:00
|
|
|
/* write out zeroed pages for sections */
|
2006-12-28 11:57:43 +01:00
|
|
|
memset( page, 0, sizeof page );
|
2010-07-21 15:57:37 +02:00
|
|
|
for ( i = page_size; i < file_size; i += page_size )
|
|
|
|
{
|
|
|
|
DWORD size = min(page_size, file_size - i);
|
|
|
|
WriteFile( file, page, size, &written, NULL );
|
|
|
|
}
|
2006-12-28 11:57:43 +01:00
|
|
|
|
|
|
|
CloseHandle( file );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void update_missing_exe( void )
|
|
|
|
{
|
|
|
|
HANDLE res;
|
|
|
|
|
2007-04-26 10:08:10 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-21 10:02:31 +02:00
|
|
|
res = BeginUpdateResourceA( filename, TRUE );
|
2007-04-26 10:08:10 +02:00
|
|
|
GLE = GetLastError();
|
2006-12-28 11:57:43 +01:00
|
|
|
ok( res == NULL, "BeginUpdateResource should fail\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void update_empty_exe( void )
|
|
|
|
{
|
|
|
|
HANDLE file, res, test;
|
|
|
|
BOOL r;
|
|
|
|
|
2013-10-21 10:02:31 +02:00
|
|
|
file = CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
|
2006-12-28 11:57:43 +01:00
|
|
|
ok (file != INVALID_HANDLE_VALUE, "failed to create file\n");
|
|
|
|
|
|
|
|
CloseHandle( file );
|
|
|
|
|
2013-10-21 10:02:31 +02:00
|
|
|
res = BeginUpdateResourceA( filename, TRUE );
|
2009-10-07 12:28:07 +02:00
|
|
|
if ( res != NULL || GetLastError() != ERROR_FILE_INVALID )
|
|
|
|
{
|
|
|
|
ok( res != NULL, "BeginUpdateResource failed\n");
|
2006-12-28 11:57:43 +01:00
|
|
|
|
2009-10-07 12:28:07 +02:00
|
|
|
/* check if it's possible to open the file now */
|
2013-10-21 10:02:31 +02:00
|
|
|
test = CreateFileA(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0);
|
2009-10-07 12:28:07 +02:00
|
|
|
ok (test != INVALID_HANDLE_VALUE, "failed to create file\n");
|
2006-12-28 11:57:43 +01:00
|
|
|
|
2009-10-07 12:28:07 +02:00
|
|
|
CloseHandle( test );
|
2006-12-28 11:57:43 +01:00
|
|
|
|
2013-10-21 10:02:31 +02:00
|
|
|
r = EndUpdateResourceA( res, FALSE );
|
2009-10-07 12:28:07 +02:00
|
|
|
ok( r == FALSE, "EndUpdateResource failed\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
skip( "Can't update resource in empty file\n" );
|
2006-12-28 11:57:43 +01:00
|
|
|
|
2013-10-21 10:02:31 +02:00
|
|
|
res = BeginUpdateResourceA( filename, FALSE );
|
2006-12-28 11:57:43 +01:00
|
|
|
ok( res == NULL, "BeginUpdateResource failed\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void update_resources_none( void )
|
|
|
|
{
|
|
|
|
HMODULE res;
|
|
|
|
BOOL r;
|
|
|
|
|
2013-10-21 10:02:31 +02:00
|
|
|
res = BeginUpdateResourceA( filename, FALSE );
|
2006-12-28 11:58:35 +01:00
|
|
|
ok( res != NULL, "BeginUpdateResource failed\n");
|
2006-12-28 11:57:43 +01:00
|
|
|
|
2013-10-21 10:02:31 +02:00
|
|
|
r = EndUpdateResourceA( res, FALSE );
|
2008-01-23 15:16:30 +01:00
|
|
|
ok( r, "EndUpdateResource failed\n");
|
2006-12-28 11:57:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void update_resources_delete( void )
|
|
|
|
{
|
|
|
|
HMODULE res;
|
|
|
|
BOOL r;
|
|
|
|
|
2013-10-21 10:02:31 +02:00
|
|
|
res = BeginUpdateResourceA( filename, TRUE );
|
2006-12-28 11:58:35 +01:00
|
|
|
ok( res != NULL, "BeginUpdateResource failed\n");
|
2006-12-28 11:57:43 +01:00
|
|
|
|
2013-10-21 10:02:31 +02:00
|
|
|
r = EndUpdateResourceA( res, FALSE );
|
2008-01-23 15:16:30 +01:00
|
|
|
ok( r, "EndUpdateResource failed\n");
|
2006-12-28 11:57:43 +01:00
|
|
|
}
|
|
|
|
|
2010-07-21 15:57:37 +02:00
|
|
|
static void update_resources_version( void )
|
2006-12-28 11:57:43 +01:00
|
|
|
{
|
|
|
|
HANDLE res = NULL;
|
|
|
|
BOOL r;
|
|
|
|
char foo[] = "red and white";
|
|
|
|
|
2013-10-21 10:02:31 +02:00
|
|
|
res = BeginUpdateResourceA( filename, TRUE );
|
2006-12-28 11:57:43 +01:00
|
|
|
ok( res != NULL, "BeginUpdateResource failed\n");
|
|
|
|
|
2008-09-16 22:36:58 +02:00
|
|
|
if (0) /* this causes subsequent tests to fail on Vista */
|
|
|
|
{
|
2013-10-21 10:02:31 +02:00
|
|
|
r = UpdateResourceA( res,
|
|
|
|
MAKEINTRESOURCEA(0x1230),
|
|
|
|
MAKEINTRESOURCEA(0x4567),
|
2008-09-16 22:36:58 +02:00
|
|
|
0xabcd,
|
|
|
|
NULL, 0 );
|
|
|
|
ok( r == FALSE, "UpdateResource failed\n");
|
|
|
|
}
|
2006-12-28 11:57:43 +01:00
|
|
|
|
2013-10-21 10:02:31 +02:00
|
|
|
r = UpdateResourceA( res,
|
|
|
|
MAKEINTRESOURCEA(0x1230),
|
|
|
|
MAKEINTRESOURCEA(0x4567),
|
2006-12-28 11:57:43 +01:00
|
|
|
0xabcd,
|
|
|
|
foo, sizeof foo );
|
2008-08-29 04:15:27 +02:00
|
|
|
ok( r == TRUE, "UpdateResource failed: %d\n", GetLastError());
|
2006-12-28 11:57:43 +01:00
|
|
|
|
2013-10-21 10:02:31 +02:00
|
|
|
r = EndUpdateResourceA( res, FALSE );
|
2008-08-29 04:15:27 +02:00
|
|
|
ok( r, "EndUpdateResource failed: %d\n", GetLastError());
|
2006-12-28 11:57:43 +01:00
|
|
|
}
|
|
|
|
|
2010-07-21 15:57:37 +02:00
|
|
|
static void update_resources_bigdata( void )
|
2006-12-28 11:57:43 +01:00
|
|
|
{
|
2010-07-21 15:57:37 +02:00
|
|
|
HANDLE res = NULL;
|
|
|
|
BOOL r;
|
|
|
|
char foo[2*page_size] = "foobar";
|
2006-12-28 11:57:43 +01:00
|
|
|
|
2013-10-21 10:02:31 +02:00
|
|
|
res = BeginUpdateResourceA( filename, TRUE );
|
2010-07-21 15:57:37 +02:00
|
|
|
ok( res != NULL, "BeginUpdateResource succeeded\n");
|
2006-12-28 11:57:43 +01:00
|
|
|
|
2013-10-21 10:02:31 +02:00
|
|
|
r = UpdateResourceA( res,
|
|
|
|
MAKEINTRESOURCEA(0x3012),
|
|
|
|
MAKEINTRESOURCEA(0x5647),
|
2010-07-21 15:57:37 +02:00
|
|
|
0xcdba,
|
|
|
|
foo, sizeof foo );
|
|
|
|
ok( r == TRUE, "UpdateResource failed: %d\n", GetLastError());
|
2006-12-28 11:57:43 +01:00
|
|
|
|
2013-10-21 10:02:31 +02:00
|
|
|
r = EndUpdateResourceA( res, FALSE );
|
2010-07-21 15:57:37 +02:00
|
|
|
ok( r, "EndUpdateResource failed\n");
|
2006-12-28 11:57:43 +01:00
|
|
|
}
|
|
|
|
|
2010-07-21 15:57:37 +02:00
|
|
|
static void check_exe( const sec_verify *verify )
|
2006-12-28 11:57:43 +01:00
|
|
|
{
|
2010-07-21 15:57:37 +02:00
|
|
|
int i;
|
2006-12-28 11:57:43 +01:00
|
|
|
IMAGE_DOS_HEADER *dos;
|
|
|
|
IMAGE_NT_HEADERS *nt;
|
2014-06-15 23:38:38 +02:00
|
|
|
IMAGE_OPTIONAL_HEADER *opt;
|
2006-12-28 11:57:43 +01:00
|
|
|
IMAGE_SECTION_HEADER *sec;
|
|
|
|
IMAGE_RESOURCE_DIRECTORY *dir;
|
|
|
|
HANDLE file, mapping;
|
2010-07-21 15:57:37 +02:00
|
|
|
DWORD length, sec_count = 0;
|
2006-12-28 11:57:43 +01:00
|
|
|
|
2013-10-21 10:02:31 +02:00
|
|
|
file = CreateFileA(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0);
|
2006-12-28 11:57:43 +01:00
|
|
|
ok (file != INVALID_HANDLE_VALUE, "failed to create file (%d)\n", GetLastError());
|
|
|
|
|
|
|
|
length = GetFileSize( file, NULL );
|
2010-07-21 15:57:37 +02:00
|
|
|
ok( length >= verify->length, "file size wrong\n");
|
2006-12-28 11:57:43 +01:00
|
|
|
|
2013-10-21 10:02:31 +02:00
|
|
|
mapping = CreateFileMappingA( file, NULL, PAGE_READONLY, 0, 0, NULL );
|
2006-12-28 11:57:43 +01:00
|
|
|
ok (mapping != NULL, "failed to create file\n");
|
|
|
|
|
|
|
|
dos = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, length );
|
|
|
|
ok( dos != NULL, "failed to map file\n");
|
|
|
|
|
|
|
|
if (!dos)
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
nt = (void*) ((BYTE*) dos + dos->e_lfanew);
|
2014-06-15 23:38:38 +02:00
|
|
|
opt = &nt->OptionalHeader;
|
2006-12-28 11:57:43 +01:00
|
|
|
sec = (void*) &nt[1];
|
|
|
|
|
2010-07-21 15:57:37 +02:00
|
|
|
for(i = 0; i < max_sections; i++)
|
|
|
|
if (verify->sect_out[i])
|
|
|
|
{
|
|
|
|
ok( !memcmp(&verify->sect_out[i]->Name, &sec[sec_count].Name, 8), "section %d name wrong\n", sec_count);
|
|
|
|
ok( verify->sect_out[i]->VirtualAddress == sec[sec_count].VirtualAddress, "section %d vaddr wrong\n", sec_count);
|
|
|
|
ok( verify->sect_out[i]->SizeOfRawData <= sec[sec_count].SizeOfRawData, "section %d SizeOfRawData wrong (%d vs %d)\n", sec_count, verify->sect_out[i]->SizeOfRawData ,sec[sec_count].SizeOfRawData);
|
|
|
|
ok( verify->sect_out[i]->PointerToRawData == sec[sec_count].PointerToRawData, "section %d PointerToRawData wrong\n", sec_count);
|
|
|
|
ok( verify->sect_out[i]->Characteristics == sec[sec_count].Characteristics , "section %d characteristics wrong\n", sec_count);
|
|
|
|
sec_count++;
|
|
|
|
}
|
2006-12-28 11:57:43 +01:00
|
|
|
|
2010-07-21 15:57:37 +02:00
|
|
|
ok( nt->FileHeader.NumberOfSections == sec_count, "number of sections wrong\n" );
|
2006-12-28 11:57:43 +01:00
|
|
|
|
2010-07-21 15:57:37 +02:00
|
|
|
if (verify->rsrc_section >= 0 && verify->rsrc_section < nt->FileHeader.NumberOfSections)
|
|
|
|
{
|
|
|
|
dir = (void*) ((BYTE*) dos + sec[verify->rsrc_section].VirtualAddress);
|
|
|
|
|
|
|
|
ok( dir->Characteristics == 0, "Characteristics wrong\n");
|
|
|
|
ok( dir->TimeDateStamp == 0 || abs( dir->TimeDateStamp - GetTickCount() ) < 1000 /* nt4 */,
|
|
|
|
"TimeDateStamp wrong %u\n", dir->TimeDateStamp);
|
|
|
|
ok( dir->MajorVersion == 4, "MajorVersion wrong\n");
|
|
|
|
ok( dir->MinorVersion == 0, "MinorVersion wrong\n");
|
|
|
|
|
|
|
|
ok( dir->NumberOfNamedEntries == verify->NumberOfNamedEntries, "NumberOfNamedEntries should be %d instead of %d\n",
|
|
|
|
verify->NumberOfNamedEntries, dir->NumberOfNamedEntries);
|
|
|
|
ok( dir->NumberOfIdEntries == verify->NumberOfIdEntries, "NumberOfIdEntries should be %d instead of %d\n",
|
|
|
|
verify->NumberOfIdEntries, dir->NumberOfIdEntries);
|
2014-06-15 23:38:38 +02:00
|
|
|
|
|
|
|
ok(opt->DataDirectory[IMAGE_FILE_RESOURCE_DIRECTORY].VirtualAddress == sec[verify->rsrc_section].VirtualAddress,
|
|
|
|
"VirtualAddress in optional header should be %d instead of %d\n",
|
|
|
|
sec[verify->rsrc_section].VirtualAddress, opt->DataDirectory[IMAGE_FILE_RESOURCE_DIRECTORY].VirtualAddress);
|
2010-07-21 15:57:37 +02:00
|
|
|
}
|
2006-12-28 11:57:43 +01:00
|
|
|
|
|
|
|
end:
|
|
|
|
UnmapViewOfFile( dos );
|
|
|
|
|
|
|
|
CloseHandle( mapping );
|
|
|
|
|
|
|
|
CloseHandle( file );
|
|
|
|
}
|
|
|
|
|
2008-03-22 13:09:44 +01:00
|
|
|
static void test_find_resource(void)
|
|
|
|
{
|
|
|
|
HRSRC rsrc;
|
|
|
|
|
2013-10-21 10:02:31 +02:00
|
|
|
rsrc = FindResourceW( GetModuleHandleW(NULL), MAKEINTRESOURCEW(1), (LPCWSTR)RT_MENU );
|
2008-03-22 13:09:44 +01:00
|
|
|
ok( rsrc != 0, "resource not found\n" );
|
2013-10-21 10:02:31 +02:00
|
|
|
rsrc = FindResourceExW( GetModuleHandleW(NULL), (LPCWSTR)RT_MENU, MAKEINTRESOURCEW(1),
|
2008-03-22 13:09:44 +01:00
|
|
|
MAKELANGID( LANG_NEUTRAL, SUBLANG_NEUTRAL ));
|
|
|
|
ok( rsrc != 0, "resource not found\n" );
|
2013-10-21 10:02:31 +02:00
|
|
|
rsrc = FindResourceExW( GetModuleHandleW(NULL), (LPCWSTR)RT_MENU, MAKEINTRESOURCEW(1),
|
2008-03-22 13:09:44 +01:00
|
|
|
MAKELANGID( LANG_GERMAN, SUBLANG_DEFAULT ));
|
|
|
|
ok( rsrc != 0, "resource not found\n" );
|
|
|
|
|
|
|
|
SetLastError( 0xdeadbeef );
|
2013-10-21 10:02:31 +02:00
|
|
|
rsrc = FindResourceW( GetModuleHandleW(NULL), MAKEINTRESOURCEW(1), (LPCWSTR)RT_DIALOG );
|
2008-03-22 13:09:44 +01:00
|
|
|
ok( !rsrc, "resource found\n" );
|
|
|
|
ok( GetLastError() == ERROR_RESOURCE_TYPE_NOT_FOUND, "wrong error %u\n", GetLastError() );
|
|
|
|
|
|
|
|
SetLastError( 0xdeadbeef );
|
2013-10-21 10:02:31 +02:00
|
|
|
rsrc = FindResourceW( GetModuleHandleW(NULL), MAKEINTRESOURCEW(2), (LPCWSTR)RT_MENU );
|
2008-03-22 13:09:44 +01:00
|
|
|
ok( !rsrc, "resource found\n" );
|
|
|
|
ok( GetLastError() == ERROR_RESOURCE_NAME_NOT_FOUND, "wrong error %u\n", GetLastError() );
|
|
|
|
|
|
|
|
SetLastError( 0xdeadbeef );
|
2013-10-21 10:02:31 +02:00
|
|
|
rsrc = FindResourceExW( GetModuleHandleW(NULL), (LPCWSTR)RT_MENU, MAKEINTRESOURCEW(1),
|
2008-03-22 13:09:44 +01:00
|
|
|
MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT ) );
|
|
|
|
ok( !rsrc, "resource found\n" );
|
|
|
|
ok( GetLastError() == ERROR_RESOURCE_LANG_NOT_FOUND, "wrong error %u\n", GetLastError() );
|
|
|
|
|
|
|
|
SetLastError( 0xdeadbeef );
|
2013-10-21 10:02:31 +02:00
|
|
|
rsrc = FindResourceExW( GetModuleHandleW(NULL), (LPCWSTR)RT_MENU, MAKEINTRESOURCEW(1),
|
2008-03-22 13:09:44 +01:00
|
|
|
MAKELANGID( LANG_FRENCH, SUBLANG_DEFAULT ) );
|
|
|
|
ok( !rsrc, "resource found\n" );
|
|
|
|
ok( GetLastError() == ERROR_RESOURCE_LANG_NOT_FOUND, "wrong error %u\n", GetLastError() );
|
|
|
|
}
|
|
|
|
|
2018-07-26 08:49:14 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
void *unknown[6];
|
|
|
|
HGLOBAL pFileName;
|
|
|
|
} QUEUEDUPDATES;
|
|
|
|
|
|
|
|
static void test_internal_structure(void)
|
|
|
|
{
|
|
|
|
HANDLE res;
|
|
|
|
QUEUEDUPDATES *res_data;
|
|
|
|
WCHAR *res_filenameW;
|
|
|
|
|
|
|
|
res = BeginUpdateResourceW( filenameW, FALSE );
|
|
|
|
ok( res != NULL, "BeginUpdateResourceW failed\n" );
|
|
|
|
res_data = GlobalLock(res);
|
|
|
|
ok( res_data != NULL, "GlobalLock failed\n" );
|
|
|
|
res_filenameW = GlobalLock( res_data->pFileName );
|
|
|
|
ok( res_filenameW != NULL, "GlobalLock for res_filenameW failed\n" );
|
|
|
|
ok( !lstrcmpW( res_filenameW, filenameW ), "Filename fields do not match\n" );
|
|
|
|
ok( GlobalUnlock( res_filenameW ), "GlobalUnlock res_filenamed failed\n" );
|
|
|
|
ok( GlobalUnlock( res_data ), "GlobalUnlock res_data failed\n" );
|
|
|
|
ok( EndUpdateResourceW( res, TRUE ), "EndUpdateResourceW failed\n");
|
|
|
|
}
|
|
|
|
|
2006-12-28 11:57:43 +01:00
|
|
|
START_TEST(resource)
|
|
|
|
{
|
2010-07-21 15:57:37 +02:00
|
|
|
DWORD i;
|
|
|
|
|
2013-10-21 10:02:31 +02:00
|
|
|
DeleteFileA( filename );
|
2006-12-28 11:57:43 +01:00
|
|
|
update_missing_exe();
|
2007-04-26 10:08:10 +02:00
|
|
|
|
|
|
|
if (GLE == ERROR_CALL_NOT_IMPLEMENTED)
|
|
|
|
{
|
2009-02-24 00:03:07 +01:00
|
|
|
win_skip("Resource calls are not implemented\n");
|
2007-04-26 10:08:10 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-12-28 11:57:43 +01:00
|
|
|
update_empty_exe();
|
2010-07-21 15:57:37 +02:00
|
|
|
|
2018-06-27 20:56:45 +02:00
|
|
|
for(i=0; i < ARRAY_SIZE(sec_variants); i++)
|
2010-07-21 15:57:37 +02:00
|
|
|
{
|
|
|
|
const struct _sec_variants *sec = &sec_variants[i];
|
|
|
|
build_exe( &sec->build );
|
2018-07-26 08:49:14 +02:00
|
|
|
test_internal_structure();
|
2010-07-21 15:57:37 +02:00
|
|
|
update_resources_none();
|
|
|
|
check_exe( &sec->chk_none );
|
|
|
|
update_resources_delete();
|
|
|
|
check_exe( &sec->chk_delete );
|
|
|
|
update_resources_version();
|
|
|
|
check_exe( &sec->chk_version );
|
|
|
|
update_resources_bigdata();
|
|
|
|
check_exe( &sec->chk_bigdata );
|
2013-10-21 10:02:31 +02:00
|
|
|
DeleteFileA( filename );
|
2010-07-21 15:57:37 +02:00
|
|
|
}
|
2008-03-22 13:09:44 +01:00
|
|
|
test_find_resource();
|
2006-12-28 11:57:43 +01:00
|
|
|
}
|