Skip to content

Instantly share code, notes, and snippets.

View NightwindDev's full-sized avatar

Nightwind NightwindDev

View GitHub Profile
@leptos-null
leptos-null / swift-hook.md
Last active September 13, 2024 18:23
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

@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