Example #1
0
//================================================================
//----------------------------------------------------------------
// calulates the Offset from a RVA
// Base    - base of the MMF
// dwRVA - the RVA to calculate
// returns 0 if an error occurred else the calculated Offset will be returned
DWORD CPELibrary::RVA2Offset(DWORD dwRVA)
{
    DWORD _offset;
    PIMAGE_SECTION_HEADER section;
    section=ImageRVA2Section(dwRVA);//ImageRvaToSection(pimage_nt_headers,Base,dwRVA);
    if(section==NULL)
    {
        return(0);
    }
    _offset=dwRVA+section->PointerToRawData-section->VirtualAddress;
    return(_offset);
}
Example #2
0
DWORD RVA2Offset(void * pImageBase, DWORD dwRVA)
{
	DWORD offset;
	PIMAGE_SECTION_HEADER section;
	PIMAGE_DOS_HEADER pimage_dos_header;
	PIMAGE_NT_HEADERS pimage_nt_headers;
	pimage_dos_header = PIMAGE_DOS_HEADER(pImageBase);
	pimage_nt_headers = (PIMAGE_NT_HEADERS)( ((SIZE_T)pimage_dos_header) + pimage_dos_header -> e_lfanew);
	section = ImageRVA2Section(pimage_nt_headers, dwRVA);
	if (section == nullptr)
	{
		return 0;
	}
	offset = dwRVA + section->PointerToRawData - section->VirtualAddress;
	return offset;
}