DiskImages2

From The iPhone Wiki
Revision as of 18:35, 24 November 2022 by Dabezt (talk | contribs) (Created page with "= 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 DiskI...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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

DiskImages2.h:

 1 // To compile for macOS:
 2 // clang main.m -fmodules -iframework /System/Library/PrivateFrameworks -framework DiskImages2 -I.
 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 -(id)initWithURL:(NSURL * _Nonnull)arg1 error:(NSError ** _Nonnull)arg2 SWIFT_THROWS;
18 @end
19 
20 @interface DiskImages2 : NSObject
21 // Attaches a Disk image with the given attach params
22 +(BOOL)attachWithParams:(DIAttachParams *)param handle:(DIDeviceHandle * _Nullable * _Nullable)h error:(NSError **)err SWIFT_THROWS;
23 @end
24 
25 
26 NS_ASSUME_NONNULL_END
27 
28 int main(int argc, char *argv[]) {
29     printf("objc example started\n");
30     if (argc < 2) {
31         printf("usage: %s <path-to-disk-image>\n", argv[0]);
32         return -1;
33     }
34     NSURL *dmgURL = [NSURL fileURLWithPath: @(argv[1])];
35     DIAttachParams *params = [[DIAttachParams alloc] initWithURL: dmgURL error: nil ];
36 
37     DIDeviceHandle *deviceAttached;
38     [DiskImages2 attachWithParams: params handle: &deviceAttached error: nil];
39     
40     if (deviceAttached) {
41         printf("Attached dmg, BSD Name: %s\n", [deviceAttached BSDName].UTF8String);
42     } else {
43         fprintf(stderr, "couldn't get device handle\n");
44         return -1;
45     }
46 
47     return 0;
48 }