api_hashtable.cpp 1011 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include "api_hashtable.h"
  2. #include <furi.h>
  3. #include <algorithm>
  4. #define TAG "hashtable_api"
  5. bool elf_resolve_from_hashtable(
  6. const ElfApiInterface* interface,
  7. const char* name,
  8. Elf32_Addr* address) {
  9. const HashtableApiInterface* hashtable_interface =
  10. static_cast<const HashtableApiInterface*>(interface);
  11. bool result = false;
  12. uint32_t gnu_sym_hash = elf_gnu_hash(name);
  13. sym_entry key = {
  14. .hash = gnu_sym_hash,
  15. .address = 0,
  16. };
  17. auto find_res =
  18. std::lower_bound(hashtable_interface->table_cbegin, hashtable_interface->table_cend, key);
  19. if((find_res == hashtable_interface->table_cend || (find_res->hash != gnu_sym_hash))) {
  20. FURI_LOG_W(
  21. TAG,
  22. "Can't find symbol '%s' (hash %lx) @ %p!",
  23. name,
  24. gnu_sym_hash,
  25. hashtable_interface->table_cbegin);
  26. result = false;
  27. } else {
  28. result = true;
  29. *address = find_res->address;
  30. }
  31. return result;
  32. }