Skip to content

Instantly share code, notes, and snippets.

View indragiek's full-sized avatar

Indragie Karunaratne indragiek

View GitHub Profile
@indragiek
indragiek / main.c
Created November 29, 2012 01:10
Simple key logger for OS X using CGEventTap
// Super simple key logger that uses a CGEventTap to log
// the unicode strings for each key down event
// Doesn't handle special keys (enter, backspace, etc.)
#include <stdio.h>
#import <Carbon/Carbon.h>
#import <ApplicationServices/ApplicationServices.h>
CGEventRef loggerCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void* context)
{
@indragiek
indragiek / ios_sim_arm64.patch
Last active April 21, 2023 03:28
Bazel 3.7.1 patch to build an arm64 slice targeting the iOS Simulator. Use it by running `bazel build ... --cpu=ios_sim_arm64 --apple_platform_type=ios`
diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/ApplePlatform.java b/src/main/java/com/google/devtools/build/lib/rules/apple/ApplePlatform.java
index 7759984b03..6f41eca83b 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/apple/ApplePlatform.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/apple/ApplePlatform.java
@@ -42,7 +42,7 @@ public enum ApplePlatform implements ApplePlatformApi {
CATALYST("catalyst", "MacOSX", PlatformType.CATALYST, true);
private static final ImmutableSet<String> IOS_SIMULATOR_TARGET_CPUS =
- ImmutableSet.of("ios_x86_64", "ios_i386");
+ ImmutableSet.of("ios_x86_64", "ios_i386", "ios_sim_arm64");
@indragiek
indragiek / gist:5297435
Last active March 5, 2023 21:55
Draft of a ReactiveCocoa based interface for CoreData
//
// FGOManagedObjectContextStack.h
//
// Created by Indragie Karunaratne on 2012-12-23.
//
#import <Foundation/Foundation.h>
typedef void (^FGOConfigurationBlock)(id);
@indragiek
indragiek / Image.swift
Created October 18, 2015 00:45
vImage_Buffer wrapper
// Copyright © 2015 Indragie Karunaratne. All rights reserved.
import Foundation
import Accelerate
public class Image {
private var buffer: vImage_Buffer
public var size: CGSize {
return vImageBuffer_GetSize(&buffer)
@indragiek
indragiek / BadgeCount.m
Created November 19, 2011 20:04
Automatically updating NSDockTile with badge count
@interface AppDelegate : NSObject
@property (nonatomic, assign) NSInteger badgeCount;
@end
@implementation AppDelegate
@synthesize badgeCount;
// Override the badgeCount setter to update the dock tile whenever the count is set
- (void)setBadgeCount:(NSInteger)count
{

iOS Shared Cache Extraction

Having fallen off the iOS-exploration train due to completing my Masters and other commitments, I have finally climbed back aboard in pursuit of understanding the telephony stack.

Like most things in iOS that are used frequently, the vast majority of the frameworks and libraries used in the telephony stack reside in the DYLD shared cache located at /System/Library/Caches/com.apple.dyld/dyld_shared_cache_armv7.

In this post I am going to explain how to go about extracting this cache file so that you can then work with each library individually.

Get The Cache

The first step in all of this is to copy the cache over to your local machine. I did this using a program called iExplorer, but you can just as easily do it over SSH. As a side note, you can connect to your iDevice using SSH over USB if you install a tool called iProxy.

@indragiek
indragiek / movies_batch_load.patch
Last active December 10, 2020 03:31
The code change to enable batch loading of all data up-front in a single HTTP request.
@@ -287,7 +287,7 @@ class MovieDetailViewController: UIViewController, UIScrollViewDelegate, MovieDe
private func fetchMovieDetails() {
let spanName = "fetch-movie-details"
Specto.startSpan(spanName)
- client.getMovieDetails(movie: movie) { result in
+ client.getMovieDetails(movie: movie, additionalData: [.credits, .videos]) { result in
switch result {
case let .success(details):
self.details = details
@indragiek
indragiek / dsc_extractor.patch
Created November 2, 2020 21:29 — forked from lightbulbone/dsc_extractor.patch
Patch for Apple's dsc_extractor in the dyld package.
--- dyld-210.2.3/launch-cache/dsc_extractor.cpp 2012-05-21 02:35:15.000000000 -0400
+++ dyld-210.2.3/launch-cache/dsc_extractor.cpp 2013-07-26 16:05:03.000000000 -0400
@@ -37,6 +37,7 @@
#include <mach-o/arch.h>
#include <mach-o/loader.h>
#include <Availability.h>
+#include <dlfcn.h>
#define NO_ULEB
#include "Architectures.hpp"
# Use Google Cloud Platform stackdriver with python structlog
from google.cloud.logging import Client
from google.cloud.logging import _helpers
from google.cloud.logging.handlers import CloudLoggingHandler
from google.cloud.logging.handlers.transports.background_thread import _Worker
# pip install python-json-logger
from pythonjsonlogger import jsonlogger
@indragiek
indragiek / CStringArray.swift
Last active November 14, 2019 02:03
Helper for working with char ** in Swift
// Copyright © 2015 Indragie Karunaratne. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in