• Home
  • Raw
  • Download

Lines Matching refs:elfFile

99 static int readElfHeader(ifstream& elfFile, Elf64_Ehdr* eh) {  in readElfHeader()  argument
100 elfFile.seekg(0); in readElfHeader()
101 if (elfFile.fail()) return -1; in readElfHeader()
103 if (!elfFile.read((char*)eh, sizeof(*eh))) return -1; in readElfHeader()
109 static int readSectionHeadersAll(ifstream& elfFile, vector<Elf64_Shdr>& shTable) { in readSectionHeadersAll() argument
113 ret = readElfHeader(elfFile, &eh); in readSectionHeadersAll()
116 elfFile.seekg(eh.e_shoff); in readSectionHeadersAll()
117 if (elfFile.fail()) return -1; in readSectionHeadersAll()
122 if (!elfFile.read((char*)shTable.data(), (eh.e_shnum * eh.e_shentsize))) return -ENOMEM; in readSectionHeadersAll()
128 static int readSectionByIdx(ifstream& elfFile, int id, vector<char>& sec) { in readSectionByIdx() argument
132 ret = readSectionHeadersAll(elfFile, shTable); in readSectionByIdx()
136 elfFile.seekg(shTable[id].sh_offset); in readSectionByIdx()
137 if (elfFile.fail()) return -1; in readSectionByIdx()
140 if (!elfFile.read(sec.data(), shTable[id].sh_size)) return -1; in readSectionByIdx()
146 static int readSectionHeaderStrtab(ifstream& elfFile, vector<char>& strtab) { in readSectionHeaderStrtab() argument
150 ret = readElfHeader(elfFile, &eh); in readSectionHeaderStrtab()
153 ret = readSectionByIdx(elfFile, eh.e_shstrndx, strtab); in readSectionHeaderStrtab()
160 static int getSymName(ifstream& elfFile, int nameOff, string& name) { in getSymName() argument
164 ret = readSectionHeaderStrtab(elfFile, secStrTab); in getSymName()
174 static int readSectionByName(const char* name, ifstream& elfFile, vector<char>& data) { in readSectionByName() argument
179 ret = readSectionHeadersAll(elfFile, shTable); in readSectionByName()
182 ret = readSectionHeaderStrtab(elfFile, secStrTab); in readSectionByName()
193 elfFile.seekg(shTable[i].sh_offset); in readSectionByName()
194 if (elfFile.fail()) return -1; in readSectionByName()
196 if (!elfFile.read((char*)dataTmp.data(), shTable[i].sh_size)) return -1; in readSectionByName()
205 static int readSectionByType(ifstream& elfFile, int type, vector<char>& data) { in readSectionByType() argument
209 ret = readSectionHeadersAll(elfFile, shTable); in readSectionByType()
218 elfFile.seekg(shTable[i].sh_offset); in readSectionByType()
219 if (elfFile.fail()) return -1; in readSectionByType()
221 if (!elfFile.read((char*)dataTmp.data(), shTable[i].sh_size)) return -1; in readSectionByType()
233 static int readSymTab(ifstream& elfFile, int sort, vector<Elf64_Sym>& data) { in readSymTab() argument
238 ret = readSectionByType(elfFile, SHT_SYMTAB, secData); in readSymTab()
282 static int readCodeSections(ifstream& elfFile, vector<codeSection>& cs) { in readCodeSections() argument
286 ret = readSectionHeadersAll(elfFile, shTable); in readCodeSections()
295 ret = getSymName(elfFile, shTable[i].sh_name, name); in readCodeSections()
304 ret = readSectionByIdx(elfFile, i, cs_temp.data); in readCodeSections()
311 ret = getSymName(elfFile, shTable[i + 1].sh_name, name); in readCodeSections()
315 ret = readSectionByIdx(elfFile, i + 1, cs_temp.rel_data); in readCodeSections()
329 static int getSymNameByIdx(ifstream& elfFile, int index, string& name) { in getSymNameByIdx() argument
333 ret = readSymTab(elfFile, 0 /* !sort */, symtab); in getSymNameByIdx()
338 return getSymName(elfFile, symtab[index].st_name, name); in getSymNameByIdx()
341 static int getMapNames(ifstream& elfFile, vector<string>& names) { in getMapNames() argument
347 ret = readSymTab(elfFile, 1 /* sort */, symtab); in getMapNames()
351 ret = readSectionHeadersAll(elfFile, shTable); in getMapNames()
356 ret = getSymName(elfFile, shTable[i].sh_name, mapName); in getMapNames()
374 ret = getSymName(elfFile, symtab[i].st_name, s); in getMapNames()
383 static int createMaps(const char* elfPath, ifstream& elfFile, vector<int>& mapFds) { in createMaps() argument
390 ret = readSectionByName("maps", elfFile, mdData); in createMaps()
395 ret = getMapNames(elfFile, mapNames); in createMaps()
475 static void applyMapRelo(ifstream& elfFile, vector<int> mapFds, vector<codeSection>& cs) { in applyMapRelo() argument
478 int ret = getMapNames(elfFile, mapNames); in applyMapRelo()
489 ret = getSymNameByIdx(elfFile, symIndex, symName); in applyMapRelo()
554 ifstream elfFile(elfPath, ios::in | ios::binary); in loadProg() local
555 if (!elfFile.is_open()) return -1; in loadProg()
557 ret = readSectionByName("license", elfFile, license); in loadProg()
565 ret = readCodeSections(elfFile, cs); in loadProg()
574 ret = createMaps(elfPath, elfFile, mapFds); in loadProg()
583 applyMapRelo(elfFile, mapFds, cs); in loadProg()