Skip to content

Instantly share code, notes, and snippets.

@sunflsks
Last active February 7, 2022 16:35
Show Gist options
  • Save sunflsks/e48ab7fb1ac5d58e445eeeda29f84dd3 to your computer and use it in GitHub Desktop.
Save sunflsks/e48ab7fb1ac5d58e445eeeda29f84dd3 to your computer and use it in GitHub Desktop.
Program for reading bundle info on iOS
// Copyright (C) 2021 sunflsks
// This file is available under the MPL license, which can be found here at the time of writing (03/06/2021):
// https://www.mozilla.org/media/MPL/2.0/index.815ca599c9df.txt
#import <Foundation/Foundation.h>
#import <sys/types.h>
#include <sys/ioctl.h>
#define BUNDLE_PATH @"/var/containers/Bundle/Application"
#define DOC_BUNDLE_PATH @"/var/mobile/Containers/Data/Application"
void args(char* name) {
printf("Usage: %s {docs|bundles} [UUID for more info]\n", name);
}
typedef enum {
BundleDir,
DocsDir,
} locs;
void print_all_bundles(void);
void print_all_document_bundles(void);
int print_doc_bundle(char* bundle);
int print_bundle(char* bundle);
int main(int argc, char** argv) {
if (argc < 2) {
args(argv[0]);
return 1;
}
if (argc == 2) {
if (!strcmp(argv[1], "bundles")) {
print_all_bundles();
}
else if (!strcmp(argv[1], "docs")) {
print_all_document_bundles();
}
else {
args(argv[0]);
return 69;
}
}
else if (argc == 3) {
if (!strcmp(argv[1], "docs")) {
return print_doc_bundle(argv[2]);
}
else if (!strcmp(argv[1], "bundles")) {
return print_bundle(argv[2]);
}
}
}
void print_all_document_bundles(void) {
NSArray* bundles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:DOC_BUNDLE_PATH error:nil];
NSMutableDictionary* dictToPrint = [[NSMutableDictionary alloc] init];
for (NSString* path in bundles) {
NSString* plistPath = [NSString stringWithFormat:@"%@/%@/.com.apple.mobile_container_manager.metadata.plist", DOC_BUNDLE_PATH, path];
if ([[NSFileManager defaultManager] fileExistsAtPath:plistPath]) {
NSDictionary* dict = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
[dictToPrint setObject:path forKey:dict[@"MCMMetadataIdentifier"]];
}
}
for (NSString* key in [[dictToPrint allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]) {
printf("\033[94m%s \033[0m-> \033[32m%s\n", [dictToPrint[key] UTF8String], [key UTF8String]);
}
}
int print_doc_bundle(char* bundle) {
NSString* uuid_str = [NSString stringWithFormat:@"%s", bundle];
NSString* plist = [NSString stringWithFormat:@"%@/%@/.com.apple.mobile_container_manager.metadata.plist", DOC_BUNDLE_PATH, uuid_str];
if (![[NSFileManager defaultManager] fileExistsAtPath:plist]) {
printf("Could not find file %s\n", [plist UTF8String]);
return 2;
}
NSDictionary* dict = [[NSDictionary alloc] initWithContentsOfFile:plist];
if (dict == nil) return 3;
for (NSString* key in dict)
printf("%s -> %s\n", [key UTF8String], [[dict[key] description] UTF8String]);
return 0;
}
int print_bundle(char* bundle) {
NSString* uuid_str = [NSString stringWithFormat:@"%s", bundle];
NSString* plist = [NSString stringWithFormat:@"%@/%@/iTunesMetadata.plist", BUNDLE_PATH, uuid_str];
if (![[NSFileManager defaultManager] fileExistsAtPath:plist]) {
printf("Could not find file %s\n", [plist UTF8String]);
return 2;
}
NSDictionary* dict = [[NSDictionary alloc] initWithContentsOfFile:plist];
if (dict == nil) return 3;
for (NSString* key in dict)
printf("%s -> %s\n", [key UTF8String], [[dict[key] description] UTF8String]);
return 0;
}
void print_all_bundles(void) {
NSArray* bundles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:BUNDLE_PATH error:nil];
NSMutableDictionary* dictToPrint = [[NSMutableDictionary alloc] init];
for (NSString* path in bundles) {
NSString* plistPath = [NSString stringWithFormat:@"%@/%@/iTunesMetadata.plist", BUNDLE_PATH, path];
if ([[NSFileManager defaultManager] fileExistsAtPath:plistPath]) {
NSDictionary* dict = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
[dictToPrint setObject:path forKey:dict[@"itemName"]];
}
}
for (NSString* key in [[dictToPrint allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]) {
printf("\033[94m%s \033[0m-> \033[32m%s\n", [dictToPrint[key] UTF8String], [key UTF8String]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment