00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
00035
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
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;
00058 };
00059 typedef std::vector<Section> TSections;
00060
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
00088
00089
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
00102
00103 const Section* GetSection(vma_t address) const;
00104
00105 static const Section* GetErrorSection() { return &errorSection; }
00106
00107
00108 const TSections& GetSections() const
00109 { return sections; }
00110 private:
00111 TSections sections;
00112
00113
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