MCPcopy Create free account
hub / github.com/cinit/TMoe / getExtSymGotRelVirtAddr

Method getExtSymGotRelVirtAddr

app/src/main/cpp/utils/elfsym/ElfView.cpp:243–358  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

241}
242
243std::vector<uint64_t> ElfView::getExtSymGotRelVirtAddr(const char *symbol) const {
244 if (symbol == nullptr) {
245 return {};
246 }
247 if (mPointerSize == 4) {
248 // ELF32
249 std::vector<uint64_t> result;
250 ElfInfo info = {};
251 if (getElfInfo(info) != mPointerSize) {
252 return result;
253 }
254 // find symbol
255 const Elf32_Sym *sym = nullptr;
256 uint32_t symidx = 0;
257 if (findSymByName32(info, symbol, &sym, &symidx)) {
258 if (info.use_rela) {
259 for (int i = 0; i < info.relplt_size; i++) {
260 const Elf32_Rela &rel = ((const Elf32_Rela *) info.relplt)[i];
261 if (ELF32_R_SYM(rel.r_info) == symidx
262 && (ELF32_R_TYPE(rel.r_info) == R_ARM_JUMP_SLOT
263 || ELF32_R_TYPE(rel.r_info) == R_386_JMP_SLOT)) {
264 result.emplace_back(uint64_t(rel.r_offset));
265 break;
266 }
267 }
268 for (int i = 0; i < info.reldyn_size; i++) {
269 const Elf32_Rela &rel = ((const Elf32_Rela *) info.reldyn)[i];
270 if (ELF32_R_SYM(rel.r_info) == symidx &&
271 (ELF32_R_TYPE(rel.r_info) == R_ARM_ABS32
272 || ELF32_R_TYPE(rel.r_info) == R_ARM_GLOB_DAT
273 || ELF32_R_TYPE(rel.r_info) == R_386_32
274 || ELF32_R_TYPE(rel.r_info) == R_386_GLOB_DAT)) {
275 result.emplace_back(uint64_t(rel.r_offset));
276 }
277 }
278 } else {
279 for (int i = 0; i < info.relplt_size; i++) {
280 const Elf32_Rela &rel = ((const Elf32_Rela *) info.relplt)[i];
281 if (ELF32_R_SYM(rel.r_info) == symidx
282 && (ELF32_R_TYPE(rel.r_info) == R_ARM_JUMP_SLOT
283 || ELF32_R_TYPE(rel.r_info) == R_386_JMP_SLOT)) {
284 result.emplace_back(uint64_t(rel.r_offset));
285 break;
286 }
287 }
288 for (int i = 0; i < info.reldyn_size; i++) {
289 const Elf32_Rela &rel = ((const Elf32_Rela *) info.reldyn)[i];
290 if (ELF32_R_SYM(rel.r_info) == symidx &&
291 (ELF32_R_TYPE(rel.r_info) == R_ARM_ABS32
292 || ELF32_R_TYPE(rel.r_info) == R_ARM_GLOB_DAT
293 || ELF32_R_TYPE(rel.r_info) == R_386_32
294 || ELF32_R_TYPE(rel.r_info) == R_386_GLOB_DAT)) {
295 result.emplace_back(uint64_t(rel.r_offset));
296 }
297 }
298 }
299 }
300 return result;

Callers

nothing calls this directly

Calls 2

findSymByName32Function · 0.85
findSymByName64Function · 0.85

Tested by

no test coverage detected