Chameleon

Chameleon Svn Source Tree

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

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
34typedef struct symbolList_t
35{
36char* symbol;
37unsigned int addr;
38struct symbolList_t* next;
39} symbolList_t;
40
41typedef struct moduleList_t
42{
43char* module;
44unsigned int version;
45unsigned int compat;
46struct moduleList_t* next;
47} moduleList_t;
48
49typedef struct callbackList_t
50{
51void(*callback)(void*, void*, void*, void*);
52struct callbackList_t* next;
53} callbackList_t;
54
55typedef struct moduleHook_t
56{
57const char* name;
58callbackList_t* callbacks;
59struct moduleHook_t* next;
60} moduleHook_t;
61
62
63
64int init_module_system();
65void load_all_modules();
66
67
68
69int load_module(char* module);
70int is_module_loaded(const char* name);
71void module_loaded(const char* name/*, UInt32 version, UInt32 compat*/);
72
73
74
75
76/********************************************************************************/
77/*Symbol Functions*/
78/********************************************************************************/
79long longadd_symbol(char* symbol, long long addr, char is64);
80unsigned intlookup_all_symbols(const char* name);
81
82
83
84/********************************************************************************/
85/*Macho Parser*/
86/********************************************************************************/
87void*parse_mach(void* binary,
88int(*dylib_loader)(char*),
89long long(*symbol_handler)(char*, long long, char));
90unsigned inthandle_symtable(UInt32 base,
91 struct symtab_command* symtabCommand,
92 long long(*symbol_handler)(char*, long long, char),
93 char is64);
94voidrebase_macho(void* base, char* rebase_stream, UInt32 size);
95inline voidrebase_location(UInt32* location, char* base, int type);
96voidbind_macho(void* base, char* bind_stream, UInt32 size);
97inline voidbind_location(UInt32* location, char* value, UInt32 addend, int type);
98
99
100
101
102/********************************************************************************/
103/*Module Interface*/
104/********************************************************************************/
105intreplace_function(const char* symbol, void* newAddress);
106intexecute_hook(const char* name, void*, void*, void*, void*);
107voidregister_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*));
108moduleHook_t*hook_exists(const char* name);
109
110#if DEBUG_MODULES
111voidprint_hook_list();
112#endif
113
114/********************************************************************************/
115/*dyld Interface*/
116/********************************************************************************/
117void dyld_stub_binder();
118
119#endif /* __BOOT_MODULES_H */

Archive Download this file

Revision: 721