// Copyright (c) 2022, _xeroxz // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // 1. Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // 2. Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // // 3. Neither the name of the copyright holder nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. // #pragma once #include #include #include /// /// this namespace encompasses all recomposition related code. /// namespace theo::recomp { /// /// a function which is called by recomp_t to resolve external symbols /// using resolver_t = std::function; /// /// a function which is called by recomp_t to copy symbols into memory. /// using copier_t = std::function; /// /// a function which is called to allocate space for a symbol. /// /// the first param is the size of the symbol, the second param is the /// characteristics of the section which the symbol is allocated in. /// using allocator_t = std::function; /// /// the main class responsible for recomposition /// class recomp_t { public: /// /// the explicit constructor for the recomp_t class. /// /// pointer to a decomp_t class. /// lambda function which is used to allocate memory for /// symbols. lambda function used to copy bytes /// into allocations. lambda function used to /// resolve external symbols. explicit recomp_t(decomp::decomp_t* dcmp, allocator_t alloc, copier_t copy, resolver_t resolve); /// /// when called, this function allocates space for every symbol. /// void allocate(); /// /// when called, this function resolves all relocations in every symbol. /// void resolve(); /// /// when called, this function copies symbols into allocations. /// void copy_syms(); /// /// setter for the allocater lambda function. /// /// lambda function which allocates memory for /// symbols. void allocator(allocator_t alloc); /// /// setter for the copier lambda function. /// /// copier lambda function used to copy bytes into /// allocations made by the allocator. void copier(copier_t copy); /// /// setter for the resolve lambda function. /// /// lambda function to resolve external symbols. void resolver(resolver_t resolve); /// /// resolves the address of a function given its name. /// /// the name of the symbol to resolve the location /// of. the address of the symbol. std::uintptr_t resolve(const std::string&& sym); private: decomp::decomp_t* m_dcmp; resolver_t m_resolver; copier_t m_copier; allocator_t m_allocator; }; } // namespace theo::recomp