Theodosius  v3.0
Jit linker, mapper, obfuscator, and mutator
Public Member Functions | Static Public Member Functions | List of all members
theo::decomp::symbol_t Class Reference

symbol_t is an abstraction upon the coff symbol. this allows for easier manipulation of the symbol. symbols can be different things, sections, functions, and even instructions (when functions are broken down). More...

#include <symbol.hpp>

Public Member Functions

 symbol_t (coff::image_t *img, std::string name, std::uintptr_t offset, std::vector< std::uint8_t > data, coff::section_header_t *scn={}, coff::symbol_t *sym={}, std::vector< recomp::reloc_t > relocs={}, sym_type_t dcmp_type={})
 the explicit constructor of this symbol. More...
 
std::string name () const
 gets the name of the symbol. More...
 
std::uintptr_t offset () const
 gets the offset into the section where the symbol is located. More...
 
std::uintptr_t allocated_at () const
 returns the address where the symbol is allocated. More...
 
std::uint32_t size () const
 returns the size of the symbol. More...
 
coff::section_header_t * scn () const
 gets the section header of the section in which the symbol is contained. More...
 
coff::image_t * img () const
 gets the imagine in which the symbol is located inside of. More...
 
std::vector< std::uint8_t > & data ()
 returns a vector by reference of bytes containing the data of the symbol. More...
 
coff::symbol_t * sym () const
 returns a pointer to the coff symbol object. More...
 
sym_type_t type () const
 returns the type of the symbol. More...
 
std::vector< recomp::reloc_t > & relocs ()
 returns a vector of relocations. More...
 
void allocated_at (std::uintptr_t allocated_at)
 set the address where the symbol is allocated at. More...
 
std::size_t hash ()
 gets the hash of the symbol name. More...
 

Static Public Member Functions

static std::size_t hash (const std::string &sym)
 generate a hash given the name of the symbol. More...
 
static std::string name (const coff::image_t *img, coff::symbol_t *sym)
 get the name of a symbol. this function will create a symbol name if the symbol is opaquely named. More...
 

Detailed Description

symbol_t is an abstraction upon the coff symbol. this allows for easier manipulation of the symbol. symbols can be different things, sections, functions, and even instructions (when functions are broken down).

this class is used throughout theodosius and is a keystone of the project. ensure you understand how this class works and what it contains.

Constructor & Destructor Documentation

◆ symbol_t()

theo::decomp::symbol_t::symbol_t ( coff::image_t *  img,
std::string  name,
std::uintptr_t  offset,
std::vector< std::uint8_t >  data,
coff::section_header_t *  scn = {},
coff::symbol_t *  sym = {},
std::vector< recomp::reloc_t relocs = {},
sym_type_t  dcmp_type = {} 
)
explicit

the explicit constructor of this symbol.

Parameters
imgthe image in which the symbol is located in.
namethe name of the symbol.
offsetoffset into the section where this symbol is located.
datathe data of the symbol. there can be no data.
scnthe section header describing the section which contains the symbol.
symthe coff symbol itself.
relocsa vector of relocations this symbol has (if any).
dcmp_typethe type of symbol
42  : m_name(name),
43  m_offset(offset),
44  m_data(data),
45  m_scn(scn),
46  m_relocs(relocs),
47  m_sym_type(dcmp_type),
48  m_sym(sym),
49  m_img(img),
50  m_allocated_at(0) {}
coff::symbol_t * sym() const
returns a pointer to the coff symbol object.
Definition: symbol.cpp:92
coff::section_header_t * scn() const
gets the section header of the section in which the symbol is contained.
Definition: symbol.cpp:64
std::uintptr_t offset() const
gets the offset into the section where the symbol is located.
Definition: symbol.cpp:56
std::string name() const
gets the name of the symbol.
Definition: symbol.cpp:52
std::vector< std::uint8_t > & data()
returns a vector by reference of bytes containing the data of the symbol.
Definition: symbol.cpp:76
std::vector< recomp::reloc_t > & relocs()
returns a vector of relocations.
Definition: symbol.cpp:96
coff::image_t * img() const
gets the imagine in which the symbol is located inside of.
Definition: symbol.cpp:68

Member Function Documentation

◆ allocated_at() [1/2]

std::uintptr_t theo::decomp::symbol_t::allocated_at ( ) const

returns the address where the symbol is allocated.

Returns
the address where the symbol is allocated.
60  {
61  return m_allocated_at;
62 }

◆ allocated_at() [2/2]

void theo::decomp::symbol_t::allocated_at ( std::uintptr_t  allocated_at)

set the address where the symbol is allocated at.

Parameters
allocated_atwhere the symbol is allocated at.
84  {
85  m_allocated_at = allocated_at;
86 }
std::uintptr_t allocated_at() const
returns the address where the symbol is allocated.
Definition: symbol.cpp:60

◆ data()

std::vector< std::uint8_t > & theo::decomp::symbol_t::data ( )

returns a vector by reference of bytes containing the data of the symbol.

Returns
a vector by reference of bytes containing the data of the symbol.
76  {
77  return m_data;
78 }

◆ hash() [1/2]

std::size_t theo::decomp::symbol_t::hash ( )

gets the hash of the symbol name.

Returns
the hash of the symbol name.
88  {
89  return hash(m_name);
90 }
std::size_t hash()
gets the hash of the symbol name.
Definition: symbol.cpp:88

◆ hash() [2/2]

std::size_t theo::decomp::symbol_t::hash ( const std::string &  sym)
static

generate a hash given the name of the symbol.

Parameters
symthe symbol name to create a hash from.
Returns
the symbol name hash
100  {
101  return std::hash<std::string>{}(sym);
102 }

◆ img()

coff::image_t * theo::decomp::symbol_t::img ( ) const

gets the imagine in which the symbol is located inside of.

Returns
the imagine in which the symbol is located inside of.
68  {
69  return m_img;
70 }

◆ name() [1/2]

std::string theo::decomp::symbol_t::name ( ) const

gets the name of the symbol.

Returns
the name of the symbol.
52  {
53  return m_name;
54 }

◆ name() [2/2]

std::string theo::decomp::symbol_t::name ( const coff::image_t *  img,
coff::symbol_t *  sym 
)
static

get the name of a symbol. this function will create a symbol name if the symbol is opaquely named.

for example in c++ if you define something like this:

some_struct_t val = { value_one, value_two };

"val" will be stored in the .data section of the coff file. however the symbol name will be opaque (the name of the symbol will be ".data"). this causes issues with theo since each symbol needs its own unqiue name to generate a unique symbol name hash. for symbols like this, theo will create a name for it with the following format:

.data::section_index!coff_file_timestamp+offset_into_section

Parameters
imgthe coff file containing the symbol.
symthe coff symbol itself.
Returns
the name of the symbol, or a created one.
104  {
105  if (sym->has_section() &&
106  sym->storage_class == coff::storage_class_id::private_symbol &&
107  sym->derived_type == coff::derived_type_id::none) {
108  auto scn = img->get_section(sym->section_index - 1);
109  auto res = std::string(scn->name.to_string(img->get_strings()).data())
110  .append("#")
111  .append(std::to_string(sym->section_index))
112  .append("!")
113  .append(std::to_string(img->file_header.timedate_stamp))
114  .append("+")
115  .append(std::to_string(sym->value));
116 
117  return res;
118  }
119  return std::string(sym->name.to_string(img->get_strings()));
120 }

◆ offset()

std::uintptr_t theo::decomp::symbol_t::offset ( ) const

gets the offset into the section where the symbol is located.

Returns
the offset into the section where the symbol is located.
56  {
57  return m_offset;
58 }

◆ relocs()

std::vector< recomp::reloc_t > & theo::decomp::symbol_t::relocs ( )

returns a vector of relocations.

Returns
a vector of relocations.
96  {
97  return m_relocs;
98 }

◆ scn()

coff::section_header_t * theo::decomp::symbol_t::scn ( ) const

gets the section header of the section in which the symbol is contained.

Returns
the section header of the section in which the symbol is contained.
64  {
65  return m_scn;
66 }

◆ size()

std::uint32_t theo::decomp::symbol_t::size ( ) const

returns the size of the symbol.

Returns
the size of the symbol.
72  {
73  return m_data.size();
74 }

◆ sym()

coff::symbol_t * theo::decomp::symbol_t::sym ( ) const

returns a pointer to the coff symbol object.

Returns
a pointer to the coff symbol object.
92  {
93  return m_sym;
94 }

◆ type()

sym_type_t theo::decomp::symbol_t::type ( ) const

returns the type of the symbol.

Returns
the type of the symbol.
80  {
81  return m_sym_type;
82 }

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