Theodosius  v3.0
Jit linker, mapper, obfuscator, and mutator
Classes | Typedefs | Functions | Variables
theo::obf::transform Namespace Reference

this namespace encompasses the code for transforming relocations. More...

Classes

class  add_op_t
 
class  operation_t
 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...
 
class  rol_op_t
 
class  ror_op_t
 
class  sub_op_t
 
class  xor_op_t
 

Typedefs

using transform_t = std::function< std::size_t(std::size_t, std::uint32_t)>
 lambda function which takes in a 64bit value (relocation address) and a 32bit value (random value used in transformation). More...
 

Functions

std::vector< std::uint8_t > generate (xed_decoded_inst_t *inst, recomp::reloc_t *reloc, std::uint8_t low, std::uint8_t high)
 generate a sequence of transformations given an instruction that has a relocation in it. More...
 

Variables

std::map< xed_iclass_enum_t, operation_t * > operations
 map of all of the operations and their type. More...
 

Detailed Description

this namespace encompasses the code for transforming relocations.

Typedef Documentation

◆ transform_t

using theo::obf::transform::transform_t = typedef std::function<std::size_t(std::size_t, std::uint32_t)>

lambda function which takes in a 64bit value (relocation address) and a 32bit value (random value used in transformation).

Function Documentation

◆ generate()

std::vector<std::uint8_t> theo::obf::transform::generate ( xed_decoded_inst_t *  inst,
recomp::reloc_t reloc,
std::uint8_t  low,
std::uint8_t  high 
)
inline

generate a sequence of transformations given an instruction that has a relocation in it.

Parameters
instinstruction that has a relocation in it.
relocmeta data relocation object for the instruction.
lowlowest number of transformations to generate.
highhighest number of transformations to generate.
Returns
48  {
49  auto num_transforms = transform::operation_t::random(low, high);
50  auto num_ops = transform::operations.size();
51  std::vector<std::uint8_t> new_inst_bytes;
52 
53  std::uint32_t inst_len = {};
54  std::uint8_t inst_buff[XED_MAX_INSTRUCTION_BYTES];
55  xed_encoder_request_t req;
56 
57  xed_state_t istate{XED_MACHINE_MODE_LONG_64, XED_ADDRESS_WIDTH_64b};
58  xed_encoder_request_zero_set_mode(&req, &istate);
59  xed_encoder_request_set_effective_operand_width(&req, 64);
60  xed_encoder_request_set_iclass(&req, XED_ICLASS_PUSHFQ);
61  xed_encode(&req, inst_buff, sizeof(inst_buff), &inst_len);
62  new_inst_bytes.insert(new_inst_bytes.end(), inst_buff, inst_buff + inst_len);
63 
64  for (auto cnt = 0u; cnt < num_transforms; ++cnt) {
65  std::uint32_t imm = transform::operation_t::random(
66  0, std::numeric_limits<std::int32_t>::max());
67 
68  auto itr = transform::operations.begin();
69  std::advance(itr, transform::operation_t::random(0, num_ops - 1));
70  auto transform_bytes = itr->second->native(inst, imm);
71  new_inst_bytes.insert(new_inst_bytes.end(), transform_bytes.begin(),
72  transform_bytes.end());
73 
74  reloc->add_transform(
75  {transform::operations[itr->second->inverse()]->get_transform(), imm});
76  }
77 
78  xed_encoder_request_zero_set_mode(&req, &istate);
79  xed_encoder_request_set_effective_operand_width(&req, 64);
80  xed_encoder_request_set_iclass(&req, XED_ICLASS_POPFQ);
81  xed_encode(&req, inst_buff, sizeof(inst_buff), &inst_len);
82  new_inst_bytes.insert(new_inst_bytes.end(), inst_buff, inst_buff + inst_len);
83 
84  // inverse the order in which the transformations are executed...
85  //
86  std::reverse(reloc->get_transforms().begin(), reloc->get_transforms().end());
87  return new_inst_bytes;
88 }
std::map< xed_iclass_enum_t, operation_t * > operations
map of all of the operations and their type.
Definition: transform.hpp:42

Variable Documentation

◆ operations

std::map<xed_iclass_enum_t, operation_t*> theo::obf::transform::operations
inline
Initial value:
= {
{XED_ICLASS_ADD, add_op_t::get()},
{XED_ICLASS_SUB, sub_op_t::get()},
{XED_ICLASS_ROL, rol_op_t::get()},
{XED_ICLASS_ROR, ror_op_t::get()},
{XED_ICLASS_XOR, xor_op_t::get()}}

map of all of the operations and their type.