ReactOS  0.4.14-dev-323-g6fe6a88
frommem.c File Reference
#include <ntdef.h>
#include <reactos/rossym.h>
#include "rossympriv.h"
#include <ntimage.h>
#include <debug.h>
Include dependency graph for frommem.c:

Go to the source code of this file.

Macros

#define NTOSAPI
 
#define NDEBUG
 

Functions

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

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 16 of file frommem.c.

◆ NTOSAPI

#define NTOSAPI

Definition at line 10 of file frommem.c.

Function Documentation

◆ 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
union _IMAGE_SECTION_HEADER::@1545 Misc
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
#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
#define ROSSYM_SECTION_NAME
Definition: rossym.h:13
unsigned int ULONG
Definition: retypes.h:1
PIMAGE_NT_HEADERS32 PIMAGE_NT_HEADERS
Definition: ntddk_ex.h:187