1 | /*␊ |
2 | * Module Loading functionality␊ |
3 | * Copyright 2009-2015 Evan Lojewski. All rights reserved.␊ |
4 | *␊ |
5 | */␊ |
6 | ␊ |
7 | #include <saio_types.h>␊ |
8 | #include <mach-o/loader.h>␊ |
9 | #include <mach-o/nlist.h>␊ |
10 | ␊ |
11 | ␊ |
12 | #ifndef __BOOT_MODULES_H␊ |
13 | #define __BOOT_MODULES_H␊ |
14 | ␊ |
15 | #define MODULE_PATH␉␉"/Extra/modules/"␊ |
16 | ␊ |
17 | #define SYMBOLS_MODULE␉␉"Symbols.dylib"␊ |
18 | #define SYMBOLS_AUTHOR␉␉"Chameleon"␊ |
19 | #define SYMBOLS_DESCRIPTION␉"Chameleon symbols for linking"␊ |
20 | #define SYMBOLS_VERSION␉␉0␊ |
21 | #define SYMBOLS_COMPAT␉␉0␊ |
22 | ␊ |
23 | #define VOID_SYMBOL␉␉"dyld_void_start"␊ |
24 | ␊ |
25 | ␊ |
26 | ␊ |
27 | typedef struct symbolList_t␊ |
28 | {␊ |
29 | ␉char␉␉␉*symbol;␊ |
30 | ␉UInt64␉␉␉addr;␊ |
31 | ␉struct symbolList_t␉*next;␊ |
32 | } symbolList_t;␊ |
33 | ␊ |
34 | typedef struct callbackList_t␊ |
35 | {␊ |
36 | ␉void(*callback)(void*, void*, void*, void*);␊ |
37 | ␉struct callbackList_t *next;␊ |
38 | } callbackList_t;␊ |
39 | ␊ |
40 | typedef struct moduleHook_t␊ |
41 | {␊ |
42 | ␉const char *name;␊ |
43 | ␉callbackList_t *callbacks;␊ |
44 | ␉struct moduleHook_t *next;␊ |
45 | } moduleHook_t;␊ |
46 | ␊ |
47 | typedef struct modulesList_t␊ |
48 | {␊ |
49 | ␉const char␉␉*name;␊ |
50 | ␉const char␉␉*author;␊ |
51 | ␉const char␉␉*description;␊ |
52 | ␉UInt32␉␉␉version;␊ |
53 | ␉UInt32␉␉␉compat;␊ |
54 | ␉struct modulesList_t␉*next;␊ |
55 | } moduleList_t;␊ |
56 | ␊ |
57 | ␊ |
58 | ␊ |
59 | int init_module_system();␊ |
60 | void load_all_modules();␊ |
61 | ␊ |
62 | void start_built_in_module(const char␉*name,␊ |
63 | const char␉*author,␊ |
64 | const char␉*description,␊ |
65 | UInt32␉version,␊ |
66 | UInt32␉compat,␊ |
67 | void(*start_function)(void));␊ |
68 | ␊ |
69 | int load_module(char* module);␊ |
70 | int is_module_loaded(const char* name);␊ |
71 | void module_loaded(const char *name, void *start, const char *author, const char *description, UInt32 version, UInt32 compat);␊ |
72 | ␊ |
73 | ␊ |
74 | ␊ |
75 | ␊ |
76 | /********************************************************************************/␊ |
77 | /*␉Symbol Functions␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉*/␊ |
78 | /********************************************************************************/␊ |
79 | long long␉␉add_symbol(char *symbol, long long addr, char is64);␊ |
80 | unsigned int␉lookup_all_symbols(const char *name);␊ |
81 | ␊ |
82 | ␊ |
83 | ␊ |
84 | /********************************************************************************/␊ |
85 | /*␉Macho Parser␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉*/␊ |
86 | /********************************************************************************/␊ |
87 | void*␉␉␉parse_mach(void *binary, ␊ |
88 | ␉␉␉␉␉␉␉int(*dylib_loader)(char*),␊ |
89 | ␉␉␉␉␉␉␉long long(*symbol_handler)(char*, long long, char),␊ |
90 | void (*section_handler)(char *section, char *segment, void *cmd, UInt64 offset, UInt64 address)␊ |
91 | );␊ |
92 | unsigned int␉handle_symtable(UInt32 base,␊ |
93 | ␉␉␉␉␉␉␉ struct symtab_command *symtabCommand,␊ |
94 | ␉␉␉␉␉␉␉ long long(*symbol_handler)(char*, long long, char),␊ |
95 | ␉␉␉␉␉␉␉ char is64);␊ |
96 | void␉␉␉rebase_macho(void *base, char *rebase_stream, UInt32 size);␊ |
97 | ␊ |
98 | void␉␉␉bind_macho(void *base, UInt8 *bind_stream, UInt32 size);␊ |
99 | ␊ |
100 | ␊ |
101 | /********************************************************************************/␊ |
102 | /*␉Module Interface␉␉␉␉␉␉␉␉␉␉␉␉␉␉*/␊ |
103 | /********************************************************************************/␊ |
104 | int␉␉replace_function(const char *symbol, void *newAddress);␊ |
105 | int␉␉execute_hook(const char *name, void*, void*, void*, void*);␊ |
106 | void␉␉register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*));␊ |
107 | moduleHook_t␉*hook_exists(const char* name);␊ |
108 | ␊ |
109 | #if DEBUG_MODULES␊ |
110 | void␉␉␉print_hook_list();␊ |
111 | #endif␊ |
112 | ␊ |
113 | /********************************************************************************/␊ |
114 | /*␉dyld Interface␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉*/␊ |
115 | /********************************************************************************/␊ |
116 | void dyld_stub_binder();␊ |
117 | ␊ |
118 | #endif /* __BOOT_MODULES_H */␊ |
119 | |