00001 #ifndef _XCoffFile_h_
00002 #define _XCoffFile_h_
00003
00004 #include <Base.h>
00005 #include <BinaryFile.h>
00006
00007 class FileHeader;
00008 class AOutHeader;
00009 class SectHeader;
00010 class RawSection;
00011 class SymbolTable;
00012 class StringTable;
00013 class DebugSection;
00014 class HashCode;
00015 class BasicBlock;
00016 class RelocationTable;
00017 class LineInfoTable;
00018
00019 class XCoffFile {
00020 private:
00021 bool is64BitFlag;
00022
00023 char* xcoffFileName;
00024
00025 BinaryInputFile binaryInputFile;
00026
00027 FileHeader* fileHeader;
00028 AOutHeader* aOutHeader;
00029 SectHeader** sectHeaders;
00030 RawSection** rawSections;
00031
00032 SymbolTable* symbolTable;
00033 StringTable* stringTable;
00034
00035 uint32_t numberOfSections;
00036
00037 uint16_t textSectionIndex;
00038 uint16_t dataSectionIndex;
00039 uint16_t bssSectionIndex;
00040 uint16_t loaderSectionIndex;
00041 uint16_t tocSectionIndex;
00042 uint16_t entrySectionIndex;
00043
00044 uint32_t numberOfFunctions;
00045 uint32_t numberOfBlocks;
00046 uint32_t numberOfMemoryOps;
00047 uint32_t numberOfFloatPOps;
00048
00049 void readFileHeader();
00050 void readAuxilaryHeader();
00051 void readSectionHeaders();
00052 void processOverflowSections();
00053 void readRawSectionData();
00054 void readSymbolStringTable(DebugSection* dbg);
00055 void readRelocLineInfoTable();
00056
00057
00058 void findFunctions();
00059 void generateCFGs();
00060 void findMemoryFloatOps();
00061
00062 public:
00063
00064 XCoffFile(char* f): is64BitFlag(false),xcoffFileName(f),
00065 fileHeader(NULL),aOutHeader(NULL),sectHeaders(NULL),rawSections(NULL),
00066 symbolTable(NULL),stringTable(NULL),numberOfSections(0),
00067 textSectionIndex(0),dataSectionIndex(0),bssSectionIndex(0),
00068 loaderSectionIndex(0),tocSectionIndex(0),entrySectionIndex(0),
00069 numberOfFunctions(0),numberOfBlocks(0),numberOfMemoryOps(0),numberOfFloatPOps(0) {}
00070
00071 ~XCoffFile() { }
00072
00073 bool is64Bit() { return is64BitFlag; }
00074
00075 void parse();
00076
00077 void briefPrint();
00078 void print();
00079 void displaySymbols();
00080
00081 RawSection* findRawSection(uint64_t addr);
00082 uint64_t getTOCAddress();
00083 RawSection* getTOCSection();
00084 uint32_t getTOCSectionIndex() { return tocSectionIndex; }
00085 uint64_t readTOC(int32_t offset);
00086 char* getXCoffFileName() { return xcoffFileName; }
00087
00088 uint32_t getNumberOfSections() { return numberOfSections; }
00089
00090 FileHeader* getFileHeader() { return fileHeader; }
00091 AOutHeader* getAOutHeader() { return aOutHeader; }
00092 SymbolTable* getSymbolTable() { return symbolTable; }
00093 StringTable* getStringTable() { return stringTable; }
00094
00095 SectHeader* getSectHeader(uint32_t idx) { return sectHeaders[idx]; }
00096 RawSection* getRawSection(uint32_t idx) { return rawSections[idx]; }
00097 RelocationTable* getRelocationTable(uint32_t idx);
00098 LineInfoTable* getLineInfoTable(uint32_t idx);
00099
00100 uint32_t getNumberOfFunctions() { return numberOfFunctions; }
00101 uint32_t getNumberOfBlocks() { return numberOfBlocks; }
00102 uint32_t getNumberOfMemoryOps() { return numberOfMemoryOps; }
00103 uint32_t getNumberOfFloatPOps() { return numberOfFloatPOps; }
00104
00105 BasicBlock* findBasicBlock(HashCode* hashCode);
00106 uint32_t getAllBlocks(BasicBlock** arr);
00107
00108 uint32_t getFileSize();
00109
00110 uint16_t getLoaderSectionIndex() { return loaderSectionIndex; }
00111 RawSection* getLoaderSection();
00112 uint16_t getDataSectionIndex() { return dataSectionIndex; }
00113 uint64_t getDataSectionVAddr();
00114 uint32_t getDataSectionSize();
00115 RawSection* getBSSSection();
00116 uint16_t getBSSSectionIndex() { return bssSectionIndex; }
00117 uint64_t getBSSSectionVAddr();
00118 uint64_t getTextSectionIndex() { return textSectionIndex; }
00119 uint64_t getTextSectionVAddr();
00120
00121 void setLineInfoFinder();
00122 void findLoops();
00123
00124 void testBitSet();
00125
00126 };
00127
00198 #endif