PRIVATE void _objc_load_module(struct objc_loader_module *module, void *kernel_module) { if (!objc_runtime_initialized){ objc_runtime_init(); } /* First, check the version. */ objc_assert(module->version == objc_abi_version_kernel_1, "Unknown version of module version (%i)\n", module->version); objc_debug_log("Loading a module named %s\n", module->name); struct objc_symbol_table *table = module->symbol_table; objc_debug_log("Symbol table: %p\n", table); objc_debug_log("\tSelector ref count: %i\n", table->selector_reference_count); objc_debug_log("\tSelector refs: %p\n", table->selector_references); objc_debug_log("\tClass count: %i\n", table->class_count); objc_debug_log("\tClasses: %p\n", table->classes); objc_debug_log("\tCategory count: %i\n", table->category_count); objc_debug_log("\tCategories: %p\n", table->categories); objc_debug_log("\tProtocol count: %i\n", table->protocol_count); objc_debug_log("\tProtocols: %p\n", table->protocols); /* Register selectors. */ objc_register_selector_array(table->selector_references, table->selector_reference_count); for (int i = 0; i < table->class_count; ++i){ /* Mark the class as owned by the kernel module. */ table->classes[i]->kernel_module = kernel_module; objc_debug_log("Should be registering class[%i; %p] %s\n", i, table->classes[i], table->classes[i]->name); Class super_class = table->classes[i]->super_class; objc_debug_log("\tSuperclass[%p]: %s\n", super_class, super_class == NULL ? "" : super_class->name); } objc_class_register_classes(table->classes, table->class_count); for (int i = 0; i < table->category_count; ++i){ objc_debug_log("Should be registering category[%i; %p] %s for class %s\n", i, table->categories[i], table->categories[i]->category_name, table->categories[i]->class_name); objc_category_try_load(table->categories[i]); } for (int i = 0; i < table->protocol_count; ++i){ objc_debug_log("Registering protocol %s\n", table->protocols[i]->name); objc_registerProtocol(table->protocols[i]); } }
Protocol* RegisterProtocol(const protocol_t* prot, intptr_t slide) { Protocol *existingProtocol = objc_getProtocol(prot->name); // Return existing protocols if (existingProtocol) { LOG << "Found existing ObjC Protocol: " << prot->name << std::endl; return existingProtocol; } LOG << "Processing ObjC Protocol: " << prot->name << std::endl; Protocol* conv = objc_allocateProtocol(prot->name); size_t methodIndex = 0; if (prot->protocols) { for (size_t i = 0; i < prot->protocols->count; i++) { const char* name = prot->protocols->elem(i, slide)->name; protocol_addProtocol(conv, objc_getProtocol(name)); } } if (prot->methods) RegisterProtocolMethods(conv, prot->methods, prot->extMethTypes, methodIndex, true, true); if (prot->staticMethods) RegisterProtocolMethods(conv, prot->staticMethods, prot->extMethTypes, methodIndex, true, false); if (prot->optMethods) RegisterProtocolMethods(conv, prot->optMethods, prot->extMethTypes, methodIndex, false, true); if (prot->optStaticMethods) RegisterProtocolMethods(conv, prot->optStaticMethods, prot->extMethTypes, methodIndex, false, false); if (prot->properties) ConvertProperties(prot->properties, [conv](const char* name, const objc_property_attribute_t* attr, unsigned int count) { protocol_addProperty(conv, name, attr, count, true, true); }); objc_registerProtocol(conv); return conv; }