Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
3946944
Reorganized source files
lukaskubanek Mar 25, 2025
09e19ee
Replaced XCTest assertion for throwing errors
lukaskubanek Mar 25, 2025
d25ea1d
Reworked HookState
lukaskubanek Mar 25, 2025
5b34576
Centralized deprecated code
lukaskubanek Mar 25, 2025
8d4e170
Marked `AnyHook.State` as deprecated
lukaskubanek Mar 25, 2025
0c3f4c1
Deprecated fluent overloads of `apply()` and `revert()`
lukaskubanek Mar 25, 2025
5ff2462
Introduced Hook protocol
lukaskubanek Mar 25, 2025
7b0e94d
Initial step towards strategy-based approach
lukaskubanek Mar 25, 2025
86c05aa
Moved originalIMP to AnyHookStrategy
lukaskubanek Mar 25, 2025
1fbf432
First take on ClassHookStrategy
lukaskubanek Mar 25, 2025
93d756b
More tweaks to HookStrategy types
lukaskubanek Mar 25, 2025
dee3e0c
Minor tweaks
lukaskubanek Mar 25, 2025
d635810
Removed guts from ClassHook
lukaskubanek Mar 25, 2025
a68d49d
Fixed typos in tests
lukaskubanek Mar 25, 2025
8641446
Raised minimum supported OS versions
lukaskubanek Mar 25, 2025
953daaf
Introduced HookImplementationBuilder
lukaskubanek Mar 26, 2025
23eb321
Breaking: method and hook signatures have to be explicitly specified
lukaskubanek Mar 26, 2025
8fa936e
Removed HookSignature generic parameter from TypedHook
lukaskubanek Mar 26, 2025
da0ea37
Introduced HookProxy
lukaskubanek Mar 26, 2025
1700ad9
Removed MethodSignature generic parameter from TypedHook
lukaskubanek Mar 26, 2025
f3ae5aa
Merged TypedHook into AnyHook
lukaskubanek Mar 26, 2025
38a2df1
HookStrategy now conforms to CustomDebugStringConvertible
lukaskubanek Mar 26, 2025
59cdbef
Merged AnyHook and Hook
lukaskubanek Mar 26, 2025
4127d26
Merged remainings of ClassHook into Hook
lukaskubanek Mar 26, 2025
3f7513c
Refactored hook builder & addHook → applyHook
lukaskubanek Mar 26, 2025
50ce7d4
Preps for ObjectHookStrategy
lukaskubanek Mar 26, 2025
5510600
Preps for ObjectHookStrategy 2/
lukaskubanek Mar 26, 2025
b85ef8e
Removed generic parameter from ObjectHook
lukaskubanek Mar 26, 2025
5d781f7
Moved more code to ObjectHookStrategy
lukaskubanek Mar 26, 2025
9d1b88b
`storeHook(…)` now works with IMP rather than block
lukaskubanek Mar 26, 2025
75a498a
replacementIMP → hookIMP
lukaskubanek Mar 26, 2025
01307ad
First take on ObjectHookLink
lukaskubanek Mar 26, 2025
fb634bd
Moved replace/restore methods to HookStrategy
lukaskubanek Mar 26, 2025
b31d282
Removed ObjectHook
lukaskubanek Mar 26, 2025
99ee08e
Tweaks to Hook
lukaskubanek Mar 26, 2025
1d6b83e
ObjectHookRegistry & ObjectHookHandle
lukaskubanek Mar 26, 2025
4c19c51
Cleaned up debug descriptions
lukaskubanek Mar 26, 2025
0d9646d
Refactored `ObjectHookStrategy._findParentHook(…)`
lukaskubanek Mar 26, 2025
183178c
`HookStrategy.lookUpIMP()`
lukaskubanek Mar 26, 2025
44be65f
Validation in HookStrategy & HookScope
lukaskubanek Mar 26, 2025
8ae9fad
Improve initializers in Hook
lukaskubanek Mar 26, 2025
7b3272a
`HookStrategy.originalIMP` is no longer optional
lukaskubanek Mar 26, 2025
e2b1422
Eliminated obsolete `Hook.validate(…)` method
lukaskubanek Mar 26, 2025
6836949
Hook: Improved file structure
lukaskubanek Mar 26, 2025
f7956cc
Tweaks strategy storage
lukaskubanek Mar 26, 2025
12b7938
Moved hook-related types to Hook.swift
lukaskubanek Mar 26, 2025
56a082a
Initial refactoring in InterposeSubclass
lukaskubanek Mar 26, 2025
57d2a7a
Improved docs
lukaskubanek Mar 27, 2025
b7d3e57
Moved files around
lukaskubanek Mar 27, 2025
b870a22
`class_setPerceivedClass(for:to:)`
lukaskubanek Mar 27, 2025
88ffe00
Tweaks to `Hook.originalImp`
lukaskubanek Mar 27, 2025
af3e3ac
Initial change to KVO detection
lukaskubanek Mar 27, 2025
2e11338
Tweaked docs for `class_setPerceivedClass(…)`
lukaskubanek Mar 28, 2025
014c7ed
Formalized KVO check
lukaskubanek Mar 28, 2025
8f603b5
Marked inherited tests for future polishing
lukaskubanek Mar 28, 2025
e2a025a
Added test for `object_isKVOActive(…)`
lukaskubanek Mar 28, 2025
17afb9d
Sketched out new Interpose facade class
lukaskubanek Mar 28, 2025
8b8978d
Sketched out new Interpose facade class
lukaskubanek Mar 28, 2025
c5f4ed9
Interpose no longer allows apply/revert
lukaskubanek Mar 28, 2025
106e139
Moved object validation from Interpose to ObjectHookStrategy
lukaskubanek Mar 28, 2025
209cd30
Deprecated Interpose.init(_:builder:) for classes
lukaskubanek Mar 28, 2025
d566117
Deprecated Interpose.init(_:builder:) for objects
lukaskubanek Mar 28, 2025
7901b40
Renamed hook creation methods on Interpose
lukaskubanek Mar 28, 2025
a126a31
Reworked life cycle handling across the library
lukaskubanek Mar 29, 2025
1a50325
Fixed multiline strings
lukaskubanek Mar 29, 2025
c5abecd
Interpose.fail(_:)
lukaskubanek Mar 29, 2025
334cc6d
Switched Interpose to static methods
lukaskubanek Mar 29, 2025
e834061
Commented out Interpose+Watcher.swift
lukaskubanek Mar 29, 2025
5afa11f
Final polish to Interpose facade
lukaskubanek Mar 29, 2025
11cfcb0
Removed irrelevant deprecation
lukaskubanek Mar 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import PackageDescription
let package = Package(
name: "InterposeKit",
platforms: [
.iOS(.v12),
.macOS(.v10_13),
.tvOS(.v12),
.watchOS(.v5)
.iOS(.v13),
.macOS(.v10_15),
.tvOS(.v13),
.watchOS(.v6)
],
products: [
.library(
Expand Down
99 changes: 0 additions & 99 deletions Sources/InterposeKit/AnyHook.swift

This file was deleted.

46 changes: 0 additions & 46 deletions Sources/InterposeKit/ClassHook.swift

This file was deleted.

36 changes: 36 additions & 0 deletions Sources/InterposeKit/Deprecated/Hook+Deprecated.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
extension Hook {

@available(*, deprecated, renamed: "HookState", message: "Use top-level 'HookState'.")
public typealias State = HookState

@available(*, deprecated, message: "Use 'apply()' returning Void. The overload returning 'Self' has been removed.")
@_disfavoredOverload
public func apply() throws -> Self {
try self.apply()
return self
}

@available(*, deprecated, message: "Use 'revert()' returning Void. The overload returning 'Self' has been removed.")
@_disfavoredOverload
public func revert() throws -> Self {
try revert()
return self
}

}

extension HookState {

@available(*, deprecated, renamed: "pending", message: "Use 'pending' instead.")
public static var prepared: Self { .pending }

@available(*, deprecated, renamed: "active", message: "Use 'active' instead.")
public static var interposed: Self { .active }

@available(*, deprecated, renamed: "failed", message: """
Use 'failed' instead. The state no longer carries an associated error—handle errors where
the hook is applied.
""")
public static var error: Self { .failed }

}
114 changes: 114 additions & 0 deletions Sources/InterposeKit/Deprecated/Interpose+Deprecated.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import ObjectiveC

extension Interpose {

@available(
*,
unavailable,
message: """
The builder-based initializer pattern is no longer supported. Use the static method \
'Interpose.applyHook(on:for:methodSignature:hookSignature:build:)' for immediate \
installation, or 'Interpose.prepareHook(…)' for manual control.
"""
)
public init(
_ class: AnyClass,
builder: (Interpose) throws -> Void
) throws {
Interpose.fail("Unavailable API")
}

@available(
*,
unavailable,
message: """
The builder-based initializer pattern is no longer supported. Use the static method \
'Interpose.applyHook(on:for:methodSignature:hookSignature:build:)' for immediate \
installation, or 'Interpose.prepareHook(…)' for manual control.
"""
)
public init(
_ object: NSObject,
builder: ((Interpose) throws -> Void)? = nil
) throws {
Interpose.fail("Unavailable API")
}

@available(
*,
unavailable,
message: """
Instance method 'hook(_:methodSignature:hookSignature:_:)' is no longer supported. \
Use 'Interpose.applyHook(on:for:methodSignature:hookSignature:build:)' instead.
"""
)
@discardableResult
public func hook<MethodSignature, HookSignature>(
_ selectorName: String,
methodSignature: MethodSignature.Type,
hookSignature: HookSignature.Type,
_ build: @escaping HookBuilder<MethodSignature, HookSignature>
) throws -> Hook {
Interpose.fail("Unavailable API")
}

@available(
*,
unavailable,
message: """
Instance method 'hook(_:methodSignature:hookSignature:_:)' is no longer supported. \
Use 'Interpose.applyHook(on:for:methodSignature:hookSignature:build:)' instead.
"""
)
@discardableResult
public func hook<MethodSignature, HookSignature>(
_ selector: Selector,
methodSignature: MethodSignature.Type,
hookSignature: HookSignature.Type,
_ build: @escaping HookBuilder<MethodSignature, HookSignature>
) throws -> Hook {
Interpose.fail("Unavailable API")
}

@available(
*,
unavailable,
message: """
Instance method 'prepareHook(_:methodSignature:hookSignature:_:)' is no longer supported. \
Use 'Interpose.prepareHook(on:for:methodSignature:hookSignature:build:)' instead.
"""
)
public func prepareHook<MethodSignature, HookSignature>(
_ selector: Selector,
methodSignature: MethodSignature.Type,
hookSignature: HookSignature.Type,
_ build: @escaping HookBuilder<MethodSignature, HookSignature>
) throws -> Hook {
Interpose.fail("Unavailable API")
}

@available(
*,
unavailable,
message: """
'apply()' is no longer supported. Use 'Interpose.applyHook(…)' to apply individual hooks \
directly using the new static API.
"""
)
public func apply(_ builder: ((Interpose) throws -> Void)? = nil) throws -> Interpose {
Interpose.fail("Unavailable API")
}

@available(
*,
unavailable,
message: """
'revert()' is no longer supported. Keep a reference to each individual hook and call \
'revert()' on them directly.
"""
)
public func revert(_ builder: ((Interpose) throws -> Void)? = nil) throws -> Interpose {
Interpose.fail("Unavailable API")
}

}
47 changes: 47 additions & 0 deletions Sources/InterposeKit/Deprecated/NSObject+Deprecated.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import ObjectiveC

extension NSObject {

@available(*, deprecated, renamed: "applyHook(for:methodSignature:hookSignature:build:)")
@discardableResult
public func hook<MethodSignature, HookSignature> (
_ selector: Selector,
methodSignature: MethodSignature.Type,
hookSignature: HookSignature.Type,
_ build: @escaping HookBuilder<MethodSignature, HookSignature>
) throws -> Hook {
precondition(
!(self is AnyClass),
"There should not be a way to cast an NSObject to AnyClass."
)

return try self.applyHook(
for: selector,
methodSignature: methodSignature,
hookSignature: hookSignature,
build: build
)
}

@available(*, deprecated, message: """
Deprecated to avoid confusion: this hooks instance methods on classes, but can be mistaken \
for hooking class methods, which is not supported. Use `Interpose(Class.self)` with \
`prepareHook(…)` to make the intent explicit.
""")
@discardableResult
public class func hook<MethodSignature, HookSignature> (
_ selector: Selector,
methodSignature: MethodSignature.Type,
hookSignature: HookSignature.Type,
_ build: @escaping HookBuilder<MethodSignature, HookSignature>
) throws -> Hook {
let hook = try Hook(
target: .class(self),
selector: selector,
build: build
)
try hook.apply()
return hook
}

}
Loading