Skip to content

Instantly share code, notes, and snippets.

import notify
import Combine
enum Notify {}
extension Notify {
struct Status: Error {
let rawValue: UInt32
init(_ rawValue: UInt32) {
self.rawValue = rawValue
class FileMon {
static let queue = DispatchQueue(label: "FileMon")
let path: String
let file: Int32
let source: DispatchSourceFileSystemObject
deinit {
source.cancel()
}
@storoj
storoj / main.m
Last active April 30, 2023 00:05
MacOS Media Key Press Emulation
@import CoreGraphics;
static const CGEventField kCGEventSubtype = 0x53;
static const CGEventField kCGEventData1 = 0x95;
static const CGEventField kCGEventData2 = 0x96;
static CGEventRef CGEventCreateMediaKeyEvent(CGEventSourceRef _Nullable source, int64_t key, BOOL down) {
CGEventFlags flags = (down ? NX_KEYDOWN : NX_KEYUP) << 8;
CGEventRef e = CGEventCreate(source);
@storoj
storoj / core_emoji.swift
Last active December 3, 2020 04:13
Reverse Engineering of CoreEmoji.framework
import Foundation
guard let bundle = Bundle(identifier: "com.apple.CoreEmoji"), bundle.load() else {
fatalError()
}
let handle = dlopen(nil, RTLD_NOW)
typealias CEMCreateEmojiLocaleData_t = @convention(c) (CFLocaleIdentifier) -> CFTypeRef
let CEMCreateEmojiLocaleData = unsafeBitCast(dlsym(handle, "CEMCreateEmojiLocaleData"),
@storoj
storoj / Hachik.h
Created December 1, 2020 12:55
ObjC Hachik
#import <objc/runtime.h>
#import <objc/message.h>
template <typename RET, typename ...Types>
class ObjcMethodHook {
typedef RET(*_IMP)(id _self, SEL _cmd, Types...);
typedef RET(^_IMPBlock)(id _self, Types...);
private:
Class m_cls;
@storoj
storoj / Localizable.m
Last active August 13, 2020 14:22
Make UIKit localizable via Localizable.strings
#import <objc/runtime.h>
/**
To localize `UIBarButtonSystemItemDone` use "Done" key in your localizable.strings:
"Done" = "Localized_Done";
*/
__attribute__((constructor))
static void Hack_NSBundle_localizedString () {
@storoj
storoj / uitableview_responds_to_selector_cache.m
Last active December 28, 2019 17:24
A demonstration of how UITableView caches the results of `[self.dataSource respondsToSelector:]` and `self.delegate respondsToSelector:]`
@import UIKit;
@import ObjectiveC.runtime;
@interface MyDataSource: NSObject <UITableViewDataSource>
@end
@implementation MyDataSource
/**
Do not implement `numberOfSectionsInTableView:` to add it dynamically in runtime
import Foundation
let nc = NotificationCenter()
extension Notification.Name {
public static let ObservableDidChange = NSNotification.Name("ObservableDidChange")
}
let ObservableNewValueUserInfoKey = "new"
let ObservableOldValueUserInfoKey = "old"