ReactOS 0.4.15-dev-5884-gab5aff5
frommem.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: lib/rossym/frommem.c
5 * PURPOSE: Creating rossym info from an in-memory image
6 *
7 * PROGRAMMERS: Ge van Geldorp (gvg@reactos.com)
8 */
9
10#define NTOSAPI
11#include <ntdef.h>
12#include <reactos/rossym.h>
13#include "rossympriv.h"
14#include <ntimage.h>
15
16#define NDEBUG
17#include <debug.h>
18
20RosSymCreateFromMem(PVOID ImageStart, ULONG_PTR ImageSize, PROSSYM_INFO *RosSymInfo)
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}
90
91/* EOF */
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
BOOLEAN RosSymCreateFromMem(PVOID ImageStart, ULONG_PTR ImageSize, PROSSYM_INFO *RosSymInfo)
Definition: frommem.c:20
#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:19
#define DPRINT
Definition: sndvol32.h:71
IMAGE_FILE_HEADER FileHeader
Definition: ntddk_ex.h:183
union _IMAGE_SECTION_HEADER::@1538 Misc
BYTE Name[IMAGE_SIZEOF_SHORT_NAME]
Definition: pedump.c:281
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
char CHAR
Definition: xmlstorage.h:175