winedump.h 8.37 KB
Newer Older
1
/*
2
 *  Winedump - A Wine DLL tool
3 4 5
 *
 *  Copyright 2000 Jon Griffiths
 *
6 7 8 9 10 11 12 13 14 15 16 17
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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 21 22
 *  References:
 *  DLL symbol extraction based on file format from alib (anthonyw.cjb.net).
 *
23
 *  Option processing shamelessly cadged from winebuild.
24 25 26 27 28 29 30 31 32 33
 *
 *  All the cool functionality (prototyping, call tracing, forwarding)
 *  relies on Patrik Stridvall's 'function_grep.pl' script to work.
 *
 *  http://www.kegel.com/mangle.html
 *  Gives information on the name mangling scheme used by MS compilers,
 *  used as the starting point for the code here. Contains a few
 *  mistakes and some incorrect assumptions, but the lists of types
 *  are pure gold.
 */
34 35
#ifndef __WINE_WINEDUMP_H
#define __WINE_WINEDUMP_H
36 37 38 39 40 41 42 43 44

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <assert.h>
#include <stdarg.h>

45 46 47 48 49
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
#include "windef.h"
#include "winbase.h"

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
/* Argument type constants */
#define MAX_FUNCTION_ARGS   32

#define ARG_VOID            0x0
#define ARG_STRING          0x1
#define ARG_WIDE_STRING     0x2
#define ARG_POINTER         0x3
#define ARG_LONG            0x4
#define ARG_DOUBLE          0x5
#define ARG_STRUCT          0x6 /* By value */
#define ARG_FLOAT           0x7
#define ARG_VARARGS         0x8

/* Compound type flags */
#define CT_BY_REFERENCE     0x1
#define CT_VOLATILE         0x2
#define CT_CONST            0x4
67 68 69 70 71 72 73
#define CT_EXTENDED         0x8

/* symbol flags */
#define SYM_CDECL           0x1
#define SYM_STDCALL         0x2
#define SYM_THISCALL        0x4
#define SYM_DATA            0x8 /* Data, not a function */
74

75
typedef enum {NONE, DMGL, SPEC, DUMP} Mode;
76

77 78 79 80
/* Structure holding a parsed symbol */
typedef struct __parsed_symbol
{
  char *symbol;
81
  int   ordinal;
82 83 84
  char *return_text;
  char  return_type;
  char *function_name;
85
  int varargs;
86
  unsigned int argc;
87
  unsigned int flags;
88 89 90 91 92 93
  char  arg_type [MAX_FUNCTION_ARGS];
  char  arg_flag [MAX_FUNCTION_ARGS];
  char *arg_text [MAX_FUNCTION_ARGS];
  char *arg_name [MAX_FUNCTION_ARGS];
} parsed_symbol;

94 95 96 97 98 99 100 101
/* FIXME: Replace with some hash such as GHashTable */
typedef struct __search_symbol
{
  struct __search_symbol *next;
  int found;
  char symbolname[1];    /* static string, be ANSI C compliant by [1] */
} search_symbol;

102 103 104
/* All globals */
typedef struct __globals
{
105 106 107 108 109 110 111 112
  Mode  mode;		   /* SPEC, DEMANGLE or DUMP */

  /* Options: generic */
  int   do_quiet;          /* -q */
  int   do_verbose;        /* -v */

  /* Option arguments: generic */
  const char *input_name;  /* */
113
  const char *input_module; /* input module name generated after input_name according mode */
114 115

  /* Options: spec mode */
116 117 118 119 120
  int   do_code;           /* -c, -t, -f */
  int   do_trace;          /* -t, -f */
  int   do_cdecl;          /* -C */
  int   do_documentation;  /* -D */

121 122 123
  /* Options: dump mode */
  int   do_demangle;        /* -d */
  int   do_dumpheader;      /* -f */
124
  int   do_dump_rawdata;    /* -x */
125
  int   do_debug;           /* -G == 1, -g == 2 */
126 127

  /* Option arguments: spec mode */
128 129
  int   start_ordinal;     /* -s */
  int   end_ordinal;       /* -e */
130
  search_symbol *search_symbol; /* -S */
131
  char *directory;         /* -I */
132 133
  const char *forward_dll; /* -f */
  const char *dll_name;    /* -o */
134
  const char *uc_dll_name;       /* -o */
135 136 137

  /* Option arguments: dump mode */
  const char *dumpsect;    /* -j */
138

139
  /* internal options */
140
  int   do_ordinals;
141 142 143 144 145 146
} _globals;

extern _globals globals;

/* Names to use for output DLL */
#define OUTPUT_DLL_NAME \
147
          (globals.dll_name ? globals.dll_name : (globals.input_module ? globals.input_module : globals.input_name))
148 149 150 151 152 153 154 155
#define OUTPUT_UC_DLL_NAME globals.uc_dll_name

/* Verbosity levels */
#define QUIET   (globals.do_quiet)
#define NORMAL  (!QUIET)
#define VERBOSE (globals.do_verbose)

/* Default calling convention */
156
#define CALLING_CONVENTION (globals.do_cdecl ? SYM_CDECL : SYM_STDCALL)
157

158 159
/* Image functions */
void	dump_file(const char* name);
160 161

/* DLL functions */
162
int   dll_open (const char *dll_name);
163

164
int   dll_next_symbol (parsed_symbol * sym);
165 166

/* Symbol functions */
167 168
int   symbol_init(parsed_symbol* symbol, const char* name);

169 170 171 172 173 174 175 176
int   symbol_demangle (parsed_symbol *symbol);

int   symbol_search (parsed_symbol *symbol);

void  symbol_clear(parsed_symbol *sym);

int   symbol_is_valid_c(const parsed_symbol *sym);

177
const char *symbol_get_call_convention(const parsed_symbol *sym);
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197

const char *symbol_get_spec_type (const parsed_symbol *sym, size_t arg);

void  symbol_clean_string (const char *string);

int   symbol_get_type (const char *string);

/* Output functions */
void  output_spec_preamble (void);

void  output_spec_symbol (const parsed_symbol *sym);

void  output_header_preamble (void);

void  output_header_symbol (const parsed_symbol *sym);

void  output_c_preamble (void);

void  output_c_symbol (const parsed_symbol *sym);

198 199
void  output_prototype (FILE *file, const parsed_symbol *sym);

200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
void  output_makefile (void);

/* Misc functions */
char *str_create (size_t num_str, ...);

char *str_create_num (size_t num_str, int num, ...);

char *str_substring(const char *start, const char *end);

char *str_replace (char *str, const char *oldstr, const char *newstr);

const char *str_match (const char *str, const char *match, int *found);

const char *str_find_set (const char *str, const char *findset);

char *str_toupper (char *str);

217 218
const char *get_machine_str(int mach);

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, SIG_EMF};
221

222 223
const void*	PRD(unsigned long prd, unsigned long len);
unsigned long	Offset(const void* ptr);
224

225
typedef void (*file_dumper)(void);
226 227 228 229 230 231
int             dump_analysis(const char*, file_dumper, enum FileSig);

void            dump_data( const unsigned char *ptr, unsigned int size, const char *prefix );
const char*	get_time_str( unsigned long );
unsigned int    strlenW( const unsigned short *str );
void            dump_unicode_str( const unsigned short *str, int len );
232
const char*     get_guid_str(const GUID* guid);
233
const char*     get_symbol_str(const char* symname);
234 235
void            dump_file_header(const IMAGE_FILE_HEADER *);
void            dump_optional_header(const IMAGE_OPTIONAL_HEADER32 *, UINT);
236
void            dump_section(const IMAGE_SECTION_HEADER *);
237

238
enum FileSig    get_kind_exec(void);
239
void            dos_dump( void );
240
void            pe_dump( void );
241 242
void            ne_dump( void );
void            le_dump( void );
243
enum FileSig    get_kind_mdmp(void);
244
void            mdmp_dump( void );
245 246 247
enum FileSig    get_kind_lib(void);
void            lib_dump( void );
enum FileSig    get_kind_dbg(void);
248
void	        dbg_dump( void );
249 250
enum FileSig    get_kind_lnk(void);
void	        lnk_dump( void );
251 252
enum FileSig    get_kind_emf(void);
void            emf_dump( void );
253 254
enum FileSig    get_kind_pdb(void);
void            pdb_dump(void);
255
int             codeview_dump_symbols(const void* root, unsigned long size);
256 257
int             codeview_dump_types_from_offsets(const void* table, const DWORD* offsets, unsigned num_types);
int             codeview_dump_types_from_block(const void* table, unsigned long len);
Alexandre Julliard's avatar
Alexandre Julliard committed
258

259 260 261 262
void            dump_stabs(const void* pv_stabs, unsigned szstabs, const char* stabstr, unsigned szstr);
void		dump_codeview(unsigned long ptr, unsigned long len);
void		dump_coff(unsigned long coffbase, unsigned long len, const void* sect_map);
void		dump_frame_pointer_omission(unsigned long base, unsigned long len);
263

264 265 266 267
FILE *open_file (const char *name, const char *ext, const char *mode);

#ifdef __GNUC__
void  do_usage (void) __attribute__ ((noreturn));
268
void  fatal (const char *message)  __attribute__ ((noreturn));
269 270
#else
void  do_usage (void);
271
void  fatal (const char *message);
272 273 274 275
#endif



276
#endif /* __WINE_WINEDUMP_H */