Skip to content

Instantly share code, notes, and snippets.

dmaclach dmaclach

Block or report user

Report or block dmaclach

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
dmaclach / MisalignedRead.m
Last active Sep 20, 2019
Compile this with Xcode 11 "release" and it will crash on ARMv7 due to misaligned read. Use a "single view" iOS App as your template, and replace AppDelegate.m with this code.
View MisalignedRead.m
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
__attribute__((noinline)) double GPBCodedInputStreamReadDouble(uint8_t *buf) {
int64_t value = OSReadLittleInt64(buf, 0);
double result;
memcpy(&result, &value, sizeof(result));
return result;
View Instrument.xml
<?xml version="1.0" encoding="UTF-8" ?>
<name>Dave MacLachlan</name>
View dyld details.txt
total time: 635.49 milliseconds (100.0%)
total images loaded: 457 (451 from dyld shared cache)
total segments mapped: 15, into 3756 pages with 408 pages pre-fetched
total images loading time: 376.31 milliseconds (59.2%)
total load time in ObjC: 64.57 milliseconds (10.1%)
total debugger pause time: 0.00 milliseconds (0.0%)
total dtrace DOF registration time: 0.11 milliseconds (0.0%)
total rebase fixups: 1,164,368
total rebase fixups time: 76.51 milliseconds (12.0%)
total binding fixups: 83,028
View AppLaunchTime.c
#include <sys/sysctl.h>
struct timeval AppLaunchTimeRelativeTo1970(void) {
id_t pid = getpid();
int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, (int)pid };
const size_t mibSize = sizeof(mib) / sizeof(mib[0]);
size_t infoSize = 0;
// Get initial size of KERN_PROC data structure.
if (sysctl(mib, mibSize, NULL, &infoSize, NULL, 0) != 0) {
dmaclach / property_encoding.csv
Last active Dec 10, 2018
Objective C property encodings
View property_encoding.csv
code meaning
R read-only
C by-copy
& by-reference
D dynamic
G getter (followed by selector name)
S setter (followed by selector name)
V instance variable (followed by variable name)
T type encoding (followed by old-style type encoding)
W weak
View objc_metadata_hider.h
* Wraps C++ classes so that they can be passed around in Objective C++ programs without
* generating a lot of useless Objective C runtime metadata.
* Example use:
* class Foo {
* public:
* ....
* };
* \@interface Bar
* \@property objc_metadata_hider_ptr<Foo> foo;
dmaclach /
Last active Nov 29, 2018
ObjectiveC wrapping C++
#import <Foundation/Foundation.h>
#include <map>
#include <string>
struct CppType {
std::map<std::string, std::string> myMap;
@interface ObjCType : NSObject {
CppType map;
dmaclach / main.m
Last active Nov 29, 2018
Create an Objective C Class at runtime
View main.m
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
Class myClass = objc_allocateClassPair([NSObject class], "MyClass", 0);
IMP methodIMP = imp_implementationWithBlock(^(id self) {
return @"Hello";
if (!class_addMethod(myClass, @selector(description), methodIMP, "@@:")) {
View main.m
// main.m
// signaltest
// Created by Dave MacLachlan on 11/12/18.
// Copyright © 2018 Dave MacLachlan. All rights reserved.
#import <Foundation/Foundation.h>
#import <pthread.h>
You can’t perform that action at this time.