ReactOS 0.4.16-dev-136-g52192f1
data.c File Reference
#include <exdisp.h>
#include <winbase.h>
#include "wine/test.h"
Include dependency graph for data.c:

Go to the source code of this file.

Classes

struct  VS_VERSIONINFO
 
struct  STRINGFILEINFO
 
struct  STRINGTABLE
 
struct  STRINGHDR
 
struct  VARFILEINFO
 
struct  VAR
 
struct  rsrc_section_t
 
struct  export_section_t
 

Macros

#define RT_VERSION_DW   16
 

Typedefs

typedef struct rsrc_section_t rsrc_section_t
 
typedef struct export_section_t export_section_t
 

Functions

void test_create_exe_imp (const WCHAR *name, int skip_rsrc_exports)
 
void test_create_ne_imp (const WCHAR *name, int skip_names)
 
void test_create_file_imp (const WCHAR *name, const char *contents, size_t len)
 
DWORD test_get_db_size ()
 
void test_create_db_imp (const WCHAR *name, int win10)
 
DWORD get_host_winver (void)
 
DWORD get_module_version (HMODULE mod)
 
void silence_debug_output (void)
 

Variables

static IMAGE_DOS_HEADER dos_header
 
static IMAGE_NT_HEADERS32 nt_header
 
static IMAGE_SECTION_HEADER section_headers []
 
static const unsigned char text_section []
 
static const rsrc_section_t rsrc_section
 
static export_section_t export_dir
 
static unsigned char win10Header [8]
 
static unsigned char rawData [2356]
 
DWORD g_WinVersion
 

Macro Definition Documentation

◆ RT_VERSION_DW

#define RT_VERSION_DW   16

Definition at line 234 of file data.c.

Typedef Documentation

◆ export_section_t

◆ rsrc_section_t

Function Documentation

◆ get_host_winver()

DWORD get_host_winver ( void  )

Definition at line 796 of file data.c.

797{
798 if (!g_WinVersion)
799 {
800 RTL_OSVERSIONINFOEXW rtlinfo = {0};
801 void (__stdcall* pRtlGetVersion)(RTL_OSVERSIONINFOEXW*);
802 pRtlGetVersion = (void (__stdcall*)(RTL_OSVERSIONINFOEXW*))GetProcAddress(GetModuleHandleA("ntdll"), "RtlGetVersion");
803
804 rtlinfo.dwOSVersionInfoSize = sizeof(rtlinfo);
805 pRtlGetVersion(&rtlinfo);
806 g_WinVersion = (rtlinfo.dwMajorVersion << 8) | rtlinfo.dwMinorVersion;
807 }
808 return g_WinVersion;
809}
#define GetProcAddress(x, y)
Definition: compat.h:753
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
DWORD g_WinVersion
Definition: data.c:795
ULONG dwMajorVersion
Definition: rtltypes.h:270
ULONG dwMinorVersion
Definition: rtltypes.h:271
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:269
#define __stdcall
Definition: typedefs.h:25

◆ get_module_version()

DWORD get_module_version ( HMODULE  mod)

Definition at line 811 of file data.c.

812{
813 DWORD dwVersion = 0;
815 DWORD dwSize = SizeofResource(mod, hResInfo);
816 if (hResInfo && dwSize)
817 {
818 VS_FIXEDFILEINFO *lpFfi;
819 UINT uLen;
820
821 HGLOBAL hResData = LoadResource(mod, hResInfo);
822 LPVOID pRes = LockResource(hResData);
823 HLOCAL pResCopy = LocalAlloc(LMEM_FIXED, dwSize);
824
825 CopyMemory(pResCopy, pRes, dwSize);
826 FreeResource(hResData);
827
828 if (VerQueryValueW(pResCopy, L"\\", (LPVOID*)&lpFfi, &uLen))
829 {
830 dwVersion = (HIWORD(lpFfi->dwProductVersionMS) << 8) | LOWORD(lpFfi->dwProductVersionMS);
831 if (!dwVersion)
832 dwVersion = (HIWORD(lpFfi->dwFileVersionMS) << 8) | LOWORD(lpFfi->dwFileVersionMS);
833 }
834
835 LocalFree(pResCopy);
836 }
837
838 return dwVersion;
839}
std::map< E_MODULE, HMODULE > mod
Definition: LocaleTests.cpp:66
DWORD dwVersion
Definition: LocaleTests.cpp:63
BOOL WINAPI FreeResource(HGLOBAL handle)
Definition: res.c:559
DWORD WINAPI SizeofResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:568
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
BOOL WINAPI VerQueryValueW(LPCVOID pBlock, LPCWSTR lpSubBlock, LPVOID *lplpBuffer, PUINT puLen)
Definition: version.c:1049
unsigned long DWORD
Definition: ntddk_ex.h:95
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1390
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
#define VS_VERSION_INFO
#define LOWORD(l)
Definition: pedump.c:82
#define RT_VERSION
Definition: pedump.c:376
#define HIWORD(l)
Definition: typedefs.h:247
#define CopyMemory
Definition: winbase.h:1710
#define FindResource
Definition: winbase.h:3793
#define LMEM_FIXED
Definition: winbase.h:368
#define MAKEINTRESOURCE
Definition: winuser.h:591

◆ silence_debug_output()

void silence_debug_output ( void  )

Definition at line 841 of file data.c.

842{
843 if (GetEnvironmentVariableA("SHIM_DEBUG_LEVEL", NULL, 0) == ERROR_ENVVAR_NOT_FOUND)
844 SetEnvironmentVariableA("SHIM_DEBUG_LEVEL", "0");
845 if (GetEnvironmentVariableA("SHIMENG_DEBUG_LEVEL", NULL, 0) == ERROR_ENVVAR_NOT_FOUND)
846 SetEnvironmentVariableA("SHIMENG_DEBUG_LEVEL", "0");
847}
#define NULL
Definition: types.h:112
#define GetEnvironmentVariableA(x, y, z)
Definition: compat.h:754
BOOL WINAPI DECLSPEC_HOTPATCH SetEnvironmentVariableA(IN LPCSTR lpName, IN LPCSTR lpValue)
Definition: environ.c:218
#define ERROR_ENVVAR_NOT_FOUND
Definition: winerror.h:261

Referenced by START_TEST().

◆ test_create_db_imp()

void test_create_db_imp ( const WCHAR name,
int  win10 
)

Definition at line 778 of file data.c.

779{
781 winetest_ok(file != INVALID_HANDLE_VALUE, "can't create file '%s'\n", wine_dbgstr_w(name));
783 {
784 DWORD size;
785 WriteFile(file, rawData, sizeof(rawData), &size, NULL);
786 if (win10)
787 {
790 }
792 }
793}
#define CloseHandle
Definition: compat.h:739
#define FILE_BEGIN
Definition: compat.h:761
#define SetFilePointer
Definition: compat.h:743
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
GLsizeiptr size
Definition: glext.h:5919
#define wine_dbgstr_w
Definition: kernel32.h:34
#define CREATE_ALWAYS
Definition: disk.h:72
static unsigned char rawData[2356]
Definition: data.c:573
static unsigned char win10Header[8]
Definition: data.c:570
static BOOL win10
Definition: render.c:66
#define GENERIC_WRITE
Definition: nt_native.h:90
void __winetest_cdecl winetest_ok(int condition, const char *msg,...)
Definition: fci.c:127
Definition: name.c:39

◆ test_create_exe_imp()

void test_create_exe_imp ( const WCHAR name,
int  skip_rsrc_exports 
)

Definition at line 467 of file data.c.

468{
469 HANDLE file;
470 char *buf, *cur;
471 DWORD size = 0x800;
472
473 buf = malloc(size);
474 winetest_ok(buf != NULL, "malloc failed\n");
475 if (buf == NULL)
476 {
477 return;
478 }
479
481 winetest_ok(file != INVALID_HANDLE_VALUE, "can't create file\n");
483 {
484 free(buf);
485 return;
486 }
487
488 memset(buf, 0, size);
489 cur = memcpy(buf, &dos_header, sizeof(dos_header));
491
492 memcpy(cur, &nt_header, sizeof(nt_header));
493 if (skip_rsrc_exports)
494 {
495 ((IMAGE_NT_HEADERS32*)cur)->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress = 0;
496 ((IMAGE_NT_HEADERS32*)cur)->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress = 0;
497 }
498 cur += sizeof(nt_header);
500
501 /* write code section: */
504
505 if (!skip_rsrc_exports)
506 {
507 /* write resource section: */
510
511 /* write minimal export directory: */
512 cur += 0x370;
513 memcpy(cur, &export_dir, sizeof(export_dir));
514 }
515
517 free(buf);
519}
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define IMAGE_DIRECTORY_ENTRY_EXPORT
Definition: compat.h:151
FxCollectionEntry * cur
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static IMAGE_DOS_HEADER dos_header
Definition: data.c:13
static IMAGE_SECTION_HEADER section_headers[]
Definition: data.c:95
static const unsigned char text_section[]
Definition: data.c:123
static const rsrc_section_t rsrc_section
Definition: data.c:235
static export_section_t export_dir
Definition: data.c:448
static IMAGE_NT_HEADERS32 nt_header
Definition: data.c:36
#define IMAGE_DIRECTORY_ENTRY_RESOURCE
Definition: pedump.c:261
#define memset(x, y, z)
Definition: compat.h:39
DWORD PointerToRawData
Definition: pedump.c:290

◆ test_create_file_imp()

void test_create_file_imp ( const WCHAR name,
const char contents,
size_t  len 
)

Definition at line 555 of file data.c.

556{
558 winetest_ok(file != INVALID_HANDLE_VALUE, "can't create file\n");
560 {
561 if (contents && len)
562 {
563 DWORD size;
565 }
567 }
568}
GLenum GLsizei len
Definition: glext.h:6722
static const char * contents
Definition: parser.c:511

Referenced by test_crc2_imp(), and test_crc_imp().

◆ test_create_ne_imp()

void test_create_ne_imp ( const WCHAR name,
int  skip_names 
)

Definition at line 523 of file data.c.

524{
525 HANDLE file;
526 DWORD size;
529 static const BYTE NE_names[] =
530 {
531 /* Show that the length is used, not the nullterm*/
532 11,'T','E','S','T','M','O','D','.','h','X','x','x',0,0,0,
533 20,'M','O','D',' ','D','E','S','C','R','I','P','T','I','O','N',' ','H','E','R','E',0,0,0
534 };
535
537 winetest_ok(file != INVALID_HANDLE_VALUE, "can't create file\n");
539 return;
540
541 MZ_hdr.e_lfanew = sizeof(MZ_hdr);
542 if (!skip_names)
543 {
544 NE_hdr.ne_restab = sizeof(NE_hdr); /* First entry (pascal string + ordinal) = module name */
545 NE_hdr.ne_nrestab = sizeof(MZ_hdr) + sizeof(NE_hdr) + 16; /* First entry (pascal string + ordinal) = module description */
546 }
547
548 WriteFile(file, &MZ_hdr, sizeof(MZ_hdr), &size, NULL);
549 WriteFile(file, &NE_hdr, sizeof(NE_hdr), &size, NULL);
550 WriteFile(file, NE_names, sizeof(NE_names), &size, NULL);
551
553}
#define IMAGE_OS2_SIGNATURE
Definition: pedump.c:90
#define IMAGE_DOS_SIGNATURE
Definition: pedump.c:89
unsigned char BYTE
Definition: xxhash.c:193

◆ test_get_db_size()

DWORD test_get_db_size ( )

Definition at line 773 of file data.c.

774{
775 return sizeof(rawData);
776}

Referenced by test_TagRef().

Variable Documentation

◆ dos_header

IMAGE_DOS_HEADER dos_header
static
Initial value:
=
{
144,
3,
0,
4,
0,
65535,
0,
184,
0,
0,
0,
64,
0,
{ 0 },
0,
0,
{ 0 },
0x80
}

Definition at line 13 of file data.c.

Referenced by main(), SOFTPUB_HashPEFile(), and test_create_exe_imp().

◆ export_dir

export_section_t export_dir
static
Initial value:
=
{
{
0,
0,
0,
0,
0x2398,
1,
0,
0,
0,
0,
0,
},
{ 'T','e','S','t','2','.','e','x','e',0 },
}

Definition at line 448 of file data.c.

Referenced by add_loadconfig(), SdbGetFileAttributes(), and test_create_exe_imp().

◆ g_WinVersion

DWORD g_WinVersion

Definition at line 795 of file data.c.

Referenced by get_host_winver().

◆ nt_header

◆ rawData

unsigned char rawData[2356]
static

Definition at line 573 of file data.c.

Referenced by test_create_db_imp(), test_get_db_size(), and WDF_LIBRARY_REGISTER_CLIENT().

◆ rsrc_section

const rsrc_section_t rsrc_section
static

Definition at line 235 of file data.c.

Referenced by test_create_exe_imp().

◆ section_headers

IMAGE_SECTION_HEADER section_headers[]
static
Initial value:
=
{
{
{ '.','t','e','x','t',0 },
{ 24 },
0x1000,
0x200,
0x200,
0,
0,
0,
0,
},
{
{ '.','r','s','r','c',0 },
{ 880 },
0x2000,
0x400,
0x400,
0,
0,
0,
0,
}
}
#define IMAGE_SCN_CNT_INITIALIZED_DATA
Definition: ntimage.h:231
#define IMAGE_SCN_CNT_CODE
Definition: ntimage.h:230
#define IMAGE_SCN_MEM_EXECUTE
Definition: ntimage.h:239
#define IMAGE_SCN_MEM_READ
Definition: ntimage.h:240

Definition at line 95 of file data.c.

Referenced by ImageGetDigestStream(), IMAGEHLP_ReportSection(), and test_create_exe_imp().

◆ text_section

const unsigned char text_section[]
static
Initial value:
=
{
0x33, 0xc0,
0xc3
}

Definition at line 123 of file data.c.

Referenced by test_create_exe_imp().

◆ win10Header

unsigned char win10Header[8]
static
Initial value:
= {
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
}

Definition at line 570 of file data.c.

Referenced by test_create_db_imp().