2001-01-04 19:45:49 +00:00
|
|
|
/*
|
2001-09-07 16:04:38 +00:00
|
|
|
* Winedump - A Wine DLL tool
|
2001-01-04 19:45:49 +00:00
|
|
|
*
|
|
|
|
* Copyright 2000 Jon Griffiths
|
|
|
|
*
|
2002-03-09 23:29:33 +00:00
|
|
|
* 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
|
2006-05-18 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-03-09 23:29:33 +00:00
|
|
|
*
|
2001-01-04 19:45:49 +00:00
|
|
|
* References:
|
|
|
|
* DLL symbol extraction based on file format from alib (anthonyw.cjb.net).
|
|
|
|
*
|
2003-11-26 03:55:01 +00:00
|
|
|
* Option processing shamelessly cadged from winebuild.
|
2001-01-04 19:45:49 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2001-09-07 16:04:38 +00:00
|
|
|
#ifndef __WINE_WINEDUMP_H
|
|
|
|
#define __WINE_WINEDUMP_H
|
2001-01-04 19:45:49 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
2006-12-07 13:43:15 +00:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
|
2001-01-04 19:45:49 +00:00
|
|
|
/* 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
|
2001-02-16 19:06:05 +00:00
|
|
|
#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 */
|
2001-01-04 19:45:49 +00:00
|
|
|
|
2006-11-29 20:40:21 +00:00
|
|
|
typedef enum {NONE, DMGL, SPEC, DUMP} Mode;
|
2001-09-07 16:04:38 +00:00
|
|
|
|
2001-01-04 19:45:49 +00:00
|
|
|
/* Structure holding a parsed symbol */
|
|
|
|
typedef struct __parsed_symbol
|
|
|
|
{
|
|
|
|
char *symbol;
|
2001-02-16 19:06:05 +00:00
|
|
|
int ordinal;
|
2001-01-04 19:45:49 +00:00
|
|
|
char *return_text;
|
|
|
|
char return_type;
|
|
|
|
char *function_name;
|
2005-07-05 14:26:54 +00:00
|
|
|
int varargs;
|
2001-01-04 19:45:49 +00:00
|
|
|
unsigned int argc;
|
2001-02-16 19:06:05 +00:00
|
|
|
unsigned int flags;
|
2001-01-04 19:45:49 +00:00
|
|
|
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;
|
|
|
|
|
2002-09-16 23:59:53 +00:00
|
|
|
/* FIXME: Replace with some hash such as GHashTable */
|
|
|
|
typedef struct __search_symbol
|
|
|
|
{
|
|
|
|
struct __search_symbol *next;
|
2013-12-04 23:58:10 +00:00
|
|
|
BOOL found;
|
2002-09-16 23:59:53 +00:00
|
|
|
char symbolname[1]; /* static string, be ANSI C compliant by [1] */
|
|
|
|
} search_symbol;
|
|
|
|
|
2001-01-04 19:45:49 +00:00
|
|
|
/* All globals */
|
|
|
|
typedef struct __globals
|
|
|
|
{
|
2001-09-07 16:04:38 +00:00
|
|
|
Mode mode; /* SPEC, DEMANGLE or DUMP */
|
|
|
|
|
|
|
|
/* Options: generic */
|
2013-12-03 22:36:09 +00:00
|
|
|
BOOL do_quiet; /* -q */
|
|
|
|
BOOL do_verbose; /* -v */
|
2001-09-07 16:04:38 +00:00
|
|
|
|
|
|
|
/* Option arguments: generic */
|
|
|
|
const char *input_name; /* */
|
2001-11-05 23:54:11 +00:00
|
|
|
const char *input_module; /* input module name generated after input_name according mode */
|
2001-09-07 16:04:38 +00:00
|
|
|
|
|
|
|
/* Options: spec mode */
|
2013-12-03 22:36:09 +00:00
|
|
|
BOOL do_code; /* -c, -t, -f */
|
|
|
|
BOOL do_trace; /* -t, -f */
|
|
|
|
BOOL do_cdecl; /* -C */
|
|
|
|
BOOL do_documentation; /* -D */
|
2001-01-04 19:45:49 +00:00
|
|
|
|
2001-09-07 16:04:38 +00:00
|
|
|
/* Options: dump mode */
|
2013-12-03 22:36:09 +00:00
|
|
|
BOOL do_demangle; /* -d */
|
|
|
|
BOOL do_dumpheader; /* -f */
|
|
|
|
BOOL do_dump_rawdata; /* -x */
|
|
|
|
BOOL do_debug; /* -G == 1, -g == 2 */
|
|
|
|
BOOL do_symbol_table; /* -t */
|
2001-09-07 16:04:38 +00:00
|
|
|
|
|
|
|
/* Option arguments: spec mode */
|
2001-01-04 19:45:49 +00:00
|
|
|
int start_ordinal; /* -s */
|
|
|
|
int end_ordinal; /* -e */
|
2002-09-16 23:59:53 +00:00
|
|
|
search_symbol *search_symbol; /* -S */
|
2004-12-20 16:52:26 +00:00
|
|
|
char *directory; /* -I */
|
2001-01-04 19:45:49 +00:00
|
|
|
const char *forward_dll; /* -f */
|
|
|
|
const char *dll_name; /* -o */
|
2005-05-23 10:28:17 +00:00
|
|
|
const char *uc_dll_name; /* -o */
|
2001-09-07 16:04:38 +00:00
|
|
|
|
|
|
|
/* Option arguments: dump mode */
|
|
|
|
const char *dumpsect; /* -j */
|
2001-01-04 19:45:49 +00:00
|
|
|
} _globals;
|
|
|
|
|
|
|
|
extern _globals globals;
|
2020-01-22 21:11:23 +00:00
|
|
|
extern void *dump_base;
|
|
|
|
extern unsigned long dump_total_len;
|
2001-01-04 19:45:49 +00:00
|
|
|
|
|
|
|
/* Names to use for output DLL */
|
|
|
|
#define OUTPUT_DLL_NAME \
|
2001-11-05 23:54:11 +00:00
|
|
|
(globals.dll_name ? globals.dll_name : (globals.input_module ? globals.input_module : globals.input_name))
|
2001-01-04 19:45:49 +00:00
|
|
|
#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 */
|
2001-02-16 19:06:05 +00:00
|
|
|
#define CALLING_CONVENTION (globals.do_cdecl ? SYM_CDECL : SYM_STDCALL)
|
2001-01-04 19:45:49 +00:00
|
|
|
|
2001-09-07 16:04:38 +00:00
|
|
|
/* Image functions */
|
|
|
|
void dump_file(const char* name);
|
2001-01-04 19:45:49 +00:00
|
|
|
|
|
|
|
/* DLL functions */
|
2013-12-04 23:58:10 +00:00
|
|
|
BOOL dll_open (const char *dll_name);
|
2001-01-04 19:45:49 +00:00
|
|
|
|
2014-01-02 01:16:51 +00:00
|
|
|
BOOL dll_next_symbol (parsed_symbol * sym);
|
2001-01-04 19:45:49 +00:00
|
|
|
|
|
|
|
/* Symbol functions */
|
2014-01-02 01:16:51 +00:00
|
|
|
void symbol_init(parsed_symbol* symbol, const char* name);
|
2001-09-17 20:26:27 +00:00
|
|
|
|
2014-01-13 20:44:00 +00:00
|
|
|
BOOL symbol_demangle (parsed_symbol *symbol);
|
2001-01-04 19:45:49 +00:00
|
|
|
|
2014-01-03 00:57:01 +00:00
|
|
|
BOOL symbol_search (parsed_symbol *symbol);
|
2001-01-04 19:45:49 +00:00
|
|
|
|
|
|
|
void symbol_clear(parsed_symbol *sym);
|
|
|
|
|
2013-12-24 09:24:27 +00:00
|
|
|
BOOL symbol_is_valid_c(const parsed_symbol *sym);
|
2001-01-04 19:45:49 +00:00
|
|
|
|
2001-02-16 19:06:05 +00:00
|
|
|
const char *symbol_get_call_convention(const parsed_symbol *sym);
|
2001-01-04 19:45:49 +00:00
|
|
|
|
|
|
|
const char *symbol_get_spec_type (const parsed_symbol *sym, size_t arg);
|
|
|
|
|
2010-04-02 16:44:37 +00:00
|
|
|
void symbol_clean_string (char *string);
|
2001-01-04 19:45:49 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2001-01-28 23:08:52 +00:00
|
|
|
void output_prototype (FILE *file, const parsed_symbol *sym);
|
|
|
|
|
2001-01-04 19:45:49 +00:00
|
|
|
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);
|
|
|
|
|
2013-12-04 23:58:10 +00:00
|
|
|
const char *str_match (const char *str, const char *match, BOOL *found);
|
2001-01-04 19:45:49 +00:00
|
|
|
|
|
|
|
const char *str_find_set (const char *str, const char *findset);
|
|
|
|
|
|
|
|
char *str_toupper (char *str);
|
|
|
|
|
2006-11-28 10:40:13 +00:00
|
|
|
const char *get_machine_str(int mach);
|
|
|
|
|
2005-03-07 11:03:53 +00:00
|
|
|
/* file dumping functions */
|
2012-12-04 12:08:53 +00:00
|
|
|
enum FileSig {SIG_UNKNOWN, SIG_DOS, SIG_PE, SIG_DBG, SIG_PDB, SIG_NE, SIG_LE, SIG_MDMP, SIG_COFFLIB, SIG_LNK,
|
2020-01-22 21:11:23 +00:00
|
|
|
SIG_EMF, SIG_FNT, SIG_TLB, SIG_NLS};
|
2002-10-02 18:50:09 +00:00
|
|
|
|
2006-04-10 18:53:50 +00:00
|
|
|
const void* PRD(unsigned long prd, unsigned long len);
|
|
|
|
unsigned long Offset(const void* ptr);
|
2002-10-02 18:50:09 +00:00
|
|
|
|
2006-11-29 20:40:12 +00:00
|
|
|
typedef void (*file_dumper)(void);
|
2013-12-04 23:58:10 +00:00
|
|
|
BOOL dump_analysis(const char*, file_dumper, enum FileSig);
|
2005-03-07 11:03:53 +00:00
|
|
|
|
|
|
|
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 );
|
2007-02-10 08:10:13 +00:00
|
|
|
const char* get_guid_str(const GUID* guid);
|
2020-03-13 09:14:49 +00:00
|
|
|
const char* get_unicode_str( const WCHAR *str, int len );
|
2007-02-10 08:10:07 +00:00
|
|
|
const char* get_symbol_str(const char* symname);
|
2019-05-18 07:37:24 +00:00
|
|
|
void print_fake_dll(void);
|
2006-12-07 13:43:15 +00:00
|
|
|
void dump_file_header(const IMAGE_FILE_HEADER *);
|
|
|
|
void dump_optional_header(const IMAGE_OPTIONAL_HEADER32 *, UINT);
|
2009-12-23 21:05:44 +00:00
|
|
|
void dump_section(const IMAGE_SECTION_HEADER *, const char* strtable);
|
2005-03-07 11:03:53 +00:00
|
|
|
|
2006-11-29 20:40:12 +00:00
|
|
|
enum FileSig get_kind_exec(void);
|
2007-01-05 20:42:19 +00:00
|
|
|
void dos_dump( void );
|
2006-11-29 20:40:12 +00:00
|
|
|
void pe_dump( void );
|
2006-11-29 20:40:00 +00:00
|
|
|
void ne_dump( void );
|
|
|
|
void le_dump( void );
|
2006-11-29 20:40:12 +00:00
|
|
|
enum FileSig get_kind_mdmp(void);
|
2005-03-07 11:03:53 +00:00
|
|
|
void mdmp_dump( void );
|
2006-11-29 20:40:12 +00:00
|
|
|
enum FileSig get_kind_lib(void);
|
|
|
|
void lib_dump( void );
|
|
|
|
enum FileSig get_kind_dbg(void);
|
2006-11-29 20:40:00 +00:00
|
|
|
void dbg_dump( void );
|
2006-11-29 20:40:16 +00:00
|
|
|
enum FileSig get_kind_lnk(void);
|
|
|
|
void lnk_dump( void );
|
2006-11-29 20:40:21 +00:00
|
|
|
enum FileSig get_kind_emf(void);
|
|
|
|
void emf_dump( void );
|
2006-11-29 20:40:58 +00:00
|
|
|
enum FileSig get_kind_pdb(void);
|
|
|
|
void pdb_dump(void);
|
2009-05-11 11:56:23 +00:00
|
|
|
enum FileSig get_kind_fnt(void);
|
|
|
|
void fnt_dump( void );
|
2018-07-10 03:41:59 +00:00
|
|
|
enum FileSig get_kind_tlb(void);
|
|
|
|
void tlb_dump(void);
|
2020-01-22 21:11:23 +00:00
|
|
|
enum FileSig get_kind_nls(void);
|
|
|
|
void nls_dump(void);
|
2012-12-04 12:08:53 +00:00
|
|
|
|
2013-12-03 22:36:09 +00:00
|
|
|
BOOL codeview_dump_symbols(const void* root, unsigned long size);
|
|
|
|
BOOL codeview_dump_types_from_offsets(const void* table, const DWORD* offsets, unsigned num_types);
|
|
|
|
BOOL codeview_dump_types_from_block(const void* table, unsigned long len);
|
2011-12-11 08:25:16 +00:00
|
|
|
void codeview_dump_linetab(const char* linetab, BOOL pascal_str, const char* pfx);
|
2008-09-29 19:32:21 +00:00
|
|
|
void codeview_dump_linetab2(const char* linetab, DWORD size, const char* strimage, DWORD strsize, const char* pfx);
|
2005-01-03 17:15:37 +00:00
|
|
|
|
2006-11-29 20:40:08 +00:00
|
|
|
void dump_stabs(const void* pv_stabs, unsigned szstabs, const char* stabstr, unsigned szstr);
|
|
|
|
void dump_codeview(unsigned long ptr, unsigned long len);
|
2011-05-01 07:46:27 +00:00
|
|
|
void dump_coff(unsigned long coffbase, unsigned long len,
|
|
|
|
const IMAGE_SECTION_HEADER *sectHead);
|
2009-12-09 19:55:18 +00:00
|
|
|
void dump_coff_symbol_table(const IMAGE_SYMBOL *coff_symbols, unsigned num_sym,
|
|
|
|
const IMAGE_SECTION_HEADER *sectHead);
|
2006-11-29 20:40:08 +00:00
|
|
|
void dump_frame_pointer_omission(unsigned long base, unsigned long len);
|
2006-08-27 06:50:46 +00:00
|
|
|
|
2001-01-04 19:45:49 +00:00
|
|
|
FILE *open_file (const char *name, const char *ext, const char *mode);
|
|
|
|
|
|
|
|
#ifdef __GNUC__
|
2009-10-02 12:52:17 +00:00
|
|
|
void do_usage (const char *arg) __attribute__ ((noreturn));
|
2001-09-07 16:04:38 +00:00
|
|
|
void fatal (const char *message) __attribute__ ((noreturn));
|
2001-01-04 19:45:49 +00:00
|
|
|
#else
|
2009-10-02 12:52:17 +00:00
|
|
|
void do_usage (const char *arg);
|
2001-09-07 16:04:38 +00:00
|
|
|
void fatal (const char *message);
|
2001-01-04 19:45:49 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-09-07 16:04:38 +00:00
|
|
|
#endif /* __WINE_WINEDUMP_H */
|