【发布时间】:2021-04-19 06:03:47
【问题描述】:
几天前,我查看了精灵符号表来比较字符串以找到我的函数。 我可以很好地找到目标字符串,并且成功获得了起始偏移量和大小。 但是,将这个偏移量与objdump的结果进行比较,可以看出1个字节是不同的。 怎么了? 我英语不好。
操作系统:Windows 10
ide : android studio ndk
目标拱门:armeabi-v7a
结果图片:
申请结果:0x00908b5
预期结果:0x00908b4
我检查了什么:
- elf32_sym、elf64_sym 已检查(没问题)
- 已检查结构字节填充(没问题)
- 结构,变量初始化检查
这是从开发者的 git 中克隆出来的。
template <typename ElfHeaderT, typename SectionHeaderT, typename CallbackT>
void read_sections(const void *image, size_t size, const CallbackT &callback)
{
const ElfHeaderT *ehdr = static_cast<const ElfHeaderT *>(image);
const SectionHeaderT *shdrs = (const SectionHeaderT *)((const uint8_t *)image + ehdr->e_shoff);
const SectionHeaderT *strhdr = &shdrs[ehdr->e_shstrndx];
const char *strtab = static_cast<const char *>(image) + strhdr->sh_offset;
for (int i = 0; i < ehdr->e_shnum; ++i)
{
section s = {0,};
s.index= i;
s.name = strtab + shdrs[i].sh_name;
s.type = shdrs[i].sh_type;
s.virtual_address = static_cast<ptrdiff_t>(shdrs[i].sh_addr);
s.file_offset = static_cast<ptrdiff_t>(shdrs[i].sh_offset);
s.size = static_cast<size_t>(shdrs[i].sh_size);
s.entry_size = static_cast<size_t>(shdrs[i].sh_entsize);
s.address_align = static_cast<size_t>(shdrs[i].sh_addralign);
callback(s);
}
}
template <typename SymbolEntryT, typename CallbackT>
void read_symbols(const void *image, unsigned int code_section_index, const section &symbols, const char *names,
const CallbackT &callback)
{
const size_t total_syms = symbols.size / sizeof(SymbolEntryT);
const SymbolEntryT *syms_data = (const SymbolEntryT *)((const uint8_t *)image + symbols.file_offset);
for (size_t i = 0; i < total_syms; ++i)
{
symbol s = {0,};
const SymbolEntryT &sd = syms_data[i];
const unsigned type = ELF32_ST_TYPE(sd.st_info);
if (type != STT_FUNC)
continue;
if (sd.st_shndx != code_section_index || !sd.st_size)
continue;
s.name = names + sd.st_name;
s.size = static_cast<size_t>(sd.st_size);
s.virtual_address = static_cast<size_t>(sd.st_value);
callback(s);
}
}
【问题讨论】:
-
这里不是 100% 确定,但我认为低位表示拇指代码。所以分支到 0x00908b5 实际上将 pc 设置为 0x00908b4 但开始在该地址执行拇指代码。
-
我知道 THUMB 模式是 16 位位命令集。我需要更详细的知识,你能解释一下吗?
-
我检查了Thumb模式的内容。如果是这样,我可以从计算的函数偏移量中减去 1 吗?