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

ByteInfos Class Reference

Mantain info for every byte of file. More...

#include <byteinfo.h>

List of all members.

Public Methods

ByteInfooperator[] (vma_t address)
 Return info for byte at given address. More...

const ByteInfooperator[] (vma_t address) const
uchar GetIstrLen (vma_t) const
 Get length of instruction at given address do not use for no instruction data. More...

void SetLen (vma_t address, unsigned len)
 Set data len (for long data (>32) ). More...

unsigned GetLen (vma_t address) const
 Get len of data. More...

bool IsOccupied (vma_t address) const
 Check if data at given address is alredy marked. More...

bool IsOccupied (vma_t address, int bytes) const
 Check if data at given address is alredy marked. More...


Private Types

typedef fix_vector< ByteInfo,
PageSize > 
TPage
typedef std::map< vma_t, freddy77::hp_auto_ptr<
TPage >, std::less< vma_t > > 
TInfos
enum  dummy { PageSize = 4096 }

Private Attributes

TInfos map

Static Private Attributes

ByteInfo emptyInfo


Detailed Description

Mantain info for every byte of file.

Definition at line 113 of file byteinfo.h.


Member Typedef Documentation

typedef std::map< vma_t,freddy77::hp_auto_ptr<TPage>,std::less<vma_t> > ByteInfos::TInfos [private]
 

Definition at line 149 of file byteinfo.h.

typedef fix_vector<ByteInfo,PageSize> ByteInfos::TPage [private]
 

Definition at line 148 of file byteinfo.h.

Referenced by operator[]().


Member Enumeration Documentation

enum ByteInfos::dummy [private]
 

Enumeration values:
PageSize 

Definition at line 147 of file byteinfo.h.

00147 { PageSize = 4096 };


Member Function Documentation

uchar ByteInfos::GetIstrLen vma_t    const
 

Get length of instruction at given address do not use for no instruction data.

Definition at line 64 of file byteinfo.cpp.

References map, PageSize, uchar, and vma_t.

Referenced by CodeParser::_ReverseScan(), IsOccupied(), CodeParser::Parse(), CodeParser::ScanCode(), THeuristicMotor::THeuristicMotor(), and CodeParser::WriteCode().

00065 {
00066   TInfos::const_iterator i = map.find(address/unsigned(PageSize));
00067   if ( i == map.end() ) return 0;
00068   return (*(*i).second)[address%unsigned(PageSize)].len;
00069 }

unsigned ByteInfos::GetLen vma_t    address const
 

Get len of data.

Definition at line 85 of file byteinfo.cpp.

References ByteInfo::Continue(), ByteInfo::len, and vma_t.

Referenced by CodeParser::WriteCode().

00086 {
00087   unsigned len;
00088   const ByteInfo *info = &((*this)[address]);
00089   len = info->len;
00090   while(info->Continue())
00091   {
00092     info = &((*this)[address+len]);
00093     len += info->len;
00094   }
00095   return len;
00096 }

bool ByteInfos::IsOccupied vma_t    address,
int    bytes
const
 

Check if data at given address is alredy marked.

Definition at line 125 of file byteinfo.cpp.

References _PRG_ASSERT, GetIstrLen(), map, PageSize, and vma_t.

00126 {
00127   _PRG_ASSERT(bytes>0);
00128         // !!! 32 = max istr length
00129   const int maxIstrSize = 32u;
00130   address += --bytes;
00131   TInfos::const_iterator i = map.find(address/unsigned(PageSize));
00132   unsigned int partial = address%unsigned(PageSize);
00133 
00134   // caso tutti su una pagina
00135   if (partial>=(unsigned int)(maxIstrSize-1+bytes))
00136   {
00137     if ( i == map.end())
00138       return false;
00139     TPage &page = *(*i).second;
00140     int n = -bytes;
00141           for(;n<0;++n,--partial)
00142           if (page[partial].len > 0)
00143           return true;
00144           for(;n<maxIstrSize;++n,--partial)
00145           if (page[partial].len > n)
00146           return true;
00147     return false;
00148   }
00149 
00150   // sfortuna, 2 pagine
00151   int n = -bytes;
00152   address -= bytes;
00153   for(;n<0;++n)
00154     if (GetIstrLen(address-n) > 0)
00155       return true;
00156   for(;n<maxIstrSize;++n)
00157     if (GetIstrLen(address-n) > n)
00158       return true;
00159   return false;
00160 }

bool ByteInfos::IsOccupied vma_t    address const
 

Check if data at given address is alredy marked.

Definition at line 99 of file byteinfo.cpp.

References GetIstrLen(), map, PageSize, and vma_t.

Referenced by CodeParser::CheckForAddress(), CodeParser::ExecuteComplexReferenceMemory(), CodeParser::GetBitStat(), CodeParser::GetPointerArrayStats(), CodeParser::GetStringStats(), CodeParser::ScanCode(), and CodeParser::WriteCode().

00100 {
00101         // !!! 32 = max istr length
00102   const int maxIstrSize = 32;
00103   TInfos::const_iterator i = map.find(address/unsigned(PageSize));
00104   unsigned partial = address%unsigned(PageSize);
00105 
00106   // caso tutti su una pagina
00107   if (partial>=(maxIstrSize-1))
00108   {
00109     if ( i == map.end())
00110       return false;
00111     TPage &page = *(*i).second;
00112           for(int n=0;n<maxIstrSize;++n,--partial)
00113           if (page[partial].len > n)
00114           return true;
00115     return false;
00116   }
00117 
00118   // sfortuna, 2 pagine
00119         for(int n=0;n<maxIstrSize;++n)
00120         if (GetIstrLen(address-n) > n)
00121         return true;
00122   return false;
00123 }

const ByteInfo & ByteInfos::operator[] vma_t    address const
 

Definition at line 54 of file byteinfo.cpp.

References emptyInfo, map, PageSize, and vma_t.

00055 {
00056   TInfos::const_iterator i = map.find(address/unsigned(PageSize));
00057   if ( i != map.end() )
00058         return (*(*i).second)[address%unsigned(PageSize)];
00059 
00060   // never alter map
00061   return emptyInfo;
00062 }

ByteInfo & ByteInfos::operator[] vma_t    address
 

Return info for byte at given address.

Parameters:
address  address to query

Definition at line 32 of file byteinfo.cpp.

References map, PageSize, TPage, and vma_t.

00033 {
00034   TInfos::const_iterator i = map.find(address/unsigned(PageSize));
00035   if ( i != map.end() )
00036           return (*(*i).second)[address%unsigned(PageSize)];
00037 
00038   map[address/unsigned(PageSize)] = freddy77::hp_auto_ptr<TPage>(new TPage());
00039   return (*map[address/unsigned(PageSize)])[address%unsigned(PageSize)];
00040 }

void ByteInfos::SetLen vma_t    address,
unsigned    len
 

Set data len (for long data (>32) ).

Definition at line 71 of file byteinfo.cpp.

References ByteInfo::len, ByteInfo::SetContinue(), and vma_t.

00072 {
00073   while(len>32)
00074   {
00075     ByteInfo &info = (*this)[address];
00076     info.len = 32;
00077     info.SetContinue();
00078     len -= 32;
00079     address += 32;
00080   }
00081   ByteInfo &info = (*this)[address];
00082   info.len = (uchar)len;
00083 }


Member Data Documentation

ByteInfo ByteInfos::emptyInfo [static, private]
 

Definition at line 42 of file byteinfo.cpp.

Referenced by operator[]().

TInfos ByteInfos::map [private]
 

Definition at line 150 of file byteinfo.h.

Referenced by GetIstrLen(), IsOccupied(), and operator[]().


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