ReactOS 0.4.16-dev-240-gdb5fa3b
pe.c File Reference
#include <ntifs.h>
#include <ndk/ntndk.h>
#include <reactos/rossym.h>
#include "rossympriv.h"
#include <ntimage.h>
#include <debug.h>
#include "dwarf.h"
#include "pe.h"
Include dependency graph for pe.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

PeSectpesection (Pe *pe, const char *name)
 
u16int peget2 (const unsigned char *ptr)
 
u32int peget4 (const unsigned char *ptr)
 
u64int peget8 (const unsigned char *ptr)
 
int readn (void *filectx, char *buffer, ulong size)
 
int seek (void *filectx, ulong position, int origin)
 
static int readblock (void *fd, DwarfBlock *b, ulong off, ulong len)
 
int loaddisksection (Pe *pe, char *name, DwarfBlock *b)
 
int loadmemsection (Pe *pe, char *name, DwarfBlock *b)
 
voidRosSymAllocMemZero (ulong size, ulong count)
 
int GetStrnlen (const char *string, int maxlen)
 
void pefree (Pe *pe)
 
void xfree (void *v)
 
ulong pefindrva (struct _IMAGE_SECTION_HEADER *SectionHeaders, int NumberOfSections, ulong TargetPhysical)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 8 of file pe.c.

Function Documentation

◆ GetStrnlen()

int GetStrnlen ( const char string,
int  maxlen 
)

Definition at line 103 of file pe.c.

103 {
104 int i;
105 for (i = 0; i < maxlen && string[i]; i++);
106 return i;
107}
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

Referenced by RosSymCreateFromFile(), and RosSymCreateFromMem().

◆ loaddisksection()

int loaddisksection ( Pe pe,
char name,
DwarfBlock b 
)

Definition at line 72 of file pe.c.

73{
74 PeSect *s;
75 if((s = pesection(pe, name)) == nil)
76 return -1;
77 return readblock(pe->fd, b, s->PointerToRawData, s->SizeOfRawData);
78}
GLdouble s
Definition: gl.h:2039
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
PeSect * pesection(Pe *pe, const char *name)
Definition: pe.c:15
static int readblock(void *fd, DwarfBlock *b, ulong off, ulong len)
Definition: pe.c:57
#define nil
Definition: compat.h:23
void * fd
Definition: pe.h:15
Definition: name.c:39

Referenced by RosSymCreateFromFile().

◆ loadmemsection()

int loadmemsection ( Pe pe,
char name,
DwarfBlock b 
)

Definition at line 81 of file pe.c.

82{
83 PeSect *s;
84
85 if((s = pesection(pe, name)) == nil)
86 return -1;
87 DPRINT("Loading section %s (ImageBase %x RVA %x)\n", name, pe->fd, s->VirtualAddress);
88 b->data = RosSymAllocMem(s->SizeOfRawData);
89 b->len = s->SizeOfRawData;
90 PCHAR DataSource = ((char *)pe->fd) + s->VirtualAddress;
91 DPRINT("Copying to %x from %x (%x)\n", DataSource, b->data, b->len);
92 RtlCopyMemory(b->data, DataSource, s->SizeOfRawData);
93
94 return s->SizeOfRawData;
95}
#define RosSymAllocMem(Size)
Definition: rossympriv.h:14
#define DPRINT
Definition: sndvol32.h:73
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
char * PCHAR
Definition: typedefs.h:51

Referenced by RosSymCreateFromMem().

◆ pefindrva()

ulong pefindrva ( struct _IMAGE_SECTION_HEADER SectionHeaders,
int  NumberOfSections,
ulong  TargetPhysical 
)

Definition at line 126 of file pe.c.

126 {
127 int i;
128 DPRINT("Finding RVA for Physical %x\n", TargetPhysical);
129 for (i = 0; i < NumberOfSections; i++) {
130 DPRINT("Section %d name %s Raw %x Virt %x\n",
131 i,
132 ANSI_NAME_STRING(&SectionHeaders[i])->Buffer,
133 SectionHeaders[i].PointerToRawData,
134 SectionHeaders[i].VirtualAddress);
135 if (TargetPhysical >= SectionHeaders[i].PointerToRawData &&
136 TargetPhysical < SectionHeaders[i].PointerToRawData + SectionHeaders[i].SizeOfRawData) {
137 DPRINT("RVA %x\n", TargetPhysical - SectionHeaders[i].PointerToRawData + SectionHeaders[i].VirtualAddress);
138 return TargetPhysical - SectionHeaders[i].PointerToRawData + SectionHeaders[i].VirtualAddress;
139 }
140 }
141 return nil;
142}
Definition: bufpool.h:45
#define ANSI_NAME_STRING(s)
Definition: pe.h:59
DWORD PointerToRawData
Definition: pedump.c:290
_Must_inspect_result_ _In_ WDFDMATRANSACTION _In_ PFN_WDF_PROGRAM_DMA _In_ WDF_DMA_DIRECTION _In_ PMDL _In_ PVOID VirtualAddress

Referenced by RosSymCreateFromMem().

◆ pefree()

void pefree ( Pe pe)

Definition at line 109 of file pe.c.

109 {
110 int i;
111 for (i = 0; i < pe->nsections; i++) {
113 }
114 for (i = 0; i < pe->nsymbols; i++) {
115 free(pe->symtab[i].name);
116 }
117 free(pe->symtab);
118 free(pe->sect);
119 free(pe);
120}
#define free
Definition: debug_ros.c:5
NTSYSAPI VOID NTAPI RtlFreeAnsiString(PANSI_STRING AnsiString)
char * name
Definition: pe.h:11
struct _IMAGE_SECTION_HEADER * sect
Definition: pe.h:24
CoffSymbol * symtab
Definition: pe.h:21
ulong nsymbols
Definition: pe.h:20
int nsections
Definition: pe.h:23

Referenced by dwarfclose().

◆ peget2()

u16int peget2 ( const unsigned char ptr)

Definition at line 35 of file pe.c.

35 {
36 return *((u16int*)ptr);
37}
static PVOID ptr
Definition: dispmode.c:27
unsigned short u16int
Definition: compat.h:11

Referenced by RosSymCreateFromFile(), and RosSymCreateFromMem().

◆ peget4()

u32int peget4 ( const unsigned char ptr)

Definition at line 39 of file pe.c.

39 {
40 return *((u32int*)ptr);
41}
unsigned int u32int
Definition: compat.h:13

Referenced by RosSymCreateFromFile(), and RosSymCreateFromMem().

◆ peget8()

u64int peget8 ( const unsigned char ptr)

Definition at line 43 of file pe.c.

43 {
44 return *((u64int*)ptr);
45}
unsigned long long u64int
Definition: compat.h:15

Referenced by RosSymCreateFromFile(), and RosSymCreateFromMem().

◆ pesection()

PeSect * pesection ( Pe pe,
const char name 
)

Definition at line 15 of file pe.c.

16{
17 int i;
18 ANSI_STRING WantName;
19 RtlInitAnsiString(&WantName, name);
20 DPRINT("Searching for section %s\n", name);
21 for (i = 0; i < pe->nsections; i++) {
23 if (WantName.Length == AnsiString->Length &&
24 !memcmp(AnsiString->Buffer, name, WantName.Length)) {
25 DPRINT("Found %s (%d) @ %x (%x)\n", name, i,
26 ((PCHAR)pe->imagebase)+pe->sect[i].VirtualAddress,
27 pe->sect[i].SizeOfRawData);
28 return &pe->sect[i];
29 }
30 }
31 DPRINT("%s not found\n", name);
32 return nil;
33}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
@ AnsiString
Definition: dnslib.h:19
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
ulong imagebase
Definition: pe.h:19

Referenced by loaddisksection(), and loadmemsection().

◆ readblock()

static int readblock ( void fd,
DwarfBlock b,
ulong  off,
ulong  len 
)
static

Definition at line 57 of file pe.c.

58{
59 b->data = malloc(len);
60 if(b->data == nil)
61 return -1;
62 if(!seek(fd, off, 0) || !readn(fd, (char *)b->data, len)){
63 free(b->data);
64 b->data = nil;
65 return -1;
66 }
67 b->len = len;
68 return 0;
69}
#define malloc
Definition: debug_ros.c:4
GLenum GLsizei len
Definition: glext.h:6722
int seek(void *filectx, ulong position, int origin)
Definition: pe.c:51
int readn(void *filectx, char *buffer, ulong size)
Definition: pe.c:47
static int fd
Definition: io.c:51

Referenced by loaddisksection().

◆ readn()

int readn ( void filectx,
char buffer,
ulong  size 
)

Definition at line 47 of file pe.c.

47 {
48 return RosSymReadFile(filectx, buffer, size);
49}
GLsizeiptr size
Definition: glext.h:5919
GLuint buffer
Definition: glext.h:5915
#define RosSymReadFile(FileContext, Buffer, Size)
Definition: rossympriv.h:16

Referenced by readblock().

◆ RosSymAllocMemZero()

void * RosSymAllocMemZero ( ulong  size,
ulong  count 
)

Definition at line 97 of file pe.c.

97 {
98 void *res = RosSymAllocMem(size * count);
99 if (res) memset(res, 0, size * count);
100 return res;
101}
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint res
Definition: glext.h:9613
#define memset(x, y, z)
Definition: compat.h:39

◆ seek()

int seek ( void filectx,
ulong  position,
int  origin 
)

Definition at line 51 of file pe.c.

51 {
52 assert(origin == 0);
53 return RosSymSeekFile(filectx, position);
54}
#define assert(x)
Definition: debug.h:53
voidpf uLong int origin
Definition: ioapi.h:144
#define RosSymSeekFile(FileContext, Position)
Definition: rossympriv.h:17

Referenced by readblock().

◆ xfree()

void xfree ( void v)

Definition at line 122 of file pe.c.

122 {
123 if (v) RosSymFreeMem(v);
124}
const GLdouble * v
Definition: gl.h:2040
#define RosSymFreeMem(Area)
Definition: rossympriv.h:15