#include <stdio.h>
#include <stdint.h>
typedef unsigned char uchar;
int f(int a, int b) {
return a + b;
}
void _end(void) {};
int main(void) {
uchar* start = f, *end = _end;
int size = (int)(end - start);
printf("size = %i\n", size);
for (int i = 0; i < size; ++i) {
printf("%02X ", *(start + i));
}
return 0;
}
#pragma once
#include <stdio.h>
#define RET 0xC3 // Опкод инструкции ret
typedef unsigned char byte;
byte* AF_address(byte* f) {
byte* real_address = NULL;
#ifdef _MSC_VER // MSVC
//printf("MSVC Compiler Detected\n");
#ifdef NDEBUG // MSVC release mode
real_address = f;
//printf("FUNCTION ADDRESS: %p\n", real_address);
#else // MSVC debug mode
byte* f_p = f;
byte* offset = (byte*)(*((int*)f_p) >> 8);
real_address = f_p + (int)offset + 5;
//printf("TABLE ADDRESS: %p\n", f_p);
//printf("OFFSET: %p\n", offset);
//printf("REAL ADDRESS: %p\n", real_address);
#endif
#elif defined(__GNUC__) // GCC
//printf("GCC Compiler Detected\n");
real_address = f;
//printf("FUNCTION ADDRESS: %p\n", real_address);
#endif
return real_address;
}
// Печатает байты от некоторого address до address+size
int AF_print_bytes(byte* a, int size) {
for (int i = 0; i < size; ++i) printf("%02X ", *(a + i));
}
// Возвращает размер произвольной функции в байтах
int AF_size(byte* f) {
byte* p = f;
for (; *p != RET; ++p);
return p - f + 1;
}
f < _end
и f > _end
?int f(int a, int b) {
return a + b;
}
void _end(void) {};
реализовать надо так, чтобы работало на ЛЮБОМ компиляторе
void _end(void) {};