Skip to content

Instantly share code, notes, and snippets.

@karajanyp
karajanyp / gist:285525aecfb71e83802d4bf1d6a33562
Created December 1, 2018 11:37 — forked from nabla-c0d3/gist:f952c6fcc1e9d359dbfe
Hooking a variadic function with Cydia Substrate
//
// LibC.m
//
// Created by Alban Diquet on 5/14/14.
// Copyright (c) 2014 Alban Diquet. All rights reserved.
//
#import <CydiaSubstrate.h>
#import "LibC.h"
@karajanyp
karajanyp / ios-custom-url-protocol
Created November 18, 2018 05:23 — forked from dtrauger/ios-custom-url-protocol
Custom URL Protocol to Globally Modify User Agent for URL Requests
@interface CustomBrowserURLProtocol : NSURLProtocol
@end
@interface CustomBrowserURLProtocol ()
@property (nonatomic, strong) NSURLConnection *connection;
@end
@implementation CustomBrowserURLProtocol
@karajanyp
karajanyp / gist:a5f6ed365800f7591ac529d285c06a86
Created September 3, 2018 08:38 — forked from snikch/gist:3661188
Find the current top view controller for your iOS application
- (UIViewController *)topViewController{
return [self topViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
}
- (UIViewController *)topViewController:(UIViewController *)rootViewController
{
if (rootViewController.presentedViewController == nil) {
return rootViewController;
}
@karajanyp
karajanyp / imp.m
Created April 11, 2018 08:39 — forked from markd2/imp.m
Jump through an IMP
#import <Foundation/Foundation.h>
// Call a method through a cached IMP pointer.
// clang -g -Wall -framework Foundation -o imp imp.m
id (*uppercase)(id, SEL, ...);
int main (void) {
@autoreleasepool {
@karajanyp
karajanyp / marsupial.m
Created April 11, 2018 08:26 — forked from markd2/marsupial.m
Support file for "Inside the Bracket, part 4" . This shows fake implementation of a method.
#import <Foundation/Foundation.h>
// clang -g -fobjc-arc -Wall -framework Foundation -o marsupial marsupial.m
@interface NSObject (AllThingsCanDance)
- (void) wombatDance: (int) repetitions;
@end
@karajanyp
karajanyp / blockforward.m
Created April 10, 2018 11:30 — forked from mikeash/blockforward.m
NSInvocation works for blocks too!
#import <dlfcn.h>
#import <Foundation/Foundation.h>
struct BlockDescriptor
{
unsigned long reserved;
unsigned long size;
void *rest[1];
@karajanyp
karajanyp / book.m
Last active April 10, 2018 05:47 — forked from mdippery/book.m
An example of using @dynamic properties in Objective-C
#import <Foundation/Foundation.h>
@interface Book : NSObject
{
NSMutableDictionary *data;
}
@property (retain) NSString *title;
@property (retain) NSString *author;
@end
@karajanyp
karajanyp / DevelopmentEnviromentDetector.m
Created February 26, 2018 03:31 — forked from steipete/DevelopmentEnviromentDetector.m
Detect if you're currently running a development version or an App Store/Ad Hoc version.
static BOOL PSPDFIsDevelopmentBuild(void) {
#if TARGET_IPHONE_SIMULATOR
return YES;
#else
static BOOL isDevelopment = NO;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// There is no provisioning profile in AppStore Apps.
NSData *data = [NSData dataWithContentsOfFile:[NSBundle.mainBundle pathForResource:@"embedded" ofType:@"mobileprovision"]];
if (data) {
@karajanyp
karajanyp / checking-ios-version.txt
Last active May 22, 2018 09:03 — forked from brownsoo/checking-ios-version.txt
Checking iOS version in above 8.0
NSString *getBuildVersion(NSString *textToBeSearch)
{
//the pattern to search for
//the \. escapes the . in regex. but the \ needs to be escaped in objective c
//thus \\.
NSString *pattern = @"Build (.*)\\)";
//capture any errors when creating the NSRegularExpression Object
NSError *error = nil;