[FORMATTING]

Apply indentation of 4 spaces.

svn path=/trunk/; revision=50093
This commit is contained in:
Timo Kreuzer 2010-12-22 13:33:09 +00:00
parent 1f982b1479
commit 2342366fe3

View file

@ -22,9 +22,10 @@
BOOLEAN BOOLEAN
NTAPI NTAPI
LdrVerifyMappedImageMatchesChecksum(IN PVOID BaseAddress, LdrVerifyMappedImageMatchesChecksum(
IN ULONG NumberOfBytes, IN PVOID BaseAddress,
IN ULONG FileLength) IN ULONG NumberOfBytes,
IN ULONG FileLength)
{ {
/* FIXME: TODO */ /* FIXME: TODO */
return TRUE; return TRUE;
@ -33,26 +34,26 @@ LdrVerifyMappedImageMatchesChecksum(IN PVOID BaseAddress,
/* /*
* @implemented * @implemented
*/ */
PIMAGE_NT_HEADERS NTAPI PIMAGE_NT_HEADERS
RtlImageNtHeader (IN PVOID BaseAddress) NTAPI
RtlImageNtHeader(IN PVOID BaseAddress)
{ {
PIMAGE_NT_HEADERS NtHeader; PIMAGE_NT_HEADERS NtHeader;
PIMAGE_DOS_HEADER DosHeader = (PIMAGE_DOS_HEADER)BaseAddress; PIMAGE_DOS_HEADER DosHeader = (PIMAGE_DOS_HEADER)BaseAddress;
if (DosHeader && SWAPW(DosHeader->e_magic) != IMAGE_DOS_SIGNATURE) if (DosHeader && SWAPW(DosHeader->e_magic) != IMAGE_DOS_SIGNATURE)
{ {
DPRINT1("DosHeader->e_magic %x\n", SWAPW(DosHeader->e_magic)); DPRINT1("DosHeader->e_magic %x\n", SWAPW(DosHeader->e_magic));
DPRINT1("NtHeader 0x%lx\n", ((ULONG_PTR)BaseAddress + SWAPD(DosHeader->e_lfanew))); DPRINT1("NtHeader 0x%lx\n", ((ULONG_PTR)BaseAddress + SWAPD(DosHeader->e_lfanew)));
}
else
{
NtHeader = (PIMAGE_NT_HEADERS)((ULONG_PTR)BaseAddress + SWAPD(DosHeader->e_lfanew));
if (SWAPD(NtHeader->Signature) == IMAGE_NT_SIGNATURE)
return NtHeader;
} }
if (DosHeader && SWAPW(DosHeader->e_magic) == IMAGE_DOS_SIGNATURE) return NULL;
{
NtHeader = (PIMAGE_NT_HEADERS)((ULONG_PTR)BaseAddress + SWAPD(DosHeader->e_lfanew));
if (SWAPD(NtHeader->Signature) == IMAGE_NT_SIGNATURE)
return NtHeader;
}
return NULL;
} }
@ -61,40 +62,41 @@ RtlImageNtHeader (IN PVOID BaseAddress)
*/ */
PVOID PVOID
NTAPI NTAPI
RtlImageDirectoryEntryToData(PVOID BaseAddress, RtlImageDirectoryEntryToData(
BOOLEAN MappedAsImage, PVOID BaseAddress,
USHORT Directory, BOOLEAN MappedAsImage,
PULONG Size) USHORT Directory,
PULONG Size)
{ {
PIMAGE_NT_HEADERS NtHeader; PIMAGE_NT_HEADERS NtHeader;
ULONG Va; ULONG Va;
/* Magic flag for non-mapped images. */ /* Magic flag for non-mapped images. */
if ((ULONG_PTR)BaseAddress & 1) if ((ULONG_PTR)BaseAddress & 1)
{ {
BaseAddress = (PVOID)((ULONG_PTR)BaseAddress & ~1); BaseAddress = (PVOID)((ULONG_PTR)BaseAddress & ~1);
MappedAsImage = FALSE; MappedAsImage = FALSE;
} }
NtHeader = RtlImageNtHeader (BaseAddress); NtHeader = RtlImageNtHeader (BaseAddress);
if (NtHeader == NULL) if (NtHeader == NULL)
return NULL; return NULL;
if (Directory >= SWAPD(NtHeader->OptionalHeader.NumberOfRvaAndSizes)) if (Directory >= SWAPD(NtHeader->OptionalHeader.NumberOfRvaAndSizes))
return NULL; return NULL;
Va = SWAPD(NtHeader->OptionalHeader.DataDirectory[Directory].VirtualAddress); Va = SWAPD(NtHeader->OptionalHeader.DataDirectory[Directory].VirtualAddress);
if (Va == 0) if (Va == 0)
return NULL; return NULL;
*Size = SWAPD(NtHeader->OptionalHeader.DataDirectory[Directory].Size); *Size = SWAPD(NtHeader->OptionalHeader.DataDirectory[Directory].Size);
if (MappedAsImage || Va < SWAPD(NtHeader->OptionalHeader.SizeOfHeaders)) if (MappedAsImage || Va < SWAPD(NtHeader->OptionalHeader.SizeOfHeaders))
return (PVOID)((ULONG_PTR)BaseAddress + Va); return (PVOID)((ULONG_PTR)BaseAddress + Va);
/* image mapped as ordinary file, we must find raw pointer */ /* image mapped as ordinary file, we must find raw pointer */
return RtlImageRvaToVa (NtHeader, BaseAddress, Va, NULL); return RtlImageRvaToVa (NtHeader, BaseAddress, Va, NULL);
} }
@ -103,28 +105,27 @@ RtlImageDirectoryEntryToData(PVOID BaseAddress,
*/ */
PIMAGE_SECTION_HEADER PIMAGE_SECTION_HEADER
NTAPI NTAPI
RtlImageRvaToSection ( RtlImageRvaToSection(
PIMAGE_NT_HEADERS NtHeader, PIMAGE_NT_HEADERS NtHeader,
PVOID BaseAddress, PVOID BaseAddress,
ULONG Rva ULONG Rva)
)
{ {
PIMAGE_SECTION_HEADER Section; PIMAGE_SECTION_HEADER Section;
ULONG Va; ULONG Va;
ULONG Count; ULONG Count;
Count = SWAPW(NtHeader->FileHeader.NumberOfSections); Count = SWAPW(NtHeader->FileHeader.NumberOfSections);
Section = IMAGE_FIRST_SECTION(NtHeader); Section = IMAGE_FIRST_SECTION(NtHeader);
while (Count--) while (Count--)
{ {
Va = SWAPD(Section->VirtualAddress); Va = SWAPD(Section->VirtualAddress);
if ((Va <= Rva) && if ((Va <= Rva) &&
(Rva < Va + SWAPD(Section->Misc.VirtualSize))) (Rva < Va + SWAPD(Section->Misc.VirtualSize)))
return Section; return Section;
Section++; Section++;
} }
return NULL; return NULL;
} }
@ -133,34 +134,33 @@ RtlImageRvaToSection (
*/ */
PVOID PVOID
NTAPI NTAPI
RtlImageRvaToVa ( RtlImageRvaToVa(
PIMAGE_NT_HEADERS NtHeader, PIMAGE_NT_HEADERS NtHeader,
PVOID BaseAddress, PVOID BaseAddress,
ULONG Rva, ULONG Rva,
PIMAGE_SECTION_HEADER *SectionHeader PIMAGE_SECTION_HEADER *SectionHeader)
)
{ {
PIMAGE_SECTION_HEADER Section = NULL; PIMAGE_SECTION_HEADER Section = NULL;
if (SectionHeader) if (SectionHeader)
Section = *SectionHeader; Section = *SectionHeader;
if (Section == NULL || if (Section == NULL ||
Rva < SWAPD(Section->VirtualAddress) || Rva < SWAPD(Section->VirtualAddress) ||
Rva >= SWAPD(Section->VirtualAddress) + SWAPD(Section->Misc.VirtualSize)) Rva >= SWAPD(Section->VirtualAddress) + SWAPD(Section->Misc.VirtualSize))
{ {
Section = RtlImageRvaToSection (NtHeader, BaseAddress, Rva); Section = RtlImageRvaToSection (NtHeader, BaseAddress, Rva);
if (Section == NULL) if (Section == NULL)
return 0; return 0;
if (SectionHeader) if (SectionHeader)
*SectionHeader = Section; *SectionHeader = Section;
} }
return (PVOID)((ULONG_PTR)BaseAddress + return (PVOID)((ULONG_PTR)BaseAddress +
Rva + Rva +
SWAPD(Section->PointerToRawData) - SWAPD(Section->PointerToRawData) -
(ULONG_PTR)SWAPD(Section->VirtualAddress)); (ULONG_PTR)SWAPD(Section->VirtualAddress));
} }
PIMAGE_BASE_RELOCATION PIMAGE_BASE_RELOCATION
@ -169,8 +169,7 @@ LdrProcessRelocationBlockLongLong(
IN ULONG_PTR Address, IN ULONG_PTR Address,
IN ULONG Count, IN ULONG Count,
IN PUSHORT TypeOffset, IN PUSHORT TypeOffset,
IN LONGLONG Delta IN LONGLONG Delta)
)
{ {
SHORT Offset; SHORT Offset;
USHORT Type; USHORT Type;
@ -197,8 +196,8 @@ LdrProcessRelocationBlockLongLong(
{*/ {*/
switch (Type) switch (Type)
{ {
/* case IMAGE_REL_BASED_SECTION : */ /* case IMAGE_REL_BASED_SECTION : */
/* case IMAGE_REL_BASED_REL32 : */ /* case IMAGE_REL_BASED_REL32 : */
case IMAGE_REL_BASED_ABSOLUTE: case IMAGE_REL_BASED_ABSOLUTE:
break; break;
@ -242,8 +241,7 @@ LdrRelocateImageWithBias(
IN PCCH LoaderName, IN PCCH LoaderName,
IN ULONG Success, IN ULONG Success,
IN ULONG Conflict, IN ULONG Conflict,
IN ULONG Invalid IN ULONG Invalid)
)
{ {
PIMAGE_NT_HEADERS NtHeaders; PIMAGE_NT_HEADERS NtHeaders;
PIMAGE_DATA_DIRECTORY RelocationDDir; PIMAGE_DATA_DIRECTORY RelocationDDir;
@ -275,16 +273,16 @@ LdrRelocateImageWithBias(
RelocationEnd = (PIMAGE_BASE_RELOCATION)((ULONG_PTR)RelocationDir + SWAPD(RelocationDDir->Size)); RelocationEnd = (PIMAGE_BASE_RELOCATION)((ULONG_PTR)RelocationDir + SWAPD(RelocationDDir->Size));
while (RelocationDir < RelocationEnd && while (RelocationDir < RelocationEnd &&
SWAPW(RelocationDir->SizeOfBlock) > 0) SWAPW(RelocationDir->SizeOfBlock) > 0)
{ {
Count = (SWAPW(RelocationDir->SizeOfBlock) - sizeof(IMAGE_BASE_RELOCATION)) / sizeof(USHORT); Count = (SWAPW(RelocationDir->SizeOfBlock) - sizeof(IMAGE_BASE_RELOCATION)) / sizeof(USHORT);
Address = (ULONG_PTR)RVA(BaseAddress, SWAPD(RelocationDir->VirtualAddress)); Address = (ULONG_PTR)RVA(BaseAddress, SWAPD(RelocationDir->VirtualAddress));
TypeOffset = (PUSHORT)(RelocationDir + 1); TypeOffset = (PUSHORT)(RelocationDir + 1);
RelocationDir = LdrProcessRelocationBlockLongLong(Address, RelocationDir = LdrProcessRelocationBlockLongLong(Address,
Count, Count,
TypeOffset, TypeOffset,
Delta); Delta);
if (RelocationDir == NULL) if (RelocationDir == NULL)
{ {
@ -295,4 +293,5 @@ LdrRelocateImageWithBias(
return Success; return Success;
} }
/* EOF */ /* EOF */