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

byteinfo.cpp

Go to the documentation of this file.
00001 /*
00002 PeRdr - PE file disassembler
00003 Copyright (C) 1999-2002 Frediano Ziglio
00004 -----
00005 
00006 This program is free software; you can redistribute it and/or modify
00007 it under the terms of the GNU General Public License as published by
00008 the Free Software Foundation; either version 2 of the License, or
00009 (at your option) any later version.
00010 
00011 This program is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 GNU General Public License for more details.
00015 
00016 You should have received a copy of the GNU General Public License
00017 along with this program; if not, write to the Free Software
00018 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019 -----
00020 
00021 INFORMATION
00022   www: https://freddy77.tripod.com/perdr/
00023   e-mail: freddy77@angelfire.com
00024 */
00025 #include "global.h"
00026 #ifdef HAVE_HDRSTOP
00027 #pragma hdrstop
00028 #endif
00029 
00030 #include "byteinfo.h"
00031 
00032 ByteInfo& ByteInfos::operator[](vma_t address)
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 }
00041 
00042 ByteInfo ByteInfos::emptyInfo;
00043 
00044 /*
00045 ByteInfos::TSetInfoResult ByteInfos::SetInfo(vma_t address,unsigned len,ByteInfo::TType type,ByteInfo::TPriority priority)
00046 {
00047   TInfos::iterator i = map.find(address/unsigned(PageSize));
00048   unsigned partial = address%unsigned(PageSize);
00049   if ( i == map.end() )  
00050       i = map.insert( TInfos::value_type(address/unsigned(PageSize), freddy77::hp_auto_ptr<TPage>(new TPage()) ) ).first;
00051 }
00052 */
00053 
00054 const ByteInfo& ByteInfos::operator[](vma_t address) const
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 }
00063 
00064 uchar ByteInfos::GetIstrLen(vma_t address) const
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 }
00070 
00071 void ByteInfos::SetLen(vma_t address,unsigned len)
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 }
00084 
00085 unsigned ByteInfos::GetLen(vma_t address) const
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 }
00097 
00098 // il codice al dato indirizzo e' occupato da un'altra istruzione ?
00099 bool ByteInfos::IsOccupied(vma_t address) const
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 }
00124 
00125 bool ByteInfos::IsOccupied(vma_t address,int bytes) const
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 }
00161 

Generated on Mon Jan 13 22:20:33 2003 for perdr by doxygen1.2.15