minecraft-pi-docker/mods/include/libcore/libcore.h

49 lines
1.4 KiB
C
Raw Normal View History

2020-09-25 16:43:53 +00:00
#ifndef LIBLOADER_H
#define LIBLOADER_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
#define HOOK(name, return_type, args) \
typedef return_type (*name##_t)args; \
static name##_t real_##name = NULL; \
\
__attribute__((__unused__)) static void ensure_##name() { \
if (!real_##name) { \
dlerror(); \
real_##name = (name##_t) dlsym(RTLD_NEXT, #name); \
if (!real_##name) { \
fprintf(stderr, "Error Resolving Symbol: "#name": %s\n", dlerror()); \
exit(1); \
} \
} \
}; \
\
__attribute__((__used__)) return_type name args
2020-10-26 19:58:28 +00:00
#define INFO(msg, ...) fprintf(stderr, "[INFO]: " msg "\n", __VA_ARGS__);
#define ERR(msg, ...) fprintf(stderr, "[ERR]: " msg "\n", __VA_ARGS__); exit(1);
2020-10-04 00:30:15 +00:00
void *_overwrite(const char *file, int line, void *start, void *target);
2020-10-03 16:57:58 +00:00
#define overwrite(start, target) _overwrite(__FILE__, __LINE__, start, target);
2020-10-01 15:08:46 +00:00
void revert_overwrite(void *start, void *original);
2020-10-03 16:57:58 +00:00
2020-10-04 00:30:15 +00:00
void _patch(const char *file, int line, void *start, unsigned char patch[]);
2020-10-03 16:57:58 +00:00
#define patch(start, patch) _patch(__FILE__, __LINE__, start, patch);
2020-10-04 00:30:15 +00:00
void _patch_address(const char *file, int line, void *start, void *target);
2020-10-03 16:57:58 +00:00
#define patch_address(start, target) _patch_address(__FILE__, __LINE__, start, target);
2020-09-25 16:43:53 +00:00
#ifdef __cplusplus
}
#endif
#endif