void addArch( KcgenArgs * toolArgs, const NXArchInfo * arch) { if (CFArrayContainsValue(toolArgs->targetArchs, RANGE_ALL(toolArgs->targetArchs), arch)) { return; } CFArrayAppendValue(toolArgs->targetArchs, arch); }
void filterKextID(const void * vValue, void * vContext) { CFStringRef kextID = (CFStringRef)vValue; FilterIDContext * context = (FilterIDContext *)vContext; OSKextRef theKext = OSKextGetKextWithIdentifier(kextID); if (!theKext) { char kextIDCString[KMOD_MAX_NAME]; CFStringGetCString(kextID, kextIDCString, sizeof(kextIDCString), kCFStringEncodingUTF8); if (context->optional) { OSKextLog(/* kext */ NULL, kOSKextLogErrorLevel | kOSKextLogGeneralFlag, "Can't find kext with optional identifier %s; skipping.", kextIDCString); } else { OSKextLog(/* kext */ NULL, kOSKextLogErrorLevel | kOSKextLogGeneralFlag, "Error - can't find kext with identifier %s.", kextIDCString); context->error = TRUE; } goto finish; } if (checkKextForProblems(context->toolArgs, theKext, context->arch)) { if (!context->optional) { OSKextLog(/* kext */ NULL, kOSKextLogErrorLevel | kOSKextLogGeneralFlag, "Error - a required kext was omitted"); context->error = true; } goto finish; } if (!CFArrayContainsValue(context->kextArray, RANGE_ALL(context->kextArray), theKext)) { CFArrayAppendValue(context->kextArray, theKext); } finish: return; }
void printKextInfo(CFDictionaryRef kextInfo, KextstatArgs * toolArgs) { CFBooleanRef isKernelComponent = NULL; // do not release CFNumberRef loadTag = NULL; // do not release CFNumberRef retainCount = NULL; // do not release CFNumberRef loadAddress = NULL; // do not release CFNumberRef loadSize = NULL; // do not release CFNumberRef wiredSize = NULL; // do not release CFStringRef bundleID = NULL; // do not release CFStringRef bundleVersion = NULL; // do not release CFArrayRef dependencyLoadTags = NULL; // do not release CFMutableArrayRef sortedLoadTags = NULL; // must release uint32_t loadTagValue = kOSKextInvalidLoadTag; uint32_t retainCountValue = (uint32_t)-1; uint64_t loadAddressValue = (uint64_t)-1; uint32_t loadSizeValue = (uint32_t)-1; uint32_t wiredSizeValue = (uint32_t)-1; uint32_t cpuTypeValue = (uint32_t)-1; uint32_t cpuSubTypeValue = (uint32_t)-1; char * bundleIDCString = NULL; // must free char * bundleVersionCString = NULL; // must free CFIndex count, i; loadTag = (CFNumberRef)CFDictionaryGetValue(kextInfo, CFSTR(kOSBundleLoadTagKey)); retainCount = (CFNumberRef)CFDictionaryGetValue(kextInfo, CFSTR(kOSBundleRetainCountKey)); loadAddress = (CFNumberRef)CFDictionaryGetValue(kextInfo, CFSTR(kOSBundleLoadAddressKey)); loadSize = (CFNumberRef)CFDictionaryGetValue(kextInfo, CFSTR(kOSBundleLoadSizeKey)); wiredSize = (CFNumberRef)CFDictionaryGetValue(kextInfo, CFSTR(kOSBundleWiredSizeKey)); bundleID = (CFStringRef)CFDictionaryGetValue(kextInfo, kCFBundleIdentifierKey); bundleVersion = (CFStringRef)CFDictionaryGetValue(kextInfo, kCFBundleVersionKey); dependencyLoadTags = (CFArrayRef)CFDictionaryGetValue(kextInfo, CFSTR(kOSBundleDependenciesKey)); /* If the -k flag was given, skip any kernel components unless * they are explicitly requested. */ if (toolArgs->flagNoKernelComponents) { isKernelComponent = (CFBooleanRef)CFDictionaryGetValue(kextInfo, CFSTR(kOSKernelResourceKey)); if (isKernelComponent && CFBooleanGetValue(isKernelComponent)) { if (bundleID && kCFNotFound == CFArrayGetFirstIndexOfValue(toolArgs->bundleIDs, RANGE_ALL(toolArgs->bundleIDs), bundleID)) { goto finish; } } } if (!getNumValue(loadTag, kCFNumberSInt32Type, &loadTagValue)) { loadTagValue = kOSKextInvalidLoadTag; } /* Never print the info for the kernel (loadTag 0, id __kernel__). */ if (loadTagValue == 0) { goto finish; } if (!getNumValue(retainCount, kCFNumberSInt32Type, &retainCountValue)) { retainCountValue = (uint32_t)-1; } if (!getNumValue(loadAddress, kCFNumberSInt64Type, &loadAddressValue)) { loadAddressValue = (uint64_t)-1; } if (!getNumValue(loadSize, kCFNumberSInt32Type, &loadSizeValue)) { loadSizeValue = (uint32_t)-1; } if (!getNumValue(wiredSize, kCFNumberSInt32Type, &wiredSizeValue)) { wiredSizeValue = (uint32_t)-1; } if (!getNumValue(((CFNumberRef)CFDictionaryGetValue(kextInfo, CFSTR(kOSBundleCPUTypeKey))), kCFNumberSInt32Type, &cpuTypeValue)) { cpuTypeValue = (uint32_t)-1; } if (!getNumValue(((CFNumberRef)CFDictionaryGetValue(kextInfo, CFSTR(kOSBundleCPUSubtypeKey))), kCFNumberSInt32Type, &cpuSubTypeValue)) { cpuSubTypeValue = (uint32_t)-1; } bundleIDCString = createUTF8CStringForCFString(bundleID); bundleVersionCString = createUTF8CStringForCFString(bundleVersion); /* First column has no leading space. * * These field widths are from the old kextstat, may want to change them. */ if (loadTagValue == kOSKextInvalidLoadTag) { fprintf(stdout, "%5s", kStringInvalidShort); } else { fprintf(stdout, "%5d", loadTagValue); } if (retainCountValue == (uint32_t)-1) { fprintf(stdout, " %4s", kStringInvalidShort); } else { fprintf(stdout, " %4d", retainCountValue); } if (toolArgs->runningKernelArch->cputype & CPU_ARCH_ABI64) { if (loadAddressValue == (uint64_t)-1) { fprintf(stdout, " %-18s", kStringInvalidLong); } else { fprintf(stdout, " %#-18llx", (uint64_t)loadAddressValue); } } else { if (loadAddressValue == (uint64_t)-1) { fprintf(stdout, " %-10s", kStringInvalidLong); } else { fprintf(stdout, " %#-10x", (uint32_t)loadAddressValue); } } if (loadSizeValue == (uint32_t)-1) { fprintf(stdout, " %-10s", kStringInvalidLong); } else { fprintf(stdout, " %#-10x", loadSizeValue); } if (wiredSizeValue == (uint32_t)-1) { fprintf(stdout, " %-10s", kStringInvalidLong); } else { fprintf(stdout, " %#-10x", wiredSizeValue); } if (toolArgs->flagShowArchitecture) { // include kext cputype/cpusubtype info if (cpuTypeValue == (uint32_t) -1) { fprintf(stdout, " %10s/%-7s", kStringInvalidLong, kStringInvalidLong); } else { const NXArchInfo * archName = NXGetArchInfoFromCpuType(cpuTypeValue, cpuSubTypeValue); if (archName != NULL) { fprintf(stdout, " %-18s", archName->name); } else { fprintf(stdout, " %#010x/%#-7x", cpuTypeValue, cpuSubTypeValue); } } } fprintf(stdout, " %s", bundleIDCString ? bundleIDCString : kStringInvalidLong); fprintf(stdout, " (%s)", bundleVersionCString ? bundleVersionCString : kStringInvalidLong); if (dependencyLoadTags && CFArrayGetCount(dependencyLoadTags)) { sortedLoadTags = CFArrayCreateMutableCopy(kCFAllocatorDefault, 0, dependencyLoadTags); if (!sortedLoadTags) { OSKextLogMemError(); goto finish; } CFArraySortValues(sortedLoadTags, RANGE_ALL(sortedLoadTags), &compareNumbers, /* context */ NULL); fprintf(stdout, " <"); count = CFArrayGetCount(sortedLoadTags); for (i = 0; i < count; i++) { loadTag = (CFNumberRef)CFArrayGetValueAtIndex(sortedLoadTags, i); if (!getNumValue(loadTag, kCFNumberSInt32Type, &loadTagValue)) { loadTagValue = kOSKextInvalidLoadTag; } if (loadTagValue == kOSKextInvalidLoadTag) { fprintf(stdout, "%s%s", i == 0 ? "" : " ", kStringInvalidShort); } else { fprintf(stdout, "%s%d", i == 0 ? "" : " ", loadTagValue); } } fprintf(stdout, ">"); } fprintf(stdout, "\n"); finish: SAFE_RELEASE(sortedLoadTags); SAFE_FREE(bundleIDCString); SAFE_FREE(bundleVersionCString); return; }