Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 6 additions & 10 deletions Sources/InterposeKit/InterposeSubclass.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import SuperBuilder

class InterposeSubclass {

Expand Down Expand Up @@ -90,19 +91,14 @@ class InterposeSubclass {
NSClassFromString("SuperBuilder")?.value(forKey: "isSupportedArchitecure") as? Bool ?? false
}

private lazy var addSuperImpl: @convention(c) (AnyClass, Selector, NSErrorPointer) -> Bool = {
let handle = dlopen(nil, RTLD_LAZY)
let imp = dlsym(handle, "IKTAddSuperImplementationToClass")
return unsafeBitCast(imp, to: (@convention(c) (AnyClass, Selector, NSErrorPointer) -> Bool).self)
}()

func addSuperTrampoline(selector: Selector) {
var error: NSError?
if addSuperImpl(dynamicClass, selector, &error) == false {
Interpose.log("Failed to add super implementation to -[\(dynamicClass).\(selector)]: \(error!)")
} else {
do {
try SuperBuilder.addSuperInstanceMethod(to: dynamicClass, selector: selector)

let imp = class_getMethodImplementation(dynamicClass, selector)!
Interpose.log("Added super for -[\(dynamicClass).\(selector)]: \(imp)")
} catch {
Interpose.log("Failed to add super implementation to -[\(dynamicClass).\(selector)]: \(error)")
}
}
#else
Expand Down
6 changes: 0 additions & 6 deletions Sources/SuperBuilder/src/ITKSuperBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ static IMP ITKGetTrampolineForTypeEncoding(__unused const char *typeEncoding) {
return requiresStructDispatch ? (IMP)msgSendSuperStretTrampoline : (IMP)msgSendSuperTrampoline;
}

// Helper for binding with Swift
BOOL IKTAddSuperImplementationToClass(Class originalClass, SEL selector, NSError **error);
BOOL IKTAddSuperImplementationToClass(Class originalClass, SEL selector, NSError **error) {
return [SuperBuilder addSuperInstanceMethodToClass:originalClass selector:selector error:error];
}

#define ERROR_AND_RETURN(CODE, STRING)\
if (error) { *error = [NSError errorWithDomain:SuperBuilderErrorDomain code:CODE userInfo:@{NSLocalizedDescriptionKey: STRING}];} return NO;

Expand Down