Initial commit
This commit is contained in:
+146
@@ -0,0 +1,146 @@
|
||||
#pragma once
|
||||
|
||||
#include <pshpack1.h>
|
||||
|
||||
namespace instr
|
||||
{
|
||||
struct jump_t
|
||||
{
|
||||
size_t length() const
|
||||
{
|
||||
return sizeof((*this));
|
||||
}
|
||||
|
||||
void assign_data(uint8_t mov_register = 0xB8,
|
||||
uint8_t jmp_register = 0xE0)
|
||||
{
|
||||
memset(this, 0, sizeof(jump_t));
|
||||
|
||||
// mov rax, qword ptr (or something?!) <address>
|
||||
m_mov[0] = 0x48;
|
||||
m_mov[1] = mov_register;
|
||||
|
||||
// jmp rax
|
||||
m_jmp[0] = 0xFF;
|
||||
m_jmp[1] = jmp_register;
|
||||
}
|
||||
|
||||
jump_t()
|
||||
{
|
||||
assign_data();
|
||||
};
|
||||
|
||||
~jump_t() = default;
|
||||
|
||||
jump_t(uintptr_t destination)
|
||||
{
|
||||
assign_data();
|
||||
|
||||
memcpy(&m_dst[0], &destination, sizeof(uintptr_t));
|
||||
}
|
||||
|
||||
jump_t(uintptr_t destination,
|
||||
uint8_t mov_register, uint8_t jmp_register)
|
||||
{
|
||||
assign_data(mov_register, jmp_register);
|
||||
|
||||
memcpy(&m_dst[0], &destination, sizeof(uintptr_t));
|
||||
}
|
||||
|
||||
inline void set_registers(uint8_t mov_register, uint8_t jmp_register)
|
||||
{
|
||||
m_mov[1] = mov_register;
|
||||
m_jmp[1] = jmp_register;
|
||||
}
|
||||
|
||||
UINT8 m_mov[2];
|
||||
UINT8 m_dst[8];
|
||||
UINT8 m_jmp[2];
|
||||
};
|
||||
|
||||
struct jump_safe_t
|
||||
{
|
||||
void assign_data()
|
||||
{
|
||||
memset(this, 0, sizeof(jump_safe_t));
|
||||
|
||||
uint8_t pre[] = { 0xFF, 0x25, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
memcpy(m_pre, pre, sizeof(pre));
|
||||
}
|
||||
|
||||
jump_safe_t()
|
||||
{
|
||||
assign_data();
|
||||
};
|
||||
|
||||
~jump_safe_t() = default;
|
||||
|
||||
jump_safe_t(uintptr_t destination)
|
||||
{
|
||||
assign_data();
|
||||
|
||||
memcpy(&m_dst[0], &destination, sizeof(uintptr_t));
|
||||
}
|
||||
uint8_t m_pre[6];
|
||||
uint8_t m_dst[8];
|
||||
};
|
||||
|
||||
struct jump6_t
|
||||
{
|
||||
static jump6_t build(void* dst)
|
||||
{
|
||||
return jump6_t
|
||||
{
|
||||
0x50,
|
||||
{ 0x48, 0xB8 },
|
||||
dst,
|
||||
{ 0x48, 0x87, 0x04, 0x24 },
|
||||
0xC3
|
||||
};
|
||||
}
|
||||
|
||||
uint8_t m_push;
|
||||
uint8_t m_mov[2];
|
||||
void* m_dst;
|
||||
uint8_t m_rstor[4];
|
||||
uint8_t m_ret;
|
||||
};
|
||||
|
||||
struct system_call_t
|
||||
{
|
||||
system_call_t() = default;
|
||||
|
||||
system_call_t(uint32_t id)
|
||||
{
|
||||
memset(this, 0, sizeof(system_call_t));
|
||||
|
||||
// mov r10, rcx ;
|
||||
m_mov_r10[0] = 0x49;
|
||||
m_mov_r10[1] = 0x89;
|
||||
m_mov_r10[2] = 0xCA;
|
||||
|
||||
// mov eax, <id> ;
|
||||
m_mov_eax = 0xB8;
|
||||
|
||||
memcpy(&m_id, &id, sizeof(id));
|
||||
|
||||
// sycall ;
|
||||
m_call[0] = 0x0F;
|
||||
m_call[1] = 0x05;
|
||||
|
||||
// retn ;
|
||||
m_return = 0xC3;
|
||||
}
|
||||
|
||||
void* stub() noexcept;
|
||||
|
||||
std::uint8_t m_mov_r10[0x3];
|
||||
std::uint8_t m_mov_eax;
|
||||
std::uint8_t m_id[0x4];
|
||||
std::uint8_t m_call[0x2];
|
||||
std::uint8_t m_return;
|
||||
};
|
||||
}
|
||||
|
||||
#include <poppack.h>
|
||||
Reference in New Issue
Block a user