Chameleon

Chameleon Svn Source Tree

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

Source at commit 537 created 9 years 9 months ago.
By meklort, A few more bugfixes / typo fixes
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
19extern unsigned long long textAddress;
20extern unsigned long long textSection;
21
22
23typedef struct symbolList_t
24{
25char* symbol;
26unsigned int addr;
27struct symbolList_t* next;
28} symbolList_t;
29
30typedef struct moduleList_t
31{
32char* module;
33unsigned int version;
34unsigned int compat;
35struct moduleList_t* next;
36} moduleList_t;
37
38typedef struct callbackList_t
39{
40void(*callback)(void*, void*, void*, void*);
41struct callbackList_t* next;
42} callbackList_t;
43
44typedef struct moduleHook_t
45{
46const char* name;
47callbackList_t* callbacks;
48struct moduleHook_t* next;
49} moduleHook_t;
50
51#define SYMBOLS_MODULE "Symbols.dylib"
52
53#define SYMBOL_DYLD_STUB_BINDER"dyld_stub_binder"
54#define SYMBOL_LOOKUP_SYMBOL"_lookup_symbol"
55#define STUB_ENTRY_SIZE6
56
57#define SECT_NON_LAZY_SYMBOL_PTR"__nl_symbol_ptr"
58#define SECT_SYMBOL_STUBS"__symbol_stub"
59
60
61
62int init_module_system();
63void load_all_modules();
64
65/*
66 * Modules Interface
67 * execute_hook
68 *Exexutes a registered hook. All callbaks are
69 *called in the same order that they were added
70 *
71 * register_hook_callback
72 *registers a void function to be executed when a
73 *hook is executed.
74 */
75int execute_hook(const char* name, void*, void*, void*, void*);
76void register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*));
77
78inline void rebase_location(UInt32* location, char* base, int type);
79inline void bind_location(UInt32* location, char* value, UInt32 addend, int type);
80void rebase_macho(void* base, char* rebase_stream, UInt32 size);
81void bind_macho(void* base, char* bind_stream, UInt32 size);
82
83int load_module(char* module);
84int is_module_loaded(const char* name);
85void module_loaded(const char* name/*, UInt32 version, UInt32 compat*/);
86
87long long add_symbol(char* symbol, long long addr, char is64);
88
89void* parse_mach(void* binary,
90 int(*dylib_loader)(char*),
91 long long(*symbol_handler)(char*, long long, char)
92 );
93
94unsigned int handle_symtable(UInt32 base,
95 struct symtab_command* symtabCommand,
96 long long(*symbol_handler)(char*, long long, char),
97 char is64);
98
99unsigned int lookup_all_symbols(const char* name);
100
101int replace_function(const char* symbol, void* newAddress);
102
103extern unsigned int (*lookup_symbol)(const char*);
104
105#endif /* __BOOT_MODULES_H */

Archive Download this file

Revision: 537