elf_hashtable.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "compilesort.hpp"
  2. #include "elf_hashtable.h"
  3. #include "elf_hashtable_entry.h"
  4. #include "elf_hashtable_checks.hpp"
  5. #include <array>
  6. #include <algorithm>
  7. /* Generated table */
  8. #include <symbols.h>
  9. #define TAG "elf_hashtable"
  10. static_assert(!has_hash_collisions(elf_api_table), "Detected API method hash collision!");
  11. /**
  12. * Get function address by function name
  13. * @param name function name
  14. * @param address output for function address
  15. * @return true if the table contains a function
  16. */
  17. bool elf_resolve_from_hashtable(const char* name, Elf32_Addr* address) {
  18. bool result = false;
  19. uint32_t gnu_sym_hash = elf_gnu_hash(name);
  20. sym_entry key = {
  21. .hash = gnu_sym_hash,
  22. .address = 0,
  23. };
  24. auto find_res = std::lower_bound(elf_api_table.cbegin(), elf_api_table.cend(), key);
  25. if((find_res == elf_api_table.cend() || (find_res->hash != gnu_sym_hash))) {
  26. FURI_LOG_W(TAG, "Cant find symbol '%s' (hash %lx)!", name, gnu_sym_hash);
  27. result = false;
  28. } else {
  29. result = true;
  30. *address = find_res->address;
  31. }
  32. return result;
  33. }
  34. const ElfApiInterface hashtable_api_interface = {
  35. .api_version_major = (elf_api_version >> 16),
  36. .api_version_minor = (elf_api_version & 0xFFFF),
  37. .resolver_callback = &elf_resolve_from_hashtable,
  38. };