本文主要是介绍问题2,RVA转换成FOA的问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1,RVA转换成FOA的问题
假设:入下图,我们将37000转换成FOA?
if (rva >= (pSectionheader->VirtualAddress) && rva <= (pSectionheader->VirtualAddress + pSectionheader->Misc.VirtualSize))
第一个条件满足,第二个条件也满足;如果是36700也满足,所以不对;
所以一定是大于等于第一个条件,小于第二个条件
//RVA TO FOA
unsigned int RvaToFoa(char*buf, DWORD rva)
{
if (buf == NULL)
{
return 0;
}
PIMAGE_DOS_HEADER pdosHeader = (PIMAGE_DOS_HEADER)buf;
PIMAGE_NT_HEADERS pNtheader = (PIMAGE_NT_HEADERS)((DWORD)buf + (DWORD)pdosHeader->e_lfanew);
PIMAGE_FILE_HEADER pFileHeader = (PIMAGE_FILE_HEADER)((DWORD)buf + 4 + (DWORD)pdosHeader->e_lfanew);
PIMAGE_OPTIONAL_HEADER pOptHeader = (PIMAGE_OPTIONAL_HEADER)((DWORD)pFileHeader + sizeof(IMAGE_FILE_HEADER));
PIMAGE_SECTION_HEADER pSectionheader = (PIMAGE_SECTION_HEADER)((DWORD)pFileHeader + sizeof(IMAGE_FILE_HEADER)+pFileHeader->SizeOfOptionalHeader);
for (int i = 0; i<=pFileHeader->NumberOfSections; i++)
{
if (rva >= (pSectionheader->VirtualAddress) && rva < (pSectionheader->VirtualAddress + pSectionheader->Misc.VirtualSize))
{
return (rva - pSectionheader->VirtualAddress) + pSectionheader->PointerToRawData;
}
pSectionheader++;
}
return 0;
}
这篇关于问题2,RVA转换成FOA的问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!