From 334703ec43c7e2642a6de90e8d2ed3156287ffef Mon Sep 17 00:00:00 2001 From: James Magahern Date: Mon, 5 May 2025 19:05:49 -0700 Subject: [PATCH] Obscure mail spi --- App/Hacks/Hacks.h | 1 + App/Hacks/Hacks.m | 6 ++++++ App/Hacks/MFMailComposeViewControllerFix.m | 16 ++++------------ 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/App/Hacks/Hacks.h b/App/Hacks/Hacks.h index 8c2484a..7efaccd 100644 --- a/App/Hacks/Hacks.h +++ b/App/Hacks/Hacks.h @@ -9,3 +9,4 @@ extern Class DecodedClass(const char *encodedClassName); extern SEL DecodedSelector(const char *encodedSelectorName); +extern void SwizzleClassMethod(Class targetClass, SEL originalSelector, IMP replacementIMP); diff --git a/App/Hacks/Hacks.m b/App/Hacks/Hacks.m index ee55086..f74d2bb 100644 --- a/App/Hacks/Hacks.m +++ b/App/Hacks/Hacks.m @@ -6,6 +6,7 @@ // #import "Hacks.h" +#import Class DecodedClass(const char *encodedClassName) { NSData *data = [NSData dataWithBytesNoCopy:(void *)encodedClassName length:strlen(encodedClassName) freeWhenDone:NO]; @@ -23,3 +24,8 @@ SEL DecodedSelector(const char *encodedSelectorName) { return NSSelectorFromString(str); } +void SwizzleClassMethod(Class targetClass, SEL originalSelector, IMP replacementIMP) +{ + Method originalMethod = class_getClassMethod(targetClass, originalSelector); + method_setImplementation(originalMethod, replacementIMP); +} diff --git a/App/Hacks/MFMailComposeViewControllerFix.m b/App/Hacks/MFMailComposeViewControllerFix.m index 96880c2..8ae7803 100644 --- a/App/Hacks/MFMailComposeViewControllerFix.m +++ b/App/Hacks/MFMailComposeViewControllerFix.m @@ -9,26 +9,18 @@ #import #import #import - -@interface MFMailComposeViewController (InternalMethods) -+ (BOOL)canSendMailSourceAccountManagement:(NSInteger)sourceAccountManagement; -@end - -static void swizzleClassMethod(Class targetClass, SEL originalSelector, IMP replacementIMP) -{ - Method originalMethod = class_getClassMethod(targetClass, originalSelector); - method_setImplementation(originalMethod, replacementIMP); -} +#import "Hacks.h" __attribute__((constructor)) static void swizzleMFMailComposeViewController(void) { // Hacks to work around the fact that MFMailComposeViewController is broken in iOS 14+ - swizzleClassMethod(MFMailComposeViewController.class, @selector(canSendMail), imp_implementationWithBlock(^BOOL(void) { + SwizzleClassMethod(MFMailComposeViewController.class, @selector(canSendMail), imp_implementationWithBlock(^BOOL(void) { return YES; })); - swizzleClassMethod(MFMailComposeViewController.class, @selector(canSendMailSourceAccountManagement:), imp_implementationWithBlock(^BOOL(NSInteger sam) { + SEL canSendMailSourceAccountManagement = DecodedSelector("Y2FuU2VuZE1haWxTb3VyY2VBY2NvdW50TWFuYWdlbWVudDo="); + SwizzleClassMethod(MFMailComposeViewController.class, canSendMailSourceAccountManagement, imp_implementationWithBlock(^BOOL(NSInteger sam) { return YES; })); }