Skip to content

Commit

Permalink
fix slider
Browse files Browse the repository at this point in the history
  • Loading branch information
hrtowii committed Jan 19, 2024
1 parent f785142 commit 8d319f0
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 61 deletions.
44 changes: 2 additions & 42 deletions RootHelperSample/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,6 @@ uint64_t resolve_jbrand_value(const char* name)
return [usprebooterPath() stringByAppendingPathComponent:@"usprebooter.app"];
}

//BOOL isLdidInstalled(void)
//{
// NSString* ldidPath = [trollStoreAppPath() stringByAppendingPathComponent:@"ldid"];
// return [[NSFileManager defaultManager] fileExistsAtPath:ldidPath];
//}

int runLdid(NSArray* args, NSString** output, NSString** errorOutput)
{
NSString* ldidPath = [usprebooterappPath() stringByAppendingPathComponent:@"ldid"];
Expand Down Expand Up @@ -184,37 +178,13 @@ int runLdid(NSArray* args, NSString** output, NSString** errorOutput)

int signAdhoc(NSString *filePath, NSString *entitlements) // lets just assume ldid is included ok
{
// if(!isLdidInstalled()) return 173;

// NSString *entitlementsPath = nil;
NSString *signArg = @"-S";
NSString* errorOutput;
if(entitlements) {
// NSData *entitlementsXML = [NSPropertyListSerialization dataWithPropertyList:entitlements format:NSPropertyListXMLFormat_v1_0 options:0 error:nil];
// if (entitlementsXML) {
// entitlementsPath = [[NSTemporaryDirectory() stringByAppendingPathComponent:[NSUUID UUID].UUIDString] stringByAppendingPathExtension:@"plist"];
// [entitlementsXML writeToFile:entitlementsPath atomically:NO];
signArg = [signArg stringByAppendingString:entitlements];
// signArg = [signArg stringByAppendingString:@" -Cadhoc"];
// signArg = [signArg stringByAppendingString:@" -M"];
// signArg = [signArg stringByAppendingString:@"/sbin/launchd"];
// }
}
NSLog(@"roothelper: running ldid");
int ldidRet = runLdid(@[signArg, filePath], nil, &errorOutput);
// if (entitlementsPath) {
// [[NSFileManager defaultManager] removeItemAtPath:entitlementsPath error:nil];
// }

// NSLog(@"roothelper: ldid exited with status %d", ldidRet);
//
// NSLog(@"roothelper: - ldid error output start -");
//
// printMultilineNSString(signArg);
// printMultilineNSString(errorOutput);
//
// NSLog(@"roothelper: - ldid error output end -");

if(ldidRet == 0)
{
return 0;
Expand All @@ -223,7 +193,6 @@ int signAdhoc(NSString *filePath, NSString *entitlements) // lets just assume ld
{
return 175;
}
//}
}

NSSet<NSString*>* immutableAppBundleIdentifiers(void)
Expand All @@ -248,18 +217,9 @@ int signAdhoc(NSString *filePath, NSString *entitlements) // lets just assume ld

void replaceByte(NSString *filePath, int offset, const char *replacement) {
const char *fileCString = [filePath UTF8String];

FILE *file = fopen(fileCString, "r+");

if (file == NULL) {
NSLog(@"Error opening workinglaunchd");
perror("Error opening file");
return;
}

fseek(file, offset, SEEK_SET);
fwrite(replacement, sizeof(char), 4, file);

fclose(file);
}

Expand All @@ -275,7 +235,7 @@ void removeItemAtPathRecursively(NSString *path) {
if (error == nil) {
for (NSString *item in contents) {
if ([item isEqualToString:@".jbroot"]) {
NSLog(@"Skipping deletion of %@ in %@", item, path);
// NSLog(@"Skipping deletion of %@ in %@", item, path);
continue;
}
NSString *itemPath = [path stringByAppendingPathComponent:item];
Expand Down Expand Up @@ -397,7 +357,7 @@ int main(int argc, char *argv[], char *envp[]) {
[[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
return 2;
}
} else if ([action isEqual: @"hideText"]) {
} else if ([action isEqual: @"toggleText"]) {
NSString *filePath = @"/var/mobile/.serotonin_hidetext";
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:filePath];
if (!fileExists) {
Expand Down
6 changes: 3 additions & 3 deletions Serotonin.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -218,19 +218,19 @@
C8B1D3A52B5A620500C5562B /* SettingsManager.swift */,
C8B1D3952B5A620500C5562B /* UI */,
C82AFEF32B175AB80070EA49 /* Assets.xcassets */,
C82599EF2B4C4C07002D0DDA /* Serotonin.jp2 */,
C84002E82B4A55A300C73950 /* springboardshimsignedinjected */,
C82AFF422B17AA6C0070EA49 /* ldid */,
C8BFCC772B3FFE560008D8FD /* fun */,
C81122AB2B15E7BD00AD077B /* Info.plist */,
C84002EC2B4A64E200C73950 /* launchdentitlements.plist */,
C82AFF422B17AA6C0070EA49 /* ldid */,
C8BFCC902B3FFE560008D8FD /* libkfd */,
C8BFCCA32B3FFE570008D8FD /* libkfd.h */,
013142012B445B48006BEBE9 /* memoryControl.h */,
013141FE2B445B26006BEBE9 /* memoryControl.m */,
C83594D32B18F80300346F80 /* overwriter.h */,
C83594CE2B18F70700346F80 /* overwriter.m */,
D6E090912B48E60300AE49BF /* Private Headers I stole from the macOS SDK */,
C82599EF2B4C4C07002D0DDA /* Serotonin.jp2 */,
C84002E82B4A55A300C73950 /* springboardshimsignedinjected */,
C81122DD2B16C9CB00AD077B /* troller.h */,
C81122DE2B16C9CC00AD077B /* troller.m */,
C81122CF2B15EA8600AD077B /* usprebooter-Bridging-Header.h */,
Expand Down
16 changes: 12 additions & 4 deletions usprebooter/SettingsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@ class SettingsManager {
private init() {}

static let didStaticHeadroomChange = Notification.Name("didFontSizeChange")
static let didPuafPagesChange = Notification.Name("didFontSizeChange")

private var _staticHeadroom: Int? {
didSet { NotificationCenter.default.post(name: SettingsManager.didStaticHeadroomChange, object: nil) }
}

private var _puafPages: Int? {
didSet { NotificationCenter.default.post(name: SettingsManager.didPuafPagesChange, object: nil) }
}

var staticHeadroom: Int {
get { return _staticHeadroom ?? UserDefaults.standard.value(forKey: "staticHeadroom") as? Int ?? 512 }
set {
Expand All @@ -43,9 +48,12 @@ class SettingsManager {
set { UserDefaults.standard.set(newValue, forKey: "hideInternalText") }
}

var puafPages: Bool {
get { return UserDefaults.standard.bool(forKey: "puafPages", defaultValue: false) }
set { UserDefaults.standard.set(newValue, forKey: "puafPages") }
var puafPages: Int {
get { return _puafPages ?? UserDefaults.standard.value(forKey: "puafPages") as? Int ?? 512 }
set {
_puafPages = newValue
UserDefaults.standard.set(newValue, forKey: "puafPages")
}
}
}

Expand All @@ -63,6 +71,6 @@ extension SettingsManager {
isBetaIos = false
verboseBoot = true
hideInternalText = true
puafPages = false
puafPages = 4096
}
}
45 changes: 33 additions & 12 deletions usprebooter/UI/Tabs/OptionsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,20 @@ class OptionsViewController: UIViewController, UITableViewDelegate, UITableViewD
slider.value = Float(settingsManager.staticHeadroom)
slider.minimumValue = 0
slider.maximumValue = 1920
slider.addTarget(self, action: #selector(sliderValueChanged(_:)), for: .valueChanged)
slider.addTarget(self, action: #selector(headroomValueChanged(_:)), for: .valueChanged)

cell.accessoryView = slider
cell.detailTextLabel?.text = "\(settingsManager.staticHeadroom) MB"

case "PUAF Pages":
let switchView = UISwitch()
switchView.isOn = switchStateForSetting(cellText)
switchView.addTarget(self, action: #selector(switchChanged), for: .valueChanged)
cell.accessoryView = switchView
cell.detailTextLabel?.text = "3072"
// I have no idea how this works, but figure it out!
let slider = UISlider()
slider.value = Float(settingsManager.puafPages)
slider.minimumValue = 512
slider.maximumValue = 32768
slider.addTarget(self, action: #selector(puafValueChanged(_:)), for: .valueChanged)

cell.accessoryView = slider
cell.detailTextLabel?.text = "\(settingsManager.puafPages) MB"

case "Beta iOS", "Verbose Boot", "Hide Internal Text":
let switchView = UISwitch()
Expand All @@ -113,7 +115,7 @@ class OptionsViewController: UIViewController, UITableViewDelegate, UITableViewD
return cell
}

@objc func sliderValueChanged(_ sender: UISlider) {
@objc func headroomValueChanged(_ sender: UISlider) {
let step: Float = 128
let roundedValue = round(sender.value / step) * step
sender.value = roundedValue
Expand All @@ -132,6 +134,25 @@ class OptionsViewController: UIViewController, UITableViewDelegate, UITableViewD
}
}

@objc func puafValueChanged(_ sender: UISlider) {
let step: Float = 128
let roundedValue = round(sender.value / step) * step
sender.value = roundedValue

let value = Int(roundedValue)
settingsManager.puafPages = value

if let sectionIndex = sectionTitles.firstIndex(of: "Exploit"),
let rowIndex = tableData[sectionIndex].firstIndex(of: "PUAF Pages") {

let indexPath = IndexPath(row: rowIndex, section: sectionIndex)

if let cell = tableView.cellForRow(at: indexPath) {
cell.detailTextLabel?.text = "\(value) MB"
}
}
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cellText = tableData[indexPath.section][indexPath.row]

Expand Down Expand Up @@ -163,8 +184,8 @@ class OptionsViewController: UIViewController, UITableViewDelegate, UITableViewD
if let indexPath = tableView.indexPath(for: cell) {
let setting = tableData[indexPath.section][indexPath.row]
switch setting {
case "PUAF Pages":
settingsManager.puafPages = sender.isOn
// case "PUAF Pages":
// settingsManager.puafPages = sender.isOn
case "Beta iOS":
settingsManager.isBetaIos = sender.isOn
case "Verbose Boot":
Expand All @@ -179,8 +200,8 @@ class OptionsViewController: UIViewController, UITableViewDelegate, UITableViewD

private func switchStateForSetting(_ setting: String) -> Bool {
switch setting {
case "PUAF Pages":
return settingsManager.puafPages
// case "PUAF Pages":
// return settingsManager.puafPages
case "Beta iOS":
return settingsManager.isBetaIos
case "Verbose Boot":
Expand Down

0 comments on commit 8d319f0

Please sign in to comment.