Difference between revisions of "DiskImages2"

From The iPhone Wiki
Jump to: navigation, search
(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...")
 
(fix code)
 
(One intermediate revision by the same user not shown)
Line 4: Line 4:
 
= Example code =
 
= Example code =
 
The example code below shows a basic command line interface program to attach a .dmg disk image in Objective-C
 
The example code below shows a basic command line interface program to attach a .dmg disk image in Objective-C
 
DiskImages2.h:
 
   
 
<syntaxhighlight lang="objc" line>
 
<syntaxhighlight lang="objc" line>
 
// To compile for macOS:
 
// To compile for macOS:
// clang main.m -fmodules -iframework /System/Library/PrivateFrameworks -framework DiskImages2 -I.
+
// clang main.m -fmodules -iframework /System/Library/PrivateFrameworks -framework DiskImages2
   
 
// To compile for iOS (download DiskImages2 tbd file first from https://headers.cynder.me):
 
// To compile for iOS (download DiskImages2 tbd file first from https://headers.cynder.me):
Line 24: Line 22:
   
 
NS_ASSUME_NONNULL_BEGIN
 
NS_ASSUME_NONNULL_BEGIN
  +
@interface DIAttachParams : NSObject
 
-(id)initWithURL:(NSURL * _Nonnull)arg1 error:(NSError ** _Nonnull)arg2 SWIFT_THROWS;
 
-(id)initWithURL:(NSURL * _Nonnull)arg1 error:(NSError ** _Nonnull)arg2 SWIFT_THROWS;
 
@end
 
@end

Latest revision as of 18:38, 24 November 2022

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 }