Theodosius v3.0
Jit linker, symbol mapper, and obfuscator
Public Member Functions
theo::recomp::symbol_table_t Class Reference

this class is a high level wrapper for a hashmap that contains decomp::symbol_t values. the symbol values are references by a hashcode. More...

#include "symbol_table.hpp"

Public Member Functions

 symbol_table_t ()
 default constructor. does nothing. More...
 
 symbol_table_t (const std::vector< decomp::symbol_t > &&syms)
 this constructor will populate the m_table private field with symbols. More...
 
void put_symbol (decomp::symbol_t &sym)
 add symbol to m_table More...
 
void put_symbols (std::vector< decomp::symbol_t > &syms)
 add a vector of symbol to m_table More...
 
std::optional< decomp::symbol_t * > sym_from_hash (std::size_t hash)
 returns an optional pointer to a symbol from the symbol table given the symbols hash (hash of its name) the hash is produced by theo::decomp::symbol_t::hash More...
 
std::optional< decomp::symbol_t * > sym_from_alloc (std::uintptr_t allocated_at)
 returns an optional pointer to a symbol given its allocation location. More...
 
void for_each (std::function< void(decomp::symbol_t &sym)> fn)
 this function is a wrapper function that allows you to get at each entry in the symbol table by reference. More...
 
std::uint32_t size ()
 returns the size of the symbol table. More...
 

Detailed Description

this class is a high level wrapper for a hashmap that contains decomp::symbol_t values. the symbol values are references by a hashcode.

Definition at line 45 of file symbol_table.hpp.

Constructor & Destructor Documentation

◆ symbol_table_t() [1/2]

theo::recomp::symbol_table_t::symbol_table_t ( )
inline

default constructor. does nothing.

Definition at line 50 of file symbol_table.hpp.

50{}

◆ symbol_table_t() [2/2]

theo::recomp::symbol_table_t::symbol_table_t ( const std::vector< decomp::symbol_t > &&  syms)

this constructor will populate the m_table private field with symbols.

Parameters
symsvector of decomp::symbol_t

Definition at line 34 of file symbol_table.cpp.

34 {
35 std::for_each(syms.begin(), syms.end(), [&](decomp::symbol_t sym) {
36 m_table.insert({sym.hash(), sym});
37 });
38}

Member Function Documentation

◆ for_each()

void theo::recomp::symbol_table_t::for_each ( std::function< void(decomp::symbol_t &sym)>  fn)

this function is a wrapper function that allows you to get at each entry in the symbol table by reference.

Parameters
fna callback function that will be called for each symbol

Definition at line 49 of file symbol_table.cpp.

49 {
50 for (auto itr = m_table.begin(); itr != m_table.end(); ++itr)
51 fn(itr->second);
52}

Referenced by theo::recomp::recomp_t::allocate(), and theo::theo_t::compose().

◆ put_symbol()

void theo::recomp::symbol_table_t::put_symbol ( decomp::symbol_t sym)

add symbol to m_table

Parameters
symsymbol to be added.

Definition at line 40 of file symbol_table.cpp.

40 {
41 m_table.insert({sym.hash(), sym});
42}

References theo::decomp::symbol_t::hash().

◆ put_symbols()

void theo::recomp::symbol_table_t::put_symbols ( std::vector< decomp::symbol_t > &  syms)

add a vector of symbol to m_table

Parameters
syms

Definition at line 44 of file symbol_table.cpp.

44 {
45 std::for_each(syms.begin(), syms.end(),
46 [&](decomp::symbol_t sym) { put_symbol(sym); });
47}

◆ size()

std::uint32_t theo::recomp::symbol_table_t::size ( )

returns the size of the symbol table.

Returns
returns the size of the symbol table.

Definition at line 72 of file symbol_table.cpp.

72 {
73 return m_table.size();
74}

◆ sym_from_alloc()

std::optional< decomp::symbol_t * > theo::recomp::symbol_table_t::sym_from_alloc ( std::uintptr_t  allocated_at)

returns an optional pointer to a symbol given its allocation location.

Parameters
allocated_atthe address where the symbol is allocated at.
Returns
returns an optional pointer to a theo::decomp::symbol_t

Definition at line 60 of file symbol_table.cpp.

61 {
62 auto res =
63 std::find_if(m_table.begin(), m_table.end(),
64 [&](std::pair<const std::size_t, decomp::symbol_t> itr) {
65 return itr.second.allocated_at() == allocated_at;
66 });
67
68 return res != m_table.end() ? &res->second
69 : std::optional<decomp::symbol_t*>{};
70}

◆ sym_from_hash()

std::optional< decomp::symbol_t * > theo::recomp::symbol_table_t::sym_from_hash ( std::size_t  hash)

returns an optional pointer to a symbol from the symbol table given the symbols hash (hash of its name) the hash is produced by theo::decomp::symbol_t::hash

Parameters
hashhashcode of the symbol to get from the symbol table...
Returns
returns an optional pointer to a theo::decomp::symbol_t

Definition at line 54 of file symbol_table.cpp.

55 {
56 return m_table.count(hash) ? &m_table.at(hash)
57 : std::optional<decomp::symbol_t*>{};
58}

Referenced by theo::theo_t::resolve().


The documentation for this class was generated from the following files: