Skip to content

Commit 6605882

Browse files
committed
debugging code, and remove fork (with work-arounds)
1 parent 53c59e1 commit 6605882

File tree

1 file changed

+173
-70
lines changed

1 file changed

+173
-70
lines changed

Sources/classdumpctl/main.m

Lines changed: 173 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -611,74 +611,190 @@ int main(int argc, char *argv[]) {
611611

612612
NSFileManager *const fileManager = NSFileManager.defaultManager;
613613

614-
if ([fileManager fileExistsAtPath:outputDir]) {
615-
fprintf(stderr, "%s already exists\n", outputDir.fileSystemRepresentation);
616-
return 1;
617-
}
614+
// if ([fileManager fileExistsAtPath:outputDir]) {
615+
// fprintf(stderr, "%s already exists\n", outputDir.fileSystemRepresentation);
616+
// return 1;
617+
// }
618618

619-
NSMutableDictionary<NSNumber *, NSString *> *const pidToPath = [NSMutableDictionary dictionaryWithCapacity:maxJobs];
620-
621-
NSUInteger activeJobs = 0;
622-
NSUInteger badExitCount = 0;
623-
NSUInteger finishedImageCount = 0;
619+
NSSet *const skipPaths = [NSSet setWithArray:@[
620+
@"/usr/lib/dyld",
621+
/*
622+
Superclass of CalUISuggestionsWindow at <addr> in /System/Library/PrivateFrameworks/CalendarUI.framework/Versions/A/CalendarUI is set to 0xbad4007, indicating it is missing from an installed root
623+
*/
624+
@"/System/Library/PrivateFrameworks/CalendarUI.framework/Versions/A/CalendarUI",
625+
@"/System/Library/PrivateFrameworks/Safari.framework/Versions/A/Safari", // seems to load `CalendarUI`
626+
@"/System/Library/PrivateFrameworks/SearchUI.framework/Versions/A/SearchUI", // seems to load `CalendarUI`
627+
@"/System/Library/PrivateFrameworks/RemindersUICore.framework/Versions/A/RemindersUICore", // seems to load `CalendarUI`
628+
@"/System/Library/PrivateFrameworks/SocialUI.framework/Versions/A/SocialUI", // seems to load `CalendarUI`
629+
@"/System/Library/PrivateFrameworks/CalendarIntegrationSupport.framework/Versions/A/CalendarIntegrationSupport", // seems to load `CalendarUI`
630+
@"/System/Library/PrivateFrameworks/CalendarLink.framework/Versions/A/CalendarLink", // seems to load `CalendarUI`
631+
@"/System/Library/PrivateFrameworks/CalendarUIKitInternal.framework/Versions/A/CalendarUIKitInternal", // seems to load `CalendarUI`
632+
@"/System/Library/PrivateFrameworks/RemindersIntentsFramework.framework/Versions/A/RemindersIntentsFramework", // seems to load `CalendarUI`
633+
@"/System/Library/PrivateFrameworks/SiriNotebookUI.framework/Versions/A/SiriNotebookUI", // seems to load `CalendarUI`
634+
/*
635+
Superclass of MUIAppleIntelligenceOnboardingViewController at <addr> in /System/Library/PrivateFrameworks/MailUI.framework/Versions/A/MailUI is set to 0xbad4007, indicating it is missing from an installed root
636+
*/
637+
@"/System/Library/PrivateFrameworks/MailUI.framework/Versions/A/MailUI",
638+
/*
639+
Superclass of ILMediaBrowserMovieView at <addr> in /System/Library/PrivateFrameworks/iLifeMediaBrowser.framework/Versions/A/iLifeMediaBrowser is set to 0xbad4007, indicating it is missing from an installed root
640+
*/
641+
@"/System/Library/Frameworks/ScreenSaver.framework/Versions/A/ScreenSaver",
642+
/*
643+
Superclass of SiriUIBuddyGMEnrollmentSplashView at <addr> in /System/Library/PrivateFrameworks/SiriUI.framework/Versions/A/SiriUI is set to 0xbad4007, indicating it is missing from an installed root
644+
*/
645+
@"/System/Library/PrivateFrameworks/SiriUI.framework/Versions/A/SiriUI",
646+
/*
647+
Superclass of ILMediaBrowserMovieView at <addr> in /System/Library/PrivateFrameworks/iLifeMediaBrowser.framework/Versions/A/iLifeMediaBrowser is set to 0xbad4007, indicating it is missing from an installed root
648+
*/
649+
@"/System/Library/PrivateFrameworks/iLifeMediaBrowser.framework/Versions/A/iLifeMediaBrowser",
650+
/*
651+
Superclass of ASBackgroundAssetConsentViewController at <addr> in /System/Library/PrivateFrameworks/AppStoreUI.framework/Versions/A/AppStoreUI is set to 0xbad4007, indicating it is missing from an installed root
652+
*/
653+
@"/System/Library/PrivateFrameworks/AppStoreKit.framework/Versions/A/AppStoreKit",
654+
/* Assertion failed: (platformBinary), function +[WFActionKitStaticInitializer load], file ActionKit.m, line 49. */
655+
@"/System/Library/PrivateFrameworks/ActionKit.framework/Versions/A/ActionKit",
656+
/* Assertion failed: (platformBinary), function +[WFActionKitStaticInitializer load], file ActionKit.m, line 49. */
657+
@"/System/Library/PrivateFrameworks/ActionKitUI.framework/Versions/A/ActionKitUI",
658+
/*
659+
Superclass of CalUISuggestionsWindow at <addr> in /System/Library/PrivateFrameworks/CalendarUI.framework/Versions/A/CalendarUI is set to 0xbad4007, indicating it is missing from an installed root
660+
*/
661+
@"/System/Library/PrivateFrameworks/AppPredictionUI.framework/Versions/A/AppPredictionUI",
662+
/*
663+
Superclass of ASBackgroundAssetConsentViewController at <addr> in /System/Library/PrivateFrameworks/AppStoreUI.framework/Versions/A/AppStoreUI is set to 0xbad4007, indicating it is missing from an installed root
664+
*/
665+
@"/System/Library/PrivateFrameworks/AppStoreUI.framework/Versions/A/AppStoreUI",
666+
/*
667+
Superclass of BKUIFingerprintEnrollBuddyClientAdapterView at <addr> in /System/Library/PrivateFrameworks/BiometricKitUI.framework/Versions/A/BiometricKitUI is set to 0xbad4007, indicating it is missing from an installed root
668+
*/
669+
@"/System/Library/PrivateFrameworks/BiometricKitUI.framework/Versions/A/BiometricKitUI",
670+
/*
671+
Superclass of ASBackgroundAssetConsentViewController at <addr> in /System/Library/PrivateFrameworks/AppStoreUI.framework/Versions/A/AppStoreUI is set to 0xbad4007, indicating it is missing from an installed root
672+
*/
673+
@"/System/Library/PrivateFrameworks/GameStoreKit.framework/Versions/A/GameStoreKit",
674+
/*
675+
Superclass of SearchUIPersonHeaderViewController at <addr> in /System/Library/PrivateFrameworks/SearchUI.framework/Versions/A/SearchUI is set to 0xbad4007, indicating it is missing from an installed root
676+
*/
677+
@"/System/Library/PrivateFrameworks/IntelligenceFlowAppIntentsPreviewToolSupport.framework/Versions/A/IntelligenceFlowAppIntentsPreviewToolSupport",
678+
/*
679+
Superclass of SearchUIPersonHeaderViewController at <addr> in /System/Library/PrivateFrameworks/SearchUI.framework/Versions/A/SearchUI is set to 0xbad4007, indicating it is missing from an installed root
680+
*/
681+
@"/System/Library/PrivateFrameworks/IntelligenceFlowContextRuntime.framework/Versions/A/IntelligenceFlowContextRuntime",
682+
/*
683+
Superclass of SearchUIPersonHeaderViewController at <addr> in /System/Library/PrivateFrameworks/SearchUI.framework/Versions/A/SearchUI is set to 0xbad4007, indicating it is missing from an installed root
684+
*/
685+
@"/System/Library/PrivateFrameworks/IntelligenceFlowFeedbackDataCollector.framework/Versions/A/IntelligenceFlowFeedbackDataCollector",
686+
/*
687+
Superclass of SearchUIPersonHeaderViewController at <addr> in /System/Library/PrivateFrameworks/SearchUI.framework/Versions/A/SearchUI is set to 0xbad4007, indicating it is missing from an installed root
688+
*/
689+
@"/System/Library/PrivateFrameworks/IntelligenceFlowPlannerRuntime.framework/Versions/A/IntelligenceFlowPlannerRuntime",
690+
/*
691+
Superclass of SearchUIPersonHeaderViewController at <addr> in /System/Library/PrivateFrameworks/SearchUI.framework/Versions/A/SearchUI is set to 0xbad4007, indicating it is missing from an installed root
692+
*/
693+
@"/System/Library/PrivateFrameworks/IntelligenceFlowPlannerSupport.framework/Versions/A/IntelligenceFlowPlannerSupport",
694+
/*
695+
Superclass of SearchUIPersonHeaderViewController at <addr> in /System/Library/PrivateFrameworks/SearchUI.framework/Versions/A/SearchUI is set to 0xbad4007, indicating it is missing from an installed root
696+
*/
697+
@"/System/Library/PrivateFrameworks/IntelligenceFlowRuntime.framework/Versions/A/IntelligenceFlowRuntime",
698+
/*
699+
Superclass of CalUISuggestionsWindow at <addr> in /System/Library/PrivateFrameworks/CalendarUI.framework/Versions/A/CalendarUI is set to 0xbad4007, indicating it is missing from an installed root
700+
*/
701+
@"/System/Library/PrivateFrameworks/OmniSearch.framework/Versions/A/OmniSearch",
702+
/*
703+
Superclass of CalUISuggestionsWindow at <addr> in /System/Library/PrivateFrameworks/CalendarUI.framework/Versions/A/CalendarUI is set to 0xbad4007, indicating it is missing from an installed root
704+
*/
705+
@"/System/Library/PrivateFrameworks/OmniSearchClient.framework/Versions/A/OmniSearchClient",
706+
/*
707+
Superclass of CalUISuggestionsWindow at <addr> in /System/Library/PrivateFrameworks/CalendarUI.framework/Versions/A/CalendarUI is set to 0xbad4007, indicating it is missing from an installed root
708+
*/
709+
@"/System/Library/PrivateFrameworks/OnDeviceEvalRuntime.framework/Versions/A/OnDeviceEvalRuntime",
710+
/*
711+
Superclass of PMCredentialRequestPaneHeader at <addr> in /System/Library/PrivateFrameworks/PasswordManagerUI.framework/Versions/A/PasswordManagerUI is set to 0xbad4007, indicating it is missing from an installed root
712+
*/
713+
@"/System/Library/PrivateFrameworks/PasswordManagerUI.framework/Versions/A/PasswordManagerUI",
714+
/*
715+
Superclass of CalUISuggestionsWindow at <addr> in /System/Library/PrivateFrameworks/CalendarUI.framework/Versions/A/CalendarUI is set to 0xbad4007, indicating it is missing from an installed root
716+
*/
717+
@"/System/Library/PrivateFrameworks/PersonalSearchService.framework/Versions/A/PersonalSearchService",
718+
/*
719+
Superclass of CalUISuggestionsWindow at <addr> in /System/Library/PrivateFrameworks/CalendarUI.framework/Versions/A/CalendarUI is set to 0xbad4007, indicating it is missing from an installed root
720+
*/
721+
@"/System/Library/PrivateFrameworks/RemindersAppIntents.framework/Versions/A/RemindersAppIntents",
722+
/*
723+
Superclass of SearchUIPersonHeaderViewController at <addr> in /System/Library/PrivateFrameworks/SearchUI.framework/Versions/A/SearchUI is set to 0xbad4007, indicating it is missing from an installed root
724+
*/
725+
@"/System/Library/PrivateFrameworks/Safari.framework/Versions/A/PlugIns/Safari.wkbundle/Contents/MacOS/Safari",
726+
/*
727+
Superclass of SearchUIPersonHeaderViewController at <addr> in /System/Library/PrivateFrameworks/SearchUI.framework/Versions/A/SearchUI is set to 0xbad4007, indicating it is missing from an installed root
728+
*/
729+
@"/System/Library/PrivateFrameworks/SearchUICardKitProviderSupport.framework/Versions/A/SearchUICardKitProviderSupport",
730+
/*
731+
Class of category SetupAssistantSupportUI at <addr> in ?? is set to 0xbad4007, indicating it is missing from an installed root
732+
*/
733+
@"/System/Library/PrivateFrameworks/SetupAssistantSupportUI.framework/Versions/A/SetupAssistantSupportUI",
734+
/*
735+
Superclass of SearchUIPersonHeaderViewController at 0x1f90e54a0 in /System/Library/PrivateFrameworks/SearchUI.framework/Versions/A/SearchUI is set to 0xbad4007, indicating it is missing from an installed root
736+
*/
737+
@"/System/Library/PrivateFrameworks/SiriAppLaunchUIFramework.framework/Versions/A/SiriAppLaunchUIFramework",
738+
/*
739+
Superclass of CalUISuggestionsWindow at 0x1f8282378 in /System/Library/PrivateFrameworks/CalendarUI.framework/Versions/A/CalendarUI is set to 0xbad4007, indicating it is missing from an installed root
740+
*/
741+
@"/System/Library/PrivateFrameworks/SiriNotebook.framework/Versions/A/SiriNotebook",
742+
/*
743+
Superclass of SiriUIBuddyGMEnrollmentSplashView at 0x1f930d790 in /System/Library/PrivateFrameworks/SiriUI.framework/Versions/A/SiriUI is set to 0xbad4007, indicating it is missing from an installed root
744+
*/
745+
@"/System/Library/PrivateFrameworks/SiriSetup.framework/Versions/A/SiriSetup",
746+
/*
747+
Superclass of SearchUIPersonHeaderViewController at 0x1f90e54a0 in /System/Library/PrivateFrameworks/SearchUI.framework/Versions/A/SearchUI is set to 0xbad4007, indicating it is missing from an installed root
748+
*/
749+
@"/System/Library/PrivateFrameworks/SpotlightUIShared.framework/Versions/A/SpotlightUIShared",
750+
/*
751+
Superclass of VUIAVPlayerView at 0x2a39c5980 in /System/Library/PrivateFrameworks/VideosUI.framework/Versions/A/VideosUI is set to 0xbad4007, indicating it is missing from an installed root
752+
*/
753+
@"/System/Library/PrivateFrameworks/VideosUI.framework/Versions/A/VideosUI",
754+
/*
755+
Superclass of Welcome.CustomizedAVPlayerView at 0x2a3a2a580 in /System/Library/PrivateFrameworks/Welcome.framework/Versions/A/Welcome is set to 0xbad4007, indicating it is missing from an installed root
756+
*/
757+
@"/System/Library/PrivateFrameworks/Welcome.framework/Versions/A/Welcome",
758+
/* Assertion failed: (platformBinary), function +[WFActionKitStaticInitializer load], file ActionKit.m, line 49. */
759+
@"/System/Library/PrivateFrameworks/WorkflowUI.framework/Versions/A/WorkflowUI",
760+
/* Invalid dylib load. Clients should not load the unversioned libcrypto dylib as it does not have a stable ABI. */
761+
@"/usr/lib/libcrypto.dylib",
762+
/* Invalid dylib load. Clients should not load the unversioned libssl dylib as it does not have a stable ABI. */
763+
@"/usr/lib/libssl.dylib",
764+
/* Assertion failed: (platformBinary), function +[WFActionKitStaticInitializer load], file ActionKit.m, line 49. */
765+
@"/System/iOSSupport/System/Library/PrivateFrameworks/ActionKit.framework/Versions/A/ActionKit",
766+
/* Assertion failed: (platformBinary), function +[WFActionKitStaticInitializer load], file ActionKit.m, line 49. */
767+
@"/System/iOSSupport/System/Library/PrivateFrameworks/ActionKitUI.framework/Versions/A/ActionKitUI",
768+
/* Assertion failed: (platformBinary), function +[WFActionKitStaticInitializer load], file ActionKit.m, line 49. */
769+
@"/System/iOSSupport/System/Library/PrivateFrameworks/WorkflowUI.framework/Versions/A/WorkflowUI",
770+
/* Exception thrown while decoding class BSAuditToken for key "_bsAuditToken": +[BSAuditToken supportsSecureCoding]: unrecognized selector sent to class 0x1f8034058 */
771+
@"/System/Library/PrivateFrameworks/PreviewsInjection.framework/Versions/A/PreviewsInjection",
772+
@"/System/iOSSupport/System/Library/PrivateFrameworks/PreviewsInjection.framework/Versions/A/PreviewsInjection",
773+
774+
/* -[__NSSetM removeObject:]: object cannot be nil */
775+
// @"/System/Library/PrivateFrameworks/AOSUI.framework/Versions/A/AOSUI", // TODO: investigate (in `_forwardDeclarableClassReferences`)
776+
777+
// not sure
778+
@"/System/Library/PrivateFrameworks/UnifiedMessagingKit.framework/Versions/A/UnifiedMessagingKit",
779+
]];
624780

625781
NSUInteger const imagePathCount = imagePaths.count;
626-
for (NSUInteger imageIndex = 0; (imageIndex < imagePathCount) || (activeJobs > 0); imageIndex++) {
627-
BOOL const hasImagePath = (imageIndex < imagePathCount);
628-
629-
if (!hasImagePath || (activeJobs >= maxJobs)) {
630-
int childStatus = 0;
631-
pid_t const childPid = wait(&childStatus);
632-
activeJobs--;
633-
634-
if (childPid < 0) {
635-
perror("wait");
636-
return 1;
637-
}
638-
NSNumber *key = @(childPid);
639-
NSString *path = pidToPath[key];
640-
[pidToPath removeObjectForKey:key];
641-
finishedImageCount++;
642-
643-
if (WIFEXITED(childStatus)) {
644-
int const exitStatus = WEXITSTATUS(childStatus);
645-
if (exitStatus != 0) {
646-
printf("Child for '%s' exited with status %d\n", path.fileSystemRepresentation, exitStatus);
647-
badExitCount++;
648-
}
649-
} else if (WIFSIGNALED(childStatus)) {
650-
printf("Child for '%s' signaled with signal %d\n", path.fileSystemRepresentation, WTERMSIG(childStatus));
651-
badExitCount++;
652-
} else {
653-
printf("Child for '%s' did not finish cleanly\n", path.fileSystemRepresentation);
654-
badExitCount++;
655-
}
656-
printf(" %lu/%lu\r", finishedImageCount, imagePathCount);
657-
fflush(stdout); // important to flush after using '\r', but also critical to flush (if needed) before calling `fork`
658-
}
659-
if (hasImagePath) {
782+
for (NSUInteger imageIndex = 0; imageIndex < imagePathCount; imageIndex++) {
660783
NSString *imagePath = imagePaths[imageIndex];
661-
662-
pid_t const forkStatus = fork();
663-
if (forkStatus < 0) {
664-
perror("fork");
665-
return 1;
666-
}
667-
if (forkStatus == 0) {
668-
// child
784+
785+
if ([skipPaths containsObject:imagePath]) {
786+
NSLog(@"Skipping (%lu) %@", imageIndex, imagePath);
787+
continue;
788+
}
789+
NSLog(@"Processing (%lu) %@", imageIndex, imagePath);
790+
669791
NSString *topDir = [outputDir stringByAppendingPathComponent:imagePath];
670792

671793
NSError *error = nil;
672794
if (![fileManager createDirectoryAtPath:topDir withIntermediateDirectories:YES attributes:nil error:&error]) {
673795
NSLog(@"createDirectoryAtPathError: %@", error);
674796
return 1;
675797
}
676-
NSString *logPath = [topDir stringByAppendingPathComponent:@"log.txt"];
677-
678-
int const logHandle = open(logPath.fileSystemRepresentation, O_WRONLY | O_CREAT | O_EXCL, 0644);
679-
assert(logHandle >= 0);
680-
dup2(logHandle, STDOUT_FILENO);
681-
dup2(logHandle, STDERR_FILENO);
682798

683799
dlerror(); // clear
684800
void *imageHandle = dlopen(imagePath.fileSystemRepresentation, RTLD_NOW);
@@ -737,20 +853,7 @@ int main(int argc, char *argv[]) {
737853

738854
free(classNames);
739855
dlclose(imageHandle);
740-
741-
close(logHandle);
742-
unlink(logPath.fileSystemRepresentation);
743-
744-
return 0; // exit child process
745-
}
746-
747-
pidToPath[@(forkStatus)] = imagePath;
748-
activeJobs++;
749-
}
750856
}
751-
752-
printf("%lu images in dyld_shared_cache\n", (unsigned long)imagePaths.count);
753-
printf("Failed to load %lu images\n", (unsigned long)badExitCount);
754857
}
755858
return 0;
756859
}

0 commit comments

Comments
 (0)