added files via upload

This commit is contained in:
Balackburn
2023-06-27 09:54:41 +02:00
commit 2ff6aac218
1420 changed files with 88898 additions and 0 deletions

View File

@@ -0,0 +1,105 @@
//
// FLEXGlobalsEntry.h
// FLEX
//
// Created by Javier Soto on 7/26/14.
// Copyright (c) 2020 FLEX Team. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSUInteger, FLEXGlobalsRow) {
FLEXGlobalsRowProcessInfo,
FLEXGlobalsRowNetworkHistory,
FLEXGlobalsRowSystemLog,
FLEXGlobalsRowLiveObjects,
FLEXGlobalsRowAddressInspector,
FLEXGlobalsRowCookies,
FLEXGlobalsRowBrowseRuntime,
FLEXGlobalsRowAppKeychainItems,
FLEXGlobalsRowAppDelegate,
FLEXGlobalsRowRootViewController,
FLEXGlobalsRowUserDefaults,
FLEXGlobalsRowMainBundle,
FLEXGlobalsRowBrowseBundle,
FLEXGlobalsRowBrowseContainer,
FLEXGlobalsRowApplication,
FLEXGlobalsRowKeyWindow,
FLEXGlobalsRowMainScreen,
FLEXGlobalsRowCurrentDevice,
FLEXGlobalsRowPasteboard,
FLEXGlobalsRowURLSession,
FLEXGlobalsRowURLCache,
FLEXGlobalsRowNotificationCenter,
FLEXGlobalsRowMenuController,
FLEXGlobalsRowFileManager,
FLEXGlobalsRowTimeZone,
FLEXGlobalsRowLocale,
FLEXGlobalsRowCalendar,
FLEXGlobalsRowMainRunLoop,
FLEXGlobalsRowMainThread,
FLEXGlobalsRowOperationQueue,
FLEXGlobalsRowCount
};
typedef NSString * _Nonnull (^FLEXGlobalsEntryNameFuture)(void);
/// Simply return a view controller to be pushed on the navigation stack
typedef UIViewController * _Nullable (^FLEXGlobalsEntryViewControllerFuture)(void);
/// Do something like present an alert, then use the host
/// view controller to present or push another view controller.
typedef void (^FLEXGlobalsEntryRowAction)(__kindof UITableViewController * _Nonnull host);
/// For view controllers to conform to to indicate they support being used
/// in the globals table view controller. These methods help create concrete entries.
///
/// Previously, the concrete entries relied on "futures" for the view controller and title.
/// With this protocol, the conforming class itself can act as a future, since the methods
/// will not be invoked until the title and view controller / row action are needed.
///
/// Entries can implement \c globalsEntryViewController: to unconditionally provide a
/// view controller, or \c globalsEntryRowAction: to conditionally provide one and
/// perform some action (such as present an alert) if no view controller is available,
/// or both if there is a mix of rows where some are guaranteed to work and some are not.
/// Where both are implemented, \c globalsEntryRowAction: takes precedence; if it returns
/// an action for the requested row, that will be used instead of \c globalsEntryViewController:
@protocol FLEXGlobalsEntry <NSObject>
+ (NSString *)globalsEntryTitle:(FLEXGlobalsRow)row;
// Must respond to at least one of the below.
// globalsEntryRowAction: takes precedence if both are implemented.
@optional
+ (nullable UIViewController *)globalsEntryViewController:(FLEXGlobalsRow)row;
+ (nullable FLEXGlobalsEntryRowAction)globalsEntryRowAction:(FLEXGlobalsRow)row;
@end
@interface FLEXGlobalsEntry : NSObject
@property (nonatomic, readonly, nonnull) FLEXGlobalsEntryNameFuture entryNameFuture;
@property (nonatomic, readonly, nullable) FLEXGlobalsEntryViewControllerFuture viewControllerFuture;
@property (nonatomic, readonly, nullable) FLEXGlobalsEntryRowAction rowAction;
+ (instancetype)entryWithEntry:(Class<FLEXGlobalsEntry>)entry row:(FLEXGlobalsRow)row;
+ (instancetype)entryWithNameFuture:(FLEXGlobalsEntryNameFuture)nameFuture
viewControllerFuture:(FLEXGlobalsEntryViewControllerFuture)viewControllerFuture;
+ (instancetype)entryWithNameFuture:(FLEXGlobalsEntryNameFuture)nameFuture
action:(FLEXGlobalsEntryRowAction)rowSelectedAction;
@end
@interface NSObject (FLEXGlobalsEntry)
/// @return The result of passing self to +[FLEXGlobalsEntry entryWithEntry:]
/// if the class conforms to FLEXGlobalsEntry, else, nil.
+ (nullable FLEXGlobalsEntry *)flex_concreteGlobalsEntry:(FLEXGlobalsRow)row;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,86 @@
//
// FLEXGlobalsEntry.m
// FLEX
//
// Created by Javier Soto on 7/26/14.
// Copyright (c) 2020 FLEX Team. All rights reserved.
//
#import "FLEXGlobalsEntry.h"
@implementation FLEXGlobalsEntry
+ (instancetype)entryWithEntry:(Class<FLEXGlobalsEntry>)cls row:(FLEXGlobalsRow)row {
BOOL providesVCs = [cls respondsToSelector:@selector(globalsEntryViewController:)];
BOOL providesActions = [cls respondsToSelector:@selector(globalsEntryRowAction:)];
NSParameterAssert(cls);
NSParameterAssert(providesVCs || providesActions);
FLEXGlobalsEntry *entry = [self new];
entry->_entryNameFuture = ^{ return [cls globalsEntryTitle:row]; };
if (providesVCs) {
id action = providesActions ? [cls globalsEntryRowAction:row] : nil;
if (action) {
entry->_rowAction = action;
} else {
entry->_viewControllerFuture = ^{ return [cls globalsEntryViewController:row]; };
}
} else {
entry->_rowAction = [cls globalsEntryRowAction:row];
}
return entry;
}
+ (instancetype)entryWithNameFuture:(FLEXGlobalsEntryNameFuture)nameFuture
viewControllerFuture:(FLEXGlobalsEntryViewControllerFuture)viewControllerFuture {
NSParameterAssert(nameFuture);
NSParameterAssert(viewControllerFuture);
FLEXGlobalsEntry *entry = [self new];
entry->_entryNameFuture = [nameFuture copy];
entry->_viewControllerFuture = [viewControllerFuture copy];
return entry;
}
+ (instancetype)entryWithNameFuture:(FLEXGlobalsEntryNameFuture)nameFuture
action:(FLEXGlobalsEntryRowAction)rowSelectedAction {
NSParameterAssert(nameFuture);
NSParameterAssert(rowSelectedAction);
FLEXGlobalsEntry *entry = [self new];
entry->_entryNameFuture = [nameFuture copy];
entry->_rowAction = [rowSelectedAction copy];
return entry;
}
@end
@interface FLEXGlobalsEntry (Debugging)
@property (nonatomic, readonly) NSString *name;
@end
@implementation FLEXGlobalsEntry (Debugging)
- (NSString *)name {
return self.entryNameFuture();
}
@end
#pragma mark - flex_concreteGlobalsEntry
@implementation NSObject (FLEXGlobalsEntry)
+ (FLEXGlobalsEntry *)flex_concreteGlobalsEntry:(FLEXGlobalsRow)row {
if ([self conformsToProtocol:@protocol(FLEXGlobalsEntry)]) {
return [FLEXGlobalsEntry entryWithEntry:self row:row];
}
return nil;
}
@end

View File

@@ -0,0 +1,20 @@
//
// FLEXGlobalsSection.h
// FLEX
//
// Created by Tanner Bennett on 7/11/19.
// Copyright © 2020 FLEX Team. All rights reserved.
//
#import "FLEXTableViewSection.h"
#import "FLEXGlobalsEntry.h"
NS_ASSUME_NONNULL_BEGIN
@interface FLEXGlobalsSection : FLEXTableViewSection
+ (instancetype)title:(NSString *)title rows:(NSArray<FLEXGlobalsEntry *> *)rows;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,86 @@
//
// FLEXGlobalsSection.m
// FLEX
//
// Created by Tanner Bennett on 7/11/19.
// Copyright © 2020 FLEX Team. All rights reserved.
//
#import "FLEXGlobalsSection.h"
#import "NSArray+FLEX.h"
#import "UIFont+FLEX.h"
@interface FLEXGlobalsSection ()
/// Filtered rows
@property (nonatomic) NSArray<FLEXGlobalsEntry *> *rows;
/// Unfiltered rows
@property (nonatomic) NSArray<FLEXGlobalsEntry *> *allRows;
@end
@implementation FLEXGlobalsSection
#pragma mark - Initialization
+ (instancetype)title:(NSString *)title rows:(NSArray<FLEXGlobalsEntry *> *)rows {
FLEXGlobalsSection *s = [self new];
s->_title = title;
s.allRows = rows;
return s;
}
- (void)setAllRows:(NSArray<FLEXGlobalsEntry *> *)allRows {
_allRows = allRows.copy;
[self reloadData];
}
#pragma mark - Overrides
- (NSInteger)numberOfRows {
return self.rows.count;
}
- (void)setFilterText:(NSString *)filterText {
super.filterText = filterText;
[self reloadData];
}
- (void)reloadData {
NSString *filterText = self.filterText;
if (filterText.length) {
self.rows = [self.allRows flex_filtered:^BOOL(FLEXGlobalsEntry *entry, NSUInteger idx) {
return [entry.entryNameFuture() localizedCaseInsensitiveContainsString:filterText];
}];
} else {
self.rows = self.allRows;
}
}
- (BOOL)canSelectRow:(NSInteger)row {
return YES;
}
- (void (^)(__kindof UIViewController *))didSelectRowAction:(NSInteger)row {
return (id)self.rows[row].rowAction;
}
- (UIViewController *)viewControllerToPushForRow:(NSInteger)row {
return self.rows[row].viewControllerFuture ? self.rows[row].viewControllerFuture() : nil;
}
- (void)configureCell:(__kindof UITableViewCell *)cell forRow:(NSInteger)row {
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.font = UIFont.flex_defaultTableCellFont;
cell.textLabel.text = self.rows[row].entryNameFuture();
}
@end
@implementation FLEXGlobalsSection (Subscripting)
- (id)objectAtIndexedSubscript:(NSUInteger)idx {
return self.rows[idx];
}
@end

View File

@@ -0,0 +1,28 @@
//
// FLEXGlobalsViewController.h
// Flipboard
//
// Created by Ryan Olson on 2014-05-03.
// Copyright (c) 2020 FLEX Team. All rights reserved.
//
#import "FLEXFilteringTableViewController.h"
@protocol FLEXGlobalsTableViewControllerDelegate;
typedef NS_ENUM(NSUInteger, FLEXGlobalsSectionKind) {
FLEXGlobalsSectionCustom,
/// NSProcessInfo, Network history, system log,
/// heap, address explorer, libraries, app classes
FLEXGlobalsSectionProcessAndEvents,
/// Browse container, browse bundle, NSBundle.main,
/// NSUserDefaults.standard, UIApplication,
/// app delegate, key window, root VC, cookies
FLEXGlobalsSectionAppShortcuts,
/// UIPasteBoard.general, UIScreen, UIDevice
FLEXGlobalsSectionMisc,
FLEXGlobalsSectionCount
};
@interface FLEXGlobalsViewController : FLEXFilteringTableViewController
@end

View File

@@ -0,0 +1,200 @@
//
// FLEXGlobalsViewController.m
// Flipboard
//
// Created by Ryan Olson on 2014-05-03.
// Copyright (c) 2020 FLEX Team. All rights reserved.
//
#import "FLEXGlobalsViewController.h"
#import "FLEXUtility.h"
#import "FLEXRuntimeUtility.h"
#import "FLEXObjcRuntimeViewController.h"
#import "FLEXKeychainViewController.h"
#import "FLEXObjectExplorerViewController.h"
#import "FLEXObjectExplorerFactory.h"
#import "FLEXLiveObjectsController.h"
#import "FLEXFileBrowserController.h"
#import "FLEXCookiesViewController.h"
#import "FLEXGlobalsEntry.h"
#import "FLEXManager+Private.h"
#import "FLEXSystemLogViewController.h"
#import "FLEXNetworkMITMViewController.h"
#import "FLEXAddressExplorerCoordinator.h"
#import "FLEXGlobalsSection.h"
#import "UIBarButtonItem+FLEX.h"
@interface FLEXGlobalsViewController ()
/// Only displayed sections of the table view; empty sections are purged from this array.
@property (nonatomic) NSArray<FLEXGlobalsSection *> *sections;
/// Every section in the table view, regardless of whether or not a section is empty.
@property (nonatomic, readonly) NSArray<FLEXGlobalsSection *> *allSections;
@property (nonatomic, readonly) BOOL manuallyDeselectOnAppear;
@end
@implementation FLEXGlobalsViewController
@dynamic sections, allSections;
#pragma mark - Initialization
+ (NSString *)globalsTitleForSection:(FLEXGlobalsSectionKind)section {
switch (section) {
case FLEXGlobalsSectionCustom:
return @"Custom Additions";
case FLEXGlobalsSectionProcessAndEvents:
return @"Process and Events";
case FLEXGlobalsSectionAppShortcuts:
return @"App Shortcuts";
case FLEXGlobalsSectionMisc:
return @"Miscellaneous";
default:
@throw NSInternalInconsistencyException;
}
}
+ (FLEXGlobalsEntry *)globalsEntryForRow:(FLEXGlobalsRow)row {
switch (row) {
case FLEXGlobalsRowAppKeychainItems:
return [FLEXKeychainViewController flex_concreteGlobalsEntry:row];
case FLEXGlobalsRowAddressInspector:
return [FLEXAddressExplorerCoordinator flex_concreteGlobalsEntry:row];
case FLEXGlobalsRowBrowseRuntime:
return [FLEXObjcRuntimeViewController flex_concreteGlobalsEntry:row];
case FLEXGlobalsRowLiveObjects:
return [FLEXLiveObjectsController flex_concreteGlobalsEntry:row];
case FLEXGlobalsRowCookies:
return [FLEXCookiesViewController flex_concreteGlobalsEntry:row];
case FLEXGlobalsRowBrowseBundle:
case FLEXGlobalsRowBrowseContainer:
return [FLEXFileBrowserController flex_concreteGlobalsEntry:row];
case FLEXGlobalsRowSystemLog:
return [FLEXSystemLogViewController flex_concreteGlobalsEntry:row];
case FLEXGlobalsRowNetworkHistory:
return [FLEXNetworkMITMViewController flex_concreteGlobalsEntry:row];
case FLEXGlobalsRowKeyWindow:
case FLEXGlobalsRowRootViewController:
case FLEXGlobalsRowProcessInfo:
case FLEXGlobalsRowAppDelegate:
case FLEXGlobalsRowUserDefaults:
case FLEXGlobalsRowMainBundle:
case FLEXGlobalsRowApplication:
case FLEXGlobalsRowMainScreen:
case FLEXGlobalsRowCurrentDevice:
case FLEXGlobalsRowPasteboard:
case FLEXGlobalsRowURLSession:
case FLEXGlobalsRowURLCache:
case FLEXGlobalsRowNotificationCenter:
case FLEXGlobalsRowMenuController:
case FLEXGlobalsRowFileManager:
case FLEXGlobalsRowTimeZone:
case FLEXGlobalsRowLocale:
case FLEXGlobalsRowCalendar:
case FLEXGlobalsRowMainRunLoop:
case FLEXGlobalsRowMainThread:
case FLEXGlobalsRowOperationQueue:
return [FLEXObjectExplorerFactory flex_concreteGlobalsEntry:row];
default:
@throw [NSException
exceptionWithName:NSInternalInconsistencyException
reason:@"Missing globals case in switch" userInfo:nil
];
}
}
+ (NSArray<FLEXGlobalsSection *> *)defaultGlobalSections {
static NSMutableArray<FLEXGlobalsSection *> *sections = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSDictionary<NSNumber *, NSArray<FLEXGlobalsEntry *> *> *rowsBySection = @{
@(FLEXGlobalsSectionProcessAndEvents) : @[
[self globalsEntryForRow:FLEXGlobalsRowNetworkHistory],
[self globalsEntryForRow:FLEXGlobalsRowSystemLog],
[self globalsEntryForRow:FLEXGlobalsRowProcessInfo],
[self globalsEntryForRow:FLEXGlobalsRowLiveObjects],
[self globalsEntryForRow:FLEXGlobalsRowAddressInspector],
[self globalsEntryForRow:FLEXGlobalsRowBrowseRuntime],
],
@(FLEXGlobalsSectionAppShortcuts) : @[
[self globalsEntryForRow:FLEXGlobalsRowBrowseBundle],
[self globalsEntryForRow:FLEXGlobalsRowBrowseContainer],
[self globalsEntryForRow:FLEXGlobalsRowMainBundle],
[self globalsEntryForRow:FLEXGlobalsRowUserDefaults],
[self globalsEntryForRow:FLEXGlobalsRowAppKeychainItems],
[self globalsEntryForRow:FLEXGlobalsRowApplication],
[self globalsEntryForRow:FLEXGlobalsRowAppDelegate],
[self globalsEntryForRow:FLEXGlobalsRowKeyWindow],
[self globalsEntryForRow:FLEXGlobalsRowRootViewController],
[self globalsEntryForRow:FLEXGlobalsRowCookies],
],
@(FLEXGlobalsSectionMisc) : @[
[self globalsEntryForRow:FLEXGlobalsRowPasteboard],
[self globalsEntryForRow:FLEXGlobalsRowMainScreen],
[self globalsEntryForRow:FLEXGlobalsRowCurrentDevice],
[self globalsEntryForRow:FLEXGlobalsRowURLSession],
[self globalsEntryForRow:FLEXGlobalsRowURLCache],
[self globalsEntryForRow:FLEXGlobalsRowNotificationCenter],
[self globalsEntryForRow:FLEXGlobalsRowMenuController],
[self globalsEntryForRow:FLEXGlobalsRowFileManager],
[self globalsEntryForRow:FLEXGlobalsRowTimeZone],
[self globalsEntryForRow:FLEXGlobalsRowLocale],
[self globalsEntryForRow:FLEXGlobalsRowCalendar],
[self globalsEntryForRow:FLEXGlobalsRowMainRunLoop],
[self globalsEntryForRow:FLEXGlobalsRowMainThread],
[self globalsEntryForRow:FLEXGlobalsRowOperationQueue],
]
};
sections = [NSMutableArray array];
for (FLEXGlobalsSectionKind i = FLEXGlobalsSectionCustom + 1; i < FLEXGlobalsSectionCount; ++i) {
NSString *title = [self globalsTitleForSection:i];
[sections addObject:[FLEXGlobalsSection title:title rows:rowsBySection[@(i)]]];
}
});
return sections;
}
#pragma mark - Overrides
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"💪 FLEX";
self.showsSearchBar = YES;
self.searchBarDebounceInterval = kFLEXDebounceInstant;
self.navigationItem.backBarButtonItem = [UIBarButtonItem flex_backItemWithTitle:@"Back"];
_manuallyDeselectOnAppear = NSProcessInfo.processInfo.operatingSystemVersion.majorVersion < 10;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self disableToolbar];
if (self.manuallyDeselectOnAppear) {
[self.tableView deselectRowAtIndexPath:self.tableView.indexPathForSelectedRow animated:YES];
}
}
- (NSArray<FLEXGlobalsSection *> *)makeSections {
NSMutableArray<FLEXGlobalsSection *> *sections = [NSMutableArray array];
// Do we have custom sections to add?
if (FLEXManager.sharedManager.userGlobalEntries.count) {
NSString *title = [[self class] globalsTitleForSection:FLEXGlobalsSectionCustom];
FLEXGlobalsSection *custom = [FLEXGlobalsSection
title:title
rows:FLEXManager.sharedManager.userGlobalEntries
];
[sections addObject:custom];
}
[sections addObjectsFromArray:[self.class defaultGlobalSections]];
return sections;
}
@end