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

ObjectModule Class Reference

#include <module.h>

List of all members.

Public Types

typedef std::vector< SectionTSections

Public Methods

DataReader GetDataReader (vma_t address)
 ObjectModule (CFile &file, const RVAFileTranslator &rva, uint32_t imageBase, bool hasRelocation, const RelocationInfos &relocationInfos, const Symbols &symbols, const Symbols &exportSymbols, vma_t entryPoint)
 ObjectModule::ObjectModule (vma_t start, const unsigned char *ptr, unsigned len)
 ~ObjectModule ()
uint8_t ReadByte (vma_t address)
uint16_t ReadWord (vma_t address)
uint32_t ReadDword (vma_t address)
bool IsValid (vma_t address)
bool HasRelocation () const
const RelocationInfosGetRelocationInfos () const
const SymbolsGetSymbols () const
const SymbolsGetExportSymbols () const
vma_t GetEntryPoint () const
const SectionGetSection (vma_t address) const
const TSectionsGetSections () const

Static Public Methods

const SectionGetErrorSection ()

Private Methods

void operator= (const ObjectModule &)
 ObjectModule (const ObjectModule &)

Private Attributes

TSections sections
bool hasRelocation
RelocationInfos relocationInfos
Symbols symbols
Symbols exportSymbols
vma_t entryPoint

Static Private Attributes

const Section errorSection


Member Typedef Documentation

typedef std::vector<Section> ObjectModule::TSections
 

Definition at line 59 of file module.h.

Referenced by GetSections().


Constructor & Destructor Documentation

ObjectModule::ObjectModule CFile   file,
const RVAFileTranslator   rva,
uint32_t    imageBase,
bool    hasRelocation,
const RelocationInfos   relocationInfos,
const Symbols   symbols,
const Symbols   exportSymbols,
vma_t    entryPoint
 

Definition at line 36 of file module.cpp.

References entryPoint, RVAFileTranslator::GetSection(), RVAFileTranslator::GetSectionCount(), PeSection::IsCode(), PeSection::RawAddress, CFile::RawRead(), PeSection::RawSize, PeSection::RvaAddress, PeSection::RvaSize, sections, CFile::Seek(), and vma_t.

00039                                                                                            :
00040   sections(rva.GetSectionCount()),
00041   hasRelocation(_hasRelocation),relocationInfos(_relocationInfos),
00042         symbols(_symbols),exportSymbols(_exportSymbols)
00043 {
00044         entryPoint  = _entryPoint==0?0:_entryPoint+imageBase;
00045         
00046   unsigned numSection = rva.GetSectionCount();
00047         uint8_t *buffer;
00048   for (unsigned n=0;n<numSection;++n)
00049   {
00050     // se RawSize > RvaSize altri bytes non utilizzati (indirizzi invalidi)
00051     // se RvaSize > RawSize altri bytes non inizializzati
00052     // calcola dimensione sezione
00053           unsigned size = rva.GetSection(n)->RvaSize;
00054     // inizializza valori
00055     sections[n].begin = rva.GetSection(n)->RvaAddress + imageBase;
00056     sections[n].end   = rva.GetSection(n)->RvaAddress + imageBase + size;
00057     if ( rva.GetSection(n)->IsCode() )
00058       sections[n].SetIsCode();
00059     else
00060       sections[n].SetIsData();
00061 
00062     // inizializza buffer
00063     buffer = new uint8_t[size];
00064     memset(buffer,0,size);
00065                 
00066     // se puntatore valido leggi da memoria
00067     if ( rva.GetSection(n)->RawAddress != 0 )
00068     {
00069       unsigned rawSize = rva.GetSection(n)->RawSize;
00070       file.Seek( rva.GetSection(n)->RawAddress );
00071       file.RawRead( buffer,size<rawSize?size:rawSize );
00072     }
00073                 
00074                 sections[n].data = buffer;
00075                 sections[n].data_end = buffer+size;
00076                 if (n != 0)
00077                         sections[n-1].next = &sections[n];
00078   }
00079 }

ObjectModule::~ObjectModule  
 

Definition at line 100 of file module.cpp.

00101 {
00102 }

ObjectModule::ObjectModule const ObjectModule &    [private]
 


Member Function Documentation

ObjectModule::DataReader ObjectModule::GetDataReader vma_t    address
 

Definition at line 159 of file module.cpp.

References ObjectModule::Section::data, sections, and vma_t.

Referenced by CodeParser::ExecuteComplexReferenceMemory(), CodeParser::GetBitStat(), GetInstruction(), CodeParser::GetPointerArrayStats(), CodeParser::GetStringStats(), CodeParser::Parse(), ReadByte(), ReadDword(), ReadWord(), CodeParser::ScanCode(), CodeParser::WriteBegin(), CodeParser::WriteCode(), and CodeParser::WriteString().

00160 {
00161         // !!! optimize saving last searched section 
00162         // find sectionBuffer
00163         Section* sec;
00164   for( TSections::size_type n=0; n < sections.size(); ++n )
00165   {
00166     vma_t begin = sections[n].begin;
00167     vma_t end   = sections[n].end;
00168     if (begin <= address && address < end)
00169     {
00170                         sec = &sections[n];
00171       return DataReader(sec,sec->data + (address - begin));
00172     }
00173   }
00174         
00175   throw OutOfAddress(address);
00176 }

vma_t ObjectModule::GetEntryPoint   const [inline]
 

Definition at line 98 of file module.h.

References entryPoint, and vma_t.

Referenced by CodeParser::CheckReference(), and CodeParser::Parse().

00099         { return entryPoint; }

const Section* ObjectModule::GetErrorSection   [inline, static]
 

Definition at line 105 of file module.h.

References errorSection.

00105 { return &errorSection; }

const Symbols& ObjectModule::GetExportSymbols   const [inline]
 

Definition at line 96 of file module.h.

References exportSymbols.

Referenced by CodeParser::CheckJumpReference(), CodeParser::CheckReference(), and CodeParser::Parse().

00097   { return exportSymbols; }

const RelocationInfos& ObjectModule::GetRelocationInfos   const [inline]
 

Definition at line 92 of file module.h.

References relocationInfos.

Referenced by CodeParser::ExecuteComplexReferenceMemory(), GetInstruction(), CodeParser::GetStringStats(), CodeParser::Parse(), CodeParser::ScanCode(), and CodeParser::WriteCode().

00093   { return relocationInfos; }

const ObjectModule::Section * ObjectModule::GetSection vma_t    address const
 

Definition at line 144 of file module.cpp.

References errorSection, sections, and vma_t.

Referenced by CodeParser::ExecuteComplexReferenceMemory(), CodeParser::GetPointerArrayStats(), CodeParser::Parse(), ScanningComplexReg::ProcessInstruction(), CodeParser::ScanCode(), and THeuristicMotor::THeuristicMotor().

00145 {
00146   // cerca sezione
00147   for( TSections::size_type n=0; n < sections.size(); ++n )
00148   {
00149     vma_t begin = sections[n].begin;
00150     vma_t end   = sections[n].end;
00151     if (begin <= address && address < end)
00152     {
00153       return &sections[n];
00154     }
00155   }
00156   return &errorSection;
00157 }

const TSections& ObjectModule::GetSections   const [inline]
 

Definition at line 108 of file module.h.

References sections, and TSections.

00109   { return sections; }

const Symbols& ObjectModule::GetSymbols   const [inline]
 

Definition at line 94 of file module.h.

References symbols.

Referenced by CodeParser::AddTempFlow(), CodeParser::CheckJumpReference(), and CodeParser::IsApiReference().

00095   { return symbols; }

bool ObjectModule::HasRelocation   const [inline]
 

Definition at line 90 of file module.h.

References hasRelocation.

Referenced by CodeParser::ContainValidAddress(), CodeParser::ExecuteComplexReferenceMemory(), and CodeParser::GetStringStats().

00091   { return hasRelocation; }

bool ObjectModule::IsValid vma_t    address
 

Definition at line 105 of file module.cpp.

References sections, and vma_t.

Referenced by CodeParser::ContainValidAddress(), and CodeParser::GetPointerArrayStats().

00106 {
00107   // prova con la sezione corrente
00108 //  if ( currSection && currSection->begin <= address && address < currSection->end )
00109 //    return true;
00110 
00111   // cerca sezione
00112   for( TSections::size_type n=0; n < sections.size(); ++n )
00113   {
00114     vma_t begin = sections[n].begin;
00115     vma_t end   = sections[n].end;
00116     if (begin <= address && address < end)
00117     {
00118       return true;
00119     }
00120   }
00121         return false;
00122 }

ObjectModule::ObjectModule::ObjectModule vma_t    start,
const unsigned char *    ptr,
unsigned    len
 

void ObjectModule::operator= const ObjectModule &    [private]
 

uint8_t ObjectModule::ReadByte vma_t    address
 

Definition at line 178 of file module.cpp.

References GetDataReader(), ObjectModule::DataReader::ReadByte(), and vma_t.

00179 {
00180         DataReader reader = GetDataReader(address);
00181         return reader.ReadByte();
00182 }

uint32_t ObjectModule::ReadDword vma_t    address
 

Definition at line 190 of file module.cpp.

References GetDataReader(), ObjectModule::DataReader::ReadDword(), and vma_t.

00191 {
00192         DataReader reader = GetDataReader(address);
00193         return reader.ReadDword();
00194 }

uint16_t ObjectModule::ReadWord vma_t    address
 

Definition at line 184 of file module.cpp.

References GetDataReader(), ObjectModule::DataReader::ReadWord(), and vma_t.

00185 {
00186         DataReader reader = GetDataReader(address);
00187         return reader.ReadWord();
00188 }


Member Data Documentation

vma_t ObjectModule::entryPoint [private]
 

Definition at line 122 of file module.h.

Referenced by GetEntryPoint(), and ObjectModule().

const ObjectModule::Section ObjectModule::errorSection [static, private]
 

Definition at line 34 of file module.cpp.

Referenced by GetErrorSection(), and GetSection().

Symbols ObjectModule::exportSymbols [private]
 

Definition at line 121 of file module.h.

Referenced by GetExportSymbols().

bool ObjectModule::hasRelocation [private]
 

Definition at line 118 of file module.h.

Referenced by HasRelocation().

RelocationInfos ObjectModule::relocationInfos [private]
 

Definition at line 119 of file module.h.

Referenced by GetRelocationInfos().

TSections ObjectModule::sections [private]
 

Definition at line 111 of file module.h.

Referenced by GetDataReader(), GetSection(), GetSections(), IsValid(), and ObjectModule().

Symbols ObjectModule::symbols [private]
 

Definition at line 121 of file module.h.

Referenced by GetSymbols().


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