Theodosius  v3.0
Jit linker, mapper, obfuscator, and mutator
recomp.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 <decomp/decomp.hpp>
33 #include <obf/engine.hpp>
34 #include <recomp/symbol_table.hpp>
35 
39 namespace theo::recomp {
40 
44 using resolver_t = std::function<std::uintptr_t(std::string)>;
45 
49 using copier_t = std::function<void(std::uintptr_t, void*, std::uint32_t)>;
50 
57 using allocator_t =
58  std::function<std::uintptr_t(std::uint32_t,
59  coff::section_characteristics_t)>;
60 
64 class recomp_t {
65  public:
74  explicit recomp_t(decomp::decomp_t* dcmp,
75  allocator_t alloc,
76  copier_t copy,
78 
82  void allocate();
83 
87  void resolve();
88 
92  void copy_syms();
93 
99  void allocator(allocator_t alloc);
100 
106  void copier(copier_t copy);
107 
113 
119  std::uintptr_t resolve(const std::string&& sym);
120 
121  private:
122  decomp::decomp_t* m_dcmp;
123  resolver_t m_resolver;
124  copier_t m_copier;
125  allocator_t m_allocator;
126 };
127 } // namespace theo::recomp
the main decomposition class which is responsible for breaking down lib file into coff files,...
Definition: decomp.hpp:61
the main class responsible for recomposition
Definition: recomp.hpp:64
void copy_syms()
when called, this function copies symbols into allocations.
void allocator(allocator_t alloc)
setter for the allocater lambda function.
void resolver(resolver_t resolve)
setter for the resolve lambda function.
void resolve()
when called, this function resolves all relocations in every symbol.
void allocate()
when called, this function allocates space for every symbol.
void copier(copier_t copy)
setter for the copier lambda function.
recomp_t(decomp::decomp_t *dcmp, allocator_t alloc, copier_t copy, resolver_t resolve)
the explicit constructor for the recomp_t class.
std::uintptr_t resolve(const std::string &&sym)
resolves the address of a function given its name.
this namespace encompasses all recomposition related code.
Definition: recomp.hpp:39
std::function< void(std::uintptr_t, void *, std::uint32_t)> copier_t
a function which is called by recomp_t to copy symbols into memory.
Definition: recomp.hpp:49
std::function< std::uintptr_t(std::string)> resolver_t
a function which is called by recomp_t to resolve external symbols
Definition: recomp.hpp:44
std::function< std::uintptr_t(std::uint32_t, coff::section_characteristics_t)> allocator_t
a function which is called to allocate space for a symbol.
Definition: recomp.hpp:59