Skip to content

Instantly share code, notes, and snippets.

Avatar
🌁
Down by the Bay

Saagar Jha saagarjha

🌁
Down by the Bay
View GitHub Profile
@saagarjha
saagarjha / watchOSURLSchemes.txt
Created Jun 19, 2022
watchOS app URL schemes
View watchOSURLSchemes.txt
// Generated via
// grep -r -l CFBundleURLSchemes /Volumes/JupiterB19R570.N121bOS/ | xargs -n1 sh -c '/usr/libexec/PlistBuddy -c "Print" "$0" > /dev/null 2>&1 && echo && echo "$0" && /usr/libexec/PlistBuddy -c "Print :CFBundleURLTypes" "$0"'
// -[LSApplicationWorkspace openURL:configuration:completionHandler] is a good way to open these
/Volumes/JupiterB19R570.N121bOS/System/Library/CoreServices/Carousel.app/Info.plist
Array {
Dict {
CFBundleURLName = com.apple.carousel
CFBundleURLSchemes = Array {
@saagarjha
saagarjha / README.md
Last active Mar 12, 2022
Works around some poor performance in XCBBuildService due to slow reflection machinery (https://twitter.com/_saagarjha/status/1499599539795234816)
View README.md

To build this:

$ swiftc -emit-object XCBBuildServiceFix.swift -O
$ clang XCBBuildServiceFix.o XCBBuildServiceFix.s -shared -o libXCBBuildServiceFix.dylib -O -L /usr/lib/swift/ -lswiftCore -F /Applications/Xcode.app/Contents/SharedFrameworks/XCBuild.framework/Versions/Current/PlugIns/XCBBuildService.bundle/Contents/Frameworks/ -framework XCBUtil -framework XCBProtocol

Then inject the result into XCBBuildService, which launches from /Applications/Xcode.app/Contents/SharedFrameworks/XCBuild.framework/Versions/Current/PlugIns/XCBBuildService.bundle/Contents/MacOS/XCBBuildService, using your injection tool of choice.

@saagarjha
saagarjha / xcode_conformsToProtocol_hang_workaround.mm
Last active Jan 24, 2022
Works around a hang in Xcode when it calls -[NSObject conformsToProtocol:] a bunch (https://twitter.com/_saagarjha/status/1476739462197506048)
View xcode_conformsToProtocol_hang_workaround.mm
// https://gist.github.com/saagarjha/ed701e3369639410b5d5303612964557
#import "swizzler.h"
#import <Foundation/Foundation.h>
#import <mutex>
#import <objc/runtime.h>
#import <unordered_map>
#import <utility>
struct PairHasher {
std::size_t operator()(const std::pair<Class, Protocol *> &pair) const {
@saagarjha
saagarjha / 2022WinterSeed.txt
Created Dec 17, 2021
19D5026g/19K5527e/19S5525f
View 2022WinterSeed.txt
https://updates.cdn-apple.com/2022WinterSeed/fullrestores/002-44494/03F7854E-907A-40F8-B339-E61CF30F192D/iPhone14,5_15.3_19D5026g_Restore.ipsw
https://updates.cdn-apple.com/2022WinterSeed/fullrestores/002-44635/54B0513B-EC2D-426B-961D-8E3266957FCB/iPhone14,2_15.3_19D5026g_Restore.ipsw
https://updates.cdn-apple.com/2022WinterSeed/fullrestores/002-44518/3F901A9B-1D42-4FA2-9FF3-8A76DD0F5D1D/iPhone14,3_15.3_19D5026g_Restore.ipsw
https://updates.cdn-apple.com/2022WinterSeed/fullrestores/002-44567/8F331E94-220A-467B-B184-5F775319B55E/iPhone14,4_15.3_19D5026g_Restore.ipsw
https://updates.cdn-apple.com/2022WinterSeed/fullrestores/002-44658/EE36DA05-8A9D-4336-B200-E929040EB68D/iPhone13,2,iPhone13,3_15.3_19D5026g_Restore.ipsw
https://updates.cdn-apple.com/2022WinterSeed/fullrestores/002-44740/B3BE35AE-0259-4EFF-A0FE-9773D1FACA35/iPhone13,4_15.3_19D5026g_Restore.ipsw
https://updates.cdn-apple.com/2022WinterSeed/fullrestores/002-44924/2AF69685-63D3-4391-A10C-0089ABF9C7D6/iPhone13,1_15.3_19D5026g_Restore.ipsw
https://upda
@saagarjha
saagarjha / remote_connection_enabler.mm
Created Nov 6, 2021
Enable remote connections in Quartz Debug
View remote_connection_enabler.mm
// If you haven't already, make sure to run this so the window list works:
// defaults write com.apple.QuartzDebug QuartzDebugPrivateInterface -bool YES
// https://gist.github.com/saagarjha/ed701e3369639410b5d5303612964557
#import "swizzler.h"
#import <AppKit/AppKit.h>
static Swizzler<void, id<NSApplicationDelegate>, NSNotification *> QuartzDebug_applicationDidFinishLaunching_ {
NSClassFromString(@"QuartzDebug"), @selector(applicationDidFinishLaunching:), [](auto self, auto notification) {
QuartzDebug_applicationDidFinishLaunching_(self, notification);
@saagarjha
saagarjha / swizzler.h
Last active Aug 6, 2022
Type-safe, RAII swizzler for Objective-C++
View swizzler.h
// Example usage:
// Swizzler<NSString *, NSDateFormatter *, NSDate *> NSDateFormatter_stringFromDate_ {
// NSDateFormatter.class, @selector(stringFromDate:), [&](auto self, auto date) {
// if ([NSCalendar.currentCalendar components:NSCalendarUnitWeekday fromDate:date].weekday == 4) {
// return @"It Is Wednesday My Dudes";
// } else {
// return NSDateFormatter_stringFromDate_(self, date);
// }
// }
// };
@saagarjha
saagarjha / library_injector.cpp
Last active Sep 5, 2022
Load a library into newly spawned processes (using DYLD_INSERT_LIBRARIES and EndpointSecurity)
View library_injector.cpp
// To compile: clang++ -arch x86_64 -arch arm64 -std=c++20 library_injector.cpp -lbsm -lEndpointSecurity -o library_injector,
// then codesign with com.apple.developer.endpoint-security.client and run the
// program as root.
#include <EndpointSecurity/EndpointSecurity.h>
#include <algorithm>
#include <bsm/libbsm.h>
#include <cstdint>
#include <cstdlib>
#include <cstring>
@saagarjha
saagarjha / stop_at_entry.c
Last active Nov 6, 2021
Endpoint Security client that sends SIGSTOP to newly spawned processes
View stop_at_entry.c
// To compile: clang stop_at_entry.c -lbsm -lEndpointSecurity -o stop_at_entry,
// then codesign with com.apple.developer.endpoint-security.client and run the
// program as root.
#include <EndpointSecurity/EndpointSecurity.h>
#include <assert.h>
#include <bsm/libbsm.h>
#include <dispatch/dispatch.h>
#include <signal.h>
#include <stdbool.h>
@saagarjha
saagarjha / imessage_cleanup.py
Created Apr 26, 2021
Helps clean up large iMessage attachments by letting you search for them
View imessage_cleanup.py
#!/usr/bin/env python3
import pathlib
import sqlite3
if __name__ == "__main__":
connection = sqlite3.connect(f"{pathlib.Path.home()}/Library/Messages/chat.db")
for (name, size, chat, date) in connection.execute("""
SELECT transfer_name, total_bytes, chat_message_join.chat_id, date
FROM message_attachment_join JOIN message ON message_attachment_join.message_id = message.ROWID
@saagarjha
saagarjha / myutr.py
Created Jan 18, 2021
Add people to lists on the UTR website
View myutr.py
#!/usr/bin/env python3
import getpass
import json
import pathlib
import sys
import urllib.parse
import urllib.request