2001-01-04 20:45:49 +01:00
|
|
|
/*
|
2001-09-07 18:04:38 +02:00
|
|
|
* Winedump - A Wine DLL tool
|
2001-01-04 20:45:49 +01:00
|
|
|
*
|
|
|
|
* Copyright 2000 Jon Griffiths
|
|
|
|
*
|
2002-03-10 00:29:33 +01: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 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
2001-01-04 20:45:49 +01:00
|
|
|
* References:
|
|
|
|
* DLL symbol extraction based on file format from alib (anthonyw.cjb.net).
|
|
|
|
*
|
2003-11-26 04:55:01 +01:00
|
|
|
* Option processing shamelessly cadged from winebuild.
|
2001-01-04 20:45:49 +01:00
|
|
|
*
|
|
|
|
* All the cool functionality (prototyping, call tracing, forwarding)
|
|
|
|
* relies on Patrik Stridvall's 'function_grep.pl' script to work.
|
|
|
|
*
|
|
|
|
* http://msdn.microsoft.com/library/periodic/period96/msj/S330.htm
|
2005-06-30 20:19:33 +02:00
|
|
|
* This article provides both a description and freely downloadable
|
2001-01-04 20:45:49 +01:00
|
|
|
* implementation, in source code form, of how to extract symbols
|
2005-06-30 20:19:33 +02:00
|
|
|
* from Win32 PE executables/DLLs.
|
2001-01-04 20:45:49 +01:00
|
|
|
*
|
|
|
|
* 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 18:04:38 +02:00
|
|
|
#ifndef __WINE_WINEDUMP_H
|
|
|
|
#define __WINE_WINEDUMP_H
|
2001-01-04 20:45:49 +01:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
/* 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 20:06:05 +01: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 20:45:49 +01:00
|
|
|
|
2005-02-17 12:51:23 +01:00
|
|
|
typedef enum {NONE, DMGL, SPEC, DUMP, EMF, LNK} Mode;
|
2001-09-07 18:04:38 +02:00
|
|
|
|
2001-01-04 20:45:49 +01:00
|
|
|
/* Structure holding a parsed symbol */
|
|
|
|
typedef struct __parsed_symbol
|
|
|
|
{
|
|
|
|
char *symbol;
|
2001-02-16 20:06:05 +01:00
|
|
|
int ordinal;
|
2001-01-04 20:45:49 +01:00
|
|
|
char *return_text;
|
|
|
|
char return_type;
|
|
|
|
char *function_name;
|
2005-07-05 16:26:54 +02:00
|
|
|
int varargs;
|
2001-01-04 20:45:49 +01:00
|
|
|
unsigned int argc;
|
2001-02-16 20:06:05 +01:00
|
|
|
unsigned int flags;
|
2001-01-04 20:45:49 +01: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];
|
2005-03-07 12:03:53 +01:00
|
|
|
unsigned int n_u_refs;
|
|
|
|
char *u_ref [MAX_FUNCTION_ARGS];
|
2001-01-04 20:45:49 +01:00
|
|
|
} parsed_symbol;
|
|
|
|
|
2002-09-17 01:59:53 +02:00
|
|
|
/* 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;
|
|
|
|
|
2001-01-04 20:45:49 +01:00
|
|
|
/* All globals */
|
|
|
|
typedef struct __globals
|
|
|
|
{
|
2001-09-07 18:04:38 +02:00
|
|
|
Mode mode; /* SPEC, DEMANGLE or DUMP */
|
|
|
|
|
|
|
|
/* Options: generic */
|
|
|
|
int do_quiet; /* -q */
|
|
|
|
int do_verbose; /* -v */
|
|
|
|
|
|
|
|
/* Option arguments: generic */
|
|
|
|
const char *input_name; /* */
|
2001-11-06 00:54:11 +01:00
|
|
|
const char *input_module; /* input module name generated after input_name according mode */
|
2001-09-07 18:04:38 +02:00
|
|
|
|
|
|
|
/* Options: spec mode */
|
2001-01-04 20:45:49 +01:00
|
|
|
int do_code; /* -c, -t, -f */
|
|
|
|
int do_trace; /* -t, -f */
|
|
|
|
int do_cdecl; /* -C */
|
|
|
|
int do_documentation; /* -D */
|
|
|
|
|
2001-09-07 18:04:38 +02:00
|
|
|
/* Options: dump mode */
|
|
|
|
int do_demangle; /* -d */
|
|
|
|
int do_dumpheader; /* -f */
|
2006-08-27 08:50:46 +02:00
|
|
|
int do_debug; /* -G == 1, -g == 2 */
|
2001-09-07 18:04:38 +02:00
|
|
|
|
|
|
|
/* Option arguments: spec mode */
|
2001-01-04 20:45:49 +01:00
|
|
|
int start_ordinal; /* -s */
|
|
|
|
int end_ordinal; /* -e */
|
2002-09-17 01:59:53 +02:00
|
|
|
search_symbol *search_symbol; /* -S */
|
2004-12-20 17:52:26 +01:00
|
|
|
char *directory; /* -I */
|
2001-01-04 20:45:49 +01:00
|
|
|
const char *forward_dll; /* -f */
|
|
|
|
const char *dll_name; /* -o */
|
2005-05-23 12:28:17 +02:00
|
|
|
const char *uc_dll_name; /* -o */
|
2001-09-07 18:04:38 +02:00
|
|
|
|
|
|
|
/* Option arguments: dump mode */
|
|
|
|
const char *dumpsect; /* -j */
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-09-07 18:04:38 +02:00
|
|
|
/* internal options */
|
2001-02-16 20:06:05 +01:00
|
|
|
int do_ordinals;
|
2001-01-04 20:45:49 +01:00
|
|
|
} _globals;
|
|
|
|
|
|
|
|
extern _globals globals;
|
|
|
|
|
|
|
|
/* Names to use for output DLL */
|
|
|
|
#define OUTPUT_DLL_NAME \
|
2001-11-06 00:54:11 +01:00
|
|
|
(globals.dll_name ? globals.dll_name : (globals.input_module ? globals.input_module : globals.input_name))
|
2001-01-04 20:45:49 +01: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 20:06:05 +01:00
|
|
|
#define CALLING_CONVENTION (globals.do_cdecl ? SYM_CDECL : SYM_STDCALL)
|
2001-01-04 20:45:49 +01:00
|
|
|
|
2005-01-04 21:32:25 +01:00
|
|
|
/* EMF functions */
|
|
|
|
int dump_emf (const char *emf);
|
|
|
|
|
2005-02-17 12:51:23 +01:00
|
|
|
/* LNK functions */
|
|
|
|
int dump_lnk (const char *lnk);
|
|
|
|
|
2001-09-07 18:04:38 +02:00
|
|
|
/* Image functions */
|
|
|
|
void dump_file(const char* name);
|
2001-01-04 20:45:49 +01:00
|
|
|
|
|
|
|
/* DLL functions */
|
2004-01-15 02:47:46 +01:00
|
|
|
int dll_open (const char *dll_name);
|
2001-01-04 20:45:49 +01:00
|
|
|
|
2004-01-15 02:47:46 +01:00
|
|
|
int dll_next_symbol (parsed_symbol * sym);
|
2001-01-04 20:45:49 +01:00
|
|
|
|
|
|
|
/* Symbol functions */
|
2001-09-17 22:26:27 +02:00
|
|
|
int symbol_init(parsed_symbol* symbol, const char* name);
|
|
|
|
|
2001-01-04 20:45:49 +01:00
|
|
|
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);
|
|
|
|
|
2001-02-16 20:06:05 +01:00
|
|
|
const char *symbol_get_call_convention(const parsed_symbol *sym);
|
2001-01-04 20:45:49 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2001-01-29 00:08:52 +01:00
|
|
|
void output_prototype (FILE *file, const parsed_symbol *sym);
|
|
|
|
|
2001-01-04 20:45:49 +01: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);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2005-03-07 12:03:53 +01:00
|
|
|
/* file dumping functions */
|
|
|
|
enum FileSig {SIG_UNKNOWN, SIG_DOS, SIG_PE, SIG_DBG, SIG_NE, SIG_LE, SIG_MDMP};
|
2002-10-02 20:50:09 +02:00
|
|
|
|
2006-04-10 20:53:50 +02:00
|
|
|
const void* PRD(unsigned long prd, unsigned long len);
|
|
|
|
unsigned long Offset(const void* ptr);
|
2002-10-02 20:50:09 +02:00
|
|
|
|
2006-04-10 20:53:50 +02:00
|
|
|
typedef void (*file_dumper)(enum FileSig, const void*);
|
2005-03-07 12:03:53 +01:00
|
|
|
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 );
|
|
|
|
|
|
|
|
void ne_dump( const void *exe, size_t exe_size );
|
|
|
|
void le_dump( const void *exe, size_t exe_size );
|
|
|
|
void mdmp_dump( void );
|
2005-01-03 18:15:37 +01:00
|
|
|
|
2006-08-27 08:50:46 +02:00
|
|
|
void dump_stabs(const void* pv_stabs, unsigned szstabs, const char* stabstr, unsigned szstr);
|
|
|
|
|
2001-01-04 20:45:49 +01:00
|
|
|
FILE *open_file (const char *name, const char *ext, const char *mode);
|
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
void do_usage (void) __attribute__ ((noreturn));
|
2001-09-07 18:04:38 +02:00
|
|
|
void fatal (const char *message) __attribute__ ((noreturn));
|
2001-01-04 20:45:49 +01:00
|
|
|
#else
|
|
|
|
void do_usage (void);
|
2001-09-07 18:04:38 +02:00
|
|
|
void fatal (const char *message);
|
2001-01-04 20:45:49 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-09-07 18:04:38 +02:00
|
|
|
#endif /* __WINE_WINEDUMP_H */
|