MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / ParseSymbolTable

Method ParseSymbolTable

view/kernelcache/core/KernelCache.cpp:1681–1784  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1679
1680
1681std::vector<std::pair<uint64_t, std::pair<BNSymbolType, std::string>>> KernelCache::ParseSymbolTable(Ref<BinaryView> view, KernelCacheMachOHeader header, bool defineSymbolsInView)
1682{
1683 if (header.symtab.symoff != 0 && header.linkeditPresent)
1684 {
1685 // Mach-O View symtab processing with
1686 // a ton of stuff cut out so it can work
1687 // auto symtab = reader->ReadBuffer(header.symtab.symoff, header.symtab.nsyms * sizeof(nlist_64));
1688 auto strtab = view->GetParentView()->ReadBuffer(header.symtab.stroff, header.symtab.strsize);
1689 nlist_64 sym;
1690 memset(&sym, 0, sizeof(sym));
1691 std::vector<std::pair<uint64_t, std::pair<BNSymbolType, std::string>>> symbolInfos;
1692 for (size_t i = 0; i < header.symtab.nsyms; i++)
1693 {
1694 view->GetParentView()->Read(&sym, header.symtab.symoff + i * sizeof(nlist_64), sizeof(nlist_64));
1695 if (sym.n_strx >= header.symtab.strsize || ((sym.n_type & N_TYPE) == N_INDR))
1696 continue;
1697
1698 std::string symbol((char*)strtab.GetDataAt(sym.n_strx));
1699 // BNLogError("%s: 0x%llx", symbol.c_str(), sym.n_value);
1700 if (symbol == "<redacted>")
1701 continue;
1702
1703 BNSymbolType type = DataSymbol;
1704 uint32_t flags;
1705 if ((sym.n_type & N_TYPE) == N_SECT && sym.n_sect > 0 && (size_t)(sym.n_sect - 1) < header.sections.size())
1706 {}
1707 else if ((sym.n_type & N_TYPE) == N_ABS)
1708 {}
1709 else if ((sym.n_type & 0x1))
1710 {
1711 type = ExternalSymbol;
1712 }
1713 else
1714 continue;
1715
1716 for (auto s : header.sections)
1717 {
1718 if (s.addr < sym.n_value)
1719 {
1720 if (s.addr + s.size > sym.n_value)
1721 {
1722 flags = s.flags;
1723 }
1724 }
1725 }
1726
1727 if (type != ExternalSymbol)
1728 {
1729 if ((flags & S_ATTR_PURE_INSTRUCTIONS) == S_ATTR_PURE_INSTRUCTIONS
1730 || (flags & S_ATTR_SOME_INSTRUCTIONS) == S_ATTR_SOME_INSTRUCTIONS)
1731 type = FunctionSymbol;
1732 else
1733 type = DataSymbol;
1734 }
1735 if ((sym.n_desc & N_ARM_THUMB_DEF) == N_ARM_THUMB_DEF)
1736 sym.n_value++;
1737
1738 std::string rawName = symbol;

Callers

nothing calls this directly

Calls 15

DemangleGenericFunction · 0.85
GetParentViewMethod · 0.80
GetDataAtMethod · 0.80
Get<bool>Method · 0.80
GetStringAfterNameMethod · 0.80
GetFunctionByNameMethod · 0.80
GetDefaultPlatformMethod · 0.80
c_strMethod · 0.80
DefineAutoSymbolMethod · 0.80

Tested by

no test coverage detected