diff --git a/core/src/main/cpp/main/src/elf_util.cpp b/core/src/main/cpp/main/src/elf_util.cpp index 7512c527..949b0dc7 100644 --- a/core/src/main/cpp/main/src/elf_util.cpp +++ b/core/src/main/cpp/main/src/elf_util.cpp @@ -23,16 +23,14 @@ #include #include #include -#include #include #include "logging.h" #include "elf_util.h" using namespace SandHook; -namespace fs = std::filesystem; template -inline auto offsetOf(ElfW(Ehdr) *head, ElfW(Off) off) { +inline constexpr auto offsetOf(ElfW(Ehdr) *head, ElfW(Off) off) { return reinterpret_cast, T, T *>>( reinterpret_cast(head) + off); } @@ -68,7 +66,6 @@ ElfImg::ElfImg(std::string_view elf) : elf(elf) { if (bias == -4396) { dynsym = section_h; dynsym_offset = section_h->sh_offset; - dynsym_size = section_h->sh_size; dynsym_start = offsetOf(header, dynsym_offset); } break; @@ -116,8 +113,8 @@ ElfImg::ElfImg(std::string_view elf) : elf(elf) { gnu_bloom_size_ = d_buf[2]; gnu_shift2_ = d_buf[3]; gnu_bloom_filter_ = reinterpret_cast(d_buf + 4); - gnu_bucket_ = d_buf + 4 + gnu_bloom_size_ * - (header->e_ident[EI_CLASS] == ELFCLASS64 ? 2 : 1); + gnu_bucket_ = reinterpret_cast(gnu_bloom_filter_ + + gnu_bloom_size_); gnu_chain_ = gnu_bucket_ + gnu_nbucket_ - gnu_symndx_; break; } @@ -201,7 +198,8 @@ ElfImg::~ElfImg() { } } -ElfW(Addr) ElfImg::getSymbOffset(std::string_view name, uint32_t gnu_hash, uint32_t elf_hash) const { +ElfW(Addr) +ElfImg::getSymbOffset(std::string_view name, uint32_t gnu_hash, uint32_t elf_hash) const { if (auto offset = GnuLookup(name, gnu_hash); offset > 0) { LOGD("found %s %p in %s in dynsym by gnuhash", name.data(), reinterpret_cast(offset), elf.data()); diff --git a/core/src/main/cpp/main/src/elf_util.h b/core/src/main/cpp/main/src/elf_util.h index 6fa3cf3a..9772cd56 100644 --- a/core/src/main/cpp/main/src/elf_util.h +++ b/core/src/main/cpp/main/src/elf_util.h @@ -85,7 +85,6 @@ namespace SandHook { ElfW(Off) symtab_offset = 0; ElfW(Off) dynsym_offset = 0; ElfW(Off) symtab_size = 0; - ElfW(Off) dynsym_size = 0; uint32_t nbucket_{}; uint32_t *bucket_ = nullptr;