Skip to content

Commit

Permalink
wrapper stack alignment st uff
Browse files Browse the repository at this point in the history
  • Loading branch information
matcool committed Jun 2, 2024
1 parent 1b91f8c commit e95d955
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/generator/X64Generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,4 +293,46 @@ Result<> X64HandlerGenerator::relocateRIPInstruction(cs_insn* insn, uint8_t* buf
}
fail:
return X86HandlerGenerator::relocateRIPInstruction(insn, buffer, trampolineAddress, originalAddress, disp);
}

std::vector<uint8_t> 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<uintptr_t>(m_address));

a.updateLabels();

return std::move(a.m_buffer);
}

std::vector<uint8_t> 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<uintptr_t>(m_address));

a.updateLabels();

return std::move(a.m_buffer);
}
3 changes: 3 additions & 0 deletions src/generator/X64Generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@ namespace tulip::hook {
class X64WrapperGenerator : public X86WrapperGenerator {
public:
using X86WrapperGenerator::X86WrapperGenerator;

std::vector<uint8_t> wrapperBytes(uint64_t address) override;
std::vector<uint8_t> reverseWrapperBytes(uint64_t address) override;
};
}

0 comments on commit e95d955

Please sign in to comment.