#include <rtl.h>
#include <debug.h>
Go to the source code of this file.
|
FORCEINLINE USHORT | ChkSum (ULONG Sum, PUSHORT Src, ULONG Len) |
|
BOOLEAN NTAPI | LdrVerifyMappedImageMatchesChecksum (IN PVOID BaseAddress, IN SIZE_T ImageSize, IN ULONG FileLength) |
|
NTSTATUS NTAPI | RtlpImageNtHeaderEx (_In_ ULONG Flags, _In_ PVOID Base, _In_ ULONG64 Size, _Out_ PIMAGE_NT_HEADERS *OutHeaders) |
|
PIMAGE_NT_HEADERS NTAPI | RtlImageNtHeader (IN PVOID Base) |
|
PVOID NTAPI | RtlImageDirectoryEntryToData (PVOID BaseAddress, BOOLEAN MappedAsImage, USHORT Directory, PULONG Size) |
|
PIMAGE_SECTION_HEADER NTAPI | RtlImageRvaToSection (PIMAGE_NT_HEADERS NtHeader, PVOID BaseAddress, ULONG Rva) |
|
PVOID NTAPI | RtlImageRvaToVa (PIMAGE_NT_HEADERS NtHeader, PVOID BaseAddress, ULONG Rva, PIMAGE_SECTION_HEADER *SectionHeader) |
|
PIMAGE_BASE_RELOCATION NTAPI | LdrProcessRelocationBlockLongLong (IN ULONG_PTR Address, IN ULONG Count, IN PUSHORT TypeOffset, IN LONGLONG Delta) |
|
ULONG NTAPI | LdrRelocateImage (_In_ PVOID BaseAddress, _In_opt_ PCSTR LoaderName, _In_ ULONG Success, _In_ ULONG Conflict, _In_ ULONG Invalid) |
|
ULONG NTAPI | LdrRelocateImageWithBias (_In_ PVOID BaseAddress, _In_ LONGLONG AdditionalBias, _In_opt_ PCSTR LoaderName, _In_ ULONG Success, _In_ ULONG Conflict, _In_ ULONG Invalid) |
|
◆ NDEBUG
◆ RVA
◆ ChkSum()
Definition at line 26 of file image.c.
27{
29
31 {
32
34
35
36 Sum = (Sum & 0xFFFF) + (Sum >> 16);
37 }
38
39
40 return (Sum + (Sum >> 16)) & 0xFFFF;
41}
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
◆ LdrProcessRelocationBlockLongLong()
Definition at line 392 of file image.c.
397{
404
406 {
410
411
412
413
414
415
416
417
418
419
421 {
422
423
425 break;
426
429 break;
430
433 break;
434
437 *LongPtr =
SWAPD(*LongPtr) + (
Delta & 0xFFFFFFFF);
438 break;
439
443 break;
444
447 default:
448 DPRINT1(
"Unknown/unsupported fixup type %hu.\n",
Type);
449 DPRINT1(
"Address %p, Current %u, Count %u, *TypeOffset %x\n",
452 }
453
454 TypeOffset++;
455 }
456
458}
unsigned __int64 * PUINT64
__GNU_EXTENSION typedef unsigned __int64 * PULONGLONG
_In_ ULONG _In_ ULONG Offset
#define IMAGE_REL_BASED_HIGHLOW
#define IMAGE_REL_BASED_DIR64
#define IMAGE_REL_BASED_HIGH
#define IMAGE_REL_BASED_MIPS_JMPADDR
#define IMAGE_REL_BASED_HIGHADJ
#define IMAGE_REL_BASED_ABSOLUTE
#define IMAGE_REL_BASED_LOW
Referenced by LdrRelocateImageWithBias().
◆ LdrRelocateImage()
Definition at line 462 of file image.c.
468{
470}
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
ULONG NTAPI LdrRelocateImageWithBias(_In_ PVOID BaseAddress, _In_ LONGLONG AdditionalBias, _In_opt_ PCSTR LoaderName, _In_ ULONG Success, _In_ ULONG Conflict, _In_ ULONG Invalid)
Referenced by ImgpLoadPEImage().
◆ LdrRelocateImageWithBias()
Definition at line 474 of file image.c.
481{
489
491
493
494 if (NtHeaders ==
NULL)
496
498 {
499 return Conflict;
500 }
501
503
505 {
507 }
508
512
513 while (RelocationDir < RelocationEnd &&
515 {
518 TypeOffset = (
PUSHORT)(RelocationDir + 1);
519
522 TypeOffset,
524
525 if (RelocationDir ==
NULL)
526 {
527 DPRINT1(
"Error during call to LdrProcessRelocationBlockLongLong()!\n");
529 }
530 }
531
533}
#define UNREFERENCED_PARAMETER(P)
struct _IMAGE_BASE_RELOCATION * PIMAGE_BASE_RELOCATION
struct _IMAGE_BASE_RELOCATION IMAGE_BASE_RELOCATION
#define IMAGE_DIRECTORY_ENTRY_BASERELOC
#define IMAGE_FILE_RELOCS_STRIPPED
PIMAGE_BASE_RELOCATION NTAPI LdrProcessRelocationBlockLongLong(IN ULONG_PTR Address, IN ULONG Count, IN PUSHORT TypeOffset, IN LONGLONG Delta)
Referenced by LdrpInitializeProcess(), LdrpMapDll(), LdrRelocateImage(), LoadBootDeviceDriver(), MiReloadBootLoadedDrivers(), MmLoadSystemImage(), and PeLdrLoadImage().
◆ LdrVerifyMappedImageMatchesChecksum()
Definition at line 45 of file image.c.
49{
50#if 0
57
58
59 if (ImageSize == 0)
return TRUE;
60
61
64
65
66 HeaderSum =
Header->OptionalHeader.CheckSum;
67
68
69 if (HeaderSum == 0)
return TRUE;
70
71
72 Sum = 0;
74 for (
i = 0;
i < ImageSize /
sizeof (
USHORT);
i++)
75 {
78 {
80 }
82 }
83
84 if (ImageSize & 1)
85 {
88 {
90 }
91 }
92
94
95
96
98 {
99 CalcSum -=
LOWORD(HeaderSum);
100 }
101 else
102 {
103 CalcSum = ((
LOWORD(CalcSum) -
LOWORD(HeaderSum)) & 0xFFFF) - 1;
104 }
105
106
108 {
109 CalcSum -=
HIWORD(HeaderSum);
110 }
111 else
112 {
113 CalcSum = ((
LOWORD(CalcSum) -
HIWORD(HeaderSum)) & 0xFFFF) - 1;
114 }
115
116
117 CalcSum += ImageSize;
118
119 if (CalcSum != HeaderSum)
120 DPRINT1(
"Image %p checksum mismatches! 0x%x != 0x%x, ImageSize %x, FileLen %x\n",
BaseAddress, CalcSum, HeaderSum, ImageSize,
FileLength);
121
122 return (
BOOLEAN)(CalcSum == HeaderSum);
123#else
124
125
126
127
128
129
130
132#endif
133}
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
_Out_ PNDIS_HANDLE _Out_ PUINT FileLength
◆ RtlImageDirectoryEntryToData()
Definition at line 272 of file image.c.
277{
280
281
283 {
286 }
287
289 if (NtHeader ==
NULL)
291
293 {
295
298
300 if (Va == 0)
302
304
307 }
308 else
309 {
311
314
316 if (Va == 0)
318
320
323 }
324
325
327}
struct _IMAGE_OPTIONAL_HEADER * PIMAGE_OPTIONAL_HEADER32
_In_ BOOLEAN MappedAsImage
struct _IMAGE_OPTIONAL_HEADER64 * PIMAGE_OPTIONAL_HEADER64
#define IMAGE_NT_OPTIONAL_HDR64_MAGIC
base for all directory entries
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
◆ RtlImageNtHeader()
Definition at line 255 of file image.c.
256{
258
259
262 0,
263 &NtHeader);
264 return NtHeader;
265}
NTSTATUS NTAPI RtlImageNtHeaderEx(_In_ ULONG Flags, _In_ PVOID Base, _In_ ULONG64 Size, _Out_ PIMAGE_NT_HEADERS *OutHeaders)
#define RTL_IMAGE_NT_HEADER_EX_FLAG_NO_RANGE_CHECK
◆ RtlImageRvaToSection()
Definition at line 334 of file image.c.
338{
342
345
347 {
350 return Section;
351 Section++;
352 }
353
355}
#define IMAGE_FIRST_SECTION(NtHeader)
◆ RtlImageRvaToVa()
Definition at line 362 of file image.c.
367{
369
370 if (SectionHeader)
371 Section = *SectionHeader;
372
373 if ((Section ==
NULL) ||
376 {
380
381 if (SectionHeader)
382 *SectionHeader = Section;
383 }
384
388}
#define RtlImageRvaToSection
◆ RtlpImageNtHeaderEx()
Definition at line 140 of file image.c.
145{
149 ULONG NtHeaderOffset;
150
151
152 if (OutHeaders ==
NULL)
153 {
154 DPRINT1(
"OutHeaders is NULL\n");
156 }
157
158
160
161
163 {
166 }
167
168
170 {
173 }
174
175
177 if (WantsRangeCheck)
178 {
179
181 {
184 }
185 }
186
187
190 {
191
192 DPRINT1(
"Invalid image DOS signature!\n");
194 }
195
196
197 NtHeaderOffset = DosHeader->
e_lfanew;
198
199
200
201
202
203 if (NtHeaderOffset >= (256 * 1024 * 1024))
204 {
205
206 DPRINT1(
"NT headers offset is larger than 256MB!\n");
208 }
209
210
211 if (WantsRangeCheck)
212 {
213
214 if ((NtHeaderOffset +
216 {
217
218 DPRINT1(
"NT headers beyond image size!\n");
220 }
221 }
222
223
225
226
228 {
229
231 {
232 DPRINT1(
"Image overflows from user space into kernel space!\n");
234 }
235 }
236
237
239 {
240
241 DPRINT1(
"Invalid image NT signature!\n");
243 }
244
245
246 *OutHeaders = NtHeaders;
248}
PIMAGE_NT_HEADERS32 PIMAGE_NT_HEADERS
#define RTL_SIZEOF_THROUGH_FIELD(type, field)
#define STATUS_INVALID_IMAGE_FORMAT
#define IMAGE_NT_SIGNATURE
#define IMAGE_DOS_SIGNATURE
PVOID MmHighestUserAddress
#define STATUS_INVALID_PARAMETER
_Must_inspect_result_ _In_ ULONG Flags
Referenced by RtlImageNtHeaderEx().