ReactOS 0.4.15-dev-8339-g4028de8
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 NDEBUG
 

Functions

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

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 15 of file frommem.c.

Function Documentation

◆ RosSymCreateFromMem()

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

Definition at line 19 of file frommem.c.

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