minecraft-pi-reborn/libreborn/include/libreborn/libreborn.h

61 lines
2.0 KiB
C
Raw Normal View History

2021-01-27 21:26:19 +00:00
#pragma once
2020-09-25 16:43:53 +00:00
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
2021-02-16 17:26:40 +00:00
// Logging
2020-11-10 20:06:29 +00:00
#define INFO(msg, ...) fprintf(stderr, "[INFO]: " msg "\n", __VA_ARGS__);
2020-11-19 19:52:41 +00:00
#define ERR(msg, ...) fprintf(stderr, "[ERR]: " msg "\n", __VA_ARGS__); exit(EXIT_FAILURE);
2020-11-10 20:06:29 +00:00
2021-02-16 17:26:40 +00:00
// Check Memory Allocation
#define ALLOC_CHECK(obj) if (obj == NULL) { ERR("(%s:%i) Memory Allocation Failed", __FILE__, __LINE__); }
// Set obj To NULL On asprintf() Failure
#define asprintf(obj, ...) if (asprintf(obj, __VA_ARGS__) == -1) { *obj = NULL; }
2021-02-22 03:43:57 +00:00
// Hook Library Function
2020-09-25 16:43:53 +00:00
#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) { \
2020-11-10 20:06:29 +00:00
ERR("Error Resolving Symbol: "#name": %s", dlerror()); \
2020-09-25 16:43:53 +00:00
} \
} \
}; \
\
__attribute__((__used__)) return_type name args
2021-02-22 03:43:57 +00:00
// Sanitize String
void sanitize_string(char **str, int max_length);
// Patching Functions
2020-11-20 18:36:03 +00:00
void _overwrite_call(const char *file, int line, void *start, void *target);
#define overwrite_call(start, target) _overwrite_call(__FILE__, __LINE__, start, target);
void _overwrite_calls(const char *file, int line, void *start, void *target);
#define overwrite_calls(start, target) _overwrite_calls(__FILE__, __LINE__, start, target);
2020-10-03 16:57:58 +00:00
void _overwrite(const char *file, int line, void *start, void *target);
#define overwrite(start, target) _overwrite(__FILE__, __LINE__, start, target);
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