Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

RVAFileTranslator Class Reference

#include <rva.h>

List of all members.

Public Methods

 RVAFileTranslator (const PE_IMAGE_SECTION_HEADER *_sections, unsigned _num_section)
 ~RVAFileTranslator ()
 RVAFileTranslator (const RVAFileTranslator &rhs)
void operator= (const RVAFileTranslator &rhs)
long RVA2File (uint32_t rva) const
uint32_t File2RVA (long file) const
long RVA2FileSafe (uint32_t rva) const
uint32_t File2RVASafe (long file) const
unsigned GetSectionCount () const
const PeSectionGetSection (unsigned n) const

Private Attributes

unsigned num
PeSectionsection_infos


Constructor & Destructor Documentation

RVAFileTranslator::RVAFileTranslator const PE_IMAGE_SECTION_HEADER   _sections,
unsigned    _num_section
 

Definition at line 47 of file rva.cpp.

References _PE_IMAGE_SECTION_HEADER::Characteristics, IMAGE_SCN_CNT_UNINITIALIZED_DATA, _PE_IMAGE_SECTION_HEADER::Misc, num, _PE_IMAGE_SECTION_HEADER::PointerToRawData, section_infos, _PE_IMAGE_SECTION_HEADER::SizeOfRawData, and _PE_IMAGE_SECTION_HEADER::VirtualAddress.

00047                                                                                                   :
00048   num(_num_section),section_infos(NULL)
00049 {
00050   unsigned n;
00051 
00052   // check order and size
00053   uint32_t prevVirtualEnd = 0,prevFileEnd = 0;
00054   for( n=0; n<num; ++n )
00055   {
00056     // vedi se sezione inizializzata
00057         if (!(_sections[n].Characteristics&IMAGE_SCN_CNT_UNINITIALIZED_DATA) || _sections[n].PointerToRawData != 0)
00058                 // !!! una sezione puo' essere vuota e non avere il flag uninitialized settato
00059                 if(_sections[n].PointerToRawData != 0 || _sections[n].SizeOfRawData != 0)
00060         {
00061                 if (prevVirtualEnd > _sections[n].VirtualAddress ||
00062                         prevFileEnd > _sections[n].PointerToRawData )
00063                 throw std::runtime_error("Invalid order of sections");
00064                 prevVirtualEnd = _sections[n].VirtualAddress+_sections[n].Misc.VirtualSize;
00065         prevFileEnd    = _sections[n].PointerToRawData+_sections[n].SizeOfRawData;
00066         }
00067   }
00068 
00069   // copy
00070   section_infos = new PeSection[num];
00071   for( n=0; n<num; ++n )
00072     section_infos[n] = _sections[n];
00073 }

RVAFileTranslator::~RVAFileTranslator  
 

Definition at line 75 of file rva.cpp.

References section_infos.

00076 {
00077   delete[] section_infos;
00078 }

RVAFileTranslator::RVAFileTranslator const RVAFileTranslator &    rhs [inline]
 

Definition at line 56 of file rva.h.

References section_infos.

00056                                                  :section_infos(NULL)
00057   { (*this) = rhs; };


Member Function Documentation

uint32_t RVAFileTranslator::File2RVA long    file const
 

Definition at line 90 of file rva.cpp.

References num, PeSection::RawAddress, PeSection::RawSize, PeSection::RvaAddress, and section_infos.

Referenced by File2RVASafe().

00091 {
00092   if (_file < 0) return 0;
00093   unsigned long file = static_cast<unsigned long>(_file);
00094   for( unsigned n=0; n<num; ++n )
00095   {
00096     if (file >= section_infos[n].RawAddress && file < (section_infos[n].RawAddress+section_infos[n].RawSize) )
00097       return file - section_infos[n].RawAddress + section_infos[n].RvaAddress;
00098   }
00099   return 0;
00100 }

uint32_t RVAFileTranslator::File2RVASafe long    file const [inline]
 

Definition at line 65 of file rva.h.

References File2RVA().

Referenced by CodeParser::ExcludeFileRange().

00065                                          {
00066     uint32_t r = File2RVA(file); if (r==0) throw std::runtime_error("Invalid File offset");
00067           return r;
00068   };

const PeSection* RVAFileTranslator::GetSection unsigned    n const [inline]
 

Definition at line 71 of file rva.h.

References num, and section_infos.

Referenced by CodeParser::ExcludeFileRange(), ObjectModule::ObjectModule(), and RawDump().

00072   { return ((n<num)?&section_infos[n]:NULL); };

unsigned RVAFileTranslator::GetSectionCount   const [inline]
 

Definition at line 69 of file rva.h.

References num.

Referenced by ObjectModule::ObjectModule().

00070   { return num; }

void RVAFileTranslator::operator= const RVAFileTranslator &    rhs
 

Definition at line 102 of file rva.cpp.

References num, and section_infos.

00103 {
00104   delete section_infos;
00105   section_infos = new PeSection[rhs.num];
00106   num = rhs.num;
00107   for(unsigned n=0; n<num; ++n)
00108     section_infos[n] = rhs.section_infos[n];
00109 }

long RVAFileTranslator::RVA2File uint32_t    rva const
 

Definition at line 80 of file rva.cpp.

References num, PeSection::RawAddress, PeSection::RvaAddress, PeSection::RvaSize, and section_infos.

Referenced by RVA2FileSafe().

00081 {
00082   for( unsigned n=0; n<num; ++n )
00083   {
00084     if (rva >= section_infos[n].RvaAddress && rva < (section_infos[n].RvaAddress+section_infos[n].RvaSize) )
00085       return rva - section_infos[n].RvaAddress + section_infos[n].RawAddress;
00086   }
00087   return 0;
00088 }

long RVAFileTranslator::RVA2FileSafe uint32_t    rva const [inline]
 

Definition at line 61 of file rva.h.

References RVA2File().

Referenced by MarkImport(), PeFile::ParseExport(), PeFile::ParseResource(), and ParseResourceDirectory().

00061                                         {
00062     long r = RVA2File(rva); if (r==0) throw std::runtime_error("Invalid RVA");
00063           return r;
00064   };


Member Data Documentation

unsigned RVAFileTranslator::num [private]
 

Definition at line 74 of file rva.h.

Referenced by File2RVA(), GetSection(), GetSectionCount(), operator=(), RVA2File(), and RVAFileTranslator().

PeSection* RVAFileTranslator::section_infos [private]
 

Definition at line 76 of file rva.h.

Referenced by File2RVA(), GetSection(), operator=(), RVA2File(), RVAFileTranslator(), and ~RVAFileTranslator().


The documentation for this class was generated from the following files:
Generated on Mon Jan 13 22:20:37 2003 for perdr by doxygen1.2.15