Root/
Source at commit 429 created 13 years 7 months ago. By meklort, Updated module system. Hooks can now be used within modules when cetaion functions are called in chameleon. Note that onle two hooks currently exist, more need to be added. I also updated the HelloWorld module to use a hook instead of print out right away. | |
---|---|
1 | /*␊ |
2 | * Module Loading functionality␊ |
3 | * Copyright 2009 Evan Lojewski. All rights reserved.␊ |
4 | *␊ |
5 | */␊ |
6 | ␊ |
7 | #include <mach-o/loader.h>␊ |
8 | #include <mach-o/nlist.h>␊ |
9 | ␊ |
10 | #ifndef __BOOT_MODULES_H␊ |
11 | #define __BOOT_MODULES_H␊ |
12 | ␊ |
13 | ␊ |
14 | typedef struct symbolList_t␊ |
15 | {␊ |
16 | ␉char* symbol;␊ |
17 | ␉unsigned int addr;␊ |
18 | ␉struct symbolList_t* next;␊ |
19 | } symbolList_t;␊ |
20 | ␊ |
21 | typedef struct moduleList_t␊ |
22 | {␊ |
23 | ␉char* module;␊ |
24 | ␉unsigned int version;␊ |
25 | ␉unsigned int compat;␊ |
26 | ␉struct moduleList_t* next;␊ |
27 | } moduleList_t;␊ |
28 | ␊ |
29 | typedef struct callbackList_t␊ |
30 | {␊ |
31 | ␉void(*callback)(void*, void*, void*, void*);␊ |
32 | ␉struct callbackList_t* next;␊ |
33 | } callbackList_t;␊ |
34 | ␊ |
35 | typedef struct moduleHook_t␊ |
36 | {␊ |
37 | ␉const char* name;␊ |
38 | ␉callbackList_t* callbacks;␊ |
39 | ␉struct moduleHook_t* next;␊ |
40 | } moduleHook_t;␊ |
41 | ␊ |
42 | ␊ |
43 | #define SYMBOLS_MODULE "Symbols"␊ |
44 | ␊ |
45 | #define SYMBOL_DYLD_STUB_BINDER␉"dyld_stub_binder"␊ |
46 | #define STUB_ENTRY_SIZE␉6␊ |
47 | ␊ |
48 | #define SECT_NON_LAZY_SYMBOL_PTR␉"__nl_symbol_ptr"␊ |
49 | #define SECT_SYMBOL_STUBS␉␉␉"__symbol_stub"␊ |
50 | ␊ |
51 | ␊ |
52 | ␊ |
53 | int init_module_system();␊ |
54 | void load_all_modules();␊ |
55 | ␊ |
56 | /*␊ |
57 | * Modules Interface␊ |
58 | * register_hook␊ |
59 | *␉␉Notifies the module system that it should log requests␊ |
60 | *␉␉for callbacks on the hool execution␊ |
61 | *␊ |
62 | * execute_hook␊ |
63 | *␉␉Exexutes a registered hook. All callbaks are␊ |
64 | *␉␉called in the same order that they were added␊ |
65 | *␊ |
66 | * register_hook_callback␊ |
67 | *␉␉registers a void function to be executed when a␊ |
68 | *␉␉hook is executed.␊ |
69 | */␊ |
70 | inline void register_hook(const char* name);␊ |
71 | int execute_hook(const char* name, void*, void*, void*, void*);␊ |
72 | void register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*));␊ |
73 | ␊ |
74 | inline void rebase_location(UInt32* location, char* base);␊ |
75 | ␊ |
76 | int load_module(const char* module);␊ |
77 | int is_module_laoded(const char* name);␊ |
78 | void module_loaded(char* name, UInt32 version, UInt32 compat);␊ |
79 | ␊ |
80 | void add_symbol(char* symbol, void* addr);␊ |
81 | void* parse_mach(void* binary);␊ |
82 | ␊ |
83 | unsigned int handle_symtable(UInt32 base, struct symtab_command* symtabCommand, char* symbolStub, UInt32 nonlazy);␊ |
84 | ␊ |
85 | unsigned int lookup_all_symbols(const char* name);␊ |
86 | ␊ |
87 | extern unsigned int (*lookup_symbol)(const char*);␊ |
88 | ␊ |
89 | #endif /* __BOOT_MODULES_H */ |