ReactOS  0.4.13-dev-651-g5dbc677
rossym.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _ROSSYM_HEADER
 
struct  _ROSSYM_ENTRY
 
struct  _ROSSYM_REGISTERS
 
struct  _ROSSYM_PARAMETER
 
struct  _ROSSYM_LINEINFO
 
struct  _ROSSYM_AGGREGATE_MEMBER
 
struct  _ROSSYM_AGGREGATE
 
struct  _ROSSYM_CALLBACKS
 

Macros

#define ROSSYM_SECTION_NAME   ".rossym"
 

Typedefs

typedef struct _ROSSYM_HEADER ROSSYM_HEADER
 
typedef struct _ROSSYM_HEADERPROSSYM_HEADER
 
typedef struct _ROSSYM_ENTRY ROSSYM_ENTRY
 
typedef struct _ROSSYM_ENTRYPROSSYM_ENTRY
 
typedef struct _ROSSYM_REGISTERS ROSSYM_REGISTERS
 
typedef struct _ROSSYM_REGISTERSPROSSYM_REGISTERS
 
typedef struct _ROSSYM_PARAMETER ROSSYM_PARAMETER
 
typedef struct _ROSSYM_PARAMETERPROSSYM_PARAMETER
 
typedef enum _ROSSYM_LINEINFO_FLAGS ROSSYM_LINEINFO_FLAGS
 
typedef enum _ROSSYM_LINEINFO_TYPE ROSSYM_LINEINFO_STRINGTYPE
 
typedef struct _ROSSYM_LINEINFO ROSSYM_LINEINFO
 
typedef struct _ROSSYM_LINEINFOPROSSYM_LINEINFO
 
typedef struct _ROSSYM_AGGREGATE_MEMBER ROSSYM_AGGREGATE_MEMBER
 
typedef struct _ROSSYM_AGGREGATE_MEMBERPROSSYM_AGGREGATE_MEMBER
 
typedef struct _ROSSYM_AGGREGATE ROSSYM_AGGREGATE
 
typedef struct _ROSSYM_AGGREGATEPROSSYM_AGGREGATE
 
typedef struct _ROSSYM_CALLBACKS ROSSYM_CALLBACKS
 
typedef struct _ROSSYM_CALLBACKSPROSSYM_CALLBACKS
 
typedef struct _ROSSYM_INFOPROSSYM_INFO
 

Enumerations

enum  _ROSSYM_REGNAME {
  ROSSYM_X86_EAX = 0, ROSSYM_X86_ECX, ROSSYM_X86_EDX, ROSSYM_X86_EBX,
  ROSSYM_X86_ESP, ROSSYM_X86_EBP, ROSSYM_X86_ESI, ROSSYM_X86_EDI,
  ROSSYM_X64_RAX = 0, ROSSYM_X64_RDX, ROSSYM_X64_RCX, ROSSYM_X64_RBX,
  ROSSYM_X64_RSI, ROSSYM_X64_RDI, ROSSYM_X64_RBP, ROSSYM_X64_RSP,
  Rossym_X64_R8, ROSSYM_X64_R9, ROSSYM_X64_R10, ROSSYM_X64_R11,
  ROSSYM_X64_R12, ROSSYM_X64_R13, ROSSYM_X64_R14, ROSSYM_X64_R15
}
 
enum  _ROSSYM_LINEINFO_FLAGS { ROSSYM_LINEINFO_HAS_REGISTERS = 1 }
 
enum  _ROSSYM_LINEINFO_TYPE {
  ROSSYM_LINEINFO_UNKNOWN, ROSSYM_LINEINFO_NARROW_STRING, ROSSYM_LINEINFO_WIDE_STRING, ROSSYM_LINEINFO_ANSI_STRING,
  ROSSYM_LINEINFO_UNICODE_STRING, ROSSYM_LINEINFO_HANDLE
}
 

Functions

VOID RosSymInit (PROSSYM_CALLBACKS Callbacks)
 
VOID RosSymInitKernelMode (VOID)
 
VOID RosSymInitUserMode (VOID)
 
BOOLEAN RosSymCreateFromRaw (PVOID RawData, ULONG_PTR DataSize, PROSSYM_INFO *RosSymInfo)
 
BOOLEAN RosSymCreateFromMem (PVOID ImageStart, ULONG_PTR ImageSize, PROSSYM_INFO *RosSymInfo)
 
BOOLEAN RosSymCreateFromFile (PVOID FileContext, PROSSYM_INFO *RosSymInfo)
 
ULONG RosSymGetRawDataLength (PROSSYM_INFO RosSymInfo)
 
VOID RosSymGetRawData (PROSSYM_INFO RosSymInfo, PVOID RawData)
 
BOOLEAN RosSymGetAddressInformation (PROSSYM_INFO RosSymInfo, ULONG_PTR RelativeAddress, ULONG *LineNumber, char *FileName, char *FunctionName)
 
VOID RosSymFreeInfo (PROSSYM_LINEINFO RosSymLineInfo)
 
VOID RosSymDelete (PROSSYM_INFO RosSymInfo)
 
BOOLEAN RosSymAggregate (PROSSYM_INFO RosSymInfo, PCHAR Type, PROSSYM_AGGREGATE Aggregate)
 
VOID RosSymFreeAggregate (PROSSYM_AGGREGATE Aggregate)
 

Macro Definition Documentation

◆ ROSSYM_SECTION_NAME

#define ROSSYM_SECTION_NAME   ".rossym"

Definition at line 13 of file rossym.h.

Typedef Documentation

◆ PROSSYM_AGGREGATE

◆ PROSSYM_AGGREGATE_MEMBER

◆ PROSSYM_CALLBACKS

◆ PROSSYM_ENTRY

◆ PROSSYM_HEADER

◆ PROSSYM_INFO

Definition at line 122 of file rossym.h.

◆ PROSSYM_LINEINFO

◆ PROSSYM_PARAMETER

◆ PROSSYM_REGISTERS

◆ ROSSYM_AGGREGATE

◆ ROSSYM_AGGREGATE_MEMBER

◆ ROSSYM_CALLBACKS

◆ ROSSYM_ENTRY

◆ ROSSYM_HEADER

◆ ROSSYM_LINEINFO

◆ ROSSYM_LINEINFO_FLAGS

◆ ROSSYM_LINEINFO_STRINGTYPE

◆ ROSSYM_PARAMETER

◆ ROSSYM_REGISTERS

Enumeration Type Documentation

◆ _ROSSYM_LINEINFO_FLAGS

Enumerator
ROSSYM_LINEINFO_HAS_REGISTERS 

Definition at line 70 of file rossym.h.

70  {
enum _ROSSYM_LINEINFO_FLAGS ROSSYM_LINEINFO_FLAGS

◆ _ROSSYM_LINEINFO_TYPE

Enumerator
ROSSYM_LINEINFO_UNKNOWN 
ROSSYM_LINEINFO_NARROW_STRING 
ROSSYM_LINEINFO_WIDE_STRING 
ROSSYM_LINEINFO_ANSI_STRING 
ROSSYM_LINEINFO_UNICODE_STRING 
ROSSYM_LINEINFO_HANDLE 

Definition at line 74 of file rossym.h.

◆ _ROSSYM_REGNAME

Enumerator
ROSSYM_X86_EAX 
ROSSYM_X86_ECX 
ROSSYM_X86_EDX 
ROSSYM_X86_EBX 
ROSSYM_X86_ESP 
ROSSYM_X86_EBP 
ROSSYM_X86_ESI 
ROSSYM_X86_EDI 
ROSSYM_X64_RAX 
ROSSYM_X64_RDX 
ROSSYM_X64_RCX 
ROSSYM_X64_RBX 
ROSSYM_X64_RSI 
ROSSYM_X64_RDI 
ROSSYM_X64_RBP 
ROSSYM_X64_RSP 
Rossym_X64_R8 
ROSSYM_X64_R9 
ROSSYM_X64_R10 
ROSSYM_X64_R11 
ROSSYM_X64_R12 
ROSSYM_X64_R13 
ROSSYM_X64_R14 
ROSSYM_X64_R15 

Definition at line 33 of file rossym.h.

Function Documentation

◆ RosSymAggregate()

BOOLEAN RosSymAggregate ( PROSSYM_INFO  RosSymInfo,
PCHAR  Type,
PROSSYM_AGGREGATE  Aggregate 
)

Definition at line 137 of file find.c.

138 {
139  char *tchar;
140  ulong unit, typeoff = 0;
141  DwarfSym type = { };
142  // Get the first unit
143  if (dwarfaddrtounit(RosSymInfo, RosSymInfo->pe->codestart + RosSymInfo->pe->imagebase, &unit) == -1)
144  return FALSE;
145 
146  if (Type[0] == '#') {
147  for (tchar = Type + 1; *tchar; tchar++) {
148  typeoff *= 10;
149  typeoff += *tchar - '0';
150  }
151  if (dwarfseeksym(RosSymInfo, unit, typeoff, &type) == -1)
152  return FALSE;
153  } else if (dwarflookupnameinunit(RosSymInfo, unit, Type, &type) != 0 ||
154  (type.attrs.tag != TagStructType && type.attrs.tag != TagUnionType))
155  return FALSE;
156 
157  DwarfSym element = { }, inner = { };
158  int count = 0;
159 
160  werrstr("type %s (want %s) type %x\n", type.attrs.name, Type, type.attrs.type);
161 
162  if (type.attrs.have.type) {
163  if (dwarfseeksym(RosSymInfo, unit, type.attrs.type, &inner) == -1)
164  return FALSE;
165  type = inner;
166  }
167 
168  werrstr("finding members %d\n", type.attrs.haskids);
169  while (dwarfnextsymat(RosSymInfo, &type, &element) != -1) {
170  if (element.attrs.have.name)
171  werrstr("%x %s\n", element.attrs.tag, element.attrs.name);
172  if (element.attrs.tag == TagMember) count++;
173  }
174 
175  werrstr("%d members\n", count);
176 
177  if (!count) return FALSE;
178  memset(&element, 0, sizeof(element));
179  Aggregate->NumElements = count;
180  Aggregate->Elements = malloc(sizeof(ROSSYM_AGGREGATE_MEMBER) * count);
181  count = 0;
182  werrstr("Enumerating %s\n", Type);
183  while (dwarfnextsymat(RosSymInfo, &type, &element) != -1) {
184  memset(&Aggregate->Elements[count], 0, sizeof(*Aggregate->Elements));
185  if (element.attrs.tag == TagMember) {
186  if (element.attrs.have.name) {
187  Aggregate->Elements[count].Name = malloc(strlen(element.attrs.name) + 1);
188  strcpy(Aggregate->Elements[count].Name, element.attrs.name);
189  }
190  Aggregate->Elements[count].TypeId = element.attrs.type;
191  // Seek our range in loc
192  DwarfBuf locbuf;
193  DwarfBuf instream = { };
194 
195  locbuf.d = RosSymInfo;
196  locbuf.addrsize = RosSymInfo->addrsize;
197 
198  if (element.attrs.have.datamemberloc) {
199  instream = locbuf;
200  instream.p = element.attrs.datamemberloc.b.data;
201  instream.ep = element.attrs.datamemberloc.b.data + element.attrs.datamemberloc.b.len;
202  werrstr("datamemberloc type %x %p:%x\n",
203  element.attrs.have.datamemberloc,
204  element.attrs.datamemberloc.b.data, element.attrs.datamemberloc.b.len);
205  }
206 
207  if (dwarfgetarg(RosSymInfo, element.attrs.name, &instream, 0, NULL, &Aggregate->Elements[count].BaseOffset) == -1)
208  Aggregate->Elements[count].BaseOffset = -1;
209  werrstr("tag %x name %s base %x type %x\n",
210  element.attrs.tag, element.attrs.name,
211  Aggregate->Elements[count].BaseOffset,
212  Aggregate->Elements[count].TypeId);
213  count++;
214  }
215  }
216  for (count = 0; count < Aggregate->NumElements; count++) {
217  memset(&type, 0, sizeof(type));
218  memset(&inner, 0, sizeof(inner));
219  werrstr("seeking type %x (%s) from %s\n",
220  Aggregate->Elements[count].TypeId,
221  Aggregate->Elements[count].Type,
222  Aggregate->Elements[count].Name);
223  dwarfseeksym(RosSymInfo, unit, Aggregate->Elements[count].TypeId, &type);
224  while (type.attrs.have.type && type.attrs.tag != TagPointerType) {
225  if (dwarfseeksym(RosSymInfo, unit, type.attrs.type, &inner) == -1)
226  return FALSE;
227  type = inner;
228  }
229  //dwarfdumpsym(RosSymInfo, &type);
230  if (type.attrs.have.name) {
231  Aggregate->Elements[count].Type = malloc(strlen(type.attrs.name) + 1);
232  strcpy(Aggregate->Elements[count].Type, type.attrs.name);
233  } else {
234  char strbuf[128] = {'#'}, *bufptr = strbuf + 1;
235  ulong idcopy = Aggregate->Elements[count].TypeId;
236  ulong mult = 1;
237  while (mult * 10 < idcopy) mult *= 10;
238  while (mult > 0) {
239  *bufptr++ = '0' + ((idcopy / mult) % 10);
240  mult /= 10;
241  }
242  Aggregate->Elements[count].Type = malloc(strlen(strbuf) + 1);
243  strcpy(Aggregate->Elements[count].Type, strbuf);
244  }
245  if (type.attrs.tag == TagPointerType)
246  Aggregate->Elements[count].Size = RosSymInfo->addrsize;
247  else
248  Aggregate->Elements[count].Size = type.attrs.bytesize;
249  if (type.attrs.have.bitsize)
250  Aggregate->Elements[count].Bits = type.attrs.bitsize;
251  if (type.attrs.have.bitoffset)
252  Aggregate->Elements[count].FirstBit = type.attrs.bitoffset;
253  }
254  return TRUE;
255 }
uint addrsize
Definition: dwarf.h:212
int dwarfaddrtounit(Dwarf *, ulong, ulong *)
Definition: dwarfaranges.c:17
#define werrstr(str,...)
Definition: compat.h:34
#define TRUE
Definition: types.h:120
Type
Definition: Type.h:6
static unsigned int bufptr
Definition: tncon.cpp:77
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLuint GLuint GLsizei count
Definition: gl.h:1545
Dwarf * d
Definition: dwarf.h:209
ULONG NumElements
Definition: rossym.h:101
int dwarfnextsymat(Dwarf *, DwarfSym *, int)
Definition: dwarfinfo.c:293
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
int dwarfseeksym(Dwarf *, ulong, ulong, DwarfSym *)
Definition: dwarfinfo.c:171
png_const_structrp png_const_inforp int * unit
Definition: png.h:2161
smooth NULL
Definition: ftsmooth.c:416
static IStream instream
Definition: saxreader.c:2084
PROSSYM_AGGREGATE_MEMBER Elements
Definition: rossym.h:102
unsigned int len
Definition: writer.c:86
int dwarfgetarg(Dwarf *d, const char *name, DwarfBuf *locbuf, ulong cfa, PROSSYM_REGISTERS registers, ulong *value)
Definition: dwarfinfo.c:658
unsigned long ulong
Definition: linux.h:275
#define tchar
Definition: safestr.h:13
int dwarflookupnameinunit(Dwarf *, ulong, char *, DwarfSym *)
Definition: dwarfinfo.c:126
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define malloc
Definition: debug_ros.c:4
#define memset(x, y, z)
Definition: compat.h:39

◆ RosSymCreateFromFile()

BOOLEAN RosSymCreateFromFile ( PVOID  FileContext,
PROSSYM_INFO RosSymInfo 
)

Definition at line 20 of file fromfile.c.

21 {
22  IMAGE_DOS_HEADER DosHeader;
23  IMAGE_NT_HEADERS NtHeaders;
24  PIMAGE_SECTION_HEADER SectionHeaders, SectionHeader;
25  unsigned SectionIndex;
26  char SectionName[IMAGE_SIZEOF_SHORT_NAME];
27  ROSSYM_HEADER RosSymHeader;
28 
29  /* Load DOS header */
30  if (! RosSymReadFile(FileContext, &DosHeader, sizeof(IMAGE_DOS_HEADER)))
31  {
32  DPRINT1("Failed to read DOS header\n");
33  return FALSE;
34  }
35  if (! ROSSYM_IS_VALID_DOS_HEADER(&DosHeader))
36  {
37  DPRINT1("Image doesn't have a valid DOS header\n");
38  return FALSE;
39  }
40 
41  /* Load NT headers */
42  if (! RosSymSeekFile(FileContext, DosHeader.e_lfanew))
43  {
44  DPRINT1("Failed seeking to NT headers\n");
45  return FALSE;
46  }
47  if (! RosSymReadFile(FileContext, &NtHeaders, sizeof(IMAGE_NT_HEADERS)))
48  {
49  DPRINT1("Failed to read NT headers\n");
50  return FALSE;
51  }
52  if (! ROSSYM_IS_VALID_NT_HEADERS(&NtHeaders))
53  {
54  DPRINT1("Image doesn't have a valid PE header\n");
55  return FALSE;
56  }
57 
58  /* Load section headers */
59  if (! RosSymSeekFile(FileContext, (char *) IMAGE_FIRST_SECTION(&NtHeaders) -
60  (char *) &NtHeaders + DosHeader.e_lfanew))
61  {
62  DPRINT1("Failed seeking to section headers\n");
63  return FALSE;
64  }
65  SectionHeaders = RosSymAllocMem(NtHeaders.FileHeader.NumberOfSections
66  * sizeof(IMAGE_SECTION_HEADER));
67  if (NULL == SectionHeaders)
68  {
69  DPRINT1("Failed to allocate memory for %u section headers\n",
70  NtHeaders.FileHeader.NumberOfSections);
71  return FALSE;
72  }
73  if (! RosSymReadFile(FileContext, SectionHeaders,
75  * sizeof(IMAGE_SECTION_HEADER)))
76  {
77  RosSymFreeMem(SectionHeaders);
78  DPRINT1("Failed to read section headers\n");
79  return FALSE;
80  }
81 
82  /* Search for the section header */
84  SectionHeader = SectionHeaders;
85  for (SectionIndex = 0; SectionIndex < NtHeaders.FileHeader.NumberOfSections; SectionIndex++)
86  {
87  if (0 == memcmp(SectionName, SectionHeader->Name, IMAGE_SIZEOF_SHORT_NAME))
88  {
89  break;
90  }
91  SectionHeader++;
92  }
93  if (NtHeaders.FileHeader.NumberOfSections <= SectionIndex)
94  {
95  RosSymFreeMem(SectionHeaders);
96  DPRINT("No %s section found\n", ROSSYM_SECTION_NAME);
97  return FALSE;
98  }
99 
100  /* Load rossym header */
101  if (! RosSymSeekFile(FileContext, SectionHeader->PointerToRawData))
102  {
103  RosSymFreeMem(SectionHeaders);
104  DPRINT1("Failed seeking to section data\n");
105  return FALSE;
106  }
107  RosSymFreeMem(SectionHeaders);
108  if (! RosSymReadFile(FileContext, &RosSymHeader, sizeof(ROSSYM_HEADER)))
109  {
110  DPRINT1("Failed to read rossym header\n");
111  return FALSE;
112  }
113  if (RosSymHeader.SymbolsOffset < sizeof(ROSSYM_HEADER)
114  || RosSymHeader.StringsOffset < RosSymHeader.SymbolsOffset + RosSymHeader.SymbolsLength
115  || 0 != (RosSymHeader.SymbolsLength % sizeof(ROSSYM_ENTRY)))
116  {
117  DPRINT1("Invalid ROSSYM_HEADER\n");
118  return FALSE;
119  }
120 
121  *RosSymInfo = RosSymAllocMem(sizeof(ROSSYM_INFO) - sizeof(ROSSYM_HEADER)
122  + RosSymHeader.StringsOffset + RosSymHeader.StringsLength + 1);
123  if (NULL == *RosSymInfo)
124  {
125  DPRINT1("Failed to allocate memory for rossym\n");
126  return FALSE;
127  }
128  (*RosSymInfo)->Symbols = (PROSSYM_ENTRY)((char *) *RosSymInfo + sizeof(ROSSYM_INFO)
129  - sizeof(ROSSYM_HEADER) + RosSymHeader.SymbolsOffset);
130  (*RosSymInfo)->SymbolsCount = RosSymHeader.SymbolsLength / sizeof(ROSSYM_ENTRY);
131  (*RosSymInfo)->Strings = (PCHAR) *RosSymInfo + sizeof(ROSSYM_INFO) - sizeof(ROSSYM_HEADER)
132  + RosSymHeader.StringsOffset;
133  (*RosSymInfo)->StringsLength = RosSymHeader.StringsLength;
134  if (! RosSymReadFile(FileContext, *RosSymInfo + 1,
135  RosSymHeader.StringsOffset + RosSymHeader.StringsLength
136  - sizeof(ROSSYM_HEADER)))
137  {
138  DPRINT1("Failed to read rossym headers\n");
139  return FALSE;
140  }
141  /* Make sure the last string is null terminated, we allocated an extra byte for that */
142  (*RosSymInfo)->Strings[(*RosSymInfo)->StringsLength] = '\0';
143 
144  return TRUE;
145 }
#define TRUE
Definition: types.h:120
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define ROSSYM_IS_VALID_DOS_HEADER(DosHeader)
Definition: rossympriv.h:29
#define RosSymFreeMem(Area)
Definition: rossympriv.h:22
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
#define RosSymReadFile(FileContext, Buffer, Size)
Definition: rossympriv.h:23
Definition: rossym.h:26
DWORD PointerToRawData
Definition: pedump.c:290
#define ROSSYM_IS_VALID_NT_HEADERS(NtHeaders)
Definition: rossympriv.h:31
unsigned long StringsOffset
Definition: rossym.h:22
struct _ROSSYM_ENTRY * PROSSYM_ENTRY
#define IMAGE_FIRST_SECTION(NtHeader)
Definition: ntimage.h:427
struct _ROSSYM_HEADER ROSSYM_HEADER
smooth NULL
Definition: ftsmooth.c:416
struct _ROSSYM_INFO ROSSYM_INFO
void DPRINT(...)
Definition: polytest.cpp:61
IMAGE_FILE_HEADER FileHeader
Definition: ntddk_ex.h:183
_In_ PFCB _In_ PCD_NAME _In_ BOOLEAN _Inout_ PFILE_ENUM_CONTEXT FileContext
Definition: cdprocs.h:444
#define RosSymAllocMem(Size)
Definition: rossympriv.h:21
#define PCHAR
Definition: match.c:90
struct _ROSSYM_ENTRY ROSSYM_ENTRY
if(!(yy_init))
Definition: macro.lex.yy.c:714
unsigned long StringsLength
Definition: rossym.h:23
#define IMAGE_SIZEOF_SHORT_NAME
Definition: pedump.c:277
BYTE Name[IMAGE_SIZEOF_SHORT_NAME]
Definition: pedump.c:281
#define DPRINT1
Definition: precomp.h:8
unsigned long SymbolsLength
Definition: rossym.h:21
#define ROSSYM_SECTION_NAME
Definition: rossym.h:13
unsigned long SymbolsOffset
Definition: rossym.h:20
#define RosSymSeekFile(FileContext, Position)
Definition: rossympriv.h:24

Referenced by KdbpSymLoadModuleSymbols(), and KdbSymPrintAddress().

◆ RosSymCreateFromMem()

BOOLEAN RosSymCreateFromMem ( PVOID  ImageStart,
ULONG_PTR  ImageSize,
PROSSYM_INFO RosSymInfo 
)

Definition at line 20 of file frommem.c.

21 {
22  PIMAGE_DOS_HEADER DosHeader;
23  PIMAGE_NT_HEADERS NtHeaders;
24  PIMAGE_SECTION_HEADER SectionHeader;
25  ULONG SectionIndex;
26  BOOLEAN RosSymSectionFound = FALSE;
27  CHAR SectionName[IMAGE_SIZEOF_SHORT_NAME];
28 
29  /* Check if MZ header is valid */
30  DosHeader = (PIMAGE_DOS_HEADER) ImageStart;
31  if (ImageSize < sizeof(IMAGE_DOS_HEADER)
32  || ! ROSSYM_IS_VALID_DOS_HEADER(DosHeader))
33  {
34  DPRINT1("Image doesn't have a valid DOS header\n");
35  return FALSE;
36  }
37 
38  /* Locate NT header */
39  NtHeaders = (PIMAGE_NT_HEADERS)((char *) ImageStart + DosHeader->e_lfanew);
40  if (ImageSize < DosHeader->e_lfanew + sizeof(IMAGE_NT_HEADERS)
41  || ! ROSSYM_IS_VALID_NT_HEADERS(NtHeaders))
42  {
43  DPRINT1("Image doesn't have a valid PE header\n");
44  return FALSE;
45  }
46 
47  /* Search for the section header */
48  SectionHeader = IMAGE_FIRST_SECTION(NtHeaders);
49  if (ImageSize < (ULONG_PTR)((char *) (SectionHeader + NtHeaders->FileHeader.NumberOfSections)
50  - (char *) ImageStart))
51  {
52  DPRINT1("Image doesn't have valid section headers\n");
53  return FALSE;
54  }
56  for (SectionIndex = 0; SectionIndex < NtHeaders->FileHeader.NumberOfSections; SectionIndex++)
57  {
58  if (0 == memcmp(SectionName, SectionHeader->Name, IMAGE_SIZEOF_SHORT_NAME))
59  {
60  RosSymSectionFound = TRUE;
61  break;
62  }
63  SectionHeader++;
64  }
65 
66  if (!RosSymSectionFound)
67  {
68  DPRINT("No %s section found\n", ROSSYM_SECTION_NAME);
69  return FALSE;
70  }
71 
72  /* Locate the section itself */
73  if (ImageSize < SectionHeader->PointerToRawData + SectionHeader->SizeOfRawData
74  || SectionHeader->SizeOfRawData < sizeof(ROSSYM_HEADER))
75  {
76  DPRINT("Invalid %s section\n", ROSSYM_SECTION_NAME);
77  return FALSE;
78  }
79 
80  if (SectionHeader->VirtualAddress + SectionHeader->Misc.VirtualSize > ImageSize)
81  {
82  DPRINT("Bad %s section virtual size!\n", ROSSYM_SECTION_NAME);
83  return FALSE;
84  }
85 
86  /* Load it */
87  return RosSymCreateFromRaw((char *) ImageStart + SectionHeader->VirtualAddress,
88  SectionHeader->SizeOfRawData, RosSymInfo);
89 }
#define TRUE
Definition: types.h:120
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define ROSSYM_IS_VALID_DOS_HEADER(DosHeader)
Definition: rossympriv.h:29
BOOLEAN RosSymCreateFromRaw(PVOID RawData, ULONG_PTR DataSize, PROSSYM_INFO *RosSymInfo)
Definition: fromraw.c:19
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
char CHAR
Definition: xmlstorage.h:175
PIMAGE_NT_HEADERS32 PIMAGE_NT_HEADERS
Definition: ntddk_ex.h:187
#define ROSSYM_IS_VALID_NT_HEADERS(NtHeaders)
Definition: rossympriv.h:31
uint32_t ULONG_PTR
Definition: typedefs.h:63
DWORD e_lfanew
Definition: crypt.c:1156
#define IMAGE_FIRST_SECTION(NtHeader)
Definition: ntimage.h:427
unsigned char BOOLEAN
struct _IMAGE_DOS_HEADER * PIMAGE_DOS_HEADER
void DPRINT(...)
Definition: polytest.cpp:61
IMAGE_FILE_HEADER FileHeader
Definition: ntddk_ex.h:183
#define IMAGE_SIZEOF_SHORT_NAME
Definition: pedump.c:277
BYTE Name[IMAGE_SIZEOF_SHORT_NAME]
Definition: pedump.c:281
#define DPRINT1
Definition: precomp.h:8
union _IMAGE_SECTION_HEADER::@1526 Misc
#define ROSSYM_SECTION_NAME
Definition: rossym.h:13
unsigned int ULONG
Definition: retypes.h:1

Referenced by KdbSymProcessSymbols().

◆ RosSymCreateFromRaw()

BOOLEAN RosSymCreateFromRaw ( PVOID  RawData,
ULONG_PTR  DataSize,
PROSSYM_INFO RosSymInfo 
)

Definition at line 19 of file fromraw.c.

20 {
21  PROSSYM_HEADER RosSymHeader;
22 
23  RosSymHeader = (PROSSYM_HEADER) RawData;
24  if (RosSymHeader->SymbolsOffset < sizeof(ROSSYM_HEADER)
25  || RosSymHeader->StringsOffset < RosSymHeader->SymbolsOffset + RosSymHeader->SymbolsLength
26  || DataSize < RosSymHeader->StringsOffset + RosSymHeader->StringsLength
27  || 0 != (RosSymHeader->SymbolsLength % sizeof(ROSSYM_ENTRY)))
28  {
29  DPRINT1("Invalid ROSSYM_HEADER\n");
30  return FALSE;
31  }
32 
33  /* Copy */
34  *RosSymInfo = RosSymAllocMem(sizeof(ROSSYM_INFO) + RosSymHeader->SymbolsLength
35  + RosSymHeader->StringsLength + 1);
36  if (NULL == *RosSymInfo)
37  {
38  DPRINT1("Failed to allocate memory for rossym\n");
39  return FALSE;
40  }
41  (*RosSymInfo)->Symbols = (PROSSYM_ENTRY)((char *) *RosSymInfo + sizeof(ROSSYM_INFO));
42  (*RosSymInfo)->SymbolsCount = RosSymHeader->SymbolsLength / sizeof(ROSSYM_ENTRY);
43  (*RosSymInfo)->Strings = (PCHAR) *RosSymInfo + sizeof(ROSSYM_INFO) + RosSymHeader->SymbolsLength;
44  (*RosSymInfo)->StringsLength = RosSymHeader->StringsLength;
45  memcpy((*RosSymInfo)->Symbols, (char *) RosSymHeader + RosSymHeader->SymbolsOffset,
46  RosSymHeader->SymbolsLength);
47  memcpy((*RosSymInfo)->Strings, (char *) RosSymHeader + RosSymHeader->StringsOffset,
48  RosSymHeader->StringsLength);
49  /* Make sure the last string is null terminated, we allocated an extra byte for that */
50  (*RosSymInfo)->Strings[(*RosSymInfo)->StringsLength] = '\0';
51 
52  return TRUE;
53 }
#define TRUE
Definition: types.h:120
struct _ROSSYM_HEADER * PROSSYM_HEADER
unsigned long StringsOffset
Definition: rossym.h:22
struct _ROSSYM_ENTRY * PROSSYM_ENTRY
smooth NULL
Definition: ftsmooth.c:416
struct _ROSSYM_INFO ROSSYM_INFO
#define RosSymAllocMem(Size)
Definition: rossympriv.h:21
#define PCHAR
Definition: match.c:90
struct _ROSSYM_ENTRY ROSSYM_ENTRY
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned long StringsLength
Definition: rossym.h:23
#define DPRINT1
Definition: precomp.h:8
unsigned long SymbolsLength
Definition: rossym.h:21
unsigned long SymbolsOffset
Definition: rossym.h:20
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4751

Referenced by RosSymCreateFromMem().

◆ RosSymDelete()

VOID RosSymDelete ( PROSSYM_INFO  RosSymInfo)

Definition at line 16 of file delete.c.

17 {
18  RosSymFreeMem(RosSymInfo);
19 }
#define RosSymFreeMem(Area)
Definition: rossympriv.h:22

Referenced by KdbpSymRemoveCachedFile(), and KdbSymPrintAddress().

◆ RosSymFreeAggregate()

VOID RosSymFreeAggregate ( PROSSYM_AGGREGATE  Aggregate)

Definition at line 126 of file find.c.

127 {
128  int i;
129  for (i = 0; i < Aggregate->NumElements; i++) {
130  free(Aggregate->Elements[i].Name);
131  free(Aggregate->Elements[i].Type);
132  }
133  free(Aggregate->Elements);
134 }
#define free
Definition: debug_ros.c:5
ULONG NumElements
Definition: rossym.h:101
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
PROSSYM_AGGREGATE_MEMBER Elements
Definition: rossym.h:102

◆ RosSymFreeInfo()

VOID RosSymFreeInfo ( PROSSYM_LINEINFO  RosSymLineInfo)

Definition at line 398 of file dwarfpc.c.

399 {
400  int i;
401  free(LineInfo->FileName);
402  LineInfo->FileName = NULL;
403  free(LineInfo->FunctionName);
404  LineInfo->FunctionName = NULL;
405  for (i = 0; i < sizeof(LineInfo->Parameters)/sizeof(LineInfo->Parameters[0]); i++)
406  free(LineInfo->Parameters[i].ValueName);
407 }
#define free
Definition: debug_ros.c:5
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
smooth NULL
Definition: ftsmooth.c:416

Referenced by KdbSymPrintAddress().

◆ RosSymGetAddressInformation()

BOOLEAN RosSymGetAddressInformation ( PROSSYM_INFO  RosSymInfo,
ULONG_PTR  RelativeAddress,
ULONG LineNumber,
char FileName,
char FunctionName 
)

Definition at line 94 of file find.c.

99 {
100  PROSSYM_ENTRY RosSymEntry;
101 
102  DPRINT("RelativeAddress = 0x%08x\n", RelativeAddress);
103 
104  if (RosSymInfo->Symbols == NULL || RosSymInfo->SymbolsCount == 0 ||
105  RosSymInfo->Strings == NULL || RosSymInfo->StringsLength == 0)
106  {
107  DPRINT1("Uninitialized RosSymInfo\n");
108  return FALSE;
109  }
110 
112 
113  /* find symbol entry for function */
114  RosSymEntry = FindEntry(RosSymInfo, RelativeAddress);
115 
116  if (NULL == RosSymEntry)
117  {
118  DPRINT("None of the requested information was found!\n");
119  return FALSE;
120  }
121 
122  if (LineNumber != NULL)
123  {
124  *LineNumber = RosSymEntry->SourceLine;
125  }
126  if (FileName != NULL)
127  {
128  PCSTR Name = "";
129  if (RosSymEntry->FileOffset != 0)
130  {
131  Name = (PCHAR) RosSymInfo->Strings + RosSymEntry->FileOffset;
132  }
133  strcpy(FileName, Name);
134  }
135  if (FunctionName != NULL)
136  {
137  PCSTR Name = "";
138  if (RosSymEntry->FunctionOffset != 0)
139  {
140  Name = (PCHAR) RosSymInfo->Strings + RosSymEntry->FunctionOffset;
141  }
143  }
144 
145  return TRUE;
146 }
ULONG SourceLine
Definition: rossym.h:30
#define TRUE
Definition: types.h:120
Definition: rossym.h:26
ULONG FileOffset
Definition: rossym.h:29
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
PCHAR Strings
Definition: rossympriv.h:15
#define PCHAR
Definition: match.c:90
static PROSSYM_ENTRY FindEntry(IN PROSSYM_INFO RosSymInfo, IN ULONG_PTR RelativeAddress)
Definition: find.c:46
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
ULONG StringsLength
Definition: rossympriv.h:16
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 LineNumber
Definition: acpixf.h:1194
#define DPRINT1
Definition: precomp.h:8
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 ACPI_STATUS const char UINT32 const char * FunctionName
Definition: acpixf.h:1252
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
ULONG SymbolsCount
Definition: rossympriv.h:14
const char * PCSTR
Definition: typedefs.h:51
ULONG FunctionOffset
Definition: rossym.h:28
PROSSYM_ENTRY Symbols
Definition: rossympriv.h:13

Referenced by KdbSymGetAddressInformation().

◆ RosSymGetRawData()

VOID RosSymGetRawData ( PROSSYM_INFO  RosSymInfo,
PVOID  RawData 
)

Definition at line 24 of file getraw.c.

25 {
26  PROSSYM_HEADER RosSymHeader;
27 
28  RosSymHeader = (PROSSYM_HEADER) RawData;
29  RosSymHeader->SymbolsOffset = sizeof(ROSSYM_HEADER);
30  RosSymHeader->SymbolsLength = RosSymInfo->SymbolsCount * sizeof(ROSSYM_ENTRY);
31  RosSymHeader->StringsOffset = RosSymHeader->SymbolsOffset + RosSymHeader->SymbolsLength;
32  RosSymHeader->StringsLength = RosSymInfo->StringsLength;
33 
34  memcpy((char *) RawData + RosSymHeader->SymbolsOffset, RosSymInfo->Symbols,
35  RosSymHeader->SymbolsLength);
36  memcpy((char *) RawData + RosSymHeader->StringsOffset, RosSymInfo->Strings,
37  RosSymHeader->StringsLength);
38 }
struct _ROSSYM_HEADER * PROSSYM_HEADER
unsigned long StringsOffset
Definition: rossym.h:22
struct _ROSSYM_HEADER ROSSYM_HEADER
PCHAR Strings
Definition: rossympriv.h:15
struct _ROSSYM_ENTRY ROSSYM_ENTRY
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
ULONG StringsLength
Definition: rossympriv.h:16
unsigned long StringsLength
Definition: rossym.h:23
unsigned long SymbolsLength
Definition: rossym.h:21
ULONG SymbolsCount
Definition: rossympriv.h:14
unsigned long SymbolsOffset
Definition: rossym.h:20
PROSSYM_ENTRY Symbols
Definition: rossympriv.h:13

◆ RosSymGetRawDataLength()

ULONG RosSymGetRawDataLength ( PROSSYM_INFO  RosSymInfo)

Definition at line 16 of file getraw.c.

17 {
18  return sizeof(ROSSYM_HEADER)
19  + RosSymInfo->SymbolsCount * sizeof(ROSSYM_ENTRY)
20  + RosSymInfo->StringsLength;
21 }
Definition: rossym.h:26
struct _ROSSYM_HEADER ROSSYM_HEADER
ULONG StringsLength
Definition: rossympriv.h:16
ULONG SymbolsCount
Definition: rossympriv.h:14

◆ RosSymInit()

VOID RosSymInit ( PROSSYM_CALLBACKS  Callbacks)

Definition at line 17 of file init.c.

18 {
20 }
ROSSYM_CALLBACKS RosSymCallbacks
Definition: init.c:14
const struct winhelp_callbacks Callbacks
Definition: callback.c:161

Referenced by KdbInitialize(), RosSymInitKernelMode(), and RosSymInitUserMode().

◆ RosSymInitKernelMode()

VOID RosSymInitKernelMode ( VOID  )

Definition at line 32 of file initkm.c.

33 {
34  static ROSSYM_CALLBACKS KmCallbacks =
35  {
40  };
41 
42  RosSymInit(&KmCallbacks);
43 }
BOOLEAN RosSymZwReadFile(PVOID FileContext, PVOID Buffer, ULONG Size)
Definition: zwfile.c:16
BOOLEAN RosSymZwSeekFile(PVOID FileContext, ULONG_PTR Position)
Definition: zwfile.c:32
static PVOID RosSymAllocMemKM(ULONG_PTR Size)
Definition: initkm.c:20
static VOID RosSymFreeMemKM(PVOID Area)
Definition: initkm.c:26
VOID RosSymInit(PROSSYM_CALLBACKS Callbacks)
Definition: init.c:17

Referenced by KdbInitialize().

◆ RosSymInitUserMode()

VOID RosSymInitUserMode ( VOID  )

Definition at line 29 of file initum.c.

30 {
31  static ROSSYM_CALLBACKS KmCallbacks =
32  {
37  };
38 
39  RosSymInit(&KmCallbacks);
40 }
static VOID RosSymFreeMemUM(PVOID Area)
Definition: initum.c:23
BOOLEAN RosSymZwReadFile(PVOID FileContext, PVOID Buffer, ULONG Size)
Definition: zwfile.c:16
BOOLEAN RosSymZwSeekFile(PVOID FileContext, ULONG_PTR Position)
Definition: zwfile.c:32
VOID RosSymInit(PROSSYM_CALLBACKS Callbacks)
Definition: init.c:17
static PVOID RosSymAllocMemUM(ULONG_PTR Size)
Definition: initum.c:17