ReactOS 0.4.15-dev-8093-g3285f69
dumpstab.c File Reference
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include "rsym.h"
Include dependency graph for dumpstab.c:

Go to the source code of this file.

Macros

#define X(n)   case n: return #n;
 

Functions

const charstab_type_name (int stab_type)
 
static int GetStabInfo (void *FileData, PIMAGE_FILE_HEADER PEFileHeader, PIMAGE_SECTION_HEADER PESectionHeaders, ULONG *StabSymbolsLength, void **StabSymbolsBase, ULONG *StabStringsLength, void **StabStringsBase)
 
static void IterateStabs (ULONG StabSymbolsLength, void *StabSymbolsBase, ULONG StabStringsLength, void *StabStringsBase, ULONG_PTR ImageBase, PIMAGE_FILE_HEADER PEFileHeader, PIMAGE_SECTION_HEADER PESectionHeaders)
 
int main (int argc, char *argv[])
 

Macro Definition Documentation

◆ X

#define X (   n)    case n: return #n;

Function Documentation

◆ GetStabInfo()

static int GetStabInfo ( void FileData,
PIMAGE_FILE_HEADER  PEFileHeader,
PIMAGE_SECTION_HEADER  PESectionHeaders,
ULONG StabSymbolsLength,
void **  StabSymbolsBase,
ULONG StabStringsLength,
void **  StabStringsBase 
)
static

Definition at line 78 of file dumpstab.c.

82{
83 ULONG Idx;
84
85 /* Load .stab and .stabstr sections if available */
86 *StabSymbolsBase = NULL;
87 *StabSymbolsLength = 0;
88 *StabStringsBase = NULL;
89 *StabStringsLength = 0;
90
91 for (Idx = 0; Idx < PEFileHeader->NumberOfSections; Idx++)
92 {
93 /* printf("section: '%.08s'\n", PESectionHeaders[Idx].Name); */
94 if ((strncmp((char*)PESectionHeaders[Idx].Name, ".stab", 5) == 0)
95 && (PESectionHeaders[Idx].Name[5] == 0))
96 {
97 /* printf(".stab section found. Size %d\n",
98 PESectionHeaders[Idx].SizeOfRawData); */
99
100 *StabSymbolsLength = PESectionHeaders[Idx].SizeOfRawData;
101 *StabSymbolsBase = (void *)((char *) FileData + PESectionHeaders[Idx].PointerToRawData);
102 }
103
104 if (strncmp((char*)PESectionHeaders[Idx].Name, ".stabstr", 8) == 0)
105 {
106 /* printf(".stabstr section found. Size %d\n",
107 PESectionHeaders[Idx].SizeOfRawData); */
108
109 *StabStringsLength = PESectionHeaders[Idx].SizeOfRawData;
110 *StabStringsBase = (void *)((char *) FileData + PESectionHeaders[Idx].PointerToRawData);
111 }
112 }
113
114 return 0;
115}
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
static FILEDATA FileData[MAX_FDS]
Definition: fs.c:51
#define NULL
Definition: types.h:112
DWORD PointerToRawData
Definition: pedump.c:290
uint32_t ULONG
Definition: typedefs.h:59

Referenced by main().

◆ IterateStabs()

static void IterateStabs ( ULONG  StabSymbolsLength,
void StabSymbolsBase,
ULONG  StabStringsLength,
void StabStringsBase,
ULONG_PTR  ImageBase,
PIMAGE_FILE_HEADER  PEFileHeader,
PIMAGE_SECTION_HEADER  PESectionHeaders 
)
static

Definition at line 118 of file dumpstab.c.

122{
124 ULONG Count, i;
125
126 e = StabSymbolsBase;
127 Count = StabSymbolsLength / sizeof(STAB_ENTRY);
128 if (Count == 0) /* No symbol info */
129 return;
130
131 printf ( "type,other,desc,value,str\n" );
132 for (i = 0; i < Count; i++)
133 {
134 printf ( "%s,%lu(0x%x),%lu(0x%x),%lu(0x%x),%s\n",
135 stab_type_name(e[i].n_type),
136 e[i].n_other,
137 e[i].n_other,
138 e[i].n_desc,
139 e[i].n_desc,
140 e[i].n_value,
141 e[i].n_value,
142 (char *) StabStringsBase + e[i].n_strx );
143 }
144}
const char * stab_type_name(int stab_type)
Definition: dumpstab.c:31
#define printf
Definition: freeldr.h:97
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define e
Definition: ke_i.h:82
int Count
Definition: noreturn.cpp:7
struct _STAB_ENTRY STAB_ENTRY
Definition: rsym.h:38

Referenced by main().

◆ main()

int main ( int argc  ,
char argv[] 
)

Definition at line 146 of file dumpstab.c.

147{
148 PIMAGE_DOS_HEADER PEDosHeader;
149 PIMAGE_FILE_HEADER PEFileHeader;
150 PIMAGE_OPTIONAL_HEADER PEOptHeader;
151 PIMAGE_SECTION_HEADER PESectionHeaders;
152 ULONG ImageBase;
153 void *StabBase;
154 ULONG StabsLength;
155 void *StabStringBase;
156 ULONG StabStringsLength;
157 char* path1;
158 size_t FileSize;
159 void *FileData;
160
161 if (2 != argc)
162 {
163 fprintf(stderr, "Usage: dumpstabs <exefile>\n");
164 exit(1);
165 }
166
167 path1 = convert_path(argv[1]);
168
170 if ( !FileData )
171 {
172 fprintf ( stderr, "An error occured loading '%s'\n", path1 );
173 exit(1);
174 }
175
176 /* Check if MZ header exists */
177 PEDosHeader = (PIMAGE_DOS_HEADER) FileData;
178 if (PEDosHeader->e_magic != IMAGE_DOS_MAGIC || PEDosHeader->e_lfanew == 0L)
179 {
180 perror("Input file is not a PE image.\n");
181 free(FileData);
182 exit(1);
183 }
184
185 /* Locate PE file header */
186 /* sizeof(ULONG) = sizeof(MAGIC) */
187 PEFileHeader = (PIMAGE_FILE_HEADER)((char *) FileData + PEDosHeader->e_lfanew + sizeof(ULONG));
188
189 /* Locate optional header */
190 assert(sizeof(ULONG) == 4);
191 PEOptHeader = (PIMAGE_OPTIONAL_HEADER)(PEFileHeader + 1);
192 ImageBase = PEOptHeader->ImageBase;
193
194 /* Locate PE section headers */
195 PESectionHeaders = (PIMAGE_SECTION_HEADER)((char *) PEOptHeader + PEFileHeader->SizeOfOptionalHeader);
196
197 if (GetStabInfo(FileData, PEFileHeader, PESectionHeaders, &StabsLength, &StabBase,
198 &StabStringsLength, &StabStringBase))
199 {
200 free(FileData);
201 exit(1);
202 }
203
204 IterateStabs( StabsLength, StabBase, StabStringsLength, StabStringBase,
205 ImageBase, PEFileHeader, PESectionHeaders);
206
207 free(FileData);
208
209 return 0;
210}
static int argc
Definition: ServiceArgs.c:12
#define free
Definition: debug_ros.c:5
static UINT load_file(MSIRECORD *row, LPVOID param)
Definition: action.c:1032
#define assert(x)
Definition: debug.h:53
static void IterateStabs(ULONG StabSymbolsLength, void *StabSymbolsBase, ULONG StabStringsLength, void *StabStringsBase, ULONG_PTR ImageBase, PIMAGE_FILE_HEADER PEFileHeader, PIMAGE_SECTION_HEADER PESectionHeaders)
Definition: dumpstab.c:118
static int GetStabInfo(void *FileData, PIMAGE_FILE_HEADER PEFileHeader, PIMAGE_SECTION_HEADER PESectionHeaders, ULONG *StabSymbolsLength, void **StabSymbolsBase, ULONG *StabStringsLength, void **StabStringsBase)
Definition: dumpstab.c:78
struct _IMAGE_DOS_HEADER * PIMAGE_DOS_HEADER
struct _IMAGE_FILE_HEADER * PIMAGE_FILE_HEADER
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
Definition: fsrtlfuncs.h:108
_CRTIMP void __cdecl perror(_In_opt_z_ const char *_ErrMsg)
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
static const WCHAR path1[]
Definition: path.c:28
#define argv
Definition: mplay32.c:18
#define L(x)
Definition: ntvdm.h:50
#define IMAGE_DOS_MAGIC
Definition: pecoff.h:6
struct _IMAGE_SECTION_HEADER * PIMAGE_SECTION_HEADER
struct _IMAGE_OPTIONAL_HEADER * PIMAGE_OPTIONAL_HEADER
char * convert_path(char *origpath)
Definition: rcopy.c:11
#define exit(n)
Definition: config.h:202
WORD SizeOfOptionalHeader
Definition: ntddk_ex.h:127

◆ stab_type_name()

const char * stab_type_name ( int  stab_type)

Definition at line 31 of file dumpstab.c.

32{
33 static char buf[32];
34 switch ( stab_type )
35 {
36#define X(n) case n: return #n;
37 X(N_GYSM)
38 X(N_FNAME)
39 X(N_FUN)
40 X(N_STSYM)
41 X(N_LCSYM)
42 X(N_MAIN)
43 X(N_PC)
44 X(N_NSYMS)
45 X(N_NOMAP)
46 X(N_RSYM)
47 X(N_M2C)
48 X(N_SLINE)
49 X(N_DSLINE)
50 X(N_BSLINE)
51 //X(N_BROWS)
52 X(N_DEFD)
53 X(N_EHDECL)
54 //X(N_MOD2)
55 X(N_CATCH)
56 X(N_SSYM)
57 X(N_SO)
58 X(N_LSYM)
59 X(N_BINCL)
60 X(N_SOL)
61 X(N_PSYM)
62 X(N_EINCL)
63 X(N_ENTRY)
64 X(N_LBRAC)
65 X(N_EXCL)
66 X(N_SCOPE)
67 X(N_RBRAC)
68 X(N_BCOMM)
69 X(N_ECOMM)
70 X(N_ECOML)
71 X(N_LENG)
72 }
73 sprintf ( buf, "%lu", stab_type );
74 return buf;
75}
#define X(n)
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define N_ECOMM
Definition: rsym.h:79
#define N_ENTRY
Definition: rsym.h:73
#define N_PC
Definition: rsym.h:53
#define N_ECOML
Definition: rsym.h:80
#define N_DEFD
Definition: rsym.h:62
#define N_BSLINE
Definition: rsym.h:60
#define N_EHDECL
Definition: rsym.h:63
#define N_NOMAP
Definition: rsym.h:55
#define N_NSYMS
Definition: rsym.h:54
#define N_M2C
Definition: rsym.h:57
#define N_CATCH
Definition: rsym.h:65
#define N_DSLINE
Definition: rsym.h:59
#define N_FNAME
Definition: rsym.h:48
#define N_BCOMM
Definition: rsym.h:78
#define N_SSYM
Definition: rsym.h:66
#define N_SCOPE
Definition: rsym.h:76
#define N_LENG
Definition: rsym.h:81
#define N_GYSM
Definition: rsym.h:47
#define N_PSYM
Definition: stabs.c:89
#define N_STSYM
Definition: stabs.c:75
#define N_SOL
Definition: stabs.c:88
#define N_BINCL
Definition: stabs.c:87
#define N_SO
Definition: stabs.c:84
#define N_LBRAC
Definition: stabs.c:91
#define N_RBRAC
Definition: stabs.c:93
#define N_SLINE
Definition: stabs.c:82
#define N_FUN
Definition: stabs.c:74
#define N_EINCL
Definition: stabs.c:90
#define N_RSYM
Definition: stabs.c:81
#define N_LSYM
Definition: stabs.c:86
#define N_EXCL
Definition: stabs.c:92
#define N_LCSYM
Definition: stabs.c:76
#define N_MAIN
Definition: stabs.c:77

Referenced by IterateStabs().