// compile with // clang main.c -framework Cocoa #include #include #include #include #include #include extern id NSApp; int RunApplication(void) { // Create app event loop ((id (*)(Class, SEL)) objc_msgSend)(objc_getClass("NSApplication"), sel_registerName("sharedApplication")); if (NSApp == NULL) { fprintf(stderr, "Failed to create NSApplication! Terminating...\n"); return 2; } // yay private APIs // change process name to "Minecraft 2" CFBundleRef launchServicesBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.LaunchServices")); CFTypeRef asn = ((CFTypeRef (*)()) CFBundleGetFunctionPointerForName(launchServicesBundle, CFSTR("_LSGetCurrentApplicationASN")))(); CFStringRef *displayNameKey = CFBundleGetDataPointerForName(launchServicesBundle, CFSTR("_kLSDisplayNameKey")); OSStatus setNameResult = ((OSStatus (*)(int, CFTypeRef, CFStringRef, CFStringRef, void*)) CFBundleGetFunctionPointerForName(launchServicesBundle, CFSTR("_LSSetApplicationInformationItem")))( -2, // yay magic values asn, *displayNameKey, CFSTR("Minecraft 2"), NULL); printf("setNameResult: %d\n", setNameResult); // 0 = noErr, https://www.osstatus.com for others // Initialize & close dummy window id window = class_createInstance(objc_getClass("NSWindow"), 0); window = ((id (*)(id, SEL, struct CGRect, int, int, BOOL)) objc_msgSend)(window, sel_registerName("initWithContentRect:styleMask:backing:defer:"), (struct CGRect) {0, 0, 0, 0}, 0, 2, false); ((id (*)(id, SEL)) objc_msgSend)(window, sel_registerName("close")); // Start app event loop (to keep the program running) ((id (*)(id, SEL)) objc_msgSend)(NSApp, sel_registerName("run")); return 0; } int main(int argc, char *argv[]) { id pool = class_createInstance(objc_getClass("NSAutoreleasePool"), 0); pool = ((id (*)(id, SEL)) objc_msgSend)(pool, sel_registerName("init")); if (pool == NULL) { fprintf(stderr, "Failed to create NSAutoreleasePool! Terminating...\n"); return 1; } int code = RunApplication(); ((id (*)(id, SEL)) objc_msgSend)(pool, sel_registerName("drain")); return code; }