diff --git a/examples/demolib/main.cpp b/examples/demolib/main.cpp index cf42f3a..95b4516 100644 --- a/examples/demolib/main.cpp +++ b/examples/demolib/main.cpp @@ -15,7 +15,7 @@ test_t t = {"Hello", "World", {}}; OBF extern "C" void EntryPoint() { t.buff[0] = 1; - t.buff[1] = 1; + t.buff[1] = 0; if (t.buff[0]) MessageBoxA(nullptr, t.c, t.c2, nullptr); diff --git a/include/recomp/reloc.hpp b/include/recomp/reloc.hpp index 94b7be6..5fdd968 100644 --- a/include/recomp/reloc.hpp +++ b/include/recomp/reloc.hpp @@ -27,14 +27,11 @@ // 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 - namespace theo::recomp { - /// /// meta data about a relocation for a symbol /// @@ -53,19 +50,16 @@ class reloc_t { std::size_t hash, const std::string&& sym_name) : m_offset(offset), m_hash(hash), m_sym_name(sym_name) {} - /// /// returns the hash of the relocation symbol. /// /// hash of the relocation symbol std::size_t hash() { return m_hash; } - /// /// returns the name of the relocation symbol. /// /// returns the name of the relocation symbol. std::string name() { return m_sym_name; } - /// /// returns the offset into the symbol to which the relocation will be /// applied. the offset is in bytes. zero based. @@ -73,15 +67,35 @@ class reloc_t { /// returns the offset into the symbol to which the relocation will /// be applied. the offset is in bytes. zero based. std::uint32_t offset() { return m_offset; } - /// /// sets the offset to which the relocation gets applied too. /// /// offset to which the relocation gets applied /// too. void offset(std::uint32_t offset) { m_offset = offset; } + /// + /// adds a transformation to be applied to the relocation prior to writing it + /// into the symbol. + /// + /// a pair containing a lambda function that when executed + /// transforms a relocation. the second value in the pair is a random value + /// which is passed to the lambda. + void add_transform( + std::pair entry) { + m_transforms.push_back(entry); + } + /// + /// gets the vector of transformation. + /// + /// returns the vector of transformations. + std::vector>& + get_transforms() { + return m_transforms; + } private: + std::vector> + m_transforms; std::string m_sym_name; std::size_t m_hash; std::uint32_t m_offset; diff --git a/src/recomp/recomp.cpp b/src/recomp/recomp.cpp index 9b92f65..93f9555 100644 --- a/src/recomp/recomp.cpp +++ b/src/recomp/recomp.cpp @@ -158,7 +158,18 @@ void recomp_t::resolve() { reloc.offset()) = allocated_at; break; } - case decomp::sym_type_t::instruction: + case decomp::sym_type_t::instruction: { + auto& transforms = reloc.get_transforms(); + std::for_each( + transforms.begin(), transforms.end(), + [&](std::pair& t) { + allocated_at = (*t.first)(allocated_at, t.second); + }); + + *reinterpret_cast(sym.data().data() + + reloc.offset()) = allocated_at; + break; + } case decomp::sym_type_t::function: { *reinterpret_cast(sym.data().data() + reloc.offset()) = allocated_at;