You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Theodosius/include/obf/transform/operation.hpp

36 lines
953 B

#pragma once
#include <functional>
#include <map>
#define XED_ENCODER
extern "C" {
#include <xed-decode.h>
#include <xed-interface.h>
}
namespace theo::obf::transform {
using transform_t = std::function<std::size_t(std::size_t, std::size_t)>;
class operation_t {
public:
enum type_t { add_op, sub_op, and_op, or_op, rol_op, ror_op, xor_op };
explicit operation_t(transform_t op, type_t type)
: m_transform(op), m_type(type) {}
virtual std::vector<std::uint8_t> native(xed_inst_t* inst,
std::size_t imm) = 0;
type_t inverse() { return m_inverse_op[m_type]; }
transform_t get_transform() { return m_transform; }
private:
transform_t m_transform;
type_t m_type;
std::map<type_t, type_t> m_inverse_op = {
{add_op, sub_op}, {sub_op, add_op}, {and_op, or_op}, {or_op, and_op},
{rol_op, ror_op}, {ror_op, rol_op}, {xor_op, xor_op}};
};
} // namespace theo::obf::transform