Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Dev:DiskImages2.framework

From The Apple Wiki
DiskImages2.framework
Private Framework
Availabile14.0 – present
Class PrefixDI

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

// To compile for macOS:
// clang main.m -fmodules -iframework /System/Library/PrivateFrameworks -framework DiskImages2

// To compile for iOS (download DiskImages2 tbd file first from https://headers.cynder.me):
// xcrun -sdk iphoneos clang -arch arm64 -miphoneos-version-min=14.0 -Xlinker /path/to/DiskImages2.tbd
@import Foundation;

#define SWIFT_THROWS __attribute__((__swift_error__(nonnull_error)))

@interface DIDeviceHandle : NSObject
@property (nonnull, retain, nonatomic) NSString *BSDName;
@property (readonly, nonatomic) NSUInteger regEntryID;
@property (nonatomic) BOOL handleRefCount;
@end

NS_ASSUME_NONNULL_BEGIN
@interface DIAttachParams : NSObject
-(id)initWithURL:(NSURL * _Nonnull)arg1 error:(NSError ** _Nonnull)arg2 SWIFT_THROWS;
@end

@interface DiskImages2 : NSObject
// Attaches a Disk image with the given attach params
+(BOOL)attachWithParams:(DIAttachParams *)param handle:(DIDeviceHandle * _Nullable * _Nullable)h error:(NSError **)err SWIFT_THROWS;
@end


NS_ASSUME_NONNULL_END

int main(int argc, char *argv[]) {
    printf("objc example started\n");
    if (argc < 2) {
        printf("usage: %s <path-to-disk-image>\n", argv[0]);
        return -1;
    }
    NSURL *dmgURL = [NSURL fileURLWithPath: @(argv[1])];
    DIAttachParams *params = [[DIAttachParams alloc] initWithURL: dmgURL error: nil ];

    DIDeviceHandle *deviceAttached;
    [DiskImages2 attachWithParams: params handle: &deviceAttached error: nil];
    
    if (deviceAttached) {
        printf("Attached dmg, BSD Name: %s\n", [deviceAttached BSDName].UTF8String);
    } else {
        fprintf(stderr, "couldn't get device handle\n");
        return -1;
    }

    return 0;
}