ReactOS 0.4.16-dev-92-g0c2cdca
image.h File Reference
#include <rsym.h>
Include dependency graph for image.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

size_t fixup_offset (size_t ImageBase, size_t offset)
 
PROSSYM_ENTRY find_offset (void *data, size_t offset)
 
PIMAGE_SECTION_HEADER get_sectionheader (const void *FileData)
 
int get_ImageBase (char *fname, size_t *ImageBase)
 

Function Documentation

◆ find_offset()

PROSSYM_ENTRY find_offset ( void data,
size_t  offset 
)

Definition at line 39 of file image.c.

40{
42 PROSSYM_ENTRY Entries = (PROSSYM_ENTRY)((char *)data + RosSymHeader->SymbolsOffset);
43 size_t symbols = RosSymHeader->SymbolsLength / sizeof(ROSSYM_ENTRY);
44 size_t i;
45
46 for (i = 0; i < symbols; i++)
47 {
48 if (Entries[i].Address > offset)
49 {
50 if (!i--)
51 return NULL;
52 else
53 return &Entries[i];
54 }
55 }
56 return NULL;
57}
static const ENTRY Entries[]
#define NULL
Definition: types.h:112
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLintptr offset
Definition: glext.h:5920
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
static WCHAR Address[46]
Definition: ping.c:68
struct _ROSSYM_ENTRY * PROSSYM_ENTRY
struct _ROSSYM_ENTRY ROSSYM_ENTRY
struct _SYMBOLFILE_HEADER * PSYMBOLFILE_HEADER
Definition: rossym.h:26
ULONG SymbolsOffset
Definition: rsym.h:32
ULONG SymbolsLength
Definition: rsym.h:33

Referenced by print_offset().

◆ fixup_offset()

size_t fixup_offset ( size_t  ImageBase,
size_t  offset 
)

Definition at line 31 of file image.c.

32{
33 if (offset > ABS_TRESHOLD)
34 offset -= ImageBase;
35 return offset;
36}
#define ABS_TRESHOLD
Definition: config.h:4

Referenced by process_data().

◆ get_ImageBase()

int get_ImageBase ( char fname,
size_t ImageBase 
)

Definition at line 102 of file image.c.

103{
104 IMAGE_DOS_HEADER PEDosHeader;
105 IMAGE_FILE_HEADER PEFileHeader;
106 IMAGE_OPTIONAL_HEADER PEOptHeader;
107
108 FILE *fr;
109 off_t readLen;
110 int res;
111
112 *ImageBase = INVALID_BASE;
113 fr = fopen(fname, "rb");
114 if (!fr)
115 {
116 l2l_dbg(3, "get_ImageBase, cannot open '%s' (%s)\n", fname, strerror(errno));
117 return 1;
118 }
119
120 readLen = fread(&PEDosHeader, sizeof(IMAGE_DOS_HEADER), 1, fr);
121 if (1 != readLen)
122 {
123 l2l_dbg(1, "get_ImageBase %s, read error IMAGE_DOS_HEADER (%s)\n", fname, strerror(errno));
124 fclose(fr);
125 return 2;
126 }
127
128 /* Check if MZ header exists */
129 if (PEDosHeader.e_magic != IMAGE_DOS_MAGIC || PEDosHeader.e_lfanew == 0L)
130 {
131 l2l_dbg(2, "get_ImageBase %s, MZ header missing\n", fname);
132 fclose(fr);
133 return 3;
134 }
135
136 /* Locate PE file header */
137 res = fseek(fr, PEDosHeader.e_lfanew + sizeof(ULONG), SEEK_SET);
138 readLen = fread(&PEFileHeader, sizeof(IMAGE_FILE_HEADER), 1, fr);
139 if (1 != readLen)
140 {
141 l2l_dbg(1, "get_ImageBase %s, read error IMAGE_FILE_HEADER (%s)\n", fname, strerror(errno));
142 fclose(fr);
143 return 4;
144 }
145
146 /* Locate optional header */
147 readLen = fread(&PEOptHeader, sizeof(IMAGE_OPTIONAL_HEADER), 1, fr);
148 if (1 != readLen)
149 {
150 l2l_dbg(1, "get_ImageBase %s, read error IMAGE_OPTIONAL_HEADER (%s)\n", fname, strerror(errno));
151 fclose(fr);
152 return 5;
153 }
154
155 /* Check if it's really an IMAGE_OPTIONAL_HEADER we are interested in */
156 if (PEOptHeader.Magic != IMAGE_NT_OPTIONAL_HDR32_MAGIC &&
158 {
159 l2l_dbg(2, "get_ImageBase %s, not an IMAGE_NT_OPTIONAL_HDR 32/64 bit\n", fname);
160 fclose(fr);
161 return 6;
162 }
163
164 *ImageBase = PEOptHeader.ImageBase;
165 fclose(fr);
166 return 0;
167}
__kernel_off_t off_t
Definition: linux.h:201
GLuint res
Definition: glext.h:9613
_Check_return_opt_ _CRTIMP size_t __cdecl fread(_Out_writes_bytes_(_ElementSize *_Count) void *_DstBuf, _In_ size_t _ElementSize, _In_ size_t _Count, _Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fseek(_Inout_ FILE *_File, _In_ long _Offset, _In_ int _Origin)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
#define SEEK_SET
Definition: jmemansi.c:26
const char * strerror(int err)
Definition: compat_str.c:23
#define IMAGE_NT_OPTIONAL_HDR32_MAGIC
Definition: ntimage.h:376
#define IMAGE_NT_OPTIONAL_HDR64_MAGIC
Definition: ntimage.h:377
#define L(x)
Definition: ntvdm.h:50
#define IMAGE_DOS_MAGIC
Definition: pecoff.h:6
#define errno
Definition: errno.h:18
#define INVALID_BASE
Definition: config.h:5
#define l2l_dbg(level,...)
Definition: util.h:35
uint32_t ULONG
Definition: typedefs.h:59

Referenced by create_cache(), and translate_file().

◆ get_sectionheader()

PIMAGE_SECTION_HEADER get_sectionheader ( const void FileData)

Definition at line 60 of file image.c.

61{
62 PIMAGE_DOS_HEADER PEDosHeader;
63 PIMAGE_FILE_HEADER PEFileHeader;
64 PIMAGE_OPTIONAL_HEADER PEOptHeader;
65 PIMAGE_SECTION_HEADER PESectionHeaders;
66 PIMAGE_SECTION_HEADER PERosSymSectionHeader;
67 size_t ImageBase;
68
69 /* Check if MZ header exists */
70 PEDosHeader = (PIMAGE_DOS_HEADER)FileData;
71 if (PEDosHeader->e_magic != IMAGE_DOS_MAGIC || PEDosHeader->e_lfanew == 0L)
72 {
73 l2l_dbg(0, "Input file is not a PE image.\n");
75 return NULL;
76 }
77
78 /* Locate PE file header */
79 /* sizeof(ULONG) = sizeof(MAGIC) */
80 PEFileHeader = (PIMAGE_FILE_HEADER)((char *)FileData + PEDosHeader->e_lfanew + sizeof(ULONG));
81
82 /* Locate optional header */
83 PEOptHeader = (PIMAGE_OPTIONAL_HEADER)(PEFileHeader + 1);
84 ImageBase = PEOptHeader->ImageBase;
85
86 /* Locate PE section headers */
87 PESectionHeaders = (PIMAGE_SECTION_HEADER)((char *)PEOptHeader + PEFileHeader->SizeOfOptionalHeader);
88
89 /* find rossym section */
90 PERosSymSectionHeader = find_rossym_section(PEFileHeader, PESectionHeaders);
91 if (!PERosSymSectionHeader)
92 {
93 l2l_dbg(0, "Couldn't find rossym section in executable\n");
95 return NULL;
96 }
97
98 return PERosSymSectionHeader;
99}
static FILEDATA FileData[MAX_FDS]
Definition: fs.c:51
struct _IMAGE_DOS_HEADER * PIMAGE_DOS_HEADER
struct _IMAGE_FILE_HEADER * PIMAGE_FILE_HEADER
SUMM summ
Definition: log2lines.c:36
struct _IMAGE_SECTION_HEADER * PIMAGE_SECTION_HEADER
struct _IMAGE_OPTIONAL_HEADER * PIMAGE_OPTIONAL_HEADER
static PIMAGE_SECTION_HEADER find_rossym_section(PIMAGE_FILE_HEADER PEFileHeader, PIMAGE_SECTION_HEADER PESectionHeaders)
Definition: image.c:19
WORD SizeOfOptionalHeader
Definition: ntddk_ex.h:127
int offset_errors
Definition: stat.h:22

Referenced by process_data().