DiskImages2

From The iPhone Wiki
Jump to: navigation, search

Summary

DiskImages2 is a private system framework introduced in iOS 14, a successor to the original DiskImages framework, the main difference being that the original DiskImages framework was written in C while DiskImages2 was written in objective-c and centered around Object Oriented Programming.

Example code

The example code below shows a basic command line interface program to attach a .dmg disk image in Objective-C

 1 // To compile for macOS:
 2 // clang main.m -fmodules -iframework /System/Library/PrivateFrameworks -framework DiskImages2
 3 
 4 // To compile for iOS (download DiskImages2 tbd file first from https://headers.cynder.me):
 5 // xcrun -sdk iphoneos clang -arch arm64 -miphoneos-version-min=14.0 -Xlinker /path/to/DiskImages2.tbd
 6 @import Foundation;
 7 
 8 #define SWIFT_THROWS __attribute__((__swift_error__(nonnull_error)))
 9 
10 @interface DIDeviceHandle : NSObject
11 @property (nonnull, retain, nonatomic) NSString *BSDName;
12 @property (readonly, nonatomic) NSUInteger regEntryID;
13 @property (nonatomic) BOOL handleRefCount;
14 @end
15 
16 NS_ASSUME_NONNULL_BEGIN
17 @interface DIAttachParams : NSObject
18 -(id)initWithURL:(NSURL * _Nonnull)arg1 error:(NSError ** _Nonnull)arg2 SWIFT_THROWS;
19 @end
20 
21 @interface DiskImages2 : NSObject
22 // Attaches a Disk image with the given attach params
23 +(BOOL)attachWithParams:(DIAttachParams *)param handle:(DIDeviceHandle * _Nullable * _Nullable)h error:(NSError **)err SWIFT_THROWS;
24 @end
25 
26 
27 NS_ASSUME_NONNULL_END
28 
29 int main(int argc, char *argv[]) {
30     printf("objc example started\n");
31     if (argc < 2) {
32         printf("usage: %s <path-to-disk-image>\n", argv[0]);
33         return -1;
34     }
35     NSURL *dmgURL = [NSURL fileURLWithPath: @(argv[1])];
36     DIAttachParams *params = [[DIAttachParams alloc] initWithURL: dmgURL error: nil ];
37 
38     DIDeviceHandle *deviceAttached;
39     [DiskImages2 attachWithParams: params handle: &deviceAttached error: nil];
40     
41     if (deviceAttached) {
42         printf("Attached dmg, BSD Name: %s\n", [deviceAttached BSDName].UTF8String);
43     } else {
44         fprintf(stderr, "couldn't get device handle\n");
45         return -1;
46     }
47 
48     return 0;
49 }