Chameleon

Chameleon Svn Source Tree

Root/branches/meklort/i386/boot2/modules.h

Source at commit 735 created 13 years 2 months ago.
By meklort, GUI module bugfixes. Kext Patcher additions.
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
11// There is a bug with the module system / rebasing / binding
12// that causes static variables to be incorrectly rebased or bound
13// Disable static variables for the moment
14// #define static
15
16#ifndef __BOOT_MODULES_H
17#define __BOOT_MODULES_H
18
19#define SYMBOLS_MODULE "Symbols.dylib"
20
21#define SYMBOL_LOOKUP_SYMBOL"_lookup_symbol"
22#define STUB_ENTRY_SIZE6
23
24#define SECT_NON_LAZY_SYMBOL_PTR"__nl_symbol_ptr"
25#define SECT_SYMBOL_STUBS"__symbol_stub"
26
27
28#define VALID_FUNCTION(__x__)(__x__ && (void*)__x__ != (void*)0xFFFFFFFF)
29
30extern unsigned long long textAddress;
31extern unsigned long long textSection;
32
33
34
35typedef struct symbolList_t
36{
37char* symbol;
38unsigned int addr;
39struct symbolList_t* next;
40} symbolList_t;
41
42
43typedef struct callbackList_t
44{
45void(*callback)(void*, void*, void*, void*);
46struct callbackList_t* next;
47} callbackList_t;
48
49typedef struct moduleHook_t
50{
51const char* name;
52callbackList_t* callbacks;
53struct moduleHook_t* next;
54} moduleHook_t;
55
56typedef struct modulesList_t
57{
58char*name;
59UInt32version;
60UInt32compat;
61
62void*base_addr;
63
64symbolList_t*exported_symbols;
65symbolList_t*udefined_symbols;
66//moduleHook_t*defined_hooks;
67struct modulesList_t* next;
68} moduleList_t;
69
70
71
72int init_module_system();
73void load_all_modules();
74
75
76
77int load_module(char* module);
78int is_module_loaded(const char* name);
79void module_loaded(const char* name/*, UInt32 version, UInt32 compat*/);
80
81
82
83
84/********************************************************************************/
85/*Symbol Functions*/
86/********************************************************************************/
87long longadd_symbol(char* symbol, long long addr, char is64);
88unsigned intlookup_all_symbols(const char* name);
89
90
91
92/********************************************************************************/
93/*Macho Parser*/
94/********************************************************************************/
95void*parse_mach(void* binary,
96int(*dylib_loader)(char*),
97long long(*symbol_handler)(char*, long long, char));
98unsigned inthandle_symtable(UInt32 base,
99 struct symtab_command* symtabCommand,
100 long long(*symbol_handler)(char*, long long, char),
101 char is64);
102voidrebase_macho(void* base, char* rebase_stream, UInt32 size);
103inline voidrebase_location(UInt32* location, char* base, int type);
104voidbind_macho(void* base, char* bind_stream, UInt32 size);
105inline voidbind_location(UInt32* location, char* value, UInt32 addend, int type);
106
107
108
109
110/********************************************************************************/
111/*Module Interface*/
112/********************************************************************************/
113intreplace_function(const char* symbol, void* newAddress);
114intexecute_hook(const char* name, void*, void*, void*, void*);
115voidregister_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*));
116moduleHook_t*hook_exists(const char* name);
117
118#if DEBUG_MODULES
119voidprint_hook_list();
120#endif
121
122/********************************************************************************/
123/*dyld Interface*/
124/********************************************************************************/
125void dyld_stub_binder();
126
127#endif /* __BOOT_MODULES_H */

Archive Download this file

Revision: 735