Ejemplo n.º 1
0
std::vector<const char*> ProcessClassesOld(const struct mach_header* mh, intptr_t slide, module_info* info)
{
	unsigned long cstrLen;
	void* ptr;
	std::vector<old_class*> vecClasses;
	std::set<old_class*> setClasses;
	std::map<const char*,old_class*> mapClassNames;
	std::vector<const char*> vecClassNames;

	// ptr = getsectdata(mh, "__TEXT", "__cstring", &cstrLen);
	// if (ptr)
	// 	g_cstringSection = std::pair<uintptr_t,uintptr_t>(uintptr_t(ptr), cstrLen);
	// else
	// 	g_cstringSection = std::pair<uintptr_t,uintptr_t>(0, 0);
	
	for (uint16_t i = 0; i < info->symtab->countClasses; i++)
	{
		old_class* cls = static_cast<old_class*>(info->symtab->classesAndCategories[i]);
		mapClassNames[cls->name] = cls;
		setClasses.insert(cls);
	}

	topology_sort(setClasses, vecClasses,
		[&mapClassNames](old_class* t) -> std::set<old_class*> { auto it = mapClassNames.find(t->super_class.name); return (it != mapClassNames.end()) ? std::set<old_class*>{it->second} : std::set<old_class*>(); }
	);
			
	for (old_class* c : vecClasses)
		RegisterClass(c, info->version >= 6);

	// Change class names in 'super_class' from strings to pointers to Class
	// for (size_t i = 0; i < size / sizeof(old_class); i++)
	for (uint16_t i = 0; i < info->symtab->countClasses; i++)
	{
		old_class* cls = static_cast<old_class*>(info->symtab->classesAndCategories[i]);
		Class c = (Class) objc_getClass(cls->super_class.name);
		LOG << "ObjC fixup super_class @" << &cls->super_class << ": " << cls->super_class.name << " -> " << c << std::endl;
		cls->super_class.clsNew = c;
	}

	// Fix the same in metaclasses
	// for (size_t i = 0; i < size / sizeof(old_class); i++)
	for (uint16_t i = 0; i < info->symtab->countClasses; i++)
	{
		old_class* cls = static_cast<old_class*>(info->symtab->classesAndCategories[i])->isa.cls;
		Class c = (Class) objc_getMetaClass(cls->super_class.name);
		LOG << "ObjC fixup super_class @" << cls << ": " << cls->name << " -> " << c << std::endl;
		cls->super_class.clsNew = c;
	}

	//std::transform(mapClassNames.begin(), mapClassNames.end(), vecClassNames.begin(), [](const std::pair<const char*,old_class*>& p) { return p.first; });
	for (auto it = mapClassNames.begin(); it != mapClassNames.end(); it++)
		vecClassNames.push_back(it->first);

	return vecClassNames;
}
Ejemplo n.º 2
0
int main()
{
	int n;
	std::scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
	{
		int u;
		std::scanf("%d %d", weight + i, &u);
		f[i][0] = 0;
		f[i][1] = weight[i];
		++deg[u], fa[i] = u;
	}

	long long ans = 0;
	topology_sort(n);
	for(int i = 1; i <= n; ++i)
		if(deg[i]) ans += solve_circle(i);
	std::printf("%lld", ans);
	return 0;
}