Fix more potential conversion issues on 64bit.

This commit is contained in:
Joachim Bauch
2016-09-20 00:08:53 +02:00
parent 03cd7c91d9
commit 6c2c3e2fee
+10 -6
View File
@@ -74,7 +74,7 @@ typedef struct {
typedef struct { typedef struct {
LPVOID address; LPVOID address;
LPVOID alignedAddress; LPVOID alignedAddress;
DWORD size; SIZE_T size;
DWORD characteristics; DWORD characteristics;
BOOL last; BOOL last;
} SECTIONFINALIZEDATA, *PSECTIONFINALIZEDATA; } SECTIONFINALIZEDATA, *PSECTIONFINALIZEDATA;
@@ -192,7 +192,7 @@ static int ProtectionFlags[2][2][2] = {
}, },
}; };
static DWORD static SIZE_T
GetRealSectionSize(PMEMORYMODULE module, PIMAGE_SECTION_HEADER section) { GetRealSectionSize(PMEMORYMODULE module, PIMAGE_SECTION_HEADER section) {
DWORD size = section->SizeOfRawData; DWORD size = section->SizeOfRawData;
if (size == 0) { if (size == 0) {
@@ -202,7 +202,7 @@ GetRealSectionSize(PMEMORYMODULE module, PIMAGE_SECTION_HEADER section) {
size = module->headers->OptionalHeader.SizeOfUninitializedData; size = module->headers->OptionalHeader.SizeOfUninitializedData;
} }
} }
return size; return (SIZE_T) size;
} }
static BOOL static BOOL
@@ -271,7 +271,7 @@ FinalizeSections(PMEMORYMODULE module)
for (i=1; i<module->headers->FileHeader.NumberOfSections; i++, section++) { for (i=1; i<module->headers->FileHeader.NumberOfSections; i++, section++) {
LPVOID sectionAddress = (LPVOID)((uintptr_t)section->Misc.PhysicalAddress | imageOffset); LPVOID sectionAddress = (LPVOID)((uintptr_t)section->Misc.PhysicalAddress | imageOffset);
LPVOID alignedAddress = AlignAddressDown(sectionAddress, module->pageSize); LPVOID alignedAddress = AlignAddressDown(sectionAddress, module->pageSize);
DWORD sectionSize = GetRealSectionSize(module, section); SIZE_T sectionSize = GetRealSectionSize(module, section);
// Combine access flags of all sections that share a page // Combine access flags of all sections that share a page
// TODO(fancycode): We currently share flags of a trailing large section // TODO(fancycode): We currently share flags of a trailing large section
// with the page of a first small section. This should be optimized. // with the page of a first small section. This should be optimized.
@@ -282,7 +282,7 @@ FinalizeSections(PMEMORYMODULE module)
} else { } else {
sectionData.characteristics |= section->Characteristics; sectionData.characteristics |= section->Characteristics;
} }
sectionData.size = (((uintptr_t)sectionAddress) + sectionSize) - (uintptr_t) sectionData.address; sectionData.size = (((uintptr_t)sectionAddress) + ((uintptr_t) sectionSize)) - (uintptr_t) sectionData.address;
continue; continue;
} }
@@ -868,7 +868,11 @@ static PIMAGE_RESOURCE_DIRECTORY_ENTRY _MemorySearchResourceEntry(
cmp = _wcsnicmp(searchKey, resourceString->NameString, resourceString->Length); cmp = _wcsnicmp(searchKey, resourceString->NameString, resourceString->Length);
if (cmp == 0) { if (cmp == 0) {
// Handle partial match // Handle partial match
cmp = searchKeyLen - resourceString->Length; if (searchKeyLen > resourceString->Length) {
cmp = 1;
} else if (searchKeyLen < resourceString->Length) {
cmp = -1;
}
} }
if (cmp < 0) { if (cmp < 0) {
end = (middle != end ? middle : middle-1); end = (middle != end ? middle : middle-1);