Root/
Source at commit 1075 created 13 years 1 month ago. By meklort, Disk code | |
---|---|
1 | /*␊ |
2 | * Module Loading functionality␊ |
3 | * Copyright 2009 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 | extern UInt64 textAddress;␊ |
25 | extern UInt64 textSection;␊ |
26 | ␊ |
27 | ␊ |
28 | ␊ |
29 | typedef struct symbolList_t␊ |
30 | {␊ |
31 | ␉char* symbol;␊ |
32 | ␉UInt64 addr;␊ |
33 | ␉struct symbolList_t* next;␊ |
34 | } symbolList_t;␊ |
35 | ␊ |
36 | ␊ |
37 | typedef struct callbackList_t␊ |
38 | {␊ |
39 | ␉void(*callback)(void*, void*, void*, void*);␊ |
40 | ␉struct callbackList_t* next;␊ |
41 | } callbackList_t;␊ |
42 | ␊ |
43 | typedef struct moduleHook_t␊ |
44 | {␊ |
45 | ␉const char* name;␊ |
46 | ␉callbackList_t* callbacks;␊ |
47 | ␉struct moduleHook_t* next;␊ |
48 | } moduleHook_t;␊ |
49 | ␊ |
50 | typedef struct modulesList_t␊ |
51 | {␊ |
52 | ␉const char*␉␉␉␉name;␊ |
53 | const char* author;␊ |
54 | const char* description;␊ |
55 | ␉UInt32␉␉␉␉␉version;␊ |
56 | ␉UInt32␉␉␉␉␉compat;␊ |
57 | ␉struct modulesList_t* next;␊ |
58 | } moduleList_t;␊ |
59 | ␊ |
60 | ␊ |
61 | ␊ |
62 | int init_module_system();␊ |
63 | void load_all_modules();␊ |
64 | ␊ |
65 | void start_built_in_module(const char* name, ␊ |
66 | const char* author, ␊ |
67 | const char* description,␊ |
68 | UInt32 version,␊ |
69 | UInt32 compat,␊ |
70 | void(*start_function)(void));␊ |
71 | ␊ |
72 | int load_module(char* module);␊ |
73 | int is_module_loaded(const char* name);␊ |
74 | void module_loaded(const char* name, const char* author, const char* description, UInt32 version, UInt32 compat);␊ |
75 | ␊ |
76 | ␊ |
77 | ␊ |
78 | ␊ |
79 | /********************************************************************************/␊ |
80 | /*␉Symbol Functions␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉*/␊ |
81 | /********************************************************************************/␊ |
82 | long long␉␉add_symbol(char* symbol, long long addr, char is64);␊ |
83 | unsigned int␉lookup_all_symbols(const char* name);␊ |
84 | ␊ |
85 | ␊ |
86 | ␊ |
87 | /********************************************************************************/␊ |
88 | /*␉Macho Parser␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉*/␊ |
89 | /********************************************************************************/␊ |
90 | void*␉␉␉parse_mach(void* binary, ␊ |
91 | ␉␉␉␉␉␉␉int(*dylib_loader)(char*),␊ |
92 | ␉␉␉␉␉␉␉long long(*symbol_handler)(char*, long long, char),␊ |
93 | void (*section_handler)(char* section, char* segment, long long offset, long long address)␊ |
94 | );␊ |
95 | unsigned int␉handle_symtable(UInt32 base,␊ |
96 | ␉␉␉␉␉␉␉ struct symtab_command* symtabCommand,␊ |
97 | ␉␉␉␉␉␉␉ long long(*symbol_handler)(char*, long long, char),␊ |
98 | ␉␉␉␉␉␉␉ char is64);␊ |
99 | void␉␉␉rebase_macho(void* base, char* rebase_stream, UInt32 size);␊ |
100 | inline void␉␉rebase_location(UInt32* location, char* base, int type);␊ |
101 | void␉␉␉bind_macho(void* base, UInt8* bind_stream, UInt32 size);␊ |
102 | inline void␉␉bind_location(UInt32* location, char* value, UInt32 addend, int type);␊ |
103 | ␊ |
104 | ␊ |
105 | ␊ |
106 | ␊ |
107 | /********************************************************************************/␊ |
108 | /*␉Module Interface␉␉␉␉␉␉␉␉␉␉␉␉␉␉*/␊ |
109 | /********************************************************************************/␊ |
110 | int␉␉␉␉replace_function(const char* symbol, void* newAddress);␊ |
111 | int␉␉␉␉execute_hook(const char* name, void*, void*, void*, void*);␊ |
112 | void␉␉␉register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*));␊ |
113 | moduleHook_t*␉hook_exists(const char* name);␊ |
114 | ␊ |
115 | #if DEBUG_MODULES␊ |
116 | void␉␉␉print_hook_list();␊ |
117 | #endif␊ |
118 | ␊ |
119 | /********************************************************************************/␊ |
120 | /*␉dyld Interface␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉*/␊ |
121 | /********************************************************************************/␊ |
122 | void dyld_stub_binder();␊ |
123 | ␊ |
124 | #endif /* __BOOT_MODULES_H */ |