Theodosius v3.0
Jit linker, symbol mapper, and obfuscator
Public Member Functions | Static Public Member Functions
theo::obf::transform::operation_t Class Reference

operation_t is the base class for all types of transformations. classes that inherit this class are singleton and simply call the super constructor (operation_t::operation_t). More...

#include "operation.hpp"

Inheritance diagram for theo::obf::transform::operation_t:
theo::obf::transform::add_op_t theo::obf::transform::rol_op_t theo::obf::transform::ror_op_t theo::obf::transform::sub_op_t theo::obf::transform::xor_op_t

Public Member Functions

 operation_t (transform_t op, xed_iclass_enum_t type)
 explicit constructor for operation_t More...
 
std::vector< std::uint8_t > native (const xed_decoded_inst_t *inst, std::uint32_t imm)
 generates a native transform instruction given an existing instruction. it works like so: More...
 
xed_iclass_enum_t inverse ()
 gets the inverse operation of the current operation. More...
 
transform_tget_transform ()
 gets a pointer to the lambda function which contains the transform logic. More...
 
xed_iclass_enum_t type ()
 gets the operation type. such as XED_ICLASS_ADD, XED_ICLASS_SUB, etc... More...
 

Static Public Member Functions

static std::size_t random (std::size_t lowest, std::size_t largest)
 generate a random number in a range. More...
 

Detailed Description

operation_t is the base class for all types of transformations. classes that inherit this class are singleton and simply call the super constructor (operation_t::operation_t).

Definition at line 61 of file operation.hpp.

Constructor & Destructor Documentation

◆ operation_t()

theo::obf::transform::operation_t::operation_t ( transform_t  op,
xed_iclass_enum_t  type 
)
inlineexplicit

explicit constructor for operation_t

Parameters
oplambda function when executed applies transformations.
typetype of transformation, such as XOR, ADD, SUB, etc...

Definition at line 69 of file operation.hpp.

70 : m_transform(op), m_type(type) {}

Member Function Documentation

◆ get_transform()

transform_t * theo::obf::transform::operation_t::get_transform ( )
inline

gets a pointer to the lambda function which contains the transform logic.

Returns
a pointer to the lambda function which contains the transform logic.

Definition at line 133 of file operation.hpp.

133{ return &m_transform; }

◆ inverse()

xed_iclass_enum_t theo::obf::transform::operation_t::inverse ( )
inline

gets the inverse operation of the current operation.

Returns
the inverse operation of the current operation.

Definition at line 126 of file operation.hpp.

126{ return m_inverse_op[m_type]; }

◆ native()

std::vector< std::uint8_t > theo::obf::transform::operation_t::native ( const xed_decoded_inst_t *  inst,
std::uint32_t  imm 
)
inline

generates a native transform instruction given an existing instruction. it works like so:

mov rax, &MessageBoxA ; original instruction with relocation

; this function takes the first operand and out of the original ; instruction and uses it to generate a transformation.

xor rax, 0x39280928 ; this would be an example output for the xor ;operation.

Parameters
instinstruction with a relocation to generate a transformation for.
immrandom 32bit number used in the generate transform.
Returns
returns the bytes of the native instruction that was encoded.

Definition at line 89 of file operation.hpp.

90 {
91 std::uint32_t inst_len = {};
92 std::uint8_t inst_buff[XED_MAX_INSTRUCTION_BYTES];
93
94 xed_error_enum_t err;
95 xed_encoder_request_init_from_decode((xed_decoded_inst_s*)inst);
96 xed_encoder_request_t* req = (xed_encoder_request_t*)inst;
97
98 switch (m_type) {
99 case XED_ICLASS_ROR:
100 case XED_ICLASS_ROL:
101 xed_encoder_request_set_uimm0(req, imm, 1);
102 break;
103 default:
104 xed_encoder_request_set_uimm0(req, imm, 4);
105 break;
106 }
107
108 xed_encoder_request_set_iclass(req, m_type);
109 xed_encoder_request_set_operand_order(req, 1, XED_OPERAND_IMM0);
110
111 if ((err = xed_encode(req, inst_buff, sizeof(inst_buff), &inst_len)) !=
112 XED_ERROR_NONE) {
113 spdlog::error("failed to encode instruction... reason: {}",
114 xed_error_enum_t2str(err));
115
116 assert(err == XED_ERROR_NONE);
117 }
118
119 return std::vector<std::uint8_t>(inst_buff, inst_buff + inst_len);
120 }

◆ random()

static std::size_t theo::obf::transform::operation_t::random ( std::size_t  lowest,
std::size_t  largest 
)
inlinestatic

generate a random number in a range.

Parameters
lowestlowest value of the range.
largesthighest value of the range.
Returns
a random value in a range.

Definition at line 148 of file operation.hpp.

148 {
149 std::random_device rd;
150 std::mt19937 gen(rd());
151 std::uniform_int_distribution<std::size_t> distr(lowest, largest);
152 return distr(gen);
153 }

Referenced by theo::obf::transform::generate().

◆ type()

xed_iclass_enum_t theo::obf::transform::operation_t::type ( )
inline

gets the operation type. such as XED_ICLASS_ADD, XED_ICLASS_SUB, etc...

Returns
the operation type. such as XED_ICLASS_ADD, XED_ICLASS_SUB, etc...

Definition at line 140 of file operation.hpp.

140{ return m_type; }

The documentation for this class was generated from the following file: