Skip to content

Commit

Permalink
updated Tweak.x and HLPRLC
Browse files Browse the repository at this point in the history
  • Loading branch information
yandevelop committed Nov 11, 2021
1 parent 46899a6 commit d32f336
Show file tree
Hide file tree
Showing 12 changed files with 204 additions and 93 deletions.
Binary file modified .DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
TARGET := iphone:clang:14.8:13.0
TARGET := iphone:clang:14.4:13.0
INSTALL_TARGET_PROCESSES = MobileSlideShow
ARCHS = arm64 arm64e
THEOS_DEVICE_IP = localhost
THEOS_DEVICE_PORT = 2222
VERSION = 1.1
DEBUG = 1

include $(THEOS)/makefiles/common.mk

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# HiddenLock14
Add Face ID authentication to the hidden section in Photos.
Add Face ID authentication to the hidden section

## Installation
1. Add https://yandevelop.github.io to your package manager.
Expand Down
7 changes: 7 additions & 0 deletions Tweak.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
#import <Foundation/Foundation.h>
#include <UIKit/UIKit.h>
#import <LocalAuthentication/LocalAuthentication.h>
#include <spawn.h>
#import <Cephei/HBPreferences.h>
#import "lib/UICKeyChainStore.m"

@interface PUAlbumsGadgetViewController : UIViewController
@end
129 changes: 97 additions & 32 deletions Tweak.x
Original file line number Diff line number Diff line change
@@ -1,28 +1,54 @@
#import <Foundation/Foundation.h>
#include <UIKit/UIKit.h>
#import <LocalAuthentication/LocalAuthentication.h>
#include <spawn.h>
#include <signal.h>
#import "Tweak.h"
#import <Cephei/HBPreferences.h>
#import "lib/UICKeyChainStore.m"

// Thanks to CydaiDEV, Hearse


HBPreferences *preferences;

#define rootVC UIApplication.sharedApplication.keyWindow.rootViewController
LAPolicy policy = LAPolicyDeviceOwnerAuthentication;
NSString *reason = @"Use your passcode to view and manage hidden album.";

BOOL enabled;
BOOL itemCountEnabled;
BOOL passwordAuthEnabled;
BOOL isAuthenticated;
BOOL authOnAppStart;
BOOL accessed = nil;
BOOL popToEnabled;
static BOOL accessed = nil;
static BOOL numeric;
static BOOL userDidLogin;
static BOOL didPresentWC;

double itemCount = 0;

/* iPad
%group iPad
%hook PUSidebarViewController
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"Tapped!");
if (indexPath.row == 9) {
NSLog(@"Tapped indexPath:%ld", indexPath.row);
LAContext *context = [[LAContext alloc] init];
NSError *authError = nil;
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthentication error:&authError]) {
[context evaluatePolicy:LAPolicyDeviceOwnerAuthentication localizedReason:NSLocalizedString(@"Use your passcode to view and manage hidden album.", nil) reply:^(BOOL success, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (success) {
%orig;
} else {
}
});
}];
}
} else {
%orig;
}
}
%end
%end
*/

%group HiddenLock14
%hook PXNavigationListItem
- (id)initWithIdentifier:(id)arg1 title:(id)arg2 itemCount:(long long)arg3{
Expand All @@ -36,42 +62,49 @@ double itemCount = 0;

%hook PXNavigationListGadget
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"Value for userDidLogin: %d", userDidLogin);
//NSLog(@"Section: %ld, Row:%ld, Item:%ld, Desc:%@", indexPath.section, indexPath.row, indexPath.item, indexPath.description);
if ([[[NSUserDefaults alloc] init] boolForKey:@"HiddenAlbumVisible"] == 1) {
NSString *cellLabel = [[[tableView cellForRowAtIndexPath: indexPath] textLabel] text];
if (indexPath.row == 1 && [cellLabel isEqualToString:@"Hidden"]) {
NSLog(@"%@", cellLabel);
LAContext *context = [[LAContext alloc] init];
NSError *authError = nil;
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthentication error:&authError]) {
[context evaluatePolicy:LAPolicyDeviceOwnerAuthentication localizedReason:NSLocalizedString(@"Use your passcode to view and manage hidden album.", nil) reply:^(BOOL success, NSError *error) {
if ([context canEvaluatePolicy:policy error:&authError]) {
[context evaluatePolicy:policy localizedReason:reason reply:^(BOOL success, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (success) {
accessed = YES;
%orig;
} else {
switch (error.code) {
case LAErrorPasscodeNotSet: {
NSLog(@"Passcode Not Set");
UIAlertController *noPw = [UIAlertController alertControllerWithTitle:@"No passcode set!" message:@"You have not set a Authentication method.\n Please proceed setting a password." preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cncl = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {}];
[noPw addAction:cncl];
[rootVC presentViewController:noPw animated:YES completion:nil];
dispatch_async(dispatch_get_main_queue(), ^{
switch(error.code) {
case LAErrorUserFallback:
NSLog(@"UserFallBack!");
break;
}
case LAErrorBiometryNotAvailable: {
NSLog(@"BiometryNotAvailable");

case LAErrorPasscodeNotSet:
NSLog(@"PasscodeNotSet");
break;

case LAErrorAuthenticationFailed:
NSLog(@"Authentication failed!");
break;

case LAErrorUserCancel:
NSLog(@"User did cancel!");
break;
}
});

}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
});
}];
} else {
UIViewController *rootVC = [[[[UIApplication sharedApplication] windows] firstObject] rootViewController];
UICKeyChainStore *keychain = [UICKeyChainStore keyChainStoreWithService:@"com.apple.mobileslideshow"];
if(![[NSUserDefaults standardUserDefaults] boolForKey:@"userDidLogin"] && ![keychain stringForKey:@"hlpassword"]) {
if(![preferences objectForKey:@"userDidLogin"] || ![keychain stringForKey:@"hlpassword"]) {
UIAlertController *authFailed = [UIAlertController alertControllerWithTitle:@"Authentication failed" message:@"You have not set a proper Authentication method.\n Please proceed setting a password." preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {}];
UIAlertAction *authenticateAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
Expand All @@ -88,7 +121,7 @@ double itemCount = 0;
if ([password isEqualToString:passwordDouble]) {
;
[keychain setString:password forKey:@"hlpassword"];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"userDidLogin"];
[preferences setBool:YES forKey:@"userDidLogin"];
%orig;
} else {
UIAlertController *pwMatch = [UIAlertController alertControllerWithTitle:@"Passwords do not match" message:@"Please make sure the passwords you enter match." preferredStyle:UIAlertControllerStyleAlert];
Expand All @@ -103,12 +136,20 @@ double itemCount = 0;
[authFailed addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"Enter a password";
textField.secureTextEntry = YES;
textField.keyboardType = UIKeyboardTypeDefault;
if (numeric) {
textField.keyboardType = UIKeyboardTypeNumberPad;
} else {
textField.keyboardType = UIKeyboardTypeDefault;
}
}];
[authFailed addTextFieldWithConfigurationHandler:^(UITextField *textField1) {
textField1.placeholder = @"Confirm your password";
textField1.secureTextEntry = YES;
textField1.keyboardType = UIKeyboardTypeDefault;
if (numeric) {
textField1.keyboardType = UIKeyboardTypeNumberPad;
} else {
textField1.keyboardType = UIKeyboardTypeDefault;
}
}];
[authFailed addAction:cancel];
[authFailed addAction:authenticateAction];
Expand Down Expand Up @@ -140,7 +181,20 @@ double itemCount = 0;
[pwAuth addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"Password";
textField.secureTextEntry = YES;
textField.keyboardType = UIKeyboardTypeDefault;
UIToolbar* toolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
toolbar.barTintColor = [UIColor colorWithRed:209.0f/255.0f green:212.0f/255.0f blue:217.0f/255.0f alpha:1.0];
toolbar.items = [NSArray arrayWithObjects:
[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
[[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(doneBtn)],nil];
textField.inputAccessoryView = toolbar;
if (numeric) {
textField.keyboardType = UIKeyboardTypeNumberPad;
textField.returnKeyType = UIReturnKeyDone;
} else {
textField.keyboardType = UIKeyboardTypeDefault;
textField.returnKeyType = UIReturnKeyDone;
}
}];
[pwAuth addAction: dismiss1];
[pwAuth addAction:login];
Expand All @@ -157,6 +211,10 @@ double itemCount = 0;
%orig;
}
}
%new
-(void)doneBtn {
[[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
}
%end

%hook PUAlbumsGadgetViewController
Expand All @@ -182,13 +240,17 @@ double itemCount = 0;
%end

void resetPassword() {
UICKeyChainStore *keychain = [UICKeyChainStore keyChainStoreWithService:@"com.apple.mobileslideshow"];
[keychain removeItemForKey:@"hlpassword"];
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"userDidLogin"];
[preferences setBool:NO forKey:@"userDidLogin"];
if ([[[NSBundle mainBundle] bundleIdentifier] isEqual:@"com.apple.mobileslideshow"]) {
UICKeyChainStore *keychain = [UICKeyChainStore keyChainStoreWithService:@"com.apple.mobileslideshow"];
[keychain removeItemForKey:@"hlpassword"];
NSLog(@"received, bool:%d", userDidLogin);
}
}

%ctor {
preferences = [[HBPreferences alloc] initWithIdentifier:@"com.yan.hiddenlock14prefs"];
%init(_ungrouped);
preferences = [[HBPreferences alloc] initWithIdentifier:@"com.yan.hiddenlockpreferences"];
[preferences registerBool:&enabled default:YES forKey:@"enabled"];
if (!enabled) return;

Expand All @@ -197,6 +259,9 @@ void resetPassword() {
[preferences registerBool:&passwordAuthEnabled default:NO forKey:@"passwordAuthEnabled"];
[preferences registerBool:&authOnAppStart default:NO forKey:@"authOnAppStart"];
[preferences registerBool:&popToEnabled default:YES forKey:@"popToEnabled"];
[preferences registerBool:&numeric default:NO forKey:@"numeric"];
[preferences registerBool:&userDidLogin default:nil forKey:@"userDidLogin"];
[preferences registerBool:&didPresentWC default:nil forKey:@"didPresentWC"];

if ([[NSFileManager defaultManager] fileExistsAtPath:@"/.installed_unc0ver"] || [[NSFileManager defaultManager] fileExistsAtPath:@"/.bootstrapped"]) {
if (@available(iOS 14, *)) {
Expand Down Expand Up @@ -225,5 +290,5 @@ void resetPassword() {
}
}
}
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)resetPassword, (CFStringRef)@"com.yan.hiddenlock14/resetPassword", NULL, (CFNotificationSuspensionBehavior)kNilOptions);
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)resetPassword, (CFStringRef)@"com.yan.hiddenlockpreferences/resetPassword", NULL, (CFNotificationSuspensionBehavior)kNilOptions);
}
19 changes: 19 additions & 0 deletions hiddenlockpreferences/HLPRootListController.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,33 @@
#import <CepheiPrefs/HBRootListController.h>
#import <CepheiPrefs/HBAppearanceSettings.h>
#import <Cephei/HBRespringController.h>
#import <Cephei/HBPreferences.h>


@interface HLPRootListController : HBRootListController
@property(nonatomic, retain) UIBarButtonItem *applyButton;
@property(nonatomic, retain) UIView *headerView;
@property(nonatomic, retain) HBPreferences *preferences;
@property(nonatomic, retain) UIImageView *headerImageView;
@property(nonatomic, retain) UIImageView *iconView;
@property(nonatomic, retain) UILabel *titleLabel;
- (void)resetPassword:(id)sender;
//- (void)applySettings;
@end

@interface OBButtonTray : UIView
@property (nonatomic,retain) UIVisualEffectView * effectView;
- (void)addButton:(id)arg1;
- (void)addCaptionText:(id)arg1;;
@end

@interface OBBoldTrayButton : UIButton
-(void)setTitle:(id)arg1 forState:(unsigned long long)arg2;
+(id)buttonWithType:(long long)arg1;
@end

@interface OBWelcomeController : UIViewController
- (OBButtonTray *)buttonTray;
- (id)initWithTitle:(id)arg1 detailText:(id)arg2 icon:(id)arg3;
- (void)addBulletedListItemWithTitle:(id)arg1 description:(id)arg2 image:(id)arg3;
@end
49 changes: 43 additions & 6 deletions hiddenlockpreferences/HLPRootListController.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "HLPRootListController.h"
#import "spawn.h"

OBWelcomeController *welcomeController;

@implementation HLPRootListController

- (instancetype)init {
Expand All @@ -10,6 +12,8 @@ - (instancetype)init {
if (self) {
HBAppearanceSettings *appearanceSettings = [[HBAppearanceSettings alloc] init];

self.preferences = [[HBPreferences alloc] initWithIdentifier:@"com.yan.hiddenlockpreferences"];

self.applyButton = [[UIBarButtonItem alloc] initWithTitle:@"Apply" style: UIBarButtonItemStylePlain target: self action: @selector(applySettings)];
self.applyButton.tintColor = [UIColor whiteColor];
self.navigationItem.rightBarButtonItem= self.applyButton;
Expand Down Expand Up @@ -63,6 +67,40 @@ - (instancetype)init {
return self;
}

- (void)viewDidLoad {
[super viewDidLoad];

if (![[self preferences] objectForKey:@"didPresentWC"]) {
[self setupWelcomeController];
}
}

- (void)setupWelcomeController {
welcomeController = [[OBWelcomeController alloc] initWithTitle:@"HiddenLock14" detailText:@"Add Face ID authentication to hidden album in Photos." icon:[UIImage imageWithContentsOfFile:@"/Library/PreferenceBundles/HiddenLockPreferences.bundle/icon.png"]];

[welcomeController addBulletedListItemWithTitle:@"FaceID" description:@"Lock the hidden section with an additional layer of security" image:[UIImage imageWithContentsOfFile:@"/Library/PreferenceBundles/HiddenLockPreferences.bundle/face-id.png"]];
[welcomeController addBulletedListItemWithTitle:@"Item Count" description:@"Set the item count to any number you want!" image:[UIImage imageWithContentsOfFile:@"/Library/PreferenceBundles/HiddenLockPreferences.bundle/[email protected]"]];
[welcomeController.buttonTray addCaptionText:@"yandevelop"];

OBBoldTrayButton* continueButton = [OBBoldTrayButton buttonWithType:1];
[continueButton addTarget:self action:@selector(dismissWelcomeController) forControlEvents:UIControlEventTouchUpInside];
[continueButton setTitle:@"Experience it yourself!" forState:UIControlStateNormal];
[continueButton setClipsToBounds:YES];
[continueButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[continueButton.layer setCornerRadius:10];
continueButton.tintColor = [UIColor colorWithRed:0.34 green:0.83 blue:0.96 alpha:1.0];
[welcomeController.buttonTray addButton:continueButton];

welcomeController.modalPresentationStyle = UIModalPresentationPageSheet;
welcomeController.view.tintColor = [UIColor blackColor];//[UIColor colorWithRed:0.60 green:0.75 blue:0.85 alpha:1.0];
[self presentViewController:welcomeController animated:YES completion:nil];
}

- (void)dismissWelcomeController {
[[self preferences] setBool:YES forKey:@"didPresentWC"];
[welcomeController dismissViewControllerAnimated:YES completion:nil];
}


- (NSArray *)specifiers {
if (!_specifiers) {
Expand Down Expand Up @@ -113,15 +151,14 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
}

- (void)resetPassword:(id)sender {
UIAlertController *rstPwAlert = [UIAlertController alertControllerWithTitle:@"Reset password" message:@"" preferredStyle:UIAlertControllerStyleAlert];
UIAlertController *rstPwAlert = [UIAlertController alertControllerWithTitle:@"Reset password" message:@"Are you sure you want to reset your password?" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel" style: UIAlertActionStyleCancel handler:^(UIAlertAction * action) {}];
UIAlertAction *rstPwAction = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), (CFStringRef)@"com.yan.hiddenlock14/resetPassword", nil, nil, true);
CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), (CFStringRef)@"com.yan.hiddenlockpreferences/resetPassword", nil, nil, true);
}];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel" style: UIAlertActionStyleCancel handler:^(UIAlertAction * action {}];
[rstPwAlert addAction:rstPwAction];
// declare rootVC / self?
[rootVC presentViewController:rstPwAlert animated:YES completion:nil];

[rstPwAlert addAction:cancel];
[self presentViewController:rstPwAlert animated:YES completion:nil];
}
@end

4 changes: 1 addition & 3 deletions hiddenlockpreferences/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
TARGET := iphone:clang:latest:7.0

include $(THEOS)/makefiles/common.mk

BUNDLE_NAME = HiddenLockPreferences

HiddenLockPreferences_FILES = HLPRootListController.m
HiddenLockPreferences_FRAMEWORKS = UIKit
HiddenLockPreferences_FRAMEWORKS = UIKit OnBoardingKit
HiddenLockPreferences_PRIVATE_FRAMEWORKS = Preferences
HiddenLockPreferences_INSTALL_PATH = /Library/PreferenceBundles
HiddenLockPreferences_CFLAGS = -fobjc-arc
Expand Down
2 changes: 1 addition & 1 deletion hiddenlockpreferences/Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
<key>NSPrincipalClass</key>
<string>HLPRootListController</string>
</dict>
</plist>
</plist>
Loading

0 comments on commit d32f336

Please sign in to comment.