ReactOS  0.4.14-dev-376-gaedba84
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 }
void * fd
Definition: pe.h:15
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:48
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLdouble s
Definition: gl.h:2039
#define nil
Definition: compat.h:23
Definition: name.c:36

◆ 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 }
signed char * PCHAR
Definition: retypes.h:7
#define werrstr(str,...)
Definition: compat.h:34
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
void * fd
Definition: pe.h:15
PeSect * pesection(Pe *pe, const char *name)
Definition: pe.c:15
#define RosSymAllocMem(Size)
Definition: rossympriv.h:21
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLdouble s
Definition: gl.h:2039
#define nil
Definition: compat.h:23
Definition: name.c:36

◆ 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 }
#define werrstr(str,...)
Definition: compat.h:34
DWORD PointerToRawData
Definition: pedump.c:290
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
Definition: bufpool.h:45
_In_ ULONG _In_ BOOLEAN _Must_inspect_result_ PVOID * VirtualAddress
Definition: ndis.h:3791
#define ANSI_NAME_STRING(s)
Definition: pe.h:59
#define nil
Definition: compat.h:23

◆ 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
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
NTSYSAPI VOID NTAPI RtlFreeAnsiString(PANSI_STRING AnsiString)
int nsections
Definition: pe.h:23
#define ANSI_NAME_STRING(s)
Definition: pe.h:59
struct _IMAGE_SECTION_HEADER * sect
Definition: pe.h:24

◆ 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 }
static PVOID ptr
Definition: dispmode.c:27
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 }
static PVOID ptr
Definition: dispmode.c:27
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 }
signed char * PCHAR
Definition: retypes.h:7
#define werrstr(str,...)
Definition: compat.h:34
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
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
int nsections
Definition: pe.h:23
ulong imagebase
Definition: pe.h:19
#define ANSI_NAME_STRING(s)
Definition: pe.h:59
struct _IMAGE_SECTION_HEADER * sect
Definition: pe.h:24
#define nil
Definition: compat.h:23
Definition: name.c:36

◆ 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 }
int readn(void *filectx, char *buffer, ulong size)
Definition: pe.c:47
#define free
Definition: debug_ros.c:5
static int fd
Definition: io.c:51
int seek(void *filectx, ulong position, int origin)
Definition: pe.c:51
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLenum GLsizei len
Definition: glext.h:6722
#define nil
Definition: compat.h:23
#define malloc
Definition: debug_ros.c:4
off
Definition: i386-dis.c:3909

Referenced by loaddisksection().

◆ 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 }
#define RosSymReadFile(FileContext, Buffer, Size)
Definition: rossympriv.h:23
GLuint buffer
Definition: glext.h:5915
GLsizeiptr size
Definition: glext.h:5919

◆ 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
#define RosSymAllocMem(Size)
Definition: rossympriv.h:21
GLsizeiptr size
Definition: glext.h:5919
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:142
#define RosSymSeekFile(FileContext, Position)
Definition: rossympriv.h:24

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()