ReactOS  0.4.12-dev-918-g6c6e7b8
data.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS api tests
3  * LICENSE: GPLv2+ - See COPYING in the top level directory
4  * PURPOSE: Support functions for dbghelp api test
5  * PROGRAMMER: Mark Jansen
6  */
7 
8 #include <windows.h>
9 #include <stdio.h>
10 #include <zlib.h>
11 
12 #include "wine/test.h"
13 
15 
16 static char szTempPath[MAX_PATH];
17 
18 static const char* tmpdir()
19 {
20  if (szTempPath[0] == '\0')
21  {
23  lstrcatA(szTempPath, "dbghelp_tst");
24  }
25  return szTempPath;
26 }
27 
28 static int extract_one(const char* filename, const char* resid)
29 {
31  HGLOBAL glob;
32  PVOID data, decompressed;
33  uLongf size, dstsize;
34  DWORD gccSize, dwErr;
35  HANDLE file;
36  int ret;
37  HRSRC rsrc = FindResourceA(mod, resid, MAKEINTRESOURCEA(RT_RCDATA));
38  ok(rsrc != 0, "Failed finding '%s' res\n", resid);
39  if (!rsrc)
40  return 0;
41 
42  size = SizeofResource(mod, rsrc);
43  glob = LoadResource(mod, rsrc);
44  ok(glob != NULL, "Failed loading '%s' res\n", resid);
45  if (!glob)
46  return 0;
47 
49 
50  dstsize = 1024 * 256;
51  decompressed = malloc(dstsize);
52 
53  if (uncompress(decompressed, &dstsize, data, size) != Z_OK)
54  {
55  ok(0, "uncompress failed for %s\n", resid);
56  free(decompressed);
57  return 0;
58  }
59 
60 
62  gccSize = size;
63  ret = WriteFile(file, decompressed, dstsize, &gccSize, NULL);
64  dwErr = GetLastError();
66  free(decompressed);
67  ok(ret, "WriteFile failed (%d)\n", dwErr);
68  return ret && dstsize == gccSize;
69 }
70 
71 
72 int extract_msvc_exe(char szFile[MAX_PATH])
73 {
74  const char* dir = tmpdir();
76  ok(ret, "CreateDirectoryA failed(%d)\n", GetLastError());
77 
78  sprintf(szFile, "%s\\uffs.pdb", dir);
79  if (!extract_one(szFile, "msvc_uffs.pdb"))
80  return 0;
81 
82  sprintf(szFile, "%s\\uffs.dll", dir);
83  if (!extract_one(szFile, "msvc_uffs.dll"))
84  return 0;
85 
86  return 1;
87 }
88 
90 {
91  char szFile[MAX_PATH];
92  BOOL ret;
93  const char* dir = tmpdir();
94 
95  sprintf(szFile, "%s\\uffs.pdb", dir);
96  ret = DeleteFileA(szFile);
97  ok(ret, "DeleteFileA failed(%d)\n", GetLastError());
98 
99  sprintf(szFile, "%s\\uffs.dll", dir);
100  ret = DeleteFileA(szFile);
101  ok(ret, "DeleteFileA failed(%d)\n", GetLastError());
103  ok(ret, "RemoveDirectoryA failed(%d)\n", GetLastError());
104 }
105 
106 int extract_gcc_exe(char szFile[MAX_PATH])
107 {
108  const char* dir = tmpdir();
110  ok(ret, "CreateDirectoryA failed(%d)\n", GetLastError());
111 
112  sprintf(szFile, "%s\\uffs.dll", dir);
113  if (!extract_one(szFile, "gcc_uffs.dll"))
114  return 0;
115 
116  return 1;
117 }
118 
120 {
121  char szFile[MAX_PATH];
122  BOOL ret;
123  const char* dir = tmpdir();
124 
125  sprintf(szFile, "%s\\uffs.dll", dir);
126  ret = DeleteFileA(szFile);
127  ok(ret, "DeleteFileA failed(%d)\n", GetLastError());
129  ok(ret, "RemoveDirectoryA failed(%d)\n", GetLastError());
130 }
131 
132 
133 #if 0
134 static int compress_one(const char* src, const char* dest)
135 {
136  DWORD size, size2, res;
137  FILE* file = fopen(src, "rb");
138  fseek(file, 0, SEEK_END);
139  size = ftell(file);
140  fseek(file, 0, SEEK_SET);
141 
142  Bytef* buffer, *buffer2;
144 
145  buffer = malloc(size);
146  res = fread(buffer, 1, size, file);
147 
148  fclose(file);
149 
150  if (res != size)
151  {
152  printf("Could not read file: 0x%x\n", dwErr);
153  free(buffer);
154  CloseHandle(file);
155  return 0;
156  }
157  size2 = size *2;
158  buffer2 = malloc(size2);
159  res = compress(buffer2, &size2, buffer, size);
160 
161  free(buffer);
162 
163  if (Z_OK != res)
164  {
165  free(buffer2);
166  return 0;
167  }
168 
169  file = fopen(dest, "wb");
170  res = fwrite(buffer2, 1, size2, file);
171  fclose(file);
172 
173  free(buffer2);
174 
175  return size2 == res;
176 }
177 
179 {
180  SetCurrentDirectoryA("R:/src/trunk/reactos/modules/rostests/apitests/dbghelp");
181  if (!compress_one("testdata/msvc_uffs.dll", "testdata/msvc_uffs.dll.compr"))
182  printf("msvc_uffs.dll failed\n");
183  if (!compress_one("testdata/msvc_uffs.pdb", "testdata/msvc_uffs.pdb.compr"))
184  printf("msvc_uffs.pdb failed\n");
185  if (!compress_one("testdata/gcc_uffs.dll", "testdata/gcc_uffs.dll.compr"))
186  printf("gcc_uffs.dll failed\n");
187 }
188 #endif
189 
190 #if 0
191 typedef struct _SYMBOLFILE_HEADER {
197 
198 typedef struct _ROSSYM_ENTRY {
199  ULONG Address;
204 
205 
206 static int is_metadata(const char* name)
207 {
208  size_t len = name ? strlen(name) : 0;
209  return len > 3 && name[0] == '_' && name[1] != '_' && name[len-1] == '_' && name[len-2] == '_';
210 };
211 
212 static void dump_rsym_internal(void* data)
213 {
215  PROSSYM_ENTRY Entries = (PROSSYM_ENTRY)((char *)data + RosSymHeader->SymbolsOffset);
216  size_t symbols = RosSymHeader->SymbolsLength / sizeof(ROSSYM_ENTRY);
217  size_t i;
218  char *Strings = (char *)data + RosSymHeader->StringsOffset;
219 
220  for (i = 0; i < symbols; i++)
221  {
223  if (!Entry->FileOffset)
224  {
225  if (Entry->SourceLine)
226  printf("ERR: SOURCELINE (%D) ", Entry->SourceLine);
227  if (is_metadata(Strings + Entry->FunctionOffset))
228  printf("metadata: %s: 0x%x\n", Strings + Entry->FunctionOffset, Entry->Address);
229  else
230  printf("0x%x: %s\n", Entry->Address, Strings + Entry->FunctionOffset);
231  }
232  else
233  {
234  printf("0x%x: %s (%s:%u)\n", Entry->Address,
235  Strings + Entry->FunctionOffset,
236  Strings + Entry->FileOffset,
237  Entry->SourceLine);
238  }
239  }
240 
241 }
242 
243 void dump_rsym(const char* filename)
244 {
245  char* data;
246  long size, res;
247  PIMAGE_FILE_HEADER PEFileHeader;
248  PIMAGE_OPTIONAL_HEADER PEOptHeader;
249  PIMAGE_SECTION_HEADER PESectionHeaders;
250  WORD i;
251 
252  FILE* f = fopen(filename, "rb");
253 
254  fseek(f, 0, SEEK_END);
255  size = ftell(f);
256  fseek(f, 0, SEEK_SET);
257 
258  data = malloc(size);
259  res = fread(data, 1, size, f);
260  fclose(f);
261 
262  PEFileHeader = (PIMAGE_FILE_HEADER)((char *)data + ((PIMAGE_DOS_HEADER)data)->e_lfanew + sizeof(ULONG));
263  PEOptHeader = (PIMAGE_OPTIONAL_HEADER)(PEFileHeader + 1);
264  PESectionHeaders = (PIMAGE_SECTION_HEADER)((char *)PEOptHeader + PEFileHeader->SizeOfOptionalHeader);
265 
266  for (i = 0; i < PEFileHeader->NumberOfSections; i++)
267  {
268  if (!strcmp((char *)PESectionHeaders[i].Name, ".rossym"))
269  {
270  dump_rsym_internal(data + PESectionHeaders[i].PointerToRawData);
271  break;
272  }
273  }
274  free(data);
275 }
276 
277 #endif
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
ULONG SourceLine
Definition: rossym.h:30
#define CloseHandle
Definition: compat.h:398
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
Definition: uncompr.c:86
IMAGE_DOS_HEADER __ImageBase
Definition: mstscax.cpp:17
void create_compressed_files()
static int extract_one(const char *filename, const char *resid)
Definition: data.c:28
#define free
Definition: debug_ros.c:5
int extract_msvc_exe(char szFile[MAX_PATH])
Definition: data.c:72
HRSRC WINAPI FindResourceA(HMODULE hModule, LPCSTR name, LPCSTR type)
Definition: res.c:155
static const char * tmpdir()
Definition: data.c:18
ULONG StringsOffset
Definition: rsym.h:34
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
GLuint buffer
Definition: glext.h:5915
#define MAKEINTRESOURCEA(i)
Definition: winuser.h:581
Definition: rossym.h:26
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)
const char * filename
Definition: ioapi.h:135
void cleanup_msvc_exe()
Definition: data.c:89
struct _SYMBOLFILE_HEADER * PSYMBOLFILE_HEADER
struct _ROSSYM_ENTRY * PROSSYM_ENTRY
#define sprintf(buf, format,...)
Definition: sprintf.c:55
Byte FAR Bytef
Definition: zconf.h:400
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
ULONG FileOffset
Definition: rossym.h:29
_Check_return_opt_ _CRTIMP size_t __cdecl fread(_Out_writes_bytes_(_ElementSize *_Count) void *_DstBuf, _In_ size_t _ElementSize, _In_ size_t _Count, _Inout_ FILE *_File)
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
#define Z_OK
Definition: zlib.h:177
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
BOOL WINAPI CreateDirectoryA(IN LPCSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:37
smooth NULL
Definition: ftsmooth.c:416
_Check_return_opt_ _CRTIMP int __cdecl fseek(_Inout_ FILE *_File, _In_ long _Offset, _In_ int _Origin)
int extract_gcc_exe(char szFile[MAX_PATH])
Definition: data.c:106
struct _IMAGE_DOS_HEADER * PIMAGE_DOS_HEADER
struct _IMAGE_OPTIONAL_HEADER * PIMAGE_OPTIONAL_HEADER
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
WORD SizeOfOptionalHeader
Definition: ntddk_ex.h:127
unsigned int dir
Definition: maze.c:112
struct _SYMBOLFILE_HEADER SYMBOLFILE_HEADER
#define ok(value,...)
Definition: CComObject.cpp:34
DWORD dwErr
Definition: service.c:36
#define SEEK_SET
Definition: jmemansi.c:26
LPSTR WINAPI lstrcatA(LPSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:123
struct _ROSSYM_ENTRY ROSSYM_ENTRY
GLfloat f
Definition: glext.h:7540
GLsizeiptr size
Definition: glext.h:5919
int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
Definition: compress.c:68
struct _IMAGE_FILE_HEADER * PIMAGE_FILE_HEADER
#define MAX_PATH
Definition: compat.h:26
const char file[]
Definition: icontest.c:11
static char szTempPath[MAX_PATH]
Definition: data.c:16
unsigned short WORD
Definition: ntddk_ex.h:93
#define for
Definition: utility.h:88
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR Strings[]
Definition: reg.c:35
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
void dump_rsym(const char *filename)
#define RT_RCDATA
Definition: pedump.c:372
int ret
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
BOOL WINAPI SetCurrentDirectoryA(IN LPCSTR lpPathName)
Definition: path.c:2205
GLenum GLsizei len
Definition: glext.h:6722
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
GLenum src
Definition: glext.h:6340
HANDLE HMODULE
Definition: typedefs.h:75
uLong FAR uLongf
Definition: zconf.h:405
ULONG SymbolsOffset
Definition: rsym.h:32
struct _IMAGE_SECTION_HEADER * PIMAGE_SECTION_HEADER
#define CREATE_ALWAYS
Definition: disk.h:72
ULONG StringsLength
Definition: rsym.h:35
void cleanup_gcc_exe()
Definition: data.c:119
DWORD WINAPI GetTempPathA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2053
LIST_ENTRY Entries[5]
Definition: ExDoubleList.c:8
BOOL WINAPI RemoveDirectoryA(IN LPCSTR lpPathName)
Definition: dir.c:714
char ** glob(const char *v)
Definition: fake.c:36
DWORD WINAPI SizeofResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:568
BYTE Name[IMAGE_SIZEOF_SHORT_NAME]
Definition: pedump.c:281
ULONG SymbolsLength
Definition: rsym.h:33
Definition: name.c:36
GLuint res
Definition: glext.h:9613
_Check_return_ _CRTIMP long __cdecl ftell(_Inout_ FILE *_File)
unsigned int ULONG
Definition: retypes.h:1
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define SEEK_END
Definition: cabinet.c:27
#define malloc
Definition: debug_ros.c:4
static char * dest
Definition: rtl.c:135
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:399
ULONG FunctionOffset
Definition: rossym.h:28
ULONG_PTR Address
Definition: rossym.h:27
base of all file and directory entries
Definition: entries.h:82
#define printf
Definition: config.h:203
static int mod
Definition: i386-dis.c:1273
Definition: fci.c:126