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.

91 lines
2.3 KiB

3 years ago
#ifndef _OBFUSCATOR_H
#define _OBFUSCATOR_H
#include <vector>
#include <string>
extern "C"
{
#include "xed/xed-interface.h"
}
3 years ago
#define CLFLAG_IS_LABEL (1<<0)
#define CLFLAG_IS_REL_JUMP (1<<1)
#define CLFLAG_IS_ABS_ADDR (1<<2)
#define CLFLAG_IS_GAGET (1<<3)
3 years ago
#define ABS_JUMP_GAGT_SIZE 16
#define END_OF_GROUP_GAGT_SIZE 14
3 years ago
typedef struct _code_link_t
{
3 years ago
_code_link_t* next;
_code_link_t* prev;
3 years ago
3 years ago
uint32_t flags;
int32_t group;
std::string label_name;
3 years ago
xed_decoded_inst_t instruction;
unsigned char* raw_data;
3 years ago
unsigned int raw_data_size;
3 years ago
}code_link_t, * pcode_link_t;
typedef struct _code_group_t
{
3 years ago
uint64_t base_address;
3 years ago
pcode_link_t start;
3 years ago
pcode_link_t end;
int32_t size_in_bytes;
_code_group_t(uint64_t ba = 0, pcode_link_t s = nullptr, pcode_link_t e = nullptr, int32_t si = 0)
: base_address(ba), start(s), end(e), size_in_bytes(si) {};
3 years ago
}code_group_t, *pcode_group_t;
typedef struct _obfuscator_t
{
3 years ago
pcode_link_t code_start;
pcode_link_t code_end;
std::vector<code_group_t> groups;
int32_t current_label_id;
xed_machine_mode_enum_t machine_mode;
xed_address_width_enum_t addr_width;
3 years ago
}obfuscator_t, *pobfuscator_t;
3 years ago
typedef void* (*FnAllocateMem)(uint32_t size);
typedef void (*FnMemCopy)(void* dest, void* src, uint32_t size);
3 years ago
//snickers
void obf_one_time_please();
//duh
3 years ago
bool obf_init_from_buffer(pobfuscator_t obf, void* buffer, uint32_t buffer_size);
3 years ago
//creates the groups of instructions based on number of bytes
3 years ago
bool obf_create_groups(pobfuscator_t obf, int32_t group_size);
3 years ago
//replaces all relative jumps with the abs jump gadget
void obf_replace_rel_jmps(pobfuscator_t obf);
//replaces address in the abs jmp stub with the right address of the given label.
3 years ago
bool obf_resolve_abs_addresses(pobfuscator_t obf);
3 years ago
//generate all the labels after loaded from buffa
bool obf_gen_all_labels(pobfuscator_t obf);
//walk backwards or forwards until placing label
bool obf_gen_label(pobfuscator_t obf, pcode_link_t start, int32_t delta);
3 years ago
//allocate buffers for all groups
3 years ago
bool obf_allocate_group_buffers(pobfuscator_t obf, FnAllocateMem alloc_mem);
3 years ago
//copy all instructions from each group into allocated buffers
3 years ago
bool obf_copy_groups_into_buffers(pobfuscator_t obf, FnMemCopy mem_copy);
3 years ago
3 years ago
//print all the code
3 years ago
void obf_dbg_print_code(pobfuscator_t obf);
3 years ago
void obf_print_byte_array(void* arr, uint32_t size);
3 years ago
#endif