Skip to content

Commit

Permalink
Update KSCrashLifecycleHandler.mm
Browse files Browse the repository at this point in the history
  • Loading branch information
naftaly committed Jan 31, 2025
1 parent 66c7e7a commit 432a5e1
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions Sources/KSCrashRecording/KSCrashLifecycleHandler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#if KSCRASH_HAS_UIAPPLICATION

#import "KSCrashAppStateTracker+Private.h"
#import "KSLogger.h"

#import <objc/runtime.h>
#import <map>
Expand Down Expand Up @@ -99,10 +100,10 @@ static BOOL SwizzleInstanceMethod(Class klass, SEL originalSelector, SEL swizzle
static void __KS_CALLING_DELEGATE__(id self, SEL cmd, id arg)
{
std::string name(sel_getName(cmd));
NSLog(@"[MAP] %s", name.c_str());
KSLOG_DEBUG(@"[MAP] %s", name.c_str());
const auto it = gMappings.find(name);
if (it != gMappings.end()) {
NSLog(@"[MAP:implemented] %s", name.c_str());
KSLOG_DEBUG(@"[MAP:implemented] %s", name.c_str());
ApplicationDelegate_OneArg imp = (ApplicationDelegate_OneArg)method_getImplementation(it->second);
imp(self, cmd, arg);
}
Expand All @@ -111,10 +112,10 @@ static void __KS_CALLING_DELEGATE__(id self, SEL cmd, id arg)
static BOOL __KS_CALLING_DELEGATE__(id self, SEL cmd, id arg1, id arg2)
{
std::string name(sel_getName(cmd));
NSLog(@"[MAP] %s", name.c_str());
KSLOG_DEBUG(@"[MAP] %s", name.c_str());
const auto it = gMappings.find(name);
if (it != gMappings.end()) {
NSLog(@"[MAP:implemented] %s", name.c_str());
KSLOG_DEBUG(@"[MAP:implemented] %s", name.c_str());
ApplicationDelegate_TwoArgs imp = (ApplicationDelegate_TwoArgs)method_getImplementation(it->second);
return imp(self, cmd, arg1, arg2);
}
Expand All @@ -128,7 +129,7 @@ + (void)load
if (sDontSwizzle) {
return;
}

Check failure on line 131 in Sources/KSCrashRecording/KSCrashLifecycleHandler.mm

View workflow job for this annotation

GitHub Actions / Formatting Check

Sources/KSCrashRecording/KSCrashLifecycleHandler.mm:131:6: error: code should be clang-formatted [-Wclang-format-violations]
#if KSCRASH_HAS_UIAPPLICATION
SwizzleInstanceMethod(UIApplication.class, @selector(setDelegate:), @selector(__ks_setDelegate:));

if (@available(iOS 13.0, tvOS 13.0, *)) {
Expand All @@ -140,7 +141,6 @@ + (void)load
[scene __ks_proxyDelegate];
}];
}
#endif
}

#pragma - app delegate
Expand Down Expand Up @@ -231,18 +231,18 @@ + (void)copyMethodsFromClass:(Class)fromClass toClass:(Class)toClass baseClass:(
IMP imp = method_getImplementation(methods[i]);
const char *type = method_getTypeEncoding(methods[i]);

NSLog(@"Adding %s", sel_getName(name));
KSLOG_DEBUG(@"Adding %s", sel_getName(name));

Method originalMethod = class_getInstanceMethod(baseClass, name);
if (originalMethod) {
gMappings[sel_getName(name)] = originalMethod;
NSLog(@"-> original exists");
KSLOG_DEBUG(@"-> original exists");
} else {
NSLog(@"-> no original");
KSLOG_DEBUG(@"-> no original");
}

if (!class_addMethod(toClass, name, imp, type)) {
NSLog(@"-> Failed to add %s", sel_getName(name));
KSLOG_DEBUG(@"-> Failed to add %s", sel_getName(name));
}
}
free(methods);
Expand All @@ -269,9 +269,9 @@ + (void)proxyObject:(NSObject *)object withMethodsFromClass:(Class)methodSourceC
Class subclass = [self subclassClass:object.class copyMethodsFromClass:methodSourceClass];
Class originalClass = object_setClass(object, subclass);
if (originalClass) {
NSLog(@"[AC] Swizzled '%@' with '%@'", NSStringFromClass(originalClass), NSStringFromClass(subclass));
KSLOG_DEBUG(@"[AC] Swizzled '%@' with '%@'", NSStringFromClass(originalClass), NSStringFromClass(subclass));
} else {
NSLog(@"[AC] Swizzled failed");
KSLOG_DEBUG(@"[AC] Swizzled failed");
}
}

Expand Down

0 comments on commit 432a5e1

Please sign in to comment.