示例#1
0
/*
 * Initialize the module system by loading the Symbols.dylib module.
 * Once loaded, locate the _lookup_symbol function so that internal
 * symbols can be resolved.
 */
int init_module_system()
{
    // Start any modules that were compiled in first.
    start_built_in_modules();
    
    
	int retVal = 0;
	void (*module_start)(void) = NULL;
	char* module_data = symbols_module_start + BOOT2_ADDR;
    
	// Intialize module system
	if(symbols_module_start != (void*)0xFFFFFFFF)
	{
		// Module system  was compiled in (Symbols.dylib addr known)
		module_start = parse_mach(module_data, &load_module, &add_symbol, NULL);
		
		if(module_start && module_start != (void*)0xFFFFFFFF)
		{
			// Notify the system that it was laoded
			module_loaded(SYMBOLS_MODULE, SYMBOLS_AUTHOR, SYMBOLS_DESCRIPTION, SYMBOLS_VERSION, SYMBOLS_COMPAT);
			
			(*module_start)();	// Start the module. This will point to load_all_modules due to the way the dylib was constructed.
			execute_hook("ModulesLoaded", NULL, NULL, NULL, NULL);
			DBG("Module %s Loaded.\n", SYMBOLS_MODULE);
			retVal = 1;

		}
		else
		{
            module_data -= 0x10;    // XCODE 4 HACK
            module_start = parse_mach(module_data, &load_module, &add_symbol, NULL);
            
            if(module_start && module_start != (void*)0xFFFFFFFF)
            {
                // Notify the system that it was laoded
                module_loaded(SYMBOLS_MODULE, SYMBOLS_AUTHOR, SYMBOLS_DESCRIPTION, SYMBOLS_VERSION, SYMBOLS_COMPAT);
                
                (*module_start)();	// Start the module. This will point to load_all_modules due to the way the dylib was constructed.
                execute_hook("ModulesLoaded", NULL, NULL, NULL, NULL);
                DBG("Module %s Loaded.\n", SYMBOLS_MODULE);
                retVal = 1;
                
            }
            else
            {
                // The module does not have a valid start function
                printf("Unable to start %s\n", SYMBOLS_MODULE); getchar();
            }		
		}		
	}
	return retVal;
}
示例#2
0
/*
 * Initialize the module system by loading the Symbols.dylib module.
 * Once loaded, locate the _lookup_symbol function so that internal
 * symbols can be resolved.
 */
int init_module_system()
{
	// Start any modules that were compiled in first.
	start_built_in_modules();


	int retVal = 0;
	void (*module_start)(void) = NULL;

	extern char  symbols_start  __asm("section$start$__DATA$__Symbols");
	char* module_data = &symbols_start;

	// Intialize module system
	if(module_data)
	{
		// Module system  was compiled in (Symbols.dylib addr known)
		module_start = parse_mach(module_data, &load_module, &add_symbol, NULL);

		if(module_start && (module_start != (void*)0xFFFFFFFF))
		{
			// Notify the system that it was laoded
			module_loaded(SYMBOLS_MODULE, module_start, SYMBOLS_AUTHOR, SYMBOLS_DESCRIPTION, SYMBOLS_VERSION, SYMBOLS_COMPAT);
			(*module_start)();	// Start the module. This will point to load_all_modules due to the way the dylib was constructed.
			DBG("Module %s Loaded.\n", SYMBOLS_MODULE);
			retVal = 1;

		}
		else
		{
			// The module does not have a valid start function
			printf("Unable to start %s at 0x%x\n", SYMBOLS_MODULE, module_data);
			pause();
		}
	}

	// Look for modules located in the multiboot header.
	if(gMI && (gMI->mi_flags & MULTIBOOT_INFO_HAS_MODS))
	{
		if(gMI->mi_mods_count)
		{
			struct multiboot_module* mod = (struct multiboot_module*)gMI->mi_mods_addr;
			while(gMI->mi_mods_count--)
			{
				if(mod->mm_string)
				{
					// Convert string to module name, check for dylib.
					if(strcmp(&mod->mm_string[strlen(mod->mm_string) - sizeof("dylib")], ".dylib") == 0)
					{
						module_data = (char*)mod->mm_mod_start;

						char* last = strrchr(mod->mm_string, '/');
						if(last)
						{
							last++;
						}
						else
						{
							last = mod->mm_string;
						}

						char *name = strdup(last);
						name[strlen(last) - sizeof("dylib")] = 0;
						DBG("Loading multiboot module %s\n", name);

						module_start = parse_mach(module_data, &load_module, &add_symbol, NULL);

						if(module_start && (module_start != (void*)0xFFFFFFFF))
						{
							// Notify the system that it was laoded
							module_loaded(name, module_start, NULL, NULL, 0, 0 /*moduleName, NULL, moduleVersion, moduleCompat*/);
							(*module_start)();	// Start the module
							DBG("Module %s Loaded.\n", name); DBGPAUSE();
						}
					}
				}
			}
		}
	}

	if(retVal) execute_hook("ModulesLoaded", NULL, NULL, NULL, NULL);

	return retVal;
}