Code:
DWORD OffsetToRVA(DWORD offset, IMAGE_SECTION_HEADER *is_hdr, unsigned scount){
// Find section holding the Offset
for(unsigned i = 0; i < scount;i++)
if((offset >= is_hdr[i].PointerToRawData) && (offset <= is_hdr[i].PointerToRawData +is_hdr[i].SizeOfRawData)){
// Convert Offset to RVA
return offset+is_hdr[i].VirtualAddress-is_hdr[i].PointerToRawData;
}
return 0;
}
should work...
is_hdr is a array of IMAGE_SECTION_HEADERS and scount is the number of sections (file header)