Theodosius  v3.0
Jit linker, mapper, obfuscator, and mutator
symbol.hpp
Go to the documentation of this file.
1 // Copyright (c) 2022, _xeroxz
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 //
7 // 1. Redistributions of source code must retain the above copyright notice,
8 // this list of conditions and the following disclaimer.
9 //
10 // 2. Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 //
14 // 3. Neither the name of the copyright holder nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 // POSSIBILITY OF SUCH DAMAGE.
29 //
30 
31 #pragma once
32 #include <coff/image.hpp>
33 #include <cstdint>
34 #include <recomp/reloc.hpp>
35 #include <string>
36 #include <vector>
37 
38 namespace theo::decomp {
43 enum sym_type_t { function, instruction, data, section };
44 
53 class symbol_t {
54  public:
70  explicit symbol_t(coff::image_t* img,
71  std::string name,
72  std::uintptr_t offset,
73  std::vector<std::uint8_t> data,
74  coff::section_header_t* scn = {},
75  coff::symbol_t* sym = {},
76  std::vector<recomp::reloc_t> relocs = {},
77  sym_type_t dcmp_type = {});
78 
83  std::string name() const;
84 
90  std::uintptr_t offset() const;
91 
96  std::uintptr_t allocated_at() const;
97 
102  std::uint32_t size() const;
103 
109  coff::section_header_t* scn() const;
110 
115  coff::image_t* img() const;
116 
122  std::vector<std::uint8_t>& data();
123 
128  coff::symbol_t* sym() const;
129 
134  sym_type_t type() const;
135 
140  std::vector<recomp::reloc_t>& relocs();
141 
146  void allocated_at(std::uintptr_t allocated_at);
147 
152  std::size_t hash();
153 
159  static std::size_t hash(const std::string& sym);
160 
181  static std::string name(const coff::image_t* img, coff::symbol_t* sym);
182 
183  private:
184  std::string m_name;
185  std::uintptr_t m_offset, m_allocated_at;
186  std::vector<std::uint8_t> m_data;
187  coff::section_header_t* m_scn;
188  std::vector<recomp::reloc_t> m_relocs;
189  sym_type_t m_sym_type;
190  coff::symbol_t* m_sym;
191  coff::image_t* m_img;
192 };
193 } // namespace theo::decomp
symbol_t is an abstraction upon the coff symbol. this allows for easier manipulation of the symbol....
Definition: symbol.hpp:53
coff::symbol_t * sym() const
returns a pointer to the coff symbol object.
Definition: symbol.cpp:92
sym_type_t type() const
returns the type of the symbol.
Definition: symbol.cpp:80
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::size_t hash()
gets the hash of the symbol name.
Definition: symbol.cpp:88
std::vector< std::uint8_t > & data()
returns a vector by reference of bytes containing the data of the symbol.
Definition: symbol.cpp:76
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.
Definition: symbol.cpp:34
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
std::uint32_t size() const
returns the size of the symbol.
Definition: symbol.cpp:72
std::uintptr_t allocated_at() const
returns the address where the symbol is allocated.
Definition: symbol.cpp:60
the namespace that contains all of the decomposition related code.
Definition: decomp.hpp:49
sym_type_t
meta symbol type. this is an abstraction upon the coff symbol storage/class type.
Definition: symbol.hpp:43