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

module.h

Go to the documentation of this file.
00001 /*
00002 PeRdr - PE file disassembler
00003 Copyright (C) 1999-2003 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_MODULE_H
00026 #define FILE_MODULE_H
00027 
00028 #include "rva.h"
00029 #include "file.hpp"
00030 #include "utils/range.hpp"
00031 #include "relocationinfo.h"
00032 #include "symbols.h"
00033 
00034 // gestisce il file come se fosse caricato in memoria
00035 // throw exception
00036 class ObjectModule
00037 {
00038 public:
00039         class DataReader;
00040   class Section: public range<vma_t>
00041   {
00042         friend class ObjectModule;
00043   friend class DataReader;
00044   public:
00045     Section(): range<vma_t>(0,0),flag(0),data(NULL),data_end(NULL),next(NULL) {};
00046           ~Section();
00047     // they was bool, but this cause some warning
00048     unsigned IsCode() const { return flag & fCode; }
00049     unsigned IsData() const { return flag & fData; }
00050     void SetIsCode() { flag |= fCode; }
00051     void SetIsData() { flag |= fData; }
00052   private:
00053     enum { fCode = 1, fData = 2, fWritable = 4 };
00054     unsigned flag;
00055                 unsigned char* data;
00056                 unsigned char* data_end;
00057                 Section* next; /* for read behond */
00058   };
00059   typedef std::vector<Section> TSections;
00060         /** Class for read data on Module */
00061   class DataReader {
00062                 friend ObjectModule;
00063     const Section* sec;
00064     unsigned char* ptr; 
00065                 DataReader(const Section* sec,unsigned char* ptr);
00066   public:
00067     uint8_t ReadByte();
00068     uint16_t ReadWord();
00069     uint32_t ReadDword();
00070                 void UnReadByte();
00071     vma_t Tell();
00072         };
00073         DataReader GetDataReader(vma_t address);
00074 
00075   ObjectModule(CFile& file,const RVAFileTranslator& rva,uint32_t imageBase,bool hasRelocation,const RelocationInfos& relocationInfos, const Symbols& symbols, const Symbols& exportSymbols, vma_t entryPoint);
00076         ObjectModule::ObjectModule(vma_t start,const unsigned char *ptr, unsigned len);
00077   ~ObjectModule();
00078   struct OutOfAddress
00079   {
00080     OutOfAddress(vma_t addr):address(addr) {};
00081     vma_t address;
00082   };
00083   uint8_t ReadByte(vma_t address);
00084   uint16_t ReadWord(vma_t address);
00085   uint32_t ReadDword(vma_t address);
00086   bool IsValid(vma_t address);
00087 //  vma_t GetNextValid();
00088 
00089   // aggiunti per "compatibilita'" bfd
00090   bool HasRelocation() const
00091   { return hasRelocation; }
00092   const RelocationInfos& GetRelocationInfos() const
00093   { return relocationInfos; }
00094   const Symbols& GetSymbols() const
00095   { return symbols; }
00096   const Symbols& GetExportSymbols() const
00097   { return exportSymbols; }
00098         vma_t GetEntryPoint() const 
00099         { return entryPoint; }
00100 
00101   // section access
00102   // se non trovata nessuna sezione ritorna GetErrorSection()
00103   const Section* GetSection(vma_t address) const;
00104   // sezione usata per ritorno in caso di sezione non trovata
00105   static const Section* GetErrorSection() { return &errorSection; }
00106 
00107   //
00108   const TSections& GetSections() const
00109   { return sections; }
00110 private:
00111   TSections sections;
00112 //  Section* currSection;
00113   // not implemented
00114   void operator=(const ObjectModule&);
00115   ObjectModule(const ObjectModule&);
00116   static const Section errorSection;
00117 
00118   bool hasRelocation;
00119   RelocationInfos relocationInfos;
00120 
00121         Symbols symbols, exportSymbols;
00122         vma_t entryPoint;
00123 };
00124 #endif // FILE_MODULE_H

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