2 * Winedump - A Wine DLL tool
4 * Copyright 2000 Jon Griffiths
7 * DLL symbol extraction based on file format from alib (anthonyw.cjb.net).
9 * Option processing shamelessly cadged from winebuild (www.winehq.com).
11 * All the cool functionality (prototyping, call tracing, forwarding)
12 * relies on Patrik Stridvall's 'function_grep.pl' script to work.
14 * http://msdn.microsoft.com/library/periodic/period96/msj/S330.htm
15 * This article provides both a description and freely downloadble
16 * implementation, in source code form, of how to extract symbols
17 * from Win32 PE executables/DLL's.
19 * http://www.kegel.com/mangle.html
20 * Gives information on the name mangling scheme used by MS compilers,
21 * used as the starting point for the code here. Contains a few
22 * mistakes and some incorrect assumptions, but the lists of types
25 #ifndef __WINE_WINEDUMP_H
26 #define __WINE_WINEDUMP_H
36 /* Argument type constants */
37 #define MAX_FUNCTION_ARGS 32
40 #define ARG_STRING 0x1
41 #define ARG_WIDE_STRING 0x2
42 #define ARG_POINTER 0x3
44 #define ARG_DOUBLE 0x5
45 #define ARG_STRUCT 0x6 /* By value */
47 #define ARG_VARARGS 0x8
49 /* Compound type flags */
50 #define CT_BY_REFERENCE 0x1
51 #define CT_VOLATILE 0x2
53 #define CT_EXTENDED 0x8
57 #define SYM_STDCALL 0x2
58 #define SYM_THISCALL 0x4
59 #define SYM_DATA 0x8 /* Data, not a function */
61 typedef enum {NONE
, DMGL
, SPEC
, DUMP
} Mode
;
63 /* Structure holding a parsed symbol */
64 typedef struct __parsed_symbol
74 char arg_type
[MAX_FUNCTION_ARGS
];
75 char arg_flag
[MAX_FUNCTION_ARGS
];
76 char *arg_text
[MAX_FUNCTION_ARGS
];
77 char *arg_name
[MAX_FUNCTION_ARGS
];
81 typedef struct __globals
83 Mode mode
; /* SPEC, DEMANGLE or DUMP */
85 /* Options: generic */
86 int do_quiet
; /* -q */
87 int do_verbose
; /* -v */
89 /* Option arguments: generic */
90 const char *input_name
; /* */
91 const char *input_module
; /* input module name generated after input_name according mode */
93 /* Options: spec mode */
94 int do_code
; /* -c, -t, -f */
95 int do_trace
; /* -t, -f */
96 int do_cdecl
; /* -C */
97 int do_documentation
; /* -D */
99 /* Options: dump mode */
100 int do_demangle
; /* -d */
101 int do_dumpheader
; /* -f */
103 /* Option arguments: spec mode */
104 int start_ordinal
; /* -s */
105 int end_ordinal
; /* -e */
106 const char *directory
; /* -I */
107 const char *forward_dll
; /* -f */
108 const char *dll_name
; /* -o */
109 char *uc_dll_name
; /* -o */
111 /* Option arguments: dump mode */
112 const char *dumpsect
; /* -j */
114 /* internal options */
118 extern _globals globals
;
120 /* Names to use for output DLL */
121 #define OUTPUT_DLL_NAME \
122 (globals.dll_name ? globals.dll_name : (globals.input_module ? globals.input_module : globals.input_name))
123 #define OUTPUT_UC_DLL_NAME globals.uc_dll_name
125 /* Verbosity levels */
126 #define QUIET (globals.do_quiet)
127 #define NORMAL (!QUIET)
128 #define VERBOSE (globals.do_verbose)
130 /* Default calling convention */
131 #define CALLING_CONVENTION (globals.do_cdecl ? SYM_CDECL : SYM_STDCALL)
133 /* Image functions */
134 void dump_file(const char* name
);
137 void dll_open (const char *dll_name
);
139 int dll_next_symbol (parsed_symbol
* sym
);
141 /* Symbol functions */
142 int symbol_init(parsed_symbol
* symbol
, const char* name
);
144 int symbol_demangle (parsed_symbol
*symbol
);
146 int symbol_search (parsed_symbol
*symbol
);
148 void symbol_clear(parsed_symbol
*sym
);
150 int symbol_is_valid_c(const parsed_symbol
*sym
);
152 const char *symbol_get_call_convention(const parsed_symbol
*sym
);
154 const char *symbol_get_spec_type (const parsed_symbol
*sym
, size_t arg
);
156 void symbol_clean_string (const char *string
);
158 int symbol_get_type (const char *string
);
160 /* Output functions */
161 void output_spec_preamble (void);
163 void output_spec_symbol (const parsed_symbol
*sym
);
165 void output_header_preamble (void);
167 void output_header_symbol (const parsed_symbol
*sym
);
169 void output_c_preamble (void);
171 void output_c_symbol (const parsed_symbol
*sym
);
173 void output_prototype (FILE *file
, const parsed_symbol
*sym
);
175 void output_makefile (void);
177 void output_install_script (void);
180 char *str_create (size_t num_str
, ...);
182 char *str_create_num (size_t num_str
, int num
, ...);
184 char *str_substring(const char *start
, const char *end
);
186 char *str_replace (char *str
, const char *oldstr
, const char *newstr
);
188 const char *str_match (const char *str
, const char *match
, int *found
);
190 const char *str_find_set (const char *str
, const char *findset
);
192 char *str_toupper (char *str
);
194 FILE *open_file (const char *name
, const char *ext
, const char *mode
);
197 void do_usage (void) __attribute__ ((noreturn
));
198 void fatal (const char *message
) __attribute__ ((noreturn
));
200 void do_usage (void);
201 void fatal (const char *message
);
206 #endif /* __WINE_WINEDUMP_H */