Skip to content

Instantly share code, notes, and snippets.

View lawrencelomax's full-sized avatar

Lawrence Lomax lawrencelomax

View GitHub Profile
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/htpasswd;
@lawrencelomax
lawrencelomax / gist:b7a357d1d35a305d531d
Created June 22, 2015 14:21
Fun with Interposing
#import <Foundation/Foundation.h>
#import <objc/objc.h>
#import <objc/runtime.h>
#import <objc/message.h>
// Can use class-dump to get this from XCTest.framework
#import "XCTestConfiguration.h"
static void swizzleSetActiveTestConfiguration(void) {
Method method = class_getClassMethod(XCTestConfiguration.class, @selector(setActiveTestConfiguration:));
@lawrencelomax
lawrencelomax / DYLD_INSERT_LIBRARIES Simulator Kernel Protection.md
Last active May 10, 2018 16:36
deny-mmap for DYLD_INSERT_LIBRARIES on Simulator Process

It looks like the Simulator.app binary is now signed as of Xcode 7 as the following occurs in instruments-without-delay when using the build script:

./build.sh test <SIMULATOR-UDID>

The message that we get from the kernel is: 7/23/15 12:22:52.000 PM kernel[0]: AMFI: Simulator(pid 72600) - [deny-mmap] mapped file has no team identifier and is not a platform binary: /Users/lawrencelomax/src/instruments-without-delay/build/SimShim.dylib

This causes a crash:

@lawrencelomax
lawrencelomax / Instructions.md
Last active July 27, 2016 07:52
instruments-without-delay on Xcode 7

instruments-without-delay uses the DYLD_INSERT_LIBRARIES environment variable to shim from the instruments command line all the way down to ScriptAgentShim which is the iOS Simulator service responsible for interfacing UIAutomation JavaScript with the native UIAutomation.framework. It uses a stack of shims, starting at the instruments executable, going through Simulator.app. It is an essential part of ios-driver as it removes a pesky 200ms delay that drastically slows down the process of executing end-to-end tests. This is a fixed cost that would occur on every command.

Other than a few things being moved around and renamed in Xcode 7, there is the new issue of the codesigning of the Simulator app that triggers amfid whenever an unsigned image is loaded. This essentially means that we can't use DYLD_INSERT_LIBRARIES on the Simulator Process with SimShim

It is however, possible to inject these environment variables at the launchdaemon level. There is a plist fo

2015-09-25 10:23:18.449 xctest[80351:2903136] Port: <AVCaptureInputPort: 0x10053ce60 (AVCaptureScreenInput: 0x10053ca50) vide 0000 enabled>
2015-09-25 10:23:18.934 xctest[80351:2903717] <AVCaptureVideoDataOutput: 0x10053bcb0> Did Sample
2015-09-25 10:23:19.000 xctest[80351:2903572] <AVCaptureVideoDataOutput: 0x10053bcb0> Did Sample
2015-09-25 10:23:19.046 xctest[80351:2903572] <AVCaptureVideoDataOutput: 0x10053bcb0> Did Sample
2015-09-25 10:23:19.113 xctest[80351:2903717] <AVCaptureVideoDataOutput: 0x10053bcb0> Did Sample
2015-09-25 10:23:19.201 xctest[80351:2903717] <AVCaptureVideoDataOutput: 0x10053bcb0> Did Sample
2015-09-25 10:23:19.246 xctest[80351:2903717] <AVCaptureVideoDataOutput: 0x10053bcb0> Did Sample
2015-09-25 10:23:19.335 xctest[80351:2903572] <AVCaptureVideoDataOutput: 0x10053bcb0> Did Sample
2015-09-25 10:23:19.380 xctest[80351:2903717] <AVCaptureVideoDataOutput: 0x10053bcb0> Did Sample
2015-09-25 10:23:19.469 xctest[80351:2903572] <AVCaptureVideoDataOutput: 0x10053bcb0> Did Sample
@lawrencelomax
lawrencelomax / gist:532d23905a27f97754b7
Created October 13, 2015 09:32
Xcode7 XCTest Launch
Oct 13 08:41:44 lawrencelom-mbp syncdefaultsd[10129]: (Note ) SYDAlwaysOnAccount: no account (null)
Oct 13 08:41:44 lawrencelom-mbp CoreSimulatorBridge[9632]: Requesting launch of com.example.apple-samplecode.TableSearch with options: {
arguments = (
"-NSTreatUnknownArgumentsAsOpen",
NO,
"-ApplePersistenceIgnoreState",
YES
);
environment = {
AppTargetLocation = "/Users/lawrencelomax/Library/Developer/Xcode/DerivedData/TableSearch-avrosnidtpyztnerixabsyhzbfvt/Build/Products/Debug-iphoneos/TableSearch.app/TableSearch";
@lawrencelomax
lawrencelomax / fbsimctl.rb
Last active July 8, 2016 17:22
WIP fbsimctl brew formula
class Fbsimctl < Formula
desc "A Powerful Command Line for Managing iOS Simulators"
homepage "https://github.com/facebook/FBSimulatorControl/"
url "https://github.com/facebook/FBSimulatorControl/archive/master.zip"
sha256 ""
version "0.0.1"
depends_on "carthage"
depends_on :xcode => "7.0"
HTTP/1.1 200 OK
Content-Length: 1809
Server: Swifter 1.1.2
Content-Type: application/json
{
"status" : "success",
"events" : [
{
"event_type" : "started",
@lawrencelomax
lawrencelomax / gist:54d48d77158938258d0d7a4f8564ba89
Created July 12, 2016 07:44
homebrew recursively using install_name on nested Frameworks.
[lawrencelomax:/usr/local] master+ ± brew install --debug fbsimctl
/usr/local/Library/brew.rb (Formulary::FormulaLoader): loading /usr/local/Library/Taps/facebook/homebrew-fb/fbsimctl.rb
==> Installing fbsimctl from facebook/fb
/usr/local/Library/brew.rb (Formulary::FormulaLoader): loading /usr/local/Library/Taps/homebrew/homebrew-core/Formula/carthage.rb
/usr/local/Library/Homebrew/build.rb (Formulary::FromPathLoader): loading /usr/local/Library/Taps/facebook/homebrew-fb/fbsimctl.rb
/usr/local/Library/Homebrew/build.rb (Formulary::FormulaLoader): loading /usr/local/Library/Taps/homebrew/homebrew-core/Formula/carthage.rb
==> Downloading file:///Users/lawrencelomax/Desktop/bad.zip
######################################################################## 100.0%
Warning: Cannot verify integrity of fbsimctl-0.0.1.zip
A checksum was not provided for this resource
xcodebuild build build
2016-07-25 11:06:23.977 xctool[76237:2732422] *** Assertion failure in __LaunchXcodebuildTaskAndFeedEventsToReporters_block_invoke(), /tmp/xctool-20160725-72874-vvod9r/Common/XCToolUtil.m:380
2016-07-25 11:06:23.980 xctool[76237:2732422] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Got error while trying to deserialize event 'User defaults from command line:': The data is not in the correct
format.'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff94abf4f2 __exceptionPreprocess + 178
1 libobjc.A.dylib 0x00007fff90e51f7e objc_exception_throw + 48
2 CoreFoundation 0x00007fff94ac41ca +[NSException raise:format:arguments:] + 106
3 Foundation 0x00007fff92dca1ee -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 169