Skip to content

Commit

Permalink
Merge pull request #24 from bunny-mod/feat-intercept-broken-features
Browse files Browse the repository at this point in the history
feat: intercept broken features
  • Loading branch information
castdrian authored Nov 17, 2024
2 parents b88c2f9 + d21bf2c commit 172dc71
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 11 deletions.
Binary file added .vscode/AirDrop.shortcut
Binary file not shown.
11 changes: 8 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
},
"VsCodeTaskButtons.tasks": [
{
"label": "$(tools) Make and Copy",
"task": "Make and Copy Tweak",
"tooltip": "Make and copy Tweak"
"label": "$(tools) Build Tweak",
"task": "Build Tweak",
"tooltip": "Build Tweak"
},
{
"label": "$(cloud-upload) AirDrop Tweak",
"task": "AirDrop Tweak",
"tooltip": "AirDrop Tweak"
}
],
"externalFormatters.languages": {
Expand Down
20 changes: 18 additions & 2 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"tasks": [
{
"type": "shell",
"label": "Make and Copy Tweak",
"label": "Build Tweak",
"command": "zsh",
"args": [
"-c",
"rm -rf packages && make clean && make package FINALPACKAGE=1 THEOS_PACKAGE_SCHEME=rootless && cp ./packages/app.pyoncord_*arm64.deb ~/Library/Mobile\\ Documents/com~apple~CloudDocs/"
"rm -rf packages && make clean && make package FINALPACKAGE=1 THEOS_PACKAGE_SCHEME=rootless && cp ./packages/*arm64.deb ~/Library/Mobile\\ Documents/com~apple~CloudDocs/"
],
"problemMatcher": {
"owner": "cpp",
Expand All @@ -30,6 +30,22 @@
"clear": true,
"close": true
}
},
{
"type": "shell",
"label": "AirDrop Tweak",
"command": "zsh",
"args": [
"-c",
"shortcuts run 'AirDrop' -i ./packages/*arm64.deb"
],
"presentation": {
"panel": "shared",
"showReuseMessage": false,
"clear": true,
"close": true
},
"dependsOn": ["Build Tweak"]
}
]
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ To resolve the fixable issues, you need to match the app's bundle ID with your p
</tr>
</table>

## Doing this will break notifications if the app is backgrounded or closed.
## Doing this will break notifications if the app is backgrounded or closed

</details>

Expand All @@ -53,7 +53,7 @@ Builds can be found in the [Releases](https://github.com/pyoncord/BunnyTweak/rel
### Jailbroken

1. Install Bunny by downloading the appropriate Debian package (or by building your own, see [Building BunnyTweak locally](#building-bunnytweak-locally)) and adding it to your package manager. Use the file ending in `arm.deb` for rootful jailbreaks, and the file ending in `arm64.deb` for rootless jailbreaks.
1. Install Bunny by downloading the appropriate Debian package (or by building your own, see [Building](#building)) and adding it to your package manager. Use the file ending in `arm.deb` for rootful jailbreaks, and the file ending in `arm64.deb` for rootless jailbreaks.

### Jailed

Expand Down
95 changes: 94 additions & 1 deletion Sources/Sideloading.x
Original file line number Diff line number Diff line change
@@ -1,11 +1,68 @@
#import "Logger.h"
#import "Utils.h"
#import <Foundation/Foundation.h>
#import <Security/Security.h>
#import <UIKit/UIKit.h>
#import <dlfcn.h>

typedef struct __CMSDecoder *CMSDecoderRef;
extern CFTypeRef SecCMSDecodeGetContent(CFDataRef message);
extern OSStatus CMSDecoderCreate(CMSDecoderRef *cmsDecoder);
extern OSStatus CMSDecoderUpdateMessage(CMSDecoderRef cmsDecoder, const void *content,
size_t contentLength);
extern OSStatus CMSDecoderFinalizeMessage(CMSDecoderRef cmsDecoder);
extern OSStatus CMSDecoderCopyContent(CMSDecoderRef cmsDecoder, CFDataRef *content);

#define DISCORD_BUNDLE_ID @"com.hammerandchisel.discord"
#define DISCORD_NAME @"Discord"

typedef NS_ENUM(NSInteger, BundleIDError) {
BundleIDErrorFiles,
BundleIDErrorIcon
};

static void showBundleIDError(BundleIDError error) {
NSString *message = @"For this to work change the Bundle ID so that it matches your "
@"provisioning profile's App ID (excluding the Team ID prefix).";
NSString *title = error == BundleIDErrorFiles ? @"Cannot Access Files" : @"Cannot Change Icon";
showErrorAlert(title, message);
}

static NSString *getProvisioningAppID(void) {
NSString *provisionPath = [NSBundle.mainBundle pathForResource:@"embedded"
ofType:@"mobileprovision"];
if (!provisionPath)
return nil;
NSData *provisionData = [NSData dataWithContentsOfFile:provisionPath];
if (!provisionData)
return nil;
CMSDecoderRef decoder = NULL;
CMSDecoderCreate(&decoder);
CMSDecoderUpdateMessage(decoder, provisionData.bytes, provisionData.length);
CMSDecoderFinalizeMessage(decoder);
CFDataRef dataRef = NULL;
CMSDecoderCopyContent(decoder, &dataRef);
NSData *data = (__bridge_transfer NSData *)dataRef;
if (decoder)
CFRelease(decoder);
NSError *error = nil;
id plist = [NSPropertyListSerialization propertyListWithData:data
options:0
format:NULL
error:&error];
if (!plist || ![plist isKindOfClass:[NSDictionary class]])
return nil;
NSString *appID = plist[@"Entitlements"][@"application-identifier"];
if (!appID)
return nil;
NSArray *components = [appID componentsSeparatedByString:@"."];
if (components.count > 1) {
return [[components subarrayWithRange:NSMakeRange(1, components.count - 1)]
componentsJoinedByString:@"."];
}
return nil;
}

static NSString *getAccessGroupID(void) {
NSDictionary *query = @{
(__bridge NSString *)kSecClass : (__bridge NSString *)kSecClassGenericPassword,
Expand Down Expand Up @@ -88,11 +145,47 @@ static BOOL isSelfCall(void) {
}
%end

%hook UIApplication
- (void)setAlternateIconName:(NSString *)iconName
completionHandler:(void (^)(NSError *))completion {
void (^wrappedCompletion)(NSError *) = ^(NSError *error) {
if (error) {
showBundleIDError(BundleIDErrorIcon);
}

if (completion) {
completion(error);
}
};

%orig(iconName, wrappedCompletion);
}
%end

%hook UIViewController
- (void)presentViewController:(UIViewController *)viewControllerToPresent
animated:(BOOL)flag
completion:(void (^)(void))completion {
if ([viewControllerToPresent isKindOfClass:[UIDocumentPickerViewController class]]) {
NSString *provisioningAppID = getProvisioningAppID();
NSString *currentBundleID = [[NSBundle mainBundle] bundleIdentifier];

if (provisioningAppID && ![provisioningAppID isEqualToString:currentBundleID]) {
BunnyLog(@"Intercepted UIDocumentPickerViewController presentation");
showBundleIDError(BundleIDErrorFiles);
return;
}
}
%orig;
}
%end

%end

%ctor {
BOOL isAppStoreApp = [[NSFileManager defaultManager]
fileExistsAtPath:[[NSBundle mainBundle] appStoreReceiptURL].path];
if (!isAppStoreApp)
if (!isAppStoreApp) {
%init(Sideloading);
}
}
6 changes: 3 additions & 3 deletions control
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Package: app.pyoncord
Name: Bunny
Version: 0.4.0
Version: 0.5.0
Architecture: iphoneos-arm
Description: A client modification for Discord's mobile app.
Maintainer: Pylix
Author: Pylix, Adrian Castro, FieryFlames
Maintainer: Adrian Castro, Pylix
Author: Adrian Castro, Pylix, FieryFlames
Icon: https://avatars.githubusercontent.com/u/132727175
Section: Tweaks
Depends: mobilesubstrate (>= 0.9.5000)
Expand Down

0 comments on commit 172dc71

Please sign in to comment.