00001 #include <SymbolTable.h> 00002 #include <RelocationTable.h> 00003 #include <XCoffFile.h> 00004 #include <BinaryFile.h> 00005 00006 RelocationTable::RelocationTable(char* ptr,uint32_t s,XCoffFile* xcoff) 00007 : Base(XCoffClassTypes_relocation), 00008 relocationPtr(ptr),numOfRelocations(s), 00009 symbolTable(NULL),xCoffFile(xcoff) 00010 { 00011 if(getXCoffFile()->is64Bit()){ 00012 sizeInBytes = numOfRelocations * Size__64_bit_RelocationTable_Entry; 00013 } else { 00014 sizeInBytes = numOfRelocations * Size__32_bit_RelocationTable_Entry; 00015 } 00016 relocations = new Relocation*[numOfRelocations]; 00017 } 00018 00019 void Relocation::print(SymbolTable* symbolTable,uint32_t index){ 00020 PRINT_INFOR("\tRLC [%3d](adr %#llx)(sym %9d)(sze %3d)(typ %3d)", 00021 index,GET(r_vaddr),GET(r_symndx),GET(r_rsize),GET(r_rtype)); 00022 if(symbolTable){ 00023 symbolTable->printSymbol(GET(r_symndx)); 00024 } 00025 } 00026 00027 void RelocationTable::print(){ 00028 PRINT_INFOR("RELOCATIONTABLE"); 00029 PRINT_INFOR("\tCount : %d",numOfRelocations); 00030 00031 PRINT_INFOR("\tReloc :"); 00032 for(uint32_t i = 0;i<numOfRelocations;i++){ 00033 relocations[i]->print(symbolTable,i); 00034 } 00035 } 00036 00037 uint32_t RelocationTable::read(BinaryInputFile* binaryInputFile){ 00038 00039 PRINT_DEBUG("Reading the Relocation table"); 00040 00041 binaryInputFile->setInPointer(relocationPtr); 00042 setFileOffset(binaryInputFile->currentOffset()); 00043 00044 uint32_t currSize = Size__32_bit_RelocationTable_Entry; 00045 if(getXCoffFile()->is64Bit()){ 00046 currSize = Size__64_bit_RelocationTable_Entry; 00047 } 00048 00049 uint32_t ret = 0; 00050 for(uint32_t i = 0;i<numOfRelocations;i++){ 00051 if(getXCoffFile()->is64Bit()){ 00052 relocations[i] = new Relocation64(); 00053 } else { 00054 relocations[i] = new Relocation32(); 00055 } 00056 binaryInputFile->copyBytesIterate(relocations[i]->charStream(),currSize); 00057 ret += currSize; 00058 } 00059 00060 ASSERT((sizeInBytes == ret) && "FATAL : Somehow the number of read does not match"); 00061 00062 return sizeInBytes; 00063 }