extern "C" { /* * Module Loading functionality * Copyright 2009 Evan Lojewski. All rights reserved. * */ #include #include // There is a bug with the module system / rebasing / binding // that causes static variables to be incorrectly rebased or bound // Disable static variables for the moment // #define static #ifndef __BOOT_MODULES_H #define __BOOT_MODULES_H #define SYMBOLS_MODULE "Symbols.dylib" #define SYMBOL_LOOKUP_SYMBOL "_lookup_symbol" #define STUB_ENTRY_SIZE 6 #define SECT_NON_LAZY_SYMBOL_PTR "__nl_symbol_ptr" #define SECT_SYMBOL_STUBS "__symbol_stub" #define VALID_FUNCTION(__x__) (__x__ && (void*)__x__ != (void*)0xFFFFFFFF) extern unsigned long long textAddress; extern unsigned long long textSection; typedef struct symbolList_t { char* symbol; unsigned int addr; struct symbolList_t* next; } symbolList_t; typedef struct moduleList_t { char* module; unsigned int version; unsigned int compat; struct moduleList_t* next; } moduleList_t; typedef struct callbackList_t { void(*callback)(void*, void*, void*, void*); struct callbackList_t* next; } callbackList_t; typedef struct moduleHook_t { const char* name; callbackList_t* callbacks; struct moduleHook_t* next; } moduleHook_t; int init_module_system(); void load_all_modules(); /* * Modules Interface * execute_hook * Exexutes a registered hook. All callbaks are * called in the same order that they were added * * register_hook_callback * registers a void function to be executed when a * hook is executed. */ int execute_hook(const char* name, void*, void*, void*, void*); void register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*)); int load_module(char* module); int is_module_loaded(const char* name); void module_loaded(const char* name/*, uint32_t version, uint32_t compat*/); long long add_symbol(char* symbol, long long addr, char is64); void* parse_mach(void* binary, int(*dylib_loader)(char*), long long(*symbol_handler)(char*, long long, char) ); unsigned int handle_symtable(uint32_t base, struct symtab_command* symtabCommand, long long(*symbol_handler)(char*, long long, char), char is64); unsigned int lookup_all_symbols(const char* name); int replace_function(const char* symbol, void* newAddress); //extern unsigned int (*lookup_symbol)(const char*); #endif /* __BOOT_MODULES_H */ }