Skip to content

Commit

Permalink
update 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
BandarHL committed Jan 7, 2025
1 parent 6a89b24 commit b7dbed0
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 83 deletions.
13 changes: 13 additions & 0 deletions InstagramHeaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,21 @@
@property (nonatomic, copy, readonly) IGMedia *media;
@end

@interface IGSundialViewerControlsOverlayController: NSObject
{
IGMedia *_media;
}
@end

@interface IGSundialViewerControlsOverlayView: UIView
@property (nonatomic, weak, readwrite) id delegate; // IGSundialViewerControlsOverlayController
@property (nonatomic, assign, readonly) IGMedia *media;
@end

@interface IGSundialViewerVerticalUFI: UIView
@property (nonatomic, weak, readwrite) id delegate; // IGSundialViewerControlsOverlayView
@property (nonatomic, assign, readonly) UIButton *ufiLikeButton;
- (void)setupBHInsta;
- (void)downloadProgress:(float)progress;
- (void)downloadDidFinish:(NSURL *)filePath Filename:(NSString *)fileName;
- (void)downloadDidFailureWithError:(NSError *)error;
Expand Down
181 changes: 99 additions & 82 deletions Tweak.x
Original file line number Diff line number Diff line change
Expand Up @@ -630,22 +630,18 @@ static BOOL isAuthenticationShowed = FALSE;
%hook IGUFIInteractionCountsView
- (void)layoutSubviews {
%orig;
[self setupBHInsta];
if ([BHIManager downloadVideos]) {
[self setupBHInsta];
}
}
%new - (void)setupBHInsta {
// Prevent duplicate buttons by checking if it already exists
if ([self viewWithTag:999] != nil) {
return;
}

if (![self.delegate isKindOfClass:%c(IGFeedItemUFICell)]) return;
if (![self valueForKey:@"_sendView"]) return;
UIView *sendView = [self valueForKey:@"_sendView"];
IGFeedItemUFICell *cell = self.delegate;
if (![cell.delegate isKindOfClass:%c(IGFeedItemUFICellConfigurableDelegateImpl)]) return;
IGFeedItemUFICellConfigurableDelegateImpl *delegateImpl = cell.delegate;
if (![delegateImpl valueForKey:@"_media"]) return;
IGMedia *currentMedia = [delegateImpl valueForKey:@"_media"];

UIButton *downloadButton = [UIButton buttonWithType:UIButtonTypeSystem];
downloadButton.tag = 999;
Expand All @@ -659,6 +655,12 @@ static BOOL isAuthenticationShowed = FALSE;
[downloadButton setTranslatesAutoresizingMaskIntoConstraints:false];

[downloadButton addAction:[UIAction actionWithHandler:^(__kindof UIAction * _Nonnull action) {
if (![self.delegate isKindOfClass:%c(IGFeedItemUFICell)]) return;
IGFeedItemUFICell *cell = self.delegate;
if (![cell.delegate isKindOfClass:%c(IGFeedItemUFICellConfigurableDelegateImpl)]) return;
IGFeedItemUFICellConfigurableDelegateImpl *delegateImpl = cell.delegate;
if (![delegateImpl valueForKey:@"_media"]) return;
IGMedia *currentMedia = [delegateImpl valueForKey:@"_media"];
UIAlertController *alert = showDownloadMediaAlert(currentMedia, self, cell.pageControlCurrentPage);
[topMostController() presentViewController:alert animated:YES completion:nil];
}] forControlEvents:UIControlEventTouchUpInside];
Expand Down Expand Up @@ -698,30 +700,45 @@ static BOOL isAuthenticationShowed = FALSE;
- (void)configureWithViewModel:(IGSundialViewerUFIViewModel *)viewModel {
%orig;
if ([BHIManager downloadVideos]) {
IGMedia *currentMedia = viewModel.media;
UIButton *downloadButton = [UIButton buttonWithType:UIButtonTypeSystem];
[downloadButton setTintColor:UIColor.labelColor];
[downloadButton setImage:[UIImage systemImageNamed:@"arrow.down"] forState:UIControlStateNormal];
[downloadButton setTranslatesAutoresizingMaskIntoConstraints:false];
downloadButton.layer.shadowColor = [UIColor blackColor].CGColor;
downloadButton.layer.shadowOpacity = 0.4;
downloadButton.layer.shadowOffset = CGSizeMake(-2, 0);
downloadButton.layer.shadowRadius = 3;
downloadButton.layer.masksToBounds = NO;
[self setupBHInsta];
}
}
%new - (void)setupBHInsta {
// Prevent duplicate buttons by checking if it already exists
if ([self viewWithTag:999] != nil) {
return;
}

UIButton *downloadButton = [UIButton buttonWithType:UIButtonTypeSystem];
downloadButton.tag = 999;
[downloadButton setTintColor:UIColor.labelColor];
[downloadButton setImage:[UIImage systemImageNamed:@"arrow.down"] forState:UIControlStateNormal];
[downloadButton setTranslatesAutoresizingMaskIntoConstraints:false];
downloadButton.layer.shadowColor = [UIColor blackColor].CGColor;
downloadButton.layer.shadowOpacity = 0.4;
downloadButton.layer.shadowOffset = CGSizeMake(-2, 0);
downloadButton.layer.shadowRadius = 3;
downloadButton.layer.masksToBounds = NO;

[downloadButton addAction:[UIAction actionWithHandler:^(__kindof UIAction * _Nonnull action) {
if (![self.delegate isKindOfClass:%c(IGSundialViewerControlsOverlayView)]) return;
IGSundialViewerControlsOverlayView *delegate = self.delegate;
UIAlertController *alert = showDownloadMediaAlert(delegate.media, self, 0);
[topMostController() presentViewController:alert animated:YES completion:nil];
}] forControlEvents:UIControlEventTouchUpInside];


[self addSubview:downloadButton];
[self addSubview:downloadButton];

[NSLayoutConstraint activateConstraints:@[
[downloadButton.centerXAnchor constraintEqualToAnchor:self.centerXAnchor],
[downloadButton.bottomAnchor constraintEqualToAnchor:self.ufiLikeButton.topAnchor],
[downloadButton.widthAnchor constraintEqualToConstant:44],
[downloadButton.heightAnchor constraintEqualToConstant:44],
]];
[self addSubview:downloadButton];

[downloadButton addAction:[UIAction actionWithHandler:^(__kindof UIAction * _Nonnull action) {
UIAlertController *alert = showDownloadMediaAlert(currentMedia, self, 0);
[topMostController() presentViewController:alert animated:YES completion:nil];
}] forControlEvents:UIControlEventTouchUpInside];
}
[NSLayoutConstraint activateConstraints:@[
[downloadButton.centerXAnchor constraintEqualToAnchor:self.centerXAnchor],
[downloadButton.bottomAnchor constraintEqualToAnchor:self.ufiLikeButton.topAnchor],
[downloadButton.widthAnchor constraintEqualToConstant:44],
[downloadButton.heightAnchor constraintEqualToConstant:44],
]];
}
%new - (void)downloadProgress:(float)progress {
hud.detailTextLabel.text = [BHIManager getDownloadingPersent:progress];
Expand Down Expand Up @@ -947,62 +964,62 @@ static BOOL isAuthenticationShowed = FALSE;


// Enable all these lines of code if you want to compile for sideload
// NSString *keychainAccessGroup;
// NSURL *fakeGroupContainerURL;

// void loadKeychainAccessGroup() {
// NSDictionary* dummyItem = @{
// (__bridge id)kSecClass : (__bridge id)kSecClassGenericPassword,
// (__bridge id)kSecAttrAccount : @"dummyItem",
// (__bridge id)kSecAttrService : @"dummyService",
// (__bridge id)kSecReturnAttributes : @YES,
// };

// CFTypeRef result;
// OSStatus ret = SecItemCopyMatching((__bridge CFDictionaryRef)dummyItem, &result);
// if (ret == -25300) {
// ret = SecItemAdd((__bridge CFDictionaryRef)dummyItem, &result);
// }

// if (ret == 0 && result) {
// NSDictionary* resultDict = (__bridge id)result;
// keychainAccessGroup = resultDict[(__bridge id)kSecAttrAccessGroup];
// NSLog(@"loaded keychainAccessGroup: %@", keychainAccessGroup);
// }
// }

// %hook NSFileManager
// - (NSURL *)containerURLForSecurityApplicationGroupIdentifier:(NSString*)groupIdentifier {
// NSURL *fakeURL = [fakeGroupContainerURL URLByAppendingPathComponent:groupIdentifier];
// createDirectoryIfNotExists(fakeURL);
// createDirectoryIfNotExists([fakeURL URLByAppendingPathComponent:@"Library"]);
// createDirectoryIfNotExists([fakeURL URLByAppendingPathComponent:@"Library/Caches"]);

// return fakeURL;
// }
// %end

// %hook FBSDKKeychainStore
// - (NSString*)accessGroup{
// return keychainAccessGroup;
// }
// %end

// %hook FBKeychainItemController
// - (NSString*)accessGroup {
// return keychainAccessGroup;
// }
// %end

// %hook UICKeyChainStore
// - (NSString*)accessGroup {
// return keychainAccessGroup;
// }
// %end
NSString *keychainAccessGroup;
NSURL *fakeGroupContainerURL;

void loadKeychainAccessGroup() {
NSDictionary* dummyItem = @{
(__bridge id)kSecClass : (__bridge id)kSecClassGenericPassword,
(__bridge id)kSecAttrAccount : @"dummyItem",
(__bridge id)kSecAttrService : @"dummyService",
(__bridge id)kSecReturnAttributes : @YES,
};

CFTypeRef result;
OSStatus ret = SecItemCopyMatching((__bridge CFDictionaryRef)dummyItem, &result);
if (ret == -25300) {
ret = SecItemAdd((__bridge CFDictionaryRef)dummyItem, &result);
}

if (ret == 0 && result) {
NSDictionary* resultDict = (__bridge id)result;
keychainAccessGroup = resultDict[(__bridge id)kSecAttrAccessGroup];
NSLog(@"loaded keychainAccessGroup: %@", keychainAccessGroup);
}
}

%hook NSFileManager
- (NSURL *)containerURLForSecurityApplicationGroupIdentifier:(NSString*)groupIdentifier {
NSURL *fakeURL = [fakeGroupContainerURL URLByAppendingPathComponent:groupIdentifier];
createDirectoryIfNotExists(fakeURL);
createDirectoryIfNotExists([fakeURL URLByAppendingPathComponent:@"Library"]);
createDirectoryIfNotExists([fakeURL URLByAppendingPathComponent:@"Library/Caches"]);

return fakeURL;
}
%end

%hook FBSDKKeychainStore
- (NSString*)accessGroup{
return keychainAccessGroup;
}
%end

%hook FBKeychainItemController
- (NSString*)accessGroup {
return keychainAccessGroup;
}
%end

%hook UICKeyChainStore
- (NSString*)accessGroup {
return keychainAccessGroup;
}
%end

%ctor {
// fakeGroupContainerURL = [NSURL fileURLWithPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/FakeGroupContainers"] isDirectory:YES];
// loadKeychainAccessGroup();
fakeGroupContainerURL = [NSURL fileURLWithPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/FakeGroupContainers"] isDirectory:YES];
loadKeychainAccessGroup();

%init;
}
2 changes: 1 addition & 1 deletion control
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: com.bandarhl.bhinsta
Name: BHInsta
Version: 1.0
Version: 1.1
Architecture: iphoneos-arm
Description: An awesome tweak for Instagram!
Maintainer: Bandar Alruwaili
Expand Down

0 comments on commit b7dbed0

Please sign in to comment.