Skip to content

Instantly share code, notes, and snippets.

@pookjw
Created July 24, 2025 12:27
Show Gist options
  • Select an option

  • Save pookjw/ab173d85df15273220686e5782f79f43 to your computer and use it in GitHub Desktop.

Select an option

Save pookjw/ab173d85df15273220686e5782f79f43 to your computer and use it in GitHub Desktop.
#import <Foundation/Foundation.h>
#include <dlfcn.h>
#include <objc/message.h>
#include <objc/message.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
{
void *handle = dlopen("/System/Library/PrivateFrameworks/DiskImages2.framework/DiskImages2", RTLD_NOW);
assert(handle != NULL);
}
NSURL *url = [NSURL fileURLWithPath:@"/Volumes/Data 1/SD/Xcode/Xcode_4.6.3.dmg"];
NSError * _Nullable error = nil;
id _Nullable attachParams = ((id (*)(id, SEL, id, id *))objc_msgSend)([objc_lookUpClass("DIAttachParams") alloc], sel_registerName("initWithURL:error:"), url, &error);
assert(error == nil);
id handle;
BOOL result = ((BOOL (*)(Class, SEL, id, id *, id *))objc_msgSend)(objc_lookUpClass("DiskImages2"), sel_registerName("attachWithParams:handle:error:"), attachParams, &handle, &error);
[attachParams release];
assert(result);
result = ((BOOL (*)(id, SEL, id *))objc_msgSend)(handle, sel_registerName("waitForDeviceWithError:"), &error);
assert(result);
sleep(2);
id arb = ((id (*)(Class, SEL, id *))objc_msgSend)(objc_lookUpClass("DIDiskArb"), sel_registerName("diskArbWithError:"), &error);
assert(error == nil);
NSString *BSDName = ((id (*)(id, SEL))objc_msgSend)(handle, sel_registerName("BSDName"));
NSDictionary<NSString *, NSString *> *allMountPoints = ((id (*)(Class, SEL))objc_msgSend)(objc_lookUpClass("DIAttachedDeviceInfo"), sel_registerName("copyAllMountPoints"));
[allMountPoints enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, NSString * _Nonnull obj, BOOL * _Nonnull stop) {
if ([key hasPrefix:BSDName]) {
NSError * _Nullable error = nil;
BOOL result = ((BOOL (*)(id, SEL, id, id *))objc_msgSend)(arb, sel_registerName("unmountWithMountPoint:error:"), obj, &error);
assert(result);
}
}];
[allMountPoints release];
}
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment