Root/
Source at commit 717 created 13 years 3 months ago. By meklort, Module system fixes. Symbols.dylib now contains correct addresses for global symbols. KextPather only tries to patch dev ids with 0x433F or less, reenabled Resolution.dylib | |
---|---|
1 | /*␊ |
2 | * Symbols.c␊ |
3 | * ␊ |
4 | * Module loader support module. This module is the first module to ever be loaded.␊ |
5 | * It contains a copy of each symbol inside ov the current version of chameleon as well ␊ |
6 | * as a strcmp function. Chameleon calls lookup_symbol to resolve internal symbols␊ |
7 | * when they are requested by a module. This module does *not* depend on any intenrla␊ |
8 | * symbols, as such it can be loaded without a symbol table initialized.␊ |
9 | *␊ |
10 | * Copyright (c) 2009 Evan Lojewski. All rights reserved.␊ |
11 | */␊ |
12 | ␊ |
13 | #include "Symbols.h"␊ |
14 | ␊ |
15 | static int strcmp(const char * s1, const char * s2);␊ |
16 | ␊ |
17 | void Symbols_start()␊ |
18 | {␊ |
19 | }␊ |
20 | ␊ |
21 | unsigned int lookup_symbol(const char* symbol)␊ |
22 | {␊ |
23 | ␉if(strcmp(symbol, "dyld_stub_binder") == 0) return lookup_symbol("_dyld_stub_binder");␉// ugly hack␊ |
24 | ␉ ␊ |
25 | ␉int upperLimit = sizeof(symbolList) / sizeof(symbolList[0]) - 1;␉␉␊ |
26 | ␉int lowerLimit = 0;␊ |
27 | ␉int compareIndex = (upperLimit - lowerLimit) >> 1; // Midpoint␊ |
28 | ␉int result;␊ |
29 | ␉␊ |
30 | ␉while((result = strcmp(symbol, symbolList[compareIndex].symbol)) != 0)␊ |
31 | ␉{␊ |
32 | ␉␉if(result > 0)␉// We need to search a HIGHER index␊ |
33 | ␉␉{␊ |
34 | ␉␉␉if(compareIndex != lowerLimit)␊ |
35 | ␉␉␉{␊ |
36 | ␉␉␉␉lowerLimit = compareIndex;␊ |
37 | ␉␉␉}␊ |
38 | ␉␉␉else␊ |
39 | ␉␉␉{␊ |
40 | ␉␉␉␉return 0xFFFFFFFF;␉// Symbol not found␊ |
41 | ␉␉␉}␊ |
42 | ␉␉␉compareIndex = (upperLimit + lowerLimit + 1) >> 1;␉// Midpoint, round up␊ |
43 | ␉␉}␊ |
44 | ␉␉else // We Need to search a LOWER index␊ |
45 | ␉␉{␊ |
46 | ␉␉␉if(compareIndex != upperLimit)␊ |
47 | ␉␉␉{␊ |
48 | ␉␉␉␉upperLimit = compareIndex;␊ |
49 | ␉␉␉}␊ |
50 | ␉␉␉else␊ |
51 | ␉␉␉{␊ |
52 | ␉␉␉␉return 0xFFFFFFFF;␉// Symbol not found␊ |
53 | ␉␉␉}␊ |
54 | ␉␉␉compareIndex = (upperLimit + lowerLimit) >> 1;␉// Midpoint, round down␊ |
55 | ␉␉}␊ |
56 | ␉}␊ |
57 | ␉return symbolList[compareIndex].addr;␊ |
58 | }␊ |
59 | ␊ |
60 | /*␊ |
61 | * strcmp - Copied from libsa/string.c due to symbols not able to be resolved at this point␊ |
62 | */␊ |
63 | static int strcmp(const char * s1, const char * s2)␊ |
64 | {␊ |
65 | ␉while (*s1 && (*s1 == *s2)) {␊ |
66 | ␉␉s1++;␊ |
67 | ␉␉s2++;␊ |
68 | ␉}␊ |
69 | ␉return (*s1 - *s2);␊ |
70 | }␊ |
71 | ␊ |
72 | ␊ |
73 | ␊ |
74 |