32 #include <spdlog/spdlog.h>
41 #include <xed-decode.h>
42 #include <xed-interface.h>
70 : m_transform(op), m_type(
type) {}
89 std::vector<std::uint8_t>
native(
const xed_decoded_inst_t* inst,
91 std::uint32_t inst_len = {};
92 std::uint8_t inst_buff[XED_MAX_INSTRUCTION_BYTES];
95 xed_encoder_request_init_from_decode((xed_decoded_inst_s*)inst);
96 xed_encoder_request_t* req = (xed_encoder_request_t*)inst;
101 xed_encoder_request_set_uimm0(req, imm, 1);
104 xed_encoder_request_set_uimm0(req, imm, 4);
108 xed_encoder_request_set_iclass(req, m_type);
109 xed_encoder_request_set_operand_order(req, 1, XED_OPERAND_IMM0);
111 if ((err = xed_encode(req, inst_buff,
sizeof(inst_buff), &inst_len)) !=
113 spdlog::error(
"failed to encode instruction... reason: {}",
114 xed_error_enum_t2str(err));
116 assert(err == XED_ERROR_NONE);
119 return std::vector<std::uint8_t>(inst_buff, inst_buff + inst_len);
126 xed_iclass_enum_t
inverse() {
return m_inverse_op[m_type]; }
140 xed_iclass_enum_t
type() {
return m_type; }
148 static std::size_t
random(std::size_t lowest, std::size_t largest) {
149 std::random_device rd;
150 std::mt19937 gen(rd());
151 std::uniform_int_distribution<std::size_t> distr(lowest, largest);
157 xed_iclass_enum_t m_type;
159 std::map<xed_iclass_enum_t, xed_iclass_enum_t> m_inverse_op = {
160 {XED_ICLASS_ADD, XED_ICLASS_SUB},
161 {XED_ICLASS_SUB, XED_ICLASS_ADD},
162 {XED_ICLASS_ROL, XED_ICLASS_ROR},
163 {XED_ICLASS_ROR, XED_ICLASS_ROL},
164 {XED_ICLASS_XOR, XED_ICLASS_XOR}};