initial push

This commit is contained in:
2022-09-29 12:31:39 +02:00
commit 88a0261880
17 changed files with 1350 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
#pragma once
#include <cstdint>
#include <type_traits>
namespace util {
struct Hook {
uintptr_t _bytes = 0;
uintptr_t _target = 0;
uintptr_t _detour = 0;
uintptr_t _tramp = 0;
bool enable(uintptr_t target, uintptr_t detour);
void disable();
template <typename Target, typename Detour>
inline bool enable(Target target, Detour detour) {
return enable((uintptr_t) target, (uintptr_t) detour);
}
template <typename Func, typename... Args>
inline auto invoke(Args &&...args) const {
return ((Func) _tramp)(std::forward<Args>(args)...);
}
};
} // namespace util
#define define_hook(name, ret, call_conv, ...) \
inline util::Hook name; \
ret call_conv name##_hook(__VA_ARGS__);

View File

@@ -0,0 +1,16 @@
#pragma once
#include <cstdint>
#include <string>
namespace signatures {
constexpr static auto s_token_log_ref = "558BEC83EC08C645FC01C745";
}
namespace util {
uint8_t *find_pattern(std::string_view pattern, uint8_t *begin, size_t size, ptrdiff_t offset = 0x0);
uint8_t *scan_module(std::string_view module_name, std::string_view pattern, ptrdiff_t offset = 0x0);
} // namespace util

View File

@@ -0,0 +1,17 @@
#pragma once
#include <cstdint>
#include <string_view>
// <3 mr polish man
namespace util {
struct ModuleInfo {
uintptr_t base;
size_t size;
};
ModuleInfo get_module(std::string_view module_name);
uintptr_t get_export(std::string_view module_name, std::string_view export_name);
} // namespace util

104
ac_checker/include/vendor/hde.hpp vendored Normal file
View File

@@ -0,0 +1,104 @@
#pragma once
#include <stdint.h>
#define C_NONE 0x00
#define C_MODRM 0x01
#define C_IMM8 0x02
#define C_IMM16 0x04
#define C_IMM_P66 0x10
#define C_REL8 0x20
#define C_REL32 0x40
#define C_GROUP 0x80
#define C_ERROR 0xff
#define PRE_ANY 0x00
#define PRE_NONE 0x01
#define PRE_F2 0x02
#define PRE_F3 0x04
#define PRE_66 0x08
#define PRE_67 0x10
#define PRE_LOCK 0x20
#define PRE_SEG 0x40
#define PRE_ALL 0xff
#define DELTA_OPCODES 0x4a
#define DELTA_FPU_REG 0xf1
#define DELTA_FPU_MODRM 0xf8
#define DELTA_PREFIXES 0x130
#define DELTA_OP_LOCK_OK 0x1a1
#define DELTA_OP2_LOCK_OK 0x1b9
#define DELTA_OP_ONLY_MEM 0x1cb
#define DELTA_OP2_ONLY_MEM 0x1da
#define F_MODRM 0x00000001
#define F_SIB 0x00000002
#define F_IMM8 0x00000004
#define F_IMM16 0x00000008
#define F_IMM32 0x00000010
#define F_DISP8 0x00000020
#define F_DISP16 0x00000040
#define F_DISP32 0x00000080
#define F_RELATIVE 0x00000100
#define F_2IMM16 0x00000800
#define F_ERROR 0x00001000
#define F_ERROR_OPCODE 0x00002000
#define F_ERROR_LENGTH 0x00004000
#define F_ERROR_LOCK 0x00008000
#define F_ERROR_OPERAND 0x00010000
#define F_PREFIX_REPNZ 0x01000000
#define F_PREFIX_REPX 0x02000000
#define F_PREFIX_REP 0x03000000
#define F_PREFIX_66 0x04000000
#define F_PREFIX_67 0x08000000
#define F_PREFIX_LOCK 0x10000000
#define F_PREFIX_SEG 0x20000000
#define F_PREFIX_ANY 0x3f000000
#define PREFIX_SEGMENT_CS 0x2e
#define PREFIX_SEGMENT_SS 0x36
#define PREFIX_SEGMENT_DS 0x3e
#define PREFIX_SEGMENT_ES 0x26
#define PREFIX_SEGMENT_FS 0x64
#define PREFIX_SEGMENT_GS 0x65
#define PREFIX_LOCK 0xf0
#define PREFIX_REPNZ 0xf2
#define PREFIX_REPX 0xf3
#define PREFIX_OPERAND_SIZE 0x66
#define PREFIX_ADDRESS_SIZE 0x67
#pragma pack(push, 1)
typedef struct {
uint8_t len;
uint8_t p_rep;
uint8_t p_lock;
uint8_t p_seg;
uint8_t p_66;
uint8_t p_67;
uint8_t opcode;
uint8_t opcode2;
uint8_t modrm;
uint8_t modrm_mod;
uint8_t modrm_reg;
uint8_t modrm_rm;
uint8_t sib;
uint8_t sib_scale;
uint8_t sib_index;
uint8_t sib_base;
union {
uint8_t imm8;
uint16_t imm16;
uint32_t imm32;
} imm;
union {
uint8_t disp8;
uint16_t disp16;
uint32_t disp32;
} disp;
uint32_t flags;
} hde32s;
#pragma pack(pop)
unsigned int hde32_disasm(const void *code, hde32s *hs);

View File

@@ -0,0 +1,371 @@
#pragma once
#include <array>
#include <iostream>
#include <vector>
namespace vendor {
template <class T, std::size_t N, class Allocator = std::allocator<T>>
class small_vector {
std::array<T, N> stack_;
std::vector<T, Allocator> heap_;
std::size_t size_{0};
public:
typedef T value_type;
typedef std::size_t size_type;
typedef value_type &reference;
typedef const value_type &const_reference;
typedef Allocator allocator_type;
typedef T *pointer;
typedef const T *const_pointer;
small_vector() = default;
explicit small_vector(size_type count, const T &value = T(), const Allocator &alloc = Allocator()) {
if (count == N) {
stack_.fill(value);
} else if (count < N) {
for (size_t i = 0; i < count; i++) {
stack_[i] = value;
}
} else {
// use heap
heap_ = std::move(std::vector<T>(count, value, alloc));
}
size_ = count;
}
small_vector(const small_vector &other, const Allocator &alloc = Allocator())
: stack_(other.stack_), heap_(other.heap_, alloc), size_(other.size_) {
}
small_vector(small_vector &&other, const Allocator &alloc = Allocator())
: stack_(std::move(other.stack_)), heap_(std::move(other.heap_), alloc), size_(std::move(other.size_)) {
}
small_vector(std::initializer_list<T> initlist, const Allocator &alloc = Allocator()) {
const auto input_size = initlist.size();
if (input_size <= N) {
std::copy(initlist.begin(), initlist.end(), stack_.begin());
} else {
heap_ = std::move(std::vector<T>(initlist, alloc));
}
size_ = input_size;
}
small_vector &operator=(const small_vector &rhs) {
stack_ = rhs.stack_;
heap_ = rhs.heap_;
size_ = rhs.size_;
return *this;
}
small_vector &operator=(small_vector &&rhs) {
stack_ = std::move(rhs.stack_);
heap_ = std::move(rhs.heap_);
size_ = rhs.size_;
rhs.size_ = 0;
return *this;
}
small_vector &operator=(std::initializer_list<value_type> rhs) {
if (rhs.size() <= N) {
stack_ = rhs;
} else {
heap_ = rhs;
}
size_ = rhs.size();
}
allocator_type get_allocator() const noexcept {
return heap_.get_allocator();
}
reference at(size_type pos) {
if (size_ < N) {
return stack_.at(pos);
} else {
return heap_.at(pos);
}
}
const_reference at(size_type pos) const {
if (size_ < N) {
return stack_.at(pos);
} else {
return heap_.at(pos);
}
}
reference operator[](size_type pos) {
if (size_ < N) {
return stack_[pos];
} else {
return heap_[pos];
}
}
const_reference operator[](size_type pos) const {
if (size_ < N) {
return stack_[pos];
} else {
return heap_[pos];
}
}
reference front() {
if (size_ < N) {
return stack_.front();
} else {
return heap_.front();
}
}
const_reference front() const {
if (size_ < N) {
return stack_.front();
} else {
return heap_.front();
}
}
reference back() {
if (size_ < N) {
return stack_[size_ - 1];
} else {
return heap_[size_ - 1];
}
}
const_reference back() const {
if (size_ < N) {
return stack_[size_ - 1];
} else {
return heap_[size_ - 1];
}
}
pointer data() noexcept {
if (size_ < N) {
return stack_.data();
} else {
return heap_.data();
}
}
const_pointer data() const noexcept {
if (size_ < N) {
return stack_.data();
} else {
return heap_.data();
}
}
bool empty() const {
return size_ == 0;
}
size_type size() const {
return size_;
}
void shrink_to_fit() {
if (size_ >= N) {
heap_.shrink_to_fit();
}
}
void push_back(const T &value) {
if (size_ < N) {
stack_[size_] = value;
} else {
if (size_ == N) {
// move everything to heap
std::move(stack_.begin(), stack_.end(), std::back_inserter(heap_));
}
heap_.push_back(value);
}
size_ += 1;
}
void push_back(T &&value) {
if (size_ < N) {
stack_[size_] = std::move(value);
} else {
if (size_ == N) {
// move everything to heap
std::move(stack_.begin(), stack_.end(), std::back_inserter(heap_));
}
heap_.push_back(std::move(value));
}
size_ += 1;
}
void pop_back() {
if (size_ == 0) {
// do nothing
return;
}
if (size_ < N) {
size_ -= 1;
} else {
// currently using heap
heap_.pop_back();
size_ -= 1;
// now check if all data can fit on stack
// if so, move back to stack
if (size_ < N) {
std::move(heap_.begin(), heap_.end(), stack_.begin());
heap_.clear();
}
}
}
// Resizes the container to contain count elements.
void resize(size_type count, T value = T()) {
if (count <= N) {
// new `count` of elements completely fit on stack
if (size_ >= N) {
// currently, all data on heap
// move back to stack
std::move(heap_.begin(), heap_.end(), stack_.begin());
} else {
// all data already on stack
// just update size
}
} else {
// new `count` of data is going to be on the heap
// check if data is currently on the stack
if (size_ < N) {
// move to heap
std::move(stack_.begin(), stack_.end(), std::back_inserter(heap_));
}
heap_.resize(count, value);
}
size_ = count;
}
void swap(small_vector &other) noexcept {
std::swap(stack_, other.stack_);
std::swap(heap_, other.heap_);
std::swap(size_, other.size_);
};
// Assigns the given value value to all elements in the container
void fill(const_reference value) {
if (size_ < N) {
stack_.fill(value);
} else {
std::fill(heap_.begin(), heap_.end(), value);
}
}
class iterator {
pointer ptr_;
public:
typedef iterator self_type;
typedef T value_type;
typedef T &reference;
typedef T *pointer;
typedef std::forward_iterator_tag iterator_category;
typedef int difference_type;
iterator(pointer ptr)
: ptr_(ptr) {
}
self_type operator++() {
ptr_++;
return *this;
}
self_type operator++(int) {
self_type i = *this;
ptr_++;
return i;
}
reference operator*() {
return *ptr_;
}
pointer operator->() {
return ptr_;
}
bool operator==(const self_type &rhs) {
return ptr_ == rhs.ptr_;
}
bool operator!=(const self_type &rhs) {
return ptr_ != rhs.ptr_;
}
};
class const_iterator {
pointer ptr_;
public:
typedef const_iterator self_type;
typedef T value_type;
typedef T &reference;
typedef T *pointer;
typedef int difference_type;
typedef std::forward_iterator_tag iterator_category;
const_iterator(pointer ptr)
: ptr_(ptr) {
}
self_type operator++() {
ptr_++;
return *this;
}
self_type operator++(int) {
self_type i = *this;
ptr_++;
return i;
}
const value_type &operator*() {
return *ptr_;
}
const pointer operator->() {
return ptr_;
}
bool operator==(const self_type &rhs) {
return ptr_ == rhs.ptr_;
}
bool operator!=(const self_type &rhs) {
return ptr_ != rhs.ptr_;
}
};
iterator begin() {
if (size_ < N) {
return iterator(stack_.data());
} else {
return iterator(heap_.data());
}
}
iterator end() {
if (size_ < N) {
return iterator(stack_.data() + size_);
} else {
return iterator(heap_.data() + size_);
}
}
const_iterator begin() const {
if (size_ < N) {
return const_iterator(stack_.data());
} else {
return const_iterator(heap_.data());
}
}
const_iterator end() const {
if (size_ < N) {
return const_iterator(stack_.data() + size_);
} else {
return const_iterator(heap_.data() + size_);
}
}
};
} // namespace vendor