From e089f4af41a461b69017db3750f79fbaed1008df Mon Sep 17 00:00:00 2001 From: mrexodia Date: Fri, 22 Apr 2016 21:04:38 +0200 Subject: [PATCH] fixed some bugs with RVA -> Offset conversion (appears to be working fine for standard exes now) --- TitanEngine/TitanEngine.PE.Convert.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/TitanEngine/TitanEngine.PE.Convert.cpp b/TitanEngine/TitanEngine.PE.Convert.cpp index cef82f6..6b61105 100644 --- a/TitanEngine/TitanEngine.PE.Convert.cpp +++ b/TitanEngine/TitanEngine.PE.Convert.cpp @@ -30,7 +30,7 @@ __declspec(dllexport) long TITCALL GetPE32SectionNumberFromVA(ULONG_PTR FileMapV DWORD FoundInSection = -1; while(SectionNumber > 0) { - if(PESections->VirtualAddress <= ConvertAddress && ConvertAddress < PESections->VirtualAddress + PESections->Misc.VirtualSize) + if(PESections->VirtualAddress <= ConvertAddress && ConvertAddress < PESections->VirtualAddress + max(PESections->Misc.VirtualSize, PESections->SizeOfRawData)) { FoundInSection = PEHeader32->FileHeader.NumberOfSections - SectionNumber; } @@ -54,7 +54,7 @@ __declspec(dllexport) long TITCALL GetPE32SectionNumberFromVA(ULONG_PTR FileMapV DWORD FoundInSection = -1; while(SectionNumber > 0) { - if(PESections->VirtualAddress <= ConvertAddress && ConvertAddress < PESections->VirtualAddress + PESections->Misc.VirtualSize) + if(PESections->VirtualAddress <= ConvertAddress && ConvertAddress < PESections->VirtualAddress + max(PESections->Misc.VirtualSize, PESections->SizeOfRawData)) { FoundInSection = PEHeader64->FileHeader.NumberOfSections - SectionNumber; } @@ -114,7 +114,7 @@ __declspec(dllexport) ULONG_PTR TITCALL ConvertVAtoFileOffset(ULONG_PTR FileMapV { while(SectionNumber > 0) { - if(PESections->VirtualAddress <= ConvertAddress && ConvertAddress <= PESections->VirtualAddress + PESections->Misc.VirtualSize) + if(PESections->VirtualAddress <= ConvertAddress && ConvertAddress < PESections->VirtualAddress + max(PESections->Misc.VirtualSize, PESections->SizeOfRawData)) { if(ConvertAddress - PESections->VirtualAddress <= PESections->SizeOfRawData) { @@ -155,7 +155,7 @@ __declspec(dllexport) ULONG_PTR TITCALL ConvertVAtoFileOffset(ULONG_PTR FileMapV { while(SectionNumber > 0) { - if(PESections->VirtualAddress <= ConvertAddress && ConvertAddress <= PESections->VirtualAddress + PESections->Misc.VirtualSize) + if(PESections->VirtualAddress <= ConvertAddress && ConvertAddress < PESections->VirtualAddress + max(PESections->Misc.VirtualSize, PESections->SizeOfRawData)) { if(ConvertAddress - PESections->VirtualAddress <= PESections->SizeOfRawData) { @@ -249,7 +249,7 @@ __declspec(dllexport) ULONG_PTR TITCALL ConvertVAtoFileOffsetEx(ULONG_PTR FileMa { while(SectionNumber > 0) { - if(PESections->VirtualAddress <= ConvertAddress && ConvertAddress <= PESections->VirtualAddress + PESections->Misc.VirtualSize) + if(PESections->VirtualAddress <= ConvertAddress && ConvertAddress < PESections->VirtualAddress + max(PESections->Misc.VirtualSize, PESections->SizeOfRawData)) { if(ConvertAddress - PESections->VirtualAddress <= PESections->SizeOfRawData) { @@ -321,7 +321,7 @@ __declspec(dllexport) ULONG_PTR TITCALL ConvertVAtoFileOffsetEx(ULONG_PTR FileMa { while(SectionNumber > 0) { - if(PESections->VirtualAddress <= ConvertAddress && ConvertAddress <= PESections->VirtualAddress + PESections->Misc.VirtualSize) + if(PESections->VirtualAddress <= ConvertAddress && ConvertAddress < PESections->VirtualAddress + max(PESections->Misc.VirtualSize, PESections->SizeOfRawData)) { if(ConvertAddress - PESections->VirtualAddress <= PESections->SizeOfRawData) {