Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/tools/winedump/winedump.h
8869 views
1
/*
2
* Winedump - A Wine DLL tool
3
*
4
* Copyright 2000 Jon Griffiths
5
*
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Lesser General Public
8
* License as published by the Free Software Foundation; either
9
* version 2.1 of the License, or (at your option) any later version.
10
*
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Lesser General Public License for more details.
15
*
16
* You should have received a copy of the GNU Lesser General Public
17
* License along with this library; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19
*
20
* References:
21
* DLL symbol extraction based on file format from alib (anthonyw.cjb.net).
22
*
23
* Option processing shamelessly cadged from winebuild.
24
*
25
* All the cool functionality (prototyping, call tracing, forwarding)
26
* relies on Patrik Stridvall's 'function_grep.pl' script to work.
27
*
28
* http://www.kegel.com/mangle.html
29
* Gives information on the name mangling scheme used by MS compilers,
30
* used as the starting point for the code here. Contains a few
31
* mistakes and some incorrect assumptions, but the lists of types
32
* are pure gold.
33
*/
34
#ifndef __WINE_WINEDUMP_H
35
#define __WINE_WINEDUMP_H
36
37
#include <stdlib.h>
38
#include <stdio.h>
39
#include <string.h>
40
#include <ctype.h>
41
#include <errno.h>
42
#include <assert.h>
43
#include <stdarg.h>
44
45
#include "../tools.h"
46
#include "windef.h"
47
#include "winbase.h"
48
#include "wine/mscvpdb.h"
49
50
/* Argument type constants */
51
#define MAX_FUNCTION_ARGS 32
52
53
#define ARG_VOID 0x0
54
#define ARG_STRING 0x1
55
#define ARG_WIDE_STRING 0x2
56
#define ARG_POINTER 0x3
57
#define ARG_LONG 0x4
58
#define ARG_DOUBLE 0x5
59
#define ARG_STRUCT 0x6 /* By value */
60
#define ARG_FLOAT 0x7
61
#define ARG_VARARGS 0x8
62
63
/* Compound type flags */
64
#define CT_BY_REFERENCE 0x1
65
#define CT_VOLATILE 0x2
66
#define CT_CONST 0x4
67
#define CT_EXTENDED 0x8
68
69
/* symbol flags */
70
#define SYM_CDECL 0x1
71
#define SYM_STDCALL 0x2
72
#define SYM_THISCALL 0x4
73
#define SYM_DATA 0x8 /* Data, not a function */
74
75
typedef enum {NONE, DMGL, SPEC, DUMP} Mode;
76
77
/* Structure holding a parsed symbol */
78
typedef struct __parsed_symbol
79
{
80
char *symbol;
81
int ordinal;
82
char *return_text;
83
char return_type;
84
char *function_name;
85
int varargs;
86
unsigned int argc;
87
unsigned int flags;
88
char arg_type [MAX_FUNCTION_ARGS];
89
char arg_flag [MAX_FUNCTION_ARGS];
90
char *arg_text [MAX_FUNCTION_ARGS];
91
char *arg_name [MAX_FUNCTION_ARGS];
92
} parsed_symbol;
93
94
/* FIXME: Replace with some hash such as GHashTable */
95
typedef struct __search_symbol
96
{
97
struct __search_symbol *next;
98
BOOL found;
99
char symbolname[1]; /* static string, be ANSI C compliant by [1] */
100
} search_symbol;
101
102
/* All globals */
103
typedef struct __globals
104
{
105
Mode mode; /* SPEC, DEMANGLE or DUMP */
106
107
/* Options: generic */
108
BOOL do_quiet; /* -q */
109
BOOL do_verbose; /* -v */
110
111
/* Option arguments: generic */
112
const char *input_name; /* */
113
const char *input_module; /* input module name generated after input_name according mode */
114
115
/* Options: spec mode */
116
BOOL do_code; /* -c, -t, -f */
117
BOOL do_trace; /* -t, -f */
118
BOOL do_cdecl; /* -C */
119
BOOL do_documentation; /* -D */
120
121
/* Options: dump mode */
122
BOOL do_demangle; /* -d */
123
BOOL do_dumpheader; /* -f */
124
BOOL do_dump_rawdata; /* -x */
125
BOOL do_debug; /* -G == 1, -g == 2 */
126
BOOL do_symbol_table; /* -t */
127
128
/* Option arguments: spec mode */
129
int start_ordinal; /* -s */
130
int end_ordinal; /* -e */
131
search_symbol *search_symbol; /* -S */
132
char *directory; /* -I */
133
const char *forward_dll; /* -f */
134
const char *dll_name; /* -o */
135
const char *uc_dll_name; /* -o */
136
137
/* Option arguments: dump mode */
138
const char **dumpsect; /* -j */
139
} _globals;
140
141
extern _globals globals;
142
extern void *dump_base;
143
extern size_t dump_total_len;
144
145
BOOL globals_dump_sect(const char*);
146
BOOL globals_dump_sect_with_option(const char *, const char *, const char **);
147
BOOL globals_dump_sect_with_range(const char *, unsigned *, unsigned *);
148
149
/* Names to use for output DLL */
150
#define OUTPUT_DLL_NAME \
151
(globals.dll_name ? globals.dll_name : (globals.input_module ? globals.input_module : globals.input_name))
152
#define OUTPUT_UC_DLL_NAME globals.uc_dll_name
153
154
/* Verbosity levels */
155
#define QUIET (globals.do_quiet)
156
#define NORMAL (!QUIET)
157
#define VERBOSE (globals.do_verbose)
158
159
/* Default calling convention */
160
#define CALLING_CONVENTION (globals.do_cdecl ? SYM_CDECL : SYM_STDCALL)
161
162
/* Image functions */
163
void dump_file(const char* name);
164
165
/* DLL functions */
166
BOOL dll_open (const char *dll_name);
167
168
BOOL dll_next_symbol (parsed_symbol * sym);
169
170
/* Symbol functions */
171
void symbol_init(parsed_symbol* symbol, const char* name);
172
173
char *demangle( const char *name );
174
175
BOOL symbol_search (parsed_symbol *symbol);
176
177
void symbol_clear(parsed_symbol *sym);
178
179
BOOL symbol_is_valid_c(const parsed_symbol *sym);
180
181
const char *symbol_get_call_convention(const parsed_symbol *sym);
182
183
const char *symbol_get_spec_type (const parsed_symbol *sym, size_t arg);
184
185
void symbol_clean_string (char *string);
186
187
int symbol_get_type (const char *string);
188
189
/* Output functions */
190
void output_spec_preamble (void);
191
192
void output_spec_symbol (const parsed_symbol *sym);
193
194
void output_header_preamble (void);
195
196
void output_header_symbol (const parsed_symbol *sym);
197
198
void output_c_preamble (void);
199
200
void output_c_symbol (const parsed_symbol *sym);
201
202
void output_prototype (FILE *file, const parsed_symbol *sym);
203
204
void output_makefile (void);
205
206
/* Misc functions */
207
char *str_substring(const char *start, const char *end);
208
209
char *str_replace (char *str, const char *oldstr, const char *newstr);
210
211
const char *str_match (const char *str, const char *match, BOOL *found);
212
213
const char *str_find_set (const char *str, const char *findset);
214
215
char *str_toupper (char *str);
216
217
const char *get_machine_str(int mach);
218
219
/* file dumping functions */
220
enum FileSig {SIG_UNKNOWN, SIG_DOS, SIG_PE, SIG_DBG, SIG_PDB, SIG_NE, SIG_LE, SIG_MDMP, SIG_COFFLIB, SIG_LNK,
221
SIG_EMF, SIG_EMFSPOOL, SIG_MF, SIG_FNT, SIG_TLB, SIG_NLS, SIG_REG};
222
223
const void* PRD(unsigned long prd, unsigned long len);
224
unsigned long Offset(const void* ptr);
225
226
typedef void (*file_dumper)(void);
227
BOOL dump_analysis(const char*, file_dumper, enum FileSig);
228
229
void dump_data_offset( const unsigned char *ptr, unsigned int size, unsigned int offset, const char *prefix );
230
void dump_data( const unsigned char *ptr, unsigned int size, const char *prefix );
231
const char* get_time_str( unsigned long );
232
unsigned int strlenW( const unsigned short *str );
233
int dump_strA( const char *str, size_t len );
234
int dump_strW( const WCHAR *str, size_t len );
235
const char* get_hexint64_str( DWORD64 l );
236
const char* get_uint64_str( DWORD64 l );
237
const char* get_guid_str(const GUID* guid);
238
const char* get_unicode_str( const WCHAR *str, int len );
239
const char* get_symbol_str(const char* symname);
240
void print_fake_dll(void);
241
void dump_file_header(const IMAGE_FILE_HEADER *, BOOL);
242
void dump_optional_header(const IMAGE_OPTIONAL_HEADER32 *);
243
void dump_section(const IMAGE_SECTION_HEADER *, const char* strtable);
244
void dump_section_characteristics(DWORD characteristics, const char* sep);
245
246
enum FileSig get_kind_exec(void);
247
void dos_dump( void );
248
void pe_dump( void );
249
void ne_dump( void );
250
void le_dump( void );
251
enum FileSig get_kind_mdmp(void);
252
void mdmp_dump( void );
253
enum FileSig get_kind_lib(void);
254
void lib_dump( void );
255
enum FileSig get_kind_dbg(void);
256
void dbg_dump( void );
257
enum FileSig get_kind_lnk(void);
258
void lnk_dump( void );
259
enum FileSig get_kind_emf(void);
260
unsigned long dump_emfrecord(const char *pfx, unsigned long offset);
261
void emf_dump( void );
262
enum FileSig get_kind_emfspool(void);
263
void emfspool_dump(void);
264
enum FileSig get_kind_mf(void);
265
void mf_dump(void);
266
enum FileSig get_kind_pdb(int fd);
267
void pdb_dump(int fd);
268
enum FileSig get_kind_fnt(void);
269
void fnt_dump( void );
270
enum FileSig get_kind_tlb(void);
271
void tlb_dump(void);
272
enum FileSig get_kind_nls(void);
273
void nls_dump(void);
274
enum FileSig get_kind_reg(void);
275
void reg_dump(void);
276
277
extern void tlb_dump_resource( void *ptr, size_t size, const char *prefix );
278
279
BOOL codeview_dump_symbols(const void* root, unsigned long start, unsigned long size);
280
BOOL codeview_dump_types_from_offsets(const void* table, const DWORD* offsets, unsigned num_types);
281
BOOL codeview_dump_types_from_block(const void* table, unsigned long len, unsigned int cvtyp_from, unsigned int cvtyp_to);
282
void codeview_dump_linetab(const char* linetab, BOOL pascal_str, const char* pfx);
283
void codeview_dump_linetab2(const char* linetab, DWORD size, const PDB_STRING_TABLE*, const char* pfx);
284
const char* pdb_get_string_table_entry(const PDB_STRING_TABLE* table, unsigned ofs);
285
286
void dump_stabs(const void* pv_stabs, unsigned szstabs, const char* stabstr, unsigned szstr);
287
void dump_codeview(unsigned long ptr, unsigned long len);
288
void dump_coff(unsigned long coffbase, unsigned long len,
289
const IMAGE_SECTION_HEADER *sectHead);
290
void dump_coff_symbol_table(const IMAGE_SYMBOL *coff_symbols, unsigned num_sym,
291
const IMAGE_SECTION_HEADER *sectHead);
292
void dump_frame_pointer_omission(unsigned long base, unsigned long len);
293
294
FILE *open_file (const char *name, const char *ext, const char *mode);
295
296
#ifdef __GNUC__
297
void do_usage (const char *arg) __attribute__ ((noreturn));
298
void fatal (const char *message) __attribute__ ((noreturn));
299
#else
300
void do_usage (const char *arg);
301
void fatal (const char *message);
302
#endif
303
304
305
306
#endif /* __WINE_WINEDUMP_H */
307
308