00001 #ifndef _LoaderSection_h_ 00002 #define _LoaderSection_h 00003 00004 #include <Base.h> 00005 #include <defines/LoaderSection.d> 00006 00007 #define IMPLICIT_SYM_COUNT 3 00008 00009 class LSFileNameTable; 00010 class LSStringTable; 00011 00012 class LSHeader { 00013 protected: 00014 LSHeader() {} 00015 public: 00016 00017 virtual void print(); 00018 virtual char* charStream() { __SHOULD_NOT_ARRIVE; return NULL; } 00019 00020 LOADERHEADER_MACROS_BASIS("For the get_X field macros check the defines directory"); 00021 virtual ~LSHeader() {} 00022 00023 static LSHeader* newHeader(LSHeader* old,bool is64Bit, 00024 uint32_t l_nsyms, 00025 uint32_t l_nreloc, 00026 uint32_t l_istlen, 00027 uint32_t l_nimpid, 00028 uint32_t l_impoff, 00029 uint32_t l_stlen, 00030 uint32_t l_stoff, 00031 uint32_t l_symoff, 00032 uint32_t l_rldoff); 00033 }; 00034 00035 class LSHeader32 : public LSHeader { 00036 protected: 00037 LDHDR entry; 00038 public: 00039 LSHeader32() {} 00040 ~LSHeader32() {} 00041 char* charStream() { return (char*)&entry; } 00042 00043 LOADERHEADER_MACROS_CLASS("For the get_X field macros check the defines directory"); 00044 }; 00045 00046 class LSHeader64 : public LSHeader { 00047 protected: 00048 LDHDR_64 entry; 00049 public: 00050 LSHeader64() {} 00051 ~LSHeader64() {} 00052 char* charStream() { return (char*)&entry; } 00053 00054 LOADERHEADER_MACROS_CLASS("For the get_X field macros check the defines directory"); 00055 GET_FIELD_CLASS(uint64_t,l_symoff); 00056 GET_FIELD_CLASS(uint64_t,l_rldoff); 00057 00058 }; 00059 00060 class LSSymbol { 00061 protected: 00062 LSSymbol() {} 00063 public: 00064 virtual void print(uint32_t index,LSFileNameTable* ft,LSStringTable* st); 00065 virtual char* charStream() { __SHOULD_NOT_ARRIVE; return NULL; } 00066 virtual char* getName(LSStringTable* st) { __SHOULD_NOT_ARRIVE; return NULL; } 00067 virtual uint32_t getNameOffset() { __SHOULD_NOT_ARRIVE; return 0; } 00068 00069 LOADERSYMBOL_MACROS_BASIS("For the get_X field macros check the defines directory"); 00070 00071 static LSSymbol* newSymbol(bool is64Bit,uint32_t nameOffset,uint32_t fileNameId); 00072 virtual ~LSSymbol() {} 00073 }; 00074 00075 class LSSymbol32 : public LSSymbol { 00076 protected: 00077 LDSYM entry; 00078 public: 00079 LSSymbol32() {} 00080 ~LSSymbol32() {} 00081 char* charStream() { return (char*)&entry; } 00082 char* getName(LSStringTable* st); 00083 uint32_t getNameOffset(); 00084 00085 LOADERSYMBOL_MACROS_CLASS("For the get_X field macros check the defines directory"); 00086 GET_FIELD_CLASS(char*,l_name); \ 00087 GET_FIELD_CLASS(uint32_t,l_zeroes); \ 00088 }; 00089 00090 class LSSymbol64 : public LSSymbol { 00091 protected: 00092 LDSYM_64 entry; 00093 public: 00094 LSSymbol64() {} 00095 ~LSSymbol64() {} 00096 char* charStream() { return (char*)&entry; } 00097 char* getName(LSStringTable* st); 00098 uint32_t getNameOffset(); 00099 00100 LOADERSYMBOL_MACROS_CLASS("For the get_X field macros check the defines directory"); 00101 }; 00102 00103 class LSRelocation { 00104 protected: 00105 LSRelocation() {} 00106 public: 00107 void print(uint32_t index,LSSymbol** syms,LSStringTable* st); 00108 virtual char* charStream() { __SHOULD_NOT_ARRIVE; return NULL; } 00109 00110 LOADERRELOC_MACROS_BASIS("For the get_X field macros check the defines directory"); 00111 00112 static LSRelocation* newRelocation(bool is64Bit,uint64_t addr,uint32_t idx,uint32_t sectId); 00113 virtual ~LSRelocation() {} 00114 00115 }; 00116 00117 class LSRelocation32 : public LSRelocation { 00118 protected: 00119 LDREL entry; 00120 public: 00121 LSRelocation32() {} 00122 ~LSRelocation32() {} 00123 char* charStream() { return (char*)&entry; } 00124 00125 LOADERRELOC_MACROS_CLASS("For the get_X field macros check the defines directory"); 00126 }; 00127 00128 class LSRelocation64 : public LSRelocation { 00129 protected: 00130 LDREL_64 entry; 00131 public: 00132 LSRelocation64() {} 00133 ~LSRelocation64() {} 00134 char* charStream() { return (char*)&entry; } 00135 00136 LOADERRELOC_MACROS_CLASS("For the get_X field macros check the defines directory"); 00137 }; 00138 00139 class LSFileNameTable { 00140 protected: 00141 00142 typedef struct { 00143 char* impidpath; 00144 char* impidbase; 00145 char* impidmem; 00146 } FileNameEntry; 00147 00148 uint32_t fileNameTableSize; 00149 uint32_t fileNameEntryCount; 00150 char* fileNameTablePtr; 00151 FileNameEntry* fileInfos; 00152 00153 LSFileNameTable() : fileNameTableSize(0),fileNameEntryCount(0),fileNameTablePtr(NULL),fileInfos(NULL) {} 00154 ~LSFileNameTable() {} 00155 public: 00156 LSFileNameTable(LSHeader* lsHeader,char* base); 00157 void print(); 00158 char* getName(uint32_t index) { ASSERT(index < fileNameEntryCount); return fileInfos[index].impidbase; } 00159 uint32_t getFileNameTableSize() { return fileNameTableSize; } 00160 char* getFileNameTablePtr() { return fileNameTablePtr; } 00161 uint32_t getFileNameEntryCount() { return fileNameEntryCount; } 00162 }; 00163 00164 class LSStringTable { 00165 protected: 00166 uint32_t stringTableSize; 00167 char* stringTablePtr; 00168 00169 LSStringTable() : stringTableSize(0),stringTablePtr(NULL) {} 00170 ~LSStringTable() {} 00171 public: 00172 LSStringTable(LSHeader* lsHeader,char* base); 00173 void print(); 00174 char* getStringCopy(uint32_t offset); 00175 char* getString(uint32_t offset); 00176 uint32_t getStringTableSize() { return stringTableSize; } 00177 char* getStringTablePtr() { return stringTablePtr; } 00178 }; 00179 00180 #endif