MCPcopy Create free account
hub / github.com/MJx0/KittyMemoryEx / symbols

Method symbols

KittyMemoryEx/KittyScanner.cpp:829–876  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

827#endif
828
829std::unordered_map<std::string, uintptr_t> ElfScanner::symbols()
830{
831 if (!_symbols_init && _loadBias && _stringTable && _symbolTable && _strsz && _syment)
832 {
833 _symbols_init = true;
834
835 auto get_sym_address = [&](const KT_ElfW(Sym) * sym_ent) -> uintptr_t {
836 return sym_ent->st_value < _loadBias ? _loadBias + sym_ent->st_value : sym_ent->st_value;
837 };
838
839 size_t symtab_sz = ((_stringTable > _symbolTable) ? (_stringTable - _symbolTable)
840 : (_symbolTable - _stringTable));
841 std::vector<char> symtab_buff(symtab_sz, 0);
842 std::vector<char> strtab_buff(_strsz, 0);
843
844 if (_pMem->Read(_symbolTable, symtab_buff.data(), symtab_buff.size()) &&
845 _pMem->Read(_stringTable, strtab_buff.data(), strtab_buff.size()))
846 {
847 uintptr_t sym_start = uintptr_t(symtab_buff.data());
848 uintptr_t sym_end = uintptr_t(symtab_buff.data() + symtab_buff.size());
849 uintptr_t sym_str_end = uintptr_t(strtab_buff.data() + strtab_buff.size());
850 for (auto sym_entry = sym_start; (sym_entry + _syment) < sym_end; sym_entry += _syment)
851 {
852 const KT_ElfW(Sym) *curr_sym = reinterpret_cast<KT_ElfW(Sym) *>(sym_entry);
853
854 if (curr_sym->st_name >= _strsz)
855 break;
856
857 if (intptr_t(curr_sym->st_name) <= 0 || intptr_t(curr_sym->st_value) <= 0 ||
858 intptr_t(curr_sym->st_size) <= 0)
859 continue;
860
861 if (KT_ELF_ST_TYPE(curr_sym->st_info) != STT_OBJECT && KT_ELF_ST_TYPE(curr_sym->st_info) != STT_FUNC)
862 continue;
863
864 uintptr_t sym_str_addr = uintptr_t(strtab_buff.data() + curr_sym->st_name);
865 if (!sym_str_addr || sym_str_addr >= sym_str_end)
866 continue;
867
868 std::string sym_str = std::string(reinterpret_cast<const char *>(sym_str_addr));
869 if (!sym_str.empty() && sym_str.data())
870 _symbolsMap[sym_str] = get_sym_address(curr_sym);
871 }
872 }
873 }
874
875 return _symbolsMap;
876}
877
878std::unordered_map<std::string, uintptr_t> ElfScanner::dsymbols()
879{

Callers

nothing calls this directly

Calls 1

ReadMethod · 0.80

Tested by

no test coverage detected