winedump.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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. #include <stdlib.h>
  37. #include <stdio.h>
  38. #include <string.h>
  39. #include <ctype.h>
  40. #include <errno.h>
  41. #include <assert.h>
  42. #include <stdarg.h>
  43. #include "../tools.h"
  44. #include "windef.h"
  45. #include "winbase.h"
  46. /* Argument type constants */
  47. #define MAX_FUNCTION_ARGS 32
  48. #define ARG_VOID 0x0
  49. #define ARG_STRING 0x1
  50. #define ARG_WIDE_STRING 0x2
  51. #define ARG_POINTER 0x3
  52. #define ARG_LONG 0x4
  53. #define ARG_DOUBLE 0x5
  54. #define ARG_STRUCT 0x6 /* By value */
  55. #define ARG_FLOAT 0x7
  56. #define ARG_VARARGS 0x8
  57. /* Compound type flags */
  58. #define CT_BY_REFERENCE 0x1
  59. #define CT_VOLATILE 0x2
  60. #define CT_CONST 0x4
  61. #define CT_EXTENDED 0x8
  62. /* symbol flags */
  63. #define SYM_CDECL 0x1
  64. #define SYM_STDCALL 0x2
  65. #define SYM_THISCALL 0x4
  66. #define SYM_DATA 0x8 /* Data, not a function */
  67. typedef enum {NONE, DMGL, SPEC, DUMP} Mode;
  68. /* Structure holding a parsed symbol */
  69. typedef struct __parsed_symbol
  70. {
  71. char *symbol;
  72. int ordinal;
  73. char *return_text;
  74. char return_type;
  75. char *function_name;
  76. int varargs;
  77. unsigned int argc;
  78. unsigned int flags;
  79. char arg_type [MAX_FUNCTION_ARGS];
  80. char arg_flag [MAX_FUNCTION_ARGS];
  81. char *arg_text [MAX_FUNCTION_ARGS];
  82. char *arg_name [MAX_FUNCTION_ARGS];
  83. } parsed_symbol;
  84. /* FIXME: Replace with some hash such as GHashTable */
  85. typedef struct __search_symbol
  86. {
  87. struct __search_symbol *next;
  88. BOOL found;
  89. char symbolname[1]; /* static string, be ANSI C compliant by [1] */
  90. } search_symbol;
  91. /* All globals */
  92. typedef struct __globals
  93. {
  94. Mode mode; /* SPEC, DEMANGLE or DUMP */
  95. /* Options: generic */
  96. BOOL do_quiet; /* -q */
  97. BOOL do_verbose; /* -v */
  98. /* Option arguments: generic */
  99. const char *input_name; /* */
  100. const char *input_module; /* input module name generated after input_name according mode */
  101. /* Options: spec mode */
  102. BOOL do_code; /* -c, -t, -f */
  103. BOOL do_trace; /* -t, -f */
  104. BOOL do_cdecl; /* -C */
  105. BOOL do_documentation; /* -D */
  106. /* Options: dump mode */
  107. BOOL do_demangle; /* -d */
  108. BOOL do_dumpheader; /* -f */
  109. BOOL do_dump_rawdata; /* -x */
  110. BOOL do_debug; /* -G == 1, -g == 2 */
  111. BOOL do_symbol_table; /* -t */
  112. /* Option arguments: spec mode */
  113. int start_ordinal; /* -s */
  114. int end_ordinal; /* -e */
  115. search_symbol *search_symbol; /* -S */
  116. char *directory; /* -I */
  117. const char *forward_dll; /* -f */
  118. const char *dll_name; /* -o */
  119. const char *uc_dll_name; /* -o */
  120. /* Option arguments: dump mode */
  121. const char *dumpsect; /* -j */
  122. } _globals;
  123. extern _globals globals;
  124. extern void *dump_base;
  125. extern unsigned long dump_total_len;
  126. /* Names to use for output DLL */
  127. #define OUTPUT_DLL_NAME \
  128. (globals.dll_name ? globals.dll_name : (globals.input_module ? globals.input_module : globals.input_name))
  129. #define OUTPUT_UC_DLL_NAME globals.uc_dll_name
  130. /* Verbosity levels */
  131. #define QUIET (globals.do_quiet)
  132. #define NORMAL (!QUIET)
  133. #define VERBOSE (globals.do_verbose)
  134. /* Default calling convention */
  135. #define CALLING_CONVENTION (globals.do_cdecl ? SYM_CDECL : SYM_STDCALL)
  136. /* Image functions */
  137. void dump_file(const char* name);
  138. /* DLL functions */
  139. BOOL dll_open (const char *dll_name);
  140. BOOL dll_next_symbol (parsed_symbol * sym);
  141. /* Symbol functions */
  142. void symbol_init(parsed_symbol* symbol, const char* name);
  143. BOOL symbol_demangle (parsed_symbol *symbol);
  144. BOOL symbol_search (parsed_symbol *symbol);
  145. void symbol_clear(parsed_symbol *sym);
  146. BOOL symbol_is_valid_c(const parsed_symbol *sym);
  147. const char *symbol_get_call_convention(const parsed_symbol *sym);
  148. const char *symbol_get_spec_type (const parsed_symbol *sym, size_t arg);
  149. void symbol_clean_string (char *string);
  150. int symbol_get_type (const char *string);
  151. /* Output functions */
  152. void output_spec_preamble (void);
  153. void output_spec_symbol (const parsed_symbol *sym);
  154. void output_header_preamble (void);
  155. void output_header_symbol (const parsed_symbol *sym);
  156. void output_c_preamble (void);
  157. void output_c_symbol (const parsed_symbol *sym);
  158. void output_prototype (FILE *file, const parsed_symbol *sym);
  159. void output_makefile (void);
  160. /* Misc functions */
  161. char *str_substring(const char *start, const char *end);
  162. char *str_replace (char *str, const char *oldstr, const char *newstr);
  163. const char *str_match (const char *str, const char *match, BOOL *found);
  164. const char *str_find_set (const char *str, const char *findset);
  165. char *str_toupper (char *str);
  166. const char *get_machine_str(int mach);
  167. /* file dumping functions */
  168. enum FileSig {SIG_UNKNOWN, SIG_DOS, SIG_PE, SIG_DBG, SIG_PDB, SIG_NE, SIG_LE, SIG_MDMP, SIG_COFFLIB, SIG_LNK,
  169. SIG_EMF, SIG_MF, SIG_FNT, SIG_TLB, SIG_NLS};
  170. const void* PRD(unsigned long prd, unsigned long len);
  171. unsigned long Offset(const void* ptr);
  172. typedef void (*file_dumper)(void);
  173. BOOL dump_analysis(const char*, file_dumper, enum FileSig);
  174. void dump_data( const unsigned char *ptr, unsigned int size, const char *prefix );
  175. const char* get_time_str( unsigned long );
  176. unsigned int strlenW( const unsigned short *str );
  177. void dump_unicode_str( const unsigned short *str, int len );
  178. const char* get_guid_str(const GUID* guid);
  179. const char* get_unicode_str( const WCHAR *str, int len );
  180. const char* get_symbol_str(const char* symname);
  181. void print_fake_dll(void);
  182. void dump_file_header(const IMAGE_FILE_HEADER *);
  183. void dump_optional_header(const IMAGE_OPTIONAL_HEADER32 *, UINT);
  184. void dump_section(const IMAGE_SECTION_HEADER *, const char* strtable);
  185. enum FileSig get_kind_exec(void);
  186. void dos_dump( void );
  187. void pe_dump( void );
  188. void ne_dump( void );
  189. void le_dump( void );
  190. enum FileSig get_kind_mdmp(void);
  191. void mdmp_dump( void );
  192. enum FileSig get_kind_lib(void);
  193. void lib_dump( void );
  194. enum FileSig get_kind_dbg(void);
  195. void dbg_dump( void );
  196. enum FileSig get_kind_lnk(void);
  197. void lnk_dump( void );
  198. enum FileSig get_kind_emf(void);
  199. void emf_dump( void );
  200. enum FileSig get_kind_mf(void);
  201. void mf_dump(void);
  202. enum FileSig get_kind_pdb(void);
  203. void pdb_dump(void);
  204. enum FileSig get_kind_fnt(void);
  205. void fnt_dump( void );
  206. enum FileSig get_kind_tlb(void);
  207. void tlb_dump(void);
  208. enum FileSig get_kind_nls(void);
  209. void nls_dump(void);
  210. BOOL codeview_dump_symbols(const void* root, unsigned long start, unsigned long size);
  211. BOOL codeview_dump_types_from_offsets(const void* table, const DWORD* offsets, unsigned num_types);
  212. BOOL codeview_dump_types_from_block(const void* table, unsigned long len);
  213. void codeview_dump_linetab(const char* linetab, BOOL pascal_str, const char* pfx);
  214. void codeview_dump_linetab2(const char* linetab, DWORD size, const char* strimage, DWORD strsize, const char* pfx);
  215. void dump_stabs(const void* pv_stabs, unsigned szstabs, const char* stabstr, unsigned szstr);
  216. void dump_codeview(unsigned long ptr, unsigned long len);
  217. void dump_coff(unsigned long coffbase, unsigned long len,
  218. const IMAGE_SECTION_HEADER *sectHead);
  219. void dump_coff_symbol_table(const IMAGE_SYMBOL *coff_symbols, unsigned num_sym,
  220. const IMAGE_SECTION_HEADER *sectHead);
  221. void dump_frame_pointer_omission(unsigned long base, unsigned long len);
  222. FILE *open_file (const char *name, const char *ext, const char *mode);
  223. #ifdef __GNUC__
  224. void do_usage (const char *arg) __attribute__ ((noreturn));
  225. void fatal (const char *message) __attribute__ ((noreturn));
  226. #else
  227. void do_usage (const char *arg);
  228. void fatal (const char *message);
  229. #endif
  230. #endif /* __WINE_WINEDUMP_H */