ReactOS 0.4.15-dev-7842-g558ab78
pe.c File Reference
#include <precomp.h>
#include <debug.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 3 of file pe.c.

Function Documentation

◆ GetStrnlen()

int GetStrnlen ( const char string,
int  maxlen 
)

Definition at line 94 of file pe.c.

94 {
95 int i;
96 for (i = 0; i < maxlen && string[i]; i++);
97 return i;
98}
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

◆ loaddisksection()

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

Definition at line 63 of file pe.c.

64{
65 PeSect *s;
66 if((s = pesection(pe, name)) == nil)
67 return -1;
68 return readblock(pe->fd, b, s->PointerToRawData, s->SizeOfRawData);
69}
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

◆ loadmemsection()

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

Definition at line 72 of file pe.c.

73{
74 PeSect *s;
75
76 if((s = pesection(pe, name)) == nil)
77 return -1;
78 werrstr("Loading section %s (ImageBase %x RVA %x)\n", name, pe->fd, s->VirtualAddress);
79 b->data = RosSymAllocMem(s->SizeOfRawData);
80 b->len = s->SizeOfRawData;
81 PCHAR DataSource = ((char *)pe->fd) + s->VirtualAddress;
82 werrstr("Copying to %x from %x (%x)\n", DataSource, b->data, b->len);
83 RtlCopyMemory(b->data, DataSource, s->SizeOfRawData);
84
85 return s->SizeOfRawData;
86}
#define RosSymAllocMem(Size)
Definition: rossympriv.h:14
#define werrstr(str,...)
Definition: compat.h:34
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
char * PCHAR
Definition: typedefs.h:51

◆ pefindrva()

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

Definition at line 113 of file pe.c.

113 {
114 int i;
115 werrstr("Finding RVA for Physical %x\n", TargetPhysical);
116 for (i = 0; i < NumberOfSections; i++) {
117 werrstr("Section %d name %s Raw %x Virt %x\n",
118 i,
119 ANSI_NAME_STRING(&SectionHeaders[i])->Buffer,
120 SectionHeaders[i].PointerToRawData,
121 SectionHeaders[i].VirtualAddress);
122 if (TargetPhysical >= SectionHeaders[i].PointerToRawData &&
123 TargetPhysical < SectionHeaders[i].PointerToRawData + SectionHeaders[i].SizeOfRawData) {
124 werrstr("RVA %x\n", TargetPhysical - SectionHeaders[i].PointerToRawData + SectionHeaders[i].VirtualAddress);
125 return TargetPhysical - SectionHeaders[i].PointerToRawData + SectionHeaders[i].VirtualAddress;
126 }
127 }
128 return nil;
129}
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

◆ pefree()

void pefree ( Pe pe)

Definition at line 100 of file pe.c.

100 {
101 int i;
102 for (i = 0; i < pe->nsections; i++) {
104 }
105 free(pe->sect);
106 free(pe);
107}
#define free
Definition: debug_ros.c:5
NTSYSAPI VOID NTAPI RtlFreeAnsiString(PANSI_STRING AnsiString)
struct _IMAGE_SECTION_HEADER * sect
Definition: pe.h:24
int nsections
Definition: pe.h:23

◆ peget2()

u16int peget2 ( const unsigned char ptr)

Definition at line 26 of file pe.c.

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

◆ peget4()

u32int peget4 ( const unsigned char ptr)

Definition at line 30 of file pe.c.

30 {
31 return *((u32int*)ptr);
32}
unsigned int u32int
Definition: compat.h:13

◆ peget8()

u64int peget8 ( const unsigned char ptr)

Definition at line 34 of file pe.c.

34 {
35 return *((u64int*)ptr);
36}
unsigned long long u64int
Definition: compat.h:15

◆ pesection()

PeSect * pesection ( Pe pe,
const char name 
)

Definition at line 6 of file pe.c.

7{
8 int i;
9 ANSI_STRING WantName;
10 RtlInitAnsiString(&WantName, name);
11 werrstr("Searching for section %s\n", name);
12 for (i = 0; i < pe->nsections; i++) {
14 if (WantName.Length == AnsiString->Length &&
15 !memcmp(AnsiString->Buffer, name, WantName.Length)) {
16 werrstr("Found %s (%d) @ %x (%x)\n", name, i,
17 ((PCHAR)pe->imagebase)+pe->sect[i].VirtualAddress,
18 pe->sect[i].SizeOfRawData);
19 return &pe->sect[i];
20 }
21 }
22 werrstr("%s not found\n", name);
23 return nil;
24}
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

◆ readblock()

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

Definition at line 48 of file pe.c.

49{
50 b->data = malloc(len);
51 if(b->data == nil)
52 return -1;
53 if(!seek(fd, off, 0) || !readn(fd, (char *)b->data, len)){
54 free(b->data);
55 b->data = nil;
56 return -1;
57 }
58 b->len = len;
59 return 0;
60}
#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

◆ readn()

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

Definition at line 38 of file pe.c.

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

◆ RosSymAllocMemZero()

void * RosSymAllocMemZero ( ulong  size,
ulong  count 
)

Definition at line 88 of file pe.c.

88 {
89 void *res = RosSymAllocMem(size * count);
90 if (res) memset(res, 0, size * count);
91 return res;
92}
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 42 of file pe.c.

42 {
43 assert(origin == 0);
44 return RosSymSeekFile(filectx, position);
45}
#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 all_renderers_seek(), BmpDecoder_ReadHeaders(), check_bom(), ConvertFromREFTIME(), ConvertToREFTIME(), fdi_decomp(), found_getposition(), found_setposition(), FoundCapabilities(), FoundDuration(), GdipLoadImageFromStream(), get_decoder_info(), GifDecoder_Initialize(), has_png_transparency_chunk(), IcoDecoder_GetFrame(), IcoDecoder_Initialize(), ImagingFactory_CreateDecoderFromStream(), load_emf(), load_wmf(), MCICDA_Seek(), MediaSeekingPassThru_CheckCapabilities(), MediaSeekingPassThru_ConvertTimeFormat(), MediaSeekingPassThru_GetAvailable(), MediaSeekingPassThru_GetCapabilities(), MediaSeekingPassThru_GetCurrentPosition(), MediaSeekingPassThru_GetDuration(), MediaSeekingPassThru_GetPositions(), MediaSeekingPassThru_GetPreroll(), MediaSeekingPassThru_GetRate(), MediaSeekingPassThru_GetStopPosition(), MediaSeekingPassThru_GetTimeFormat(), MediaSeekingPassThru_IsFormatSupported(), MediaSeekingPassThru_IsUsingTimeFormat(), MediaSeekingPassThru_QueryPreferredFormat(), MediaSeekingPassThru_SetPositions(), MediaSeekingPassThru_SetRate(), MediaSeekingPassThru_SetTimeFormat(), PropertyStorage_ReadFromStream(), PropertyStorage_WriteDictionaryToStream(), PropertyStorage_WriteHeadersToStream(), PropertyStorage_WritePropertyToStream(), PropertyStorage_WriteToStream(), ReadIcoDib(), TgaDecoder_Frame_CopyPalette(), TgaDecoder_Initialize(), and TgaDecoder_ReadImage().

◆ xfree()