20#define RVA(m, b) ((PVOID)((ULONG_PTR)(b) + (ULONG_PTR)(m)))
36 Sum = (Sum & 0xFFFF) + (Sum >> 16);
40 return (Sum + (Sum >> 16)) & 0xFFFF;
59 if (ImageSize == 0)
return TRUE;
66 HeaderSum =
Header->OptionalHeader.CheckSum;
69 if (HeaderSum == 0)
return TRUE;
74 for (
i = 0;
i < ImageSize /
sizeof (
USHORT);
i++)
99 CalcSum -=
LOWORD(HeaderSum);
103 CalcSum = ((
LOWORD(CalcSum) -
LOWORD(HeaderSum)) & 0xFFFF) - 1;
109 CalcSum -=
HIWORD(HeaderSum);
113 CalcSum = ((
LOWORD(CalcSum) -
HIWORD(HeaderSum)) & 0xFFFF) - 1;
117 CalcSum += ImageSize;
119 if (CalcSum != HeaderSum)
120 DPRINT1(
"Image %p checksum mismatches! 0x%x != 0x%x, ImageSize %x, FileLen %x\n",
BaseAddress, CalcSum, HeaderSum, ImageSize,
FileLength);
122 return (
BOOLEAN)(CalcSum == HeaderSum);
149 ULONG NtHeaderOffset;
152 if (OutHeaders ==
NULL)
154 DPRINT1(
"OutHeaders is NULL\n");
192 DPRINT1(
"Invalid image DOS signature!\n");
197 NtHeaderOffset = DosHeader->
e_lfanew;
203 if (NtHeaderOffset >= (256 * 1024 * 1024))
206 DPRINT1(
"NT headers offset is larger than 256MB!\n");
214 if ((NtHeaderOffset +
218 DPRINT1(
"NT headers beyond image size!\n");
232 DPRINT1(
"Image overflows from user space into kernel space!\n");
241 DPRINT1(
"Invalid image NT signature!\n");
246 *OutHeaders = NtHeaders;
289 if (NtHeader ==
NULL)
371 Section = *SectionHeader;
373 if ((Section ==
NULL) ||
382 *SectionHeader = Section;
437 *LongPtr =
SWAPD(*LongPtr) + (
Delta & 0xFFFFFFFF);
448 DPRINT1(
"Unknown/unsupported fixup type %hu.\n",
Type);
449 DPRINT1(
"Address %p, Current %u, Count %u, *TypeOffset %x\n",
494 if (NtHeaders ==
NULL)
513 while (RelocationDir < RelocationEnd &&
518 TypeOffset = (
PUSHORT)(RelocationDir + 1);
525 if (RelocationDir ==
NULL)
527 DPRINT1(
"Error during call to LdrProcessRelocationBlockLongLong()!\n");
unsigned __int64 * PUINT64
NTSTATUS NTAPI RtlImageNtHeaderEx(_In_ ULONG Flags, _In_ PVOID Base, _In_ ULONG64 Size, _Out_ PIMAGE_NT_HEADERS *OutHeaders)
#define RtlImageRvaToSection
#define RtlImageDirectoryEntryToData
struct _IMAGE_OPTIONAL_HEADER * PIMAGE_OPTIONAL_HEADER32
PIMAGE_NT_HEADERS32 PIMAGE_NT_HEADERS
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
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
ULONG NTAPI LdrRelocateImage(_In_ PVOID BaseAddress, _In_opt_ PCSTR LoaderName, _In_ ULONG Success, _In_ ULONG Conflict, _In_ ULONG Invalid)
_Out_ PNDIS_HANDLE _Out_ PUINT FileLength
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
_In_ BOOLEAN MappedAsImage
#define RTL_IMAGE_NT_HEADER_EX_FLAG_NO_RANGE_CHECK
__GNU_EXTENSION typedef unsigned __int64 * PULONGLONG
#define RTL_SIZEOF_THROUGH_FIELD(type, field)
#define UNREFERENCED_PARAMETER(P)
_In_ ULONG _In_ ULONG Offset
struct _IMAGE_OPTIONAL_HEADER64 * PIMAGE_OPTIONAL_HEADER64
struct _IMAGE_BASE_RELOCATION * PIMAGE_BASE_RELOCATION
struct _IMAGE_BASE_RELOCATION IMAGE_BASE_RELOCATION
#define IMAGE_NT_OPTIONAL_HDR64_MAGIC
#define IMAGE_FIRST_SECTION(NtHeader)
#define STATUS_INVALID_IMAGE_FORMAT
#define IMAGE_DIRECTORY_ENTRY_BASERELOC
#define IMAGE_NT_SIGNATURE
#define IMAGE_DOS_SIGNATURE
#define IMAGE_FILE_RELOCS_STRIPPED
PVOID MmHighestUserAddress
NTSTATUS NTAPI RtlpImageNtHeaderEx(_In_ ULONG Flags, _In_ PVOID Base, _In_ ULONG64 Size, _Out_ PIMAGE_NT_HEADERS *OutHeaders)
PIMAGE_BASE_RELOCATION NTAPI LdrProcessRelocationBlockLongLong(IN ULONG_PTR Address, IN ULONG Count, IN PUSHORT TypeOffset, IN LONGLONG Delta)
BOOLEAN NTAPI LdrVerifyMappedImageMatchesChecksum(IN PVOID BaseAddress, IN SIZE_T ImageSize, IN ULONG FileLength)
ULONG NTAPI LdrRelocateImageWithBias(_In_ PVOID BaseAddress, _In_ LONGLONG AdditionalBias, _In_opt_ PCSTR LoaderName, _In_ ULONG Success, _In_ ULONG Conflict, _In_ ULONG Invalid)
FORCEINLINE USHORT ChkSum(ULONG Sum, PUSHORT Src, ULONG Len)
base for all directory entries
#define STATUS_INVALID_PARAMETER
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
#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
_Must_inspect_result_ _In_ ULONG Flags