ReactOS 0.4.16-dev-197-g92996da
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#include <ntdef.h>
11#include <reactos/rossym.h>
12#include "rossympriv.h"
13#include <ntimage.h>
14
15#define NDEBUG
16#include <debug.h>
17
19RosSymCreateFromMem(PVOID ImageStart, ULONG_PTR ImageSize, PROSSYM_INFO *RosSymInfo)
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}
89
90/* 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:19
#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
union _IMAGE_SECTION_HEADER::@1567 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