2025-01-15 18:29:50 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2025-01-15 18:51:31 +03:00
|
|
|
#include <stdint.h>
|
2025-01-15 18:29:50 +03:00
|
|
|
|
|
|
|
#define RET 0xC3 // ret opcode
|
|
|
|
|
|
|
|
typedef unsigned char byte;
|
|
|
|
|
|
|
|
byte* AF_address(byte* f) {
|
|
|
|
byte* real_address = NULL;
|
|
|
|
#ifdef _MSC_VER // MSVC
|
|
|
|
#ifdef NDEBUG // MSVC release mode
|
|
|
|
real_address = f;
|
|
|
|
#else // MSVC debug mode
|
|
|
|
byte* f_p = f;
|
2025-01-15 18:51:31 +03:00
|
|
|
byte* offset = (byte*)(*((int32_t*)f_p) >> 8);
|
|
|
|
real_address = f_p + (int32_t)offset + 5;
|
2025-01-15 18:29:50 +03:00
|
|
|
#endif
|
|
|
|
#elif defined(__GNUC__) // GCC
|
|
|
|
real_address = f;
|
|
|
|
#endif
|
|
|
|
return real_address;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Print bytes from address to address+size
|
2025-01-15 18:51:31 +03:00
|
|
|
int32_t AF_print_bytes(byte* a, int32_t size) {
|
|
|
|
for (int32_t i = 0; i < size; ++i) {
|
2025-01-15 18:43:58 +03:00
|
|
|
printf("%02X ", *(a + i));
|
|
|
|
}
|
2025-01-15 18:29:50 +03:00
|
|
|
}
|
2025-01-15 18:51:31 +03:00
|
|
|
|
2025-01-15 18:29:50 +03:00
|
|
|
// Get any function size
|
2025-01-15 18:51:31 +03:00
|
|
|
int32_t AF_size(byte* f) {
|
2025-01-15 18:29:50 +03:00
|
|
|
byte* p = f;
|
|
|
|
for (; *p != RET; ++p);
|
|
|
|
return p - f + 1;
|
|
|
|
}
|