如何将导出表的rva转成foa
答案:2 悬赏:40 手机版
解决时间 2021-03-21 02:41
- 提问者网友:棒棒糖
- 2021-03-20 18:59
如何将导出表的rva转成foa
最佳答案
- 五星知识达人网友:零点过十分
- 2021-03-20 19:47
/将RVA转换为FOA(可由lpFoa传出FOA、可由lpSection传出节序号,不在节中节序号为-1)
BOOL RvaToFoa(DWORD dwRva, LPDWORD lpFoa = NULL, LPWORD lpSection = NULL) const;
//将FOA转换为RVA(可由lpRva传出RVA、可由lpSection传出节序号,不在节中节序号为-1)
BOOL FoaToRva(DWORD dwFoa, LPDWORD lpRva = NULL, LPWORD lpSection = NULL) const;
BOOL CPeFile::RvaToFoa(DWORD dwRva, LPDWORD lpFoa, LPWORD lpSection) const
{
assert(IsAttch());
WORD nSection = m_lpNtHeader->FileHeader.NumberOfSections;
DWORD dwAlignment = m_lpNtHeader->OptionalHeader.SectionAlignment;
for (size_t i = 0; i < (size_t)nSection; ++i)
{
DWORD dwBegin = m_lpSectionHeader[i].VirtualAddress;
if (i == 0U && dwRva < dwBegin)
{
if (lpFoa)
*lpFoa = dwRva;
if (lpSection)
*lpSection = (WORD)-1;
return TRUE;
}
DWORD dwBlockCount = m_lpSectionHeader[i].SizeOfRawData / dwAlignment;
dwBlockCount += m_lpSectionHeader[i].SizeOfRawData % dwAlignment ? 1 : 0;
if (dwRva >= dwBegin && dwRva < dwBegin + dwBlockCount * dwAlignment)
{
if (lpFoa)
*lpFoa = m_lpSectionHeader[i].PointerToRawData + dwRva - dwBegin;
if (lpSection)
*lpSection = (WORD)i;
return TRUE;
}
}
return FALSE;
}
BOOL CPeFile::FoaToRva(DWORD dwFoa, LPDWORD lpRva, LPWORD lpSection) const
{
assert(IsAttch());
WORD nSection = m_lpNtHeader->FileHeader.NumberOfSections;
for (size_t i = 0; i < (size_t)nSection; ++i)
{
DWORD dwBegin = m_lpSectionHeader[i].PointerToRawData;
if (i == 0U && dwFoa < dwBegin)
{
if (lpRva)
*lpRva = dwFoa;
if (lpSection)
*lpSection = (WORD)-1;
return TRUE;
}
if (dwFoa >= dwBegin && dwFoa < dwBegin + m_lpSectionHeader[i].SizeOfRawData)
{
if (lpRva)
*lpRva = m_lpSectionHeader[i].VirtualAddress + (dwFoa - m_lpSectionHeader[i].PointerToRawData);
if (lpSection)
*lpSection = (WORD)i;
return TRUE;
}
}
return FALSE;
}
BOOL RvaToFoa(DWORD dwRva, LPDWORD lpFoa = NULL, LPWORD lpSection = NULL) const;
//将FOA转换为RVA(可由lpRva传出RVA、可由lpSection传出节序号,不在节中节序号为-1)
BOOL FoaToRva(DWORD dwFoa, LPDWORD lpRva = NULL, LPWORD lpSection = NULL) const;
BOOL CPeFile::RvaToFoa(DWORD dwRva, LPDWORD lpFoa, LPWORD lpSection) const
{
assert(IsAttch());
WORD nSection = m_lpNtHeader->FileHeader.NumberOfSections;
DWORD dwAlignment = m_lpNtHeader->OptionalHeader.SectionAlignment;
for (size_t i = 0; i < (size_t)nSection; ++i)
{
DWORD dwBegin = m_lpSectionHeader[i].VirtualAddress;
if (i == 0U && dwRva < dwBegin)
{
if (lpFoa)
*lpFoa = dwRva;
if (lpSection)
*lpSection = (WORD)-1;
return TRUE;
}
DWORD dwBlockCount = m_lpSectionHeader[i].SizeOfRawData / dwAlignment;
dwBlockCount += m_lpSectionHeader[i].SizeOfRawData % dwAlignment ? 1 : 0;
if (dwRva >= dwBegin && dwRva < dwBegin + dwBlockCount * dwAlignment)
{
if (lpFoa)
*lpFoa = m_lpSectionHeader[i].PointerToRawData + dwRva - dwBegin;
if (lpSection)
*lpSection = (WORD)i;
return TRUE;
}
}
return FALSE;
}
BOOL CPeFile::FoaToRva(DWORD dwFoa, LPDWORD lpRva, LPWORD lpSection) const
{
assert(IsAttch());
WORD nSection = m_lpNtHeader->FileHeader.NumberOfSections;
for (size_t i = 0; i < (size_t)nSection; ++i)
{
DWORD dwBegin = m_lpSectionHeader[i].PointerToRawData;
if (i == 0U && dwFoa < dwBegin)
{
if (lpRva)
*lpRva = dwFoa;
if (lpSection)
*lpSection = (WORD)-1;
return TRUE;
}
if (dwFoa >= dwBegin && dwFoa < dwBegin + m_lpSectionHeader[i].SizeOfRawData)
{
if (lpRva)
*lpRva = m_lpSectionHeader[i].VirtualAddress + (dwFoa - m_lpSectionHeader[i].PointerToRawData);
if (lpSection)
*lpSection = (WORD)i;
return TRUE;
}
}
return FALSE;
}
全部回答
- 1楼网友:woshuo
- 2021-03-20 20:11
期待看到有用的回答!
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯