From e95d9552c04ebf81c9986e0c90cc46374ee707a4 Mon Sep 17 00:00:00 2001 From: matcool <26722564+matcool@users.noreply.github.com> Date: Sun, 2 Jun 2024 03:46:30 -0300 Subject: [PATCH] wrapper stack alignment st uff --- src/generator/X64Generator.cpp | 42 ++++++++++++++++++++++++++++++++++ src/generator/X64Generator.hpp | 3 +++ 2 files changed, 45 insertions(+) diff --git a/src/generator/X64Generator.cpp b/src/generator/X64Generator.cpp index 0837f34..82a45de 100644 --- a/src/generator/X64Generator.cpp +++ b/src/generator/X64Generator.cpp @@ -293,4 +293,46 @@ Result<> X64HandlerGenerator::relocateRIPInstruction(cs_insn* insn, uint8_t* buf } fail: return X86HandlerGenerator::relocateRIPInstruction(insn, buffer, trampolineAddress, originalAddress, disp); +} + +std::vector X64WrapperGenerator::wrapperBytes(uint64_t address) { + X64Assembler a(address); + using enum X64Register; + + m_metadata.m_convention->generateIntoOriginal(a, m_metadata.m_abstract); + + a.sub(RSP, 8); + a.mov(RAX, "address"); + a.call(RAX); + a.add(RSP, 8); + + m_metadata.m_convention->generateOriginalCleanup(a, m_metadata.m_abstract); + + a.label("address"); + a.write64(reinterpret_cast(m_address)); + + a.updateLabels(); + + return std::move(a.m_buffer); +} + +std::vector X64WrapperGenerator::reverseWrapperBytes(uint64_t address) { + X64Assembler a(address); + using enum X64Register; + + m_metadata.m_convention->generateIntoDefault(a, m_metadata.m_abstract); + + a.sub(RSP, 8); + a.mov(RAX, "address"); + a.call(RAX); + a.add(RSP, 8); + + m_metadata.m_convention->generateDefaultCleanup(a, m_metadata.m_abstract); + + a.label("address"); + a.write64(reinterpret_cast(m_address)); + + a.updateLabels(); + + return std::move(a.m_buffer); } \ No newline at end of file diff --git a/src/generator/X64Generator.hpp b/src/generator/X64Generator.hpp index 57498de..64f24e2 100644 --- a/src/generator/X64Generator.hpp +++ b/src/generator/X64Generator.hpp @@ -20,5 +20,8 @@ namespace tulip::hook { class X64WrapperGenerator : public X86WrapperGenerator { public: using X86WrapperGenerator::X86WrapperGenerator; + + std::vector wrapperBytes(uint64_t address) override; + std::vector reverseWrapperBytes(uint64_t address) override; }; }