Skip to content

Commit 9e387e1

Browse files
authored
Hook individual objects (#15)
1 parent 2000000 commit 9e387e1

35 files changed

+2430
-410
lines changed

.github/workflows/swiftlint_analyze.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ on:
88
- 'InterposeKit.xcodeproj/**'
99
- 'Sources/**/*.[ch]'
1010
- 'Sources/**/*.swift'
11-
- 'Tests/**/*.swift'
11+
- '!Tests/**/*.swift'
1212
- '!Tests/LinuxMain.swift'
1313
pull_request:
1414
paths:
1515
- '.github/workflows/swiftlint_analyze.yml'
1616
- 'InterposeKit.xcodeproj/**'
1717
- 'Sources/**/*.[ch]'
1818
- 'Sources/**/*.swift'
19-
- 'Tests/**/*.swift'
19+
- '!Tests/**/*.swift'
2020
- '!Tests/LinuxMain.swift'
2121

2222
jobs:

.swiftlint.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ included:
22
- Sources
33
- Tests
44
analyzer_rules:
5-
- unused_import
6-
- unused_declaration
75
line_length: 120
86
identifier_name:
97
excluded:

Example/InterposeExample.xcodeproj/project.pbxproj

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,14 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
781095BF248D8AD7008A943C /* InterposeExampleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 781095BD248D8AD7008A943C /* InterposeExampleTests.swift */; };
1011
7880B124248280B300AD2251 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7880B123248280B300AD2251 /* AppDelegate.swift */; };
1112
7880B126248280B300AD2251 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7880B125248280B300AD2251 /* SceneDelegate.swift */; };
1213
7880B128248280B300AD2251 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7880B127248280B300AD2251 /* ViewController.swift */; };
1314
7880B12B248280B300AD2251 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7880B129248280B300AD2251 /* Main.storyboard */; };
1415
7880B12D248280B500AD2251 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7880B12C248280B500AD2251 /* Assets.xcassets */; };
1516
7880B130248280B500AD2251 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7880B12E248280B500AD2251 /* LaunchScreen.storyboard */; };
1617
78C39DDC2483363300B46395 /* InterposeKit in Frameworks */ = {isa = PBXBuildFile; productRef = 78C39DDB2483363300B46395 /* InterposeKit */; };
17-
78C39DE22483366B00B46395 /* Defaults-Release.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 78C39DDE2483366B00B46395 /* Defaults-Release.xcconfig */; };
18-
78C39DE32483366B00B46395 /* Defaults-Testing.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 78C39DDF2483366B00B46395 /* Defaults-Testing.xcconfig */; };
19-
78C39DE42483366B00B46395 /* Defaults.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 78C39DE02483366B00B46395 /* Defaults.xcconfig */; };
20-
78C39DE52483366B00B46395 /* Defaults-Debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 78C39DE12483366B00B46395 /* Defaults-Debug.xcconfig */; };
2118
/* End PBXBuildFile section */
2219

2320
/* Begin PBXContainerItemProxy section */
@@ -31,6 +28,8 @@
3128
/* End PBXContainerItemProxy section */
3229

3330
/* Begin PBXFileReference section */
31+
781095BD248D8AD7008A943C /* InterposeExampleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InterposeExampleTests.swift; sourceTree = "<group>"; };
32+
781095BE248D8AD7008A943C /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3433
7880B120248280B300AD2251 /* InterposeExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = InterposeExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
3534
7880B123248280B300AD2251 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
3635
7880B125248280B300AD2251 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
@@ -67,11 +66,21 @@
6766
/* End PBXFrameworksBuildPhase section */
6867

6968
/* Begin PBXGroup section */
69+
781095BC248D8AD7008A943C /* InterposeExampleTests */ = {
70+
isa = PBXGroup;
71+
children = (
72+
781095BD248D8AD7008A943C /* InterposeExampleTests.swift */,
73+
781095BE248D8AD7008A943C /* Info.plist */,
74+
);
75+
path = InterposeExampleTests;
76+
sourceTree = "<group>";
77+
};
7078
7880B117248280B300AD2251 = {
7179
isa = PBXGroup;
7280
children = (
7381
78C39DD8248335B100B46395 /* Interpose */,
7482
7880B122248280B300AD2251 /* InterposeExample */,
83+
781095BC248D8AD7008A943C /* InterposeExampleTests */,
7584
7880B121248280B300AD2251 /* Products */,
7685
7880B14E248281D000AD2251 /* Frameworks */,
7786
);
@@ -170,7 +179,7 @@
170179
isa = PBXProject;
171180
attributes = {
172181
LastSwiftUpdateCheck = 1150;
173-
LastUpgradeCheck = 1150;
182+
LastUpgradeCheck = 1160;
174183
ORGANIZATIONNAME = "PSPDFKit GmbH";
175184
TargetAttributes = {
176185
7880B11F248280B300AD2251 = {
@@ -210,10 +219,6 @@
210219
files = (
211220
7880B130248280B500AD2251 /* LaunchScreen.storyboard in Resources */,
212221
7880B12D248280B500AD2251 /* Assets.xcassets in Resources */,
213-
78C39DE22483366B00B46395 /* Defaults-Release.xcconfig in Resources */,
214-
78C39DE52483366B00B46395 /* Defaults-Debug.xcconfig in Resources */,
215-
78C39DE32483366B00B46395 /* Defaults-Testing.xcconfig in Resources */,
216-
78C39DE42483366B00B46395 /* Defaults.xcconfig in Resources */,
217222
7880B12B248280B300AD2251 /* Main.storyboard in Resources */,
218223
);
219224
runOnlyForDeploymentPostprocessing = 0;
@@ -242,6 +247,7 @@
242247
isa = PBXSourcesBuildPhase;
243248
buildActionMask = 2147483647;
244249
files = (
250+
781095BF248D8AD7008A943C /* InterposeExampleTests.swift in Sources */,
245251
);
246252
runOnlyForDeploymentPostprocessing = 0;
247253
};
@@ -404,6 +410,7 @@
404410
buildSettings = {
405411
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
406412
CODE_SIGN_ENTITLEMENTS = InterposeExample/InterposeExample.entitlements;
413+
CODE_SIGN_IDENTITY = "Apple Development";
407414
CODE_SIGN_STYLE = Automatic;
408415
DEVELOPMENT_TEAM = Y5PE65HELJ;
409416
INFOPLIST_FILE = InterposeExample/Info.plist;
@@ -423,6 +430,7 @@
423430
buildSettings = {
424431
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
425432
CODE_SIGN_ENTITLEMENTS = InterposeExample/InterposeExample.entitlements;
433+
CODE_SIGN_IDENTITY = "Apple Development";
426434
CODE_SIGN_STYLE = Automatic;
427435
DEVELOPMENT_TEAM = Y5PE65HELJ;
428436
INFOPLIST_FILE = InterposeExample/Info.plist;
@@ -442,6 +450,7 @@
442450
buildSettings = {
443451
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
444452
BUNDLE_LOADER = "$(TEST_HOST)";
453+
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
445454
CODE_SIGN_STYLE = Automatic;
446455
DEVELOPMENT_TEAM = Y5PE65HELJ;
447456
INFOPLIST_FILE = InterposeExampleTests/Info.plist;
@@ -464,6 +473,7 @@
464473
buildSettings = {
465474
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
466475
BUNDLE_LOADER = "$(TEST_HOST)";
476+
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
467477
CODE_SIGN_STYLE = Automatic;
468478
DEVELOPMENT_TEAM = Y5PE65HELJ;
469479
INFOPLIST_FILE = InterposeExampleTests/Info.plist;

Example/InterposeExample.xcodeproj/xcshareddata/xcschemes/InterposeExample.xcscheme

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1150"
3+
LastUpgradeVersion = "1160"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -39,6 +39,16 @@
3939
ReferencedContainer = "container:..">
4040
</BuildableReference>
4141
</TestableReference>
42+
<TestableReference
43+
skipped = "NO">
44+
<BuildableReference
45+
BuildableIdentifier = "primary"
46+
BlueprintIdentifier = "7880B135248280B500AD2251"
47+
BuildableName = "InterposeExampleTests.xctest"
48+
BlueprintName = "InterposeExampleTests"
49+
ReferencedContainer = "container:InterposeExample.xcodeproj">
50+
</BuildableReference>
51+
</TestableReference>
4252
</Testables>
4353
</TestAction>
4454
<LaunchAction

Example/InterposeExample/AppDelegate.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
3131
private func fixMacCatalystInputSystemSessionRace() {
3232
do {
3333
try Interpose.whenAvailable(["RTIInput", "SystemSession"]) {
34+
3435
let lock = DispatchQueue(label: "com.steipete.document-state-hack")
35-
try $0.hook("documentState", { store in { `self` in
36-
lock.sync {
37-
store((@convention(c) (AnyObject, Selector) -> AnyObject).self)(`self`, store.selector)
38-
}} as @convention(block) (AnyObject) -> AnyObject})
39-
40-
try $0.hook("setDocumentState:", { store in { `self`, newValue in
41-
lock.sync {
42-
store((@convention(c) (AnyObject, Selector, AnyObject) -> Void).self)(`self`, store.selector, newValue)
43-
}} as @convention(block) (AnyObject, AnyObject) -> Void})
36+
37+
try $0.hook("documentState") { (store: TypedHook<@convention(c) (AnyObject, Selector) -> AnyObject, @convention(block) (AnyObject) -> AnyObject>) in { `self` in
38+
lock.sync { store.original(`self`, store.selector) }
39+
}
40+
}
41+
42+
try $0.hook("setDocumentState:") { (store: TypedHook<@convention(c) (AnyObject, Selector, AnyObject) -> Void, @convention(block) (AnyObject, AnyObject) -> Void>) in { `self`, newValue in
43+
lock.sync { store.original(`self`, store.selector, newValue) }
44+
}
45+
}
4446
}
4547
} catch {
4648
print("Failed to fix input system: \(error).")
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>$(DEVELOPMENT_LANGUAGE)</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(PRODUCT_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>1.0</string>
19+
<key>CFBundleVersion</key>
20+
<string>1</string>
21+
</dict>
22+
</plist>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// InterposeExampleTests.swift
3+
// InterposeExampleTests
4+
//
5+
// Created by Peter Steinberger on 30.05.20.
6+
//
7+
8+
import XCTest
9+
@testable import InterposeExample
10+
11+
class InterposeExampleTests: XCTestCase {
12+
13+
override func setUpWithError() throws {
14+
// Put setup code here. This method is called before the invocation of each test method in the class.
15+
}
16+
17+
override func tearDownWithError() throws {
18+
// Put teardown code here. This method is called after the invocation of each test method in the class.
19+
}
20+
21+
func testExample() throws {
22+
// This is an example of a functional test case.
23+
// Use XCTAssert and related functions to verify your tests produce the correct results.
24+
}
25+
26+
func testPerformanceExample() throws {
27+
// This is an example of a performance test case.
28+
self.measure {
29+
// Put the code you want to measure the time of here.
30+
}
31+
}
32+
33+
}

0 commit comments

Comments
 (0)