Esempio n. 1
0
void ProcessImageLoad(const struct mach_header* mh, intptr_t slide)
{
	unsigned long size;
	std::vector<const char*> classNames;
	void* dataPtr = nullptr;

#ifdef OBJC_ABI_2
	const class_t** classes;
	ProcessProtocolsNew(mh, slide);

	classes = reinterpret_cast<const class_t**>(
		getsectdata(mh, SEG_OBJC_CLASSLIST_NEW, SECT_OBJC_CLASSLIST_NEW, &size)
	);
	if (classes)
	{
		classNames = ProcessClassesNew(mh, slide, classes, size);
		dataPtr = (void*)*classes;
	}

	ProcessCategoriesNew(mh, slide);
#else
	module_info* modinfo;
	ProcessProtocolsOld(mh, slide);

	modinfo = reinterpret_cast<module_info*>(
		getsectdata(mh, SEG_OBJC_MODINFO_OLD, SECT_OBJC_MODINFO_OLD, &size)
	);

	if (modinfo && modinfo->symtab)
	{
		classNames = ProcessClassesOld(mh, slide, modinfo);
		dataPtr = modinfo;
		ProcessCategoriesOld(mh, slide, modinfo);
	}
#endif

	UpdateClassRefs(mh);
	UpdateSelectors(mh, slide);

	// Do this only for dynamic libs (slide > 0)
	if (!classNames.empty() && slide > 0)
	{
		// Generate a NSFramework_XXXX class for GNUstep's NSBundle
		const char* path = dyld_image_path_containing_address(dataPtr);
		assert(path != nullptr);
		RegisterFramework(&classNames[0], classNames.size(), path);
	}

	static SEL selInit = sel_getUid("load");
	while (!g_pendingInitClasses.empty())
	{
		auto pair = g_pendingInitClasses.front();
		g_pendingInitClasses.pop();
		pair.second(reinterpret_cast<objc_object*>(pair.first), selInit);
	}
}
Esempio n. 2
0
void ProcessImageLoad(const struct mach_header* mh, intptr_t slide)
{
	unsigned long size;

#ifdef OBJC_ABI_2
	const class_t** classes;
	ProcessProtocolsNew(mh, slide);

	classes = reinterpret_cast<const class_t**>(
		getsectdata(mh, SEG_OBJC_CLASSLIST_NEW, SECT_OBJC_CLASSLIST_NEW, &size)
	);
	if (classes)
		ProcessClassesNew(mh, slide, classes, size);

	ProcessCategoriesNew(mh, slide);
#else
	module_info* modinfo;
	ProcessProtocolsOld(mh, slide);

	modinfo = reinterpret_cast<module_info*>(
		getsectdata(mh, SEG_OBJC_MODINFO_OLD, SECT_OBJC_MODINFO_OLD, &size)
	);

	if (modinfo && modinfo->symtab)
	{
		ProcessClassesOld(mh, slide, modinfo);
		ProcessCategoriesOld(mh, slide, modinfo);
	}
#endif

	UpdateClassRefs(mh);
	UpdateSelectors(mh, slide);

	static SEL selInit = sel_getUid("load");
	while (!g_pendingInitClasses.empty())
	{
		auto pair = g_pendingInitClasses.front();
		g_pendingInitClasses.pop();
		pair.second(reinterpret_cast<objc_object*>(pair.first), selInit);
	}
}