Skip to content

Instantly share code, notes, and snippets.

View NightwindDev's full-sized avatar

Nightwind NightwindDev

View GitHub Profile
@leptos-null
leptos-null / UIStatusBarItemType.m
Last active March 30, 2025 06:57
Recreating the UIStatusBarItemType enum
//
// statusbartypes
//
// Created by Leptos on 3/19/19.
// Copyright © 2019 Leptos. All rights reserved.
//
#import <UIKit/UIKit.h>
typedef int UIStatusBarItemType;
@leptos-null
leptos-null / EntitlementsForImage.m
Created July 22, 2019 19:11
Get the entitlements of a given Mach-O image existing in memory
#import <Foundation/Foundation.h>
#import <mach-o/loader.h>
#if __has_include(<Kernel/kern/cs_blobs.h>)
# import <Kernel/kern/cs_blobs.h>
#else
/* some Darwin distributions don't provide the cs_blobs header
* copy it from the macOS SDK if available, otherwise one of
* https://opensource.apple.com/source/xnu/xnu-4903.221.2/osfmk/kern/cs_blobs.h.auto.html
* https://github.com/apple/darwin-xnu/blob/a449c6a3b8014d9406c2ddbdc81795da24aa7443/osfmk/kern/cs_blobs.h
@leptos-null
leptos-null / swift-hook.md
Last active July 4, 2025 03:59
Hooking Swift functions

This article aims to describe how to hook Swift functions.

Thanks to help from @NightwindDev for discussion and testing.

Overall, the idea is simple: Write our own Swift code that will have the same calling convention as the target code, then get a pointer to our own code and the target code, and call MSHookFunction with these values.

Code

@EthanArbuckle
EthanArbuckle / cli-gui.m
Last active July 8, 2025 20:08
drawing a UIWindow from an iOS cli tool
#import <CoreGraphics/CoreGraphics.h>
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
#import <objc/message.h>
#import <dlfcn.h>
__attribute__((constructor)) static void init(void) {
Method bundleIdentifierMethod = class_getInstanceMethod(objc_getClass("NSBundle"), sel_registerName("bundleIdentifier"));
IMP newImp = imp_implementationWithBlock(^(id self) {
#include <mach-o/dyld.h>
#include <mach-o/loader.h>
#include <mach-o/nlist.h>
#include <mach-o/dyld_images.h>
#include <dlfcn.h>
static void *dyld_for_each_installed_shared_cache;
static void *dyld_shared_cache_for_each_image;
static void *dyld_image_get_installname;
@EthanArbuckle
EthanArbuckle / patchfind.m
Last active March 19, 2025 15:24
find function by string xref
/*
Found string at address: 0x1048aa84d
Found reference in function: hidden_function
Found function that references string: 0x1048a89ec
*/
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import <mach-o/loader.h>
@EthanArbuckle
EthanArbuckle / image_size.m
Created January 26, 2025 02:14
get size of a loaded image
uint64_t get_image_size(struct mach_header_64 *mh) {
struct load_command *cmd = (struct load_command *)((uint8_t *)mh + sizeof(struct mach_header_64));
uint64_t max_addr = 0;
for (uint32_t i = 0; i < mh->ncmds; i++) {
if (cmd->cmd == LC_SEGMENT_64) {
struct segment_command_64 *seg = (struct segment_command_64 *)cmd;
uint64_t seg_end = seg->vmaddr + seg->vmsize;
if (seg_end > max_addr) {
max_addr = seg_end;
}
@donato-fiore
donato-fiore / Tweak.x
Last active June 13, 2025 22:36
Allow ControlCenter modules to load when running in a simulator.
#import <Foundation/Foundation.h>
@interface NSObject (Private)
- (id)safeValueForKey:(NSString *)key;
@end
@interface NSArray (BaseBoard)
- (id)bs_mapNoNulls:(id (^)(id))arg1;
- (id)bs_flatten;
- (id)bs_filter:(BOOL (^)(id))arg1;