Chameleon

Chameleon Svn Source Tree

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

Source at commit 334 created 13 years 8 months ago.
By meklort, Missing 'l'
1/*
2 * Copyright 2009 Evan Lojewski. All rights reserved.
3 *
4 */
5
6#include "boot.h"
7#include "bootstruct.h"
8#include "multiboot.h"
9#include "modules.h"
10
11
12unsigned int (*lookup_symbol)(const char*) = NULL;
13
14
15void rebase_macho(void* base, char* rebase_stream, UInt32 size);
16void bind_macho(void* base, char* bind_stream, UInt32 size);
17
18int load_module(const char* module)
19{
20char modString[128];
21int fh = -1;
22sprintf(modString, "/Extra/modules/%s.dylib", module);
23fh = open(modString, 0);
24if(fh < 0)
25{
26printf("Unable to locate module %s\n", modString);
27getc();
28return ERROR;
29}
30
31unsigned int moduleSize = file_size(fh);
32char* module_base = (char*) malloc(moduleSize);
33if (read(fh, module_base, moduleSize) == moduleSize)
34{
35void (*module_start)(void) = NULL;
36
37printf("Module %s read in.\n", modString);
38
39// Module loaded into memory, parse it
40module_start = parse_mach(module_base);
41
42if(module_start)
43{
44(*module_start)();// Start the module
45printf("Module started\n");
46}
47else {
48printf("Unabel to locate module start\n");
49}
50
51
52getc();
53
54// TODO: Add module to loaded list if loaded successfuly
55
56}
57else
58{
59printf("Unable to read in module %s.dylib\n.", module);
60getc();
61}
62return 1;
63}
64
65
66void* parse_mach(void* binary)
67{
68int (*module_init)(void) = NULL;
69void (*module_start)(void) = NULL;
70
71
72char* moduleName = NULL;
73UInt32 moduleVersion = 0;
74UInt32 moduleCompat = 0;
75
76char* symbolStub = NULL;
77char* nonlazy = NULL;
78char* nonlazy_variables = NULL;
79
80char* symbolTable = NULL;
81// TODO convert all of the structs a union
82struct load_command *loadCommand;
83struct dylib_command* dylibCommand;
84struct dyld_info_command* dyldInfoCommand;
85struct symtab_command* symtabCommand;
86struct segment_command* segmentCommand;
87struct dysymtab_command* dysymtabCommand;
88struct section* section;
89UInt32 binaryIndex = sizeof(struct mach_header);
90UInt16 cmd = 0;
91
92// Parse hthrough th eload commands
93if(((struct mach_header*)binary)->magic != MH_MAGIC)
94{
95printf("Module is not 32bit\n");
96return NULL;// 32bit only
97}
98
99if(((struct mach_header*)binary)->filetype != MH_DYLIB)
100{
101printf("Module is not a dylib. Unable to load.\n");
102return NULL; // Module is in the incorrect format
103}
104
105while(cmd < ((struct mach_header*)binary)->ncmds)// TODO: for loop instead
106{
107cmd++;
108
109loadCommand = binary + binaryIndex;
110UInt32 cmdSize = loadCommand->cmdsize;
111
112
113switch ((loadCommand->cmd & 0x7FFFFFFF))
114{
115case LC_SYMTAB:
116symtabCommand = binary + binaryIndex;
117
118UInt32 symbolIndex = 0;
119char* symbolString = (UInt32)binary + (char*)symtabCommand->stroff;
120symbolTable = binary + symtabCommand->symoff;
121
122int externalIndex = 0;
123while(symbolIndex < symtabCommand->nsyms)
124{
125
126struct nlist* symbolEntry = binary + symtabCommand->symoff + (symbolIndex * sizeof(struct nlist));
127
128// If the symbol is exported by this module
129if(symbolEntry->n_value)
130{
131if(strcmp(symbolString + symbolEntry->n_un.n_strx, "_start") == 0)
132{
133// Module init located. Don't register it, only called once
134module_init = binary + symbolEntry->n_value;
135}
136else if(strcmp(symbolString + symbolEntry->n_un.n_strx, "start") == 0)
137{
138// Module start located. Start is an alias so don't register it
139module_start = binary + symbolEntry->n_value;
140}
141else
142{
143add_symbol(symbolString + symbolEntry->n_un.n_strx, binary + symbolEntry->n_value);
144}
145}
146// External symbol
147else if(symbolEntry->n_type & 0x01 && symbolStub)
148{
149printf("Located external symbol %s", symbolString + symbolEntry->n_un.n_strx);
150printf(" stub at 0x%X, (0x%X)\n", symbolStub + STUB_ENTRY_SIZE * externalIndex - (UInt32)binary, symbolStub + STUB_ENTRY_SIZE * externalIndex);
151getc();
152// Patch stub
153if(lookup_symbol == NULL)
154{
155printf("Symbol.dylib not loaded. Module loader not setup.\n");
156return NULL;
157}
158else
159{
160void* symbolAddress = (void*)lookup_symbol(symbolString + symbolEntry->n_un.n_strx);
161
162if((0xFFFFFFFF == (UInt32)symbolAddress) &&
163 strcmp(symbolString + symbolEntry->n_un.n_strx, SYMBOL_DYLD_STUB_BINDER) != 0)
164{
165printf("Unable to locate symbol %s\n", symbolString + symbolEntry->n_un.n_strx);
166
167}
168else
169{
170char* patchLocation = symbolStub + STUB_ENTRY_SIZE * externalIndex;
171//patch with far jump ;
172/*
173printf("0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n",
174 patchLocation[0],
175 patchLocation[1],
176 patchLocation[2],
177 patchLocation[3],
178 patchLocation[4],
179 patchLocation[5]);
180*/
181
182// Point the symbol stub to the nonlazy pointers
183patchLocation[0] = 0xFF;// Should already be this
184patchLocation[1] = 0x25;// Should already be this
185patchLocation[2] = ((UInt32)(nonlazy + externalIndex * 4) & 0x000000FF) >> 0;
186patchLocation[3] = ((UInt32)(nonlazy + externalIndex * 4) & 0x0000FF00) >> 8;
187patchLocation[4] = ((UInt32)(nonlazy + externalIndex * 4) & 0x00FF0000) >> 16;
188patchLocation[5] = ((UInt32)(nonlazy + externalIndex * 4) & 0xFF000000) >> 24;
189
190// Set the nonlazy pointer to the correct address
191patchLocation = (nonlazy + externalIndex*4);
192patchLocation[0] =((UInt32)symbolAddress & 0x000000FF) >> 0;
193patchLocation[1] =((UInt32)symbolAddress & 0x0000FF00) >> 8;
194patchLocation[2] =((UInt32)symbolAddress & 0x00FF0000) >> 16;
195patchLocation[3] =((UInt32)symbolAddress & 0xFF000000) >> 24;
196
197
198externalIndex++;
199
200}
201
202
203}
204
205}
206
207symbolEntry+= sizeof(struct nlist);
208symbolIndex++;// TODO remove
209}
210break;
211
212case LC_SEGMENT:
213segmentCommand = binary + binaryIndex;
214
215UInt32 sections = segmentCommand->nsects;
216section = binary + binaryIndex + sizeof(struct segment_command);
217while(sections)
218{
219// Look for the __symbol_stub section
220if(strcmp(section->sectname, "__nl_symbol_ptr") == 0)
221{
222/*printf("\tSection non lazy pointers at 0x%X, %d symbols\n",
223 section->offset,
224 section->size / 4);
225*/
226switch(section->flags)
227{
228case S_NON_LAZY_SYMBOL_POINTERS:
229nonlazy_variables = binary + section->offset;
230break;
231
232case S_LAZY_SYMBOL_POINTERS:
233nonlazy = binary + section->offset;
234// Fucntions
235break;
236
237default:
238printf("Unhandled __nl_symbol_ptr section\n");
239getc();
240break;
241}
242//getc();
243}
244else if(strcmp(section->sectname, "__symbol_stub") == 0)
245{
246/*printf("\tSection __symbol_stub at 0x%X (0x%X), %d symbols\n",
247 section->offset,
248 section->size / 6);*/
249symbolStub = binary + section->offset;
250//getc();
251}
252
253
254sections--;
255section++;
256}
257
258
259break;
260
261case LC_DYSYMTAB:
262dysymtabCommand = binary + binaryIndex;
263//printf("Unhandled loadcommand LC_DYSYMTAB\n");
264break;
265
266case LC_LOAD_DYLIB:
267//printf("Unhandled loadcommand LC_LOAD_DYLIB\n");
268break;
269
270case LC_ID_DYLIB:
271dylibCommand = binary + binaryIndex;
272moduleName =binary + binaryIndex + ((UInt32)*((UInt32*)&dylibCommand->dylib.name));
273moduleVersion =dylibCommand->dylib.current_version;
274moduleCompat =dylibCommand->dylib.compatibility_version;
275break;
276
277case LC_DYLD_INFO:
278dyldInfoCommand = binary + binaryIndex;
279/*
280 printf("LC_DYLD_INFO:\n"
281 "\tRebase Offset: 0x%X\n"
282 "\tBind Offset: 0x%X\n"
283 "\tWeak Bind Offset: 0x%X\n"
284 "\tLazy Bind Offset: 0x%X\n"
285 "\tExport Offset: 0x%X\n",
286 dyldInfoCommand->rebase_off,
287 dyldInfoCommand->bind_off,
288 dyldInfoCommand->weak_bind_off,
289 dyldInfoCommand->lazy_bind_off,
290 dyldInfoCommand->export_off);
291*/
292if(dyldInfoCommand->bind_off)
293{
294bind_macho(binary, (char*)dyldInfoCommand->bind_off, dyldInfoCommand->bind_size);
295}
296
297/*
298 // This is done later on using the __symbol_stub instead
299if(dyldInfoCommand->lazy_bind_off)
300{
301bind_macho(binary, (char*)dyldInfoCommand->lazy_bind_off, dyldInfoCommand->lazy_bind_size);
302
303}*/
304
305if(dyldInfoCommand->rebase_off)
306{
307rebase_macho(binary, (char*)dyldInfoCommand->rebase_off, dyldInfoCommand->rebase_size);
308}
309
310
311break;
312
313case LC_UUID:
314// We don't care about the UUID at the moment
315break;
316
317default:
318printf("Unhandled loadcommand 0x%X\n", loadCommand->cmd & 0x7FFFFFFF);
319break;
320
321}
322
323binaryIndex += cmdSize;
324}
325if(!moduleName) return NULL;
326
327
328// TODO: Initialize the module.
329printf("Calling _start\n");
330
331getc();
332if(module_init)
333{
334jump_pointer(module_init);
335 }
336module_loaded(moduleName, moduleVersion, moduleCompat);
337getc();
338 //*/
339return module_start; // TODO populate w/ address of _start
340
341}
342
343
344// This is for debugging, remove the jump_pointer funciton later
345int jump_pointer(int (*pointer)())
346{
347printf("Jumping to function at 0x%X\n", pointer);
348
349getc();
350return (*pointer)();
351}
352
353// Based on code from dylibinfo.cpp and ImageLoaderMachOCompressed.cpp
354void rebase_macho(void* base, char* rebase_stream, UInt32 size)
355{
356rebase_stream += (UInt32)base;
357
358UInt8 immediate = 0;
359UInt8 opcode = 0;
360UInt8 type = 0;
361
362UInt32 segmentAddress = 0;
363UInt32 address = 0;
364
365
366
367UInt32 tmp = 0;
368UInt32 tmp2 = 0;
369UInt8 bits = 0;
370int index = 0;
371
372int done = 0;
373unsigned int i = 0;
374
375while(/*!done &&*/ i < size)
376{
377immediate = rebase_stream[i] & REBASE_IMMEDIATE_MASK;
378opcode = rebase_stream[i] & REBASE_OPCODE_MASK;
379
380
381switch(opcode)
382{
383case REBASE_OPCODE_DONE:
384// Rebase complete.
385done = 1;
386break;
387
388case REBASE_OPCODE_SET_TYPE_IMM:
389// Set rebase type (pointer, absolute32, pcrel32)
390//printf("Rebase type = 0x%X\n", immediate);
391// NOTE: This is currently NOT used
392type = immediate;
393break;
394
395case REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB:
396// Locate address to begin rebasing
397segmentAddress = 0;
398
399struct segment_command* segCommand = NULL;
400
401unsigned int binIndex = 0;
402index = 0;
403do
404{
405segCommand = base + sizeof(struct mach_header) + binIndex;
406
407
408binIndex += segCommand->cmdsize;
409index++;
410}
411while(index <= immediate);
412
413
414segmentAddress = segCommand->fileoff;
415
416tmp = 0;
417bits = 0;
418do
419{
420tmp |= (rebase_stream[++i] & 0x7f) << bits;
421bits += 7;
422}
423while(rebase_stream[i] & 0x80);
424
425segmentAddress += tmp;
426
427//printf("Address = 0x%X\n", segmentAddress);
428break;
429
430case REBASE_OPCODE_ADD_ADDR_ULEB:
431// Add value to rebase address
432tmp = 0;
433bits = 0;
434do
435{
436tmp <<= bits;
437tmp |= rebase_stream[++i] & 0x7f;
438bits += 7;
439}
440while(rebase_stream[i] & 0x80);
441
442address +=tmp;
443//printf("Address (add) = 0x%X\n", address);
444break;
445
446case REBASE_OPCODE_ADD_ADDR_IMM_SCALED:
447address += immediate * sizeof(void*);
448//printf("Address (immscaled) = 0x%X\n", address);
449
450break;
451
452case REBASE_OPCODE_DO_REBASE_IMM_TIMES:
453//printf("Rebase %d time(s)\n", immediate);
454index = 0;
455for (index = 0; index < immediate; ++index) {
456//printf("\tRebasing 0x%X\n", segmentAddress);
457
458UInt32* addr = base + segmentAddress;
459addr[0] += (UInt32)base;
460
461
462segmentAddress += sizeof(void*);
463}
464break;
465
466case REBASE_OPCODE_DO_REBASE_ULEB_TIMES:
467tmp = 0;
468bits = 0;
469do
470{
471tmp |= (rebase_stream[++i] & 0x7f) << bits;
472bits += 7;
473}
474while(rebase_stream[i] & 0x80);
475
476//printf("Rebase %d time(s)\n", tmp);
477
478index = 0;
479for (index = 0; index < tmp; ++index) {
480//printf("\tRebasing 0x%X\n", segmentAddress);
481
482UInt32* addr = base + segmentAddress;
483addr[0] += (UInt32)base;
484
485segmentAddress += sizeof(void*);
486}
487break;
488
489case REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB:
490tmp = 0;
491bits = 0;
492do
493{
494tmp |= (rebase_stream[++i] & 0x7f) << bits;
495bits += 7;
496}
497while(rebase_stream[i] & 0x80);
498
499
500//printf("Rebase and add 0x%X\n", tmp);
501//printf("\tRebasing 0x%X\n", segmentAddress);
502UInt32* addr = base + segmentAddress;
503addr[0] += (UInt32)base;
504
505segmentAddress += tmp + sizeof(void*);
506break;
507
508case REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB:
509tmp = 0;
510bits = 0;
511do
512{
513tmp |= (rebase_stream[++i] & 0x7f) << bits;
514bits += 7;
515}
516while(rebase_stream[i] & 0x80);
517
518
519tmp2 = 0;
520bits = 0;
521do
522{
523tmp2 |= (rebase_stream[++i] & 0x7f) << bits;
524bits += 7;
525}
526while(rebase_stream[i] & 0x80);
527
528//printf("Rebase 0x%X times, skiping 0x%X\n",tmp, tmp2);
529index = 0;
530for (index = 0; index < tmp; ++index) {
531//printf("\tRebasing 0x%X\n", segmentAddress);
532
533UInt32* addr = base + segmentAddress;
534addr[0] += (UInt32)base;
535
536segmentAddress += tmp2 + sizeof(void*);
537}
538break;
539}
540i++;
541}
542}
543
544// Based on code from dylibinfo.cpp and ImageLoaderMachOCompressed.cpp
545// NOTE: this uses 32bit values, and not 64bit values.
546// There is apossibility that this could cause issues,
547// however the macho file is 32 bit, so it shouldn't matter too much
548void bind_macho(void* base, char* bind_stream, UInt32 size)
549{
550
551
552bind_stream += (UInt32)base;
553
554UInt8 immediate = 0;
555UInt8 opcode = 0;
556UInt8 type = 0;
557
558UInt32 segmentAddress = 0;
559
560UInt32 address = 0;
561
562SInt32 addend = 0;
563SInt32 libraryOrdinal = 0;
564
565const char* symbolName = NULL;
566UInt8 symboFlags = 0;
567UInt32 symbolAddr = 0xFFFFFFFF;
568// Temperary variables
569UInt8 bits = 0;
570UInt32 tmp = 0;
571UInt32 tmp2 = 0;
572
573UInt32 index = 0;
574int done = 0;
575unsigned int i = 0;
576
577while(/*!done &&*/ i < size)
578{
579immediate = bind_stream[i] & BIND_IMMEDIATE_MASK;
580opcode = bind_stream[i] & BIND_OPCODE_MASK;
581
582
583switch(opcode)
584{
585case BIND_OPCODE_DONE:
586done = 1;
587break;
588
589case BIND_OPCODE_SET_DYLIB_ORDINAL_IMM:
590libraryOrdinal = immediate;
591//printf("BIND_OPCODE_SET_DYLIB_ORDINAL_IMM: %d\n", libraryOrdinal);
592break;
593
594case BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB:
595libraryOrdinal = 0;
596bits = 0;
597do
598{
599libraryOrdinal |= (bind_stream[++i] & 0x7f) << bits;
600bits += 7;
601}
602while(bind_stream[i] & 0x80);
603
604//printf("BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB: %d\n", libraryOrdinal);
605
606break;
607
608case BIND_OPCODE_SET_DYLIB_SPECIAL_IMM:
609// NOTE: this is wrong, fortunately we don't use it
610libraryOrdinal = -immediate;
611//printf("BIND_OPCODE_SET_DYLIB_SPECIAL_IMM: %d\n", libraryOrdinal);
612
613break;
614
615case BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM:
616symboFlags = immediate;
617symbolName = (char*)&bind_stream[++i];
618i += strlen((char*)&bind_stream[i]);
619//printf("BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM: %s, 0x%X\n", symbolName, symboFlags);
620
621symbolAddr = lookup_symbol(symbolName);
622
623break;
624
625case BIND_OPCODE_SET_TYPE_IMM:
626// Set bind type (pointer, absolute32, pcrel32)
627type = immediate;
628//printf("BIND_OPCODE_SET_TYPE_IMM: %d\n", type);
629
630break;
631
632case BIND_OPCODE_SET_ADDEND_SLEB:
633addend = 0;
634bits = 0;
635do
636{
637addend |= (bind_stream[++i] & 0x7f) << bits;
638bits += 7;
639}
640while(bind_stream[i] & 0x80);
641
642if(!(bind_stream[i-1] & 0x40)) addend *= -1;
643
644//printf("BIND_OPCODE_SET_ADDEND_SLEB: %d\n", addend);
645break;
646
647case BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB:
648segmentAddress = 0;
649
650// Locate address
651struct segment_command* segCommand = NULL;
652
653unsigned int binIndex = 0;
654index = 0;
655do
656{
657segCommand = base + sizeof(struct mach_header) + binIndex;
658binIndex += segCommand->cmdsize;
659index++;
660}
661while(index <= immediate);
662
663segmentAddress = segCommand->fileoff;
664
665// Read in offset
666tmp = 0;
667bits = 0;
668do
669{
670tmp |= (bind_stream[++i] & 0x7f) << bits;
671bits += 7;
672}
673while(bind_stream[i] & 0x80);
674
675segmentAddress += tmp;
676
677//printf("BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB: 0x%X\n", segmentAddress);
678break;
679
680case BIND_OPCODE_ADD_ADDR_ULEB:
681// Read in offset
682tmp = 0;
683bits = 0;
684do
685{
686tmp |= (bind_stream[++i] & 0x7f) << bits;
687bits += 7;
688}
689while(bind_stream[i] & 0x80);
690
691segmentAddress += tmp;
692//printf("BIND_OPCODE_ADD_ADDR_ULEB: 0x%X\n", segmentAddress);
693break;
694
695case BIND_OPCODE_DO_BIND:
696//printf("BIND_OPCODE_DO_BIND\n");
697if(symbolAddr != 0xFFFFFFFF)
698{
699address = segmentAddress + (UInt32)base;
700
701((char*)address)[0] = (symbolAddr & 0x000000FF) >> 0;
702((char*)address)[1] = (symbolAddr & 0x0000FF00) >> 8;
703((char*)address)[2] = (symbolAddr & 0x00FF0000) >> 16;
704((char*)address)[3] = (symbolAddr & 0xFF000000) >> 24;
705}
706else if(strcmp(symbolName, SYMBOL_DYLD_STUB_BINDER) != 0)
707{
708printf("Unable to bind symbol %s\n", symbolName);
709}
710
711segmentAddress += sizeof(void*);
712break;
713
714case BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB:
715//printf("BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB\n");
716
717
718// Read in offset
719tmp = 0;
720bits = 0;
721do
722{
723tmp |= (bind_stream[++i] & 0x7f) << bits;
724bits += 7;
725}
726while(bind_stream[i] & 0x80);
727
728
729
730if(symbolAddr != 0xFFFFFFFF)
731{
732address = segmentAddress + (UInt32)base;
733
734((char*)address)[0] = (symbolAddr & 0x000000FF) >> 0;
735((char*)address)[1] = (symbolAddr & 0x0000FF00) >> 8;
736((char*)address)[2] = (symbolAddr & 0x00FF0000) >> 16;
737((char*)address)[3] = (symbolAddr & 0xFF000000) >> 24;
738}
739else if(strcmp(symbolName, SYMBOL_DYLD_STUB_BINDER) != 0)
740{
741printf("Unable to bind symbol %s\n", symbolName);
742}
743segmentAddress += tmp + sizeof(void*);
744
745
746break;
747
748case BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED:
749//printf("BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED\n");
750
751if(symbolAddr != 0xFFFFFFFF)
752{
753address = segmentAddress + (UInt32)base;
754
755((char*)address)[0] = (symbolAddr & 0x000000FF) >> 0;
756((char*)address)[1] = (symbolAddr & 0x0000FF00) >> 8;
757((char*)address)[2] = (symbolAddr & 0x00FF0000) >> 16;
758((char*)address)[3] = (symbolAddr & 0xFF000000) >> 24;
759}
760else if(strcmp(symbolName, SYMBOL_DYLD_STUB_BINDER) != 0)
761{
762printf("Unable to bind symbol %s\n", symbolName);
763}
764segmentAddress += (immediate * sizeof(void*)) + sizeof(void*);
765
766
767break;
768
769case BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB:
770
771tmp = 0;
772bits = 0;
773do
774{
775tmp |= (bind_stream[++i] & 0x7f) << bits;
776bits += 7;
777}
778while(bind_stream[i] & 0x80);
779
780
781tmp2 = 0;
782bits = 0;
783do
784{
785tmp2 |= (bind_stream[++i] & 0x7f) << bits;
786bits += 7;
787}
788while(bind_stream[i] & 0x80);
789
790
791//printf("BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB 0x%X 0x%X\n", tmp, tmp2);
792
793
794if(symbolAddr != 0xFFFFFFFF)
795{
796for(index = 0; index < tmp; index++)
797{
798
799address = segmentAddress + (UInt32)base;
800
801((char*)address)[0] = (symbolAddr & 0x000000FF) >> 0;
802((char*)address)[1] = (symbolAddr & 0x0000FF00) >> 8;
803((char*)address)[2] = (symbolAddr & 0x00FF0000) >> 16;
804((char*)address)[3] = (symbolAddr & 0xFF000000) >> 24;
805
806segmentAddress += tmp2 + sizeof(void*);
807}
808}
809else if(strcmp(symbolName, SYMBOL_DYLD_STUB_BINDER) != 0)
810{
811printf("Unable to bind symbol %s\n", symbolName);
812}
813
814
815break;
816
817}
818i++;
819}
820}
821
822/*
823 * add_symbol
824 * This function adds a symbol from a module to the list of known symbols
825 * TODO: actualy do something...
826 * possibly change to a pointer and add this to the Symbol module
827 */
828void add_symbol(const char* symbol, void* addr)
829{
830printf("Adding symbol %s at 0x%X\n", symbol, addr);
831
832//hack
833if(strcmp(symbol, "_lookup_symbol") == 0)
834{
835printf("Initializing lookup symbol function\n");
836lookup_symbol = addr;
837}
838}
839
840
841/*
842 * print out the information about the loaded module
843 * In the future, add to a list of laoded modules
844 * so that if another module depends on it we don't
845 * try to reload the same module.
846 */
847void module_loaded(const char* name, UInt32 version, UInt32 compat)
848{
849printf("\%s.dylib Version %d.%d.%d loaded\n"
850 "\tCompatibility Version: %d.%d.%d\n",
851 name,
852 (version >> 16) & 0xFFFF,
853 (version >> 8) & 0x00FF,
854 (version >> 0) & 0x00FF,
855 (compat >> 16) & 0xFFFF,
856 (compat >> 8) & 0x00FF,
857 (compat >> 0) & 0x00FF);
858
859}
860

Archive Download this file

Revision: 334