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

byteinfo.h

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 #ifndef FILE_BYTEINFO_H
00026 #define FILE_BYTEINFO_H
00027 
00028 #include <map>
00029 #include "utils/fixvect.hpp"
00030 #include "utils/f77auto_ptr"
00031 
00032 // informazioni su ogni byte riguardo all'istruzione
00033 /**
00034  * Mantain info for a byte of file
00035  */
00036 struct ByteInfo
00037 {
00038 public:
00039         /**
00040          * How sure is program about this byte
00041          */
00042   enum TPriority
00043   {
00044     priNone,           /**< not code */
00045                 priCheckOnly,      /**< internal use */
00046                 priFiller,         /**< what's this? */
00047                 priConstant,       /**< a constant in code reference this */
00048                 priApi,            /**< code exported */
00049                 priHeuristics,     /**< discovered by heuristic, not very safe */
00050                 priExport,         /**< code exported */
00051                 priSafeHeuristics, /**< discovered by heuristic, safe */
00052     priSafeExport,     /**< code exported, surely code */
00053                 priEntryPoint,     /**< executed starting from entry-point */
00054                 priMax = priEntryPoint
00055   };
00056         /**
00057          * Type of byte (contained in an instruction, a string, etc)
00058          */
00059   enum TType
00060   {
00061     typeNone, 
00062                 typeInstruction = typeNone, /**< instruction */
00063                 typeLoader,                 /**< used by loader, resource or other */
00064                 typeInteger,                /**< part of an integer */
00065                 typePointer,                /**< a pointer */
00066                 typeASCIIZ,                 /**< asciiz string */
00067     typeMax = typeASCIIZ
00068   };
00069   uchar len; /**< len of istruction/data, for long data (>32) use ByteInfos::GetLen */
00070 
00071   // constructor and reinitialization
00072   ByteInfo():len(0),priority(priNone),flag(0),type(typeNone) {};
00073         /**
00074          * Delete all info for this byte
00075          */
00076   void Reset() { priority = priNone; len = 0; flag = 0; type = typeNone; };
00077 
00078   // priority and type access
00079   void SetPriority(enum TPriority pri)
00080   { _PRG_ASSERT(pri>=0 && pri<=priMax); priority = static_cast<uchar>(pri); };
00081   enum TPriority GetPriority() const
00082   { return static_cast<enum TPriority>(priority); };
00083   void SetType(enum TType typ)
00084   { _PRG_ASSERT(typ>=0 && typ<=typeMax); type = static_cast<uchar>(typ); };
00085   enum TType GetType() const { return static_cast<enum TType>(type); };
00086 
00087   // flag operation
00088         /**
00089          * Mark this istruction have another instruction before 
00090          * (and is not a unconditional jump)
00091          */
00092   void SetIsPrevInstruction() { flag |= 1; };
00093   int IsPrevInstruction() const { return flag&1; };
00094         /**
00095          * This byte if target of a jump or a data referenced from an instruction/constant
00096          */
00097   void SetIsLabel() { flag |= 2; };
00098   int IsLabel() const { return flag&2; };
00099         /**
00100          * Used to handle long data
00101          */
00102   void SetContinue() { flag |= 4; };
00103   int Continue() const { return flag&4; };
00104 private:
00105   uchar priority;
00106   uchar flag;
00107   uchar type; // ?? type ??
00108 };
00109 
00110 /**
00111  * Mantain info for every byte of file
00112  */
00113 class ByteInfos
00114 {
00115 public:
00116         /**
00117          * Return info for byte at given address
00118          * @param address address to query
00119          */
00120   ByteInfo& operator[](vma_t address);
00121   const ByteInfo& operator[](vma_t address) const;
00122         /**
00123          * Get length of instruction at given address
00124          * do not use for no instruction data
00125          */
00126   uchar GetIstrLen(vma_t) const;
00127         /**
00128          * Set data len (for long data (>32) )
00129          */
00130   void SetLen(vma_t address,unsigned len);
00131         /**
00132          * Get len of data
00133          */
00134   unsigned GetLen(vma_t address) const;
00135         /**
00136          * Check if data at given address is alredy marked
00137          */
00138   bool IsOccupied(vma_t address) const;
00139         /**
00140          * Check if data at given address is alredy marked
00141          */
00142   bool IsOccupied(vma_t address,int bytes) const;
00143   
00144 //  typedef enum { Success } TSetInfoResult;
00145 //  TSetInfoResult SetInfo(vma_t address,unsigned len,ByteInfo::TType type,ByteInfo::TPriority priority);
00146 private:
00147   enum dummy { PageSize = 4096 };
00148   typedef fix_vector<ByteInfo,PageSize> TPage;
00149   typedef std::map< vma_t,freddy77::hp_auto_ptr<TPage>,std::less<vma_t> > TInfos;
00150   TInfos map;
00151   static ByteInfo emptyInfo;
00152 };
00153 
00154 #endif // FILE_BYTEINFO_H

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