Skip to content

Commit

Permalink
Add Jetsam limit selector
Browse files Browse the repository at this point in the history
  • Loading branch information
opa334 committed Jul 27, 2024
1 parent 1272706 commit 13ecfbf
Show file tree
Hide file tree
Showing 20 changed files with 255 additions and 98 deletions.
8 changes: 8 additions & 0 deletions Application/Dopamine.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@
8C5FA9712BDD81EF008C246F /* LICENSE_weightBufs.md in Resources */ = {isa = PBXBuildFile; fileRef = 8C5FA9702BDD81EF008C246F /* LICENSE_weightBufs.md */; };
8C609C9E2C19B4270023DD12 /* NSString+Version.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C609C9C2C19AECF0023DD12 /* NSString+Version.m */; };
8C609C9F2C19B6FA0023DD12 /* libkrw-dopamine.deb in Resources */ = {isa = PBXBuildFile; fileRef = 8C609C992C19AC250023DD12 /* libkrw-dopamine.deb */; };
8C6599DB2C555A60000FF57F /* DOPSJetsamListItemsController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C6599DA2C555A60000FF57F /* DOPSJetsamListItemsController.m */; };
8C6599DD2C555A71000FF57F /* DOPSJetsamListItemsController.h in Sources */ = {isa = PBXBuildFile; fileRef = 8C6599DC2C555A71000FF57F /* DOPSJetsamListItemsController.h */; };
8C71981A2ABF0E82003C6658 /* DOAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C7198192ABF0E82003C6658 /* DOAppDelegate.m */; };
8C71981D2ABF0E82003C6658 /* DOSceneDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C71981C2ABF0E82003C6658 /* DOSceneDelegate.m */; };
8C7198252ABF0E84003C6658 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8C7198242ABF0E84003C6658 /* Assets.xcassets */; };
Expand Down Expand Up @@ -506,6 +508,8 @@
8C609C992C19AC250023DD12 /* libkrw-dopamine.deb */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libkrw-dopamine.deb"; path = "../../../Packages/libkrw-provider/libkrw-dopamine.deb"; sourceTree = "<group>"; };
8C609C9C2C19AECF0023DD12 /* NSString+Version.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSString+Version.m"; sourceTree = "<group>"; };
8C609C9D2C19AEE70023DD12 /* NSString+Version.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSString+Version.h"; sourceTree = "<group>"; };
8C6599DA2C555A60000FF57F /* DOPSJetsamListItemsController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DOPSJetsamListItemsController.m; sourceTree = "<group>"; };
8C6599DC2C555A71000FF57F /* DOPSJetsamListItemsController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DOPSJetsamListItemsController.h; sourceTree = "<group>"; };
8C7198152ABF0E82003C6658 /* Dopamine.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Dopamine.app; sourceTree = BUILT_PRODUCTS_DIR; };
8C7198182ABF0E82003C6658 /* DOAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DOAppDelegate.h; sourceTree = "<group>"; };
8C7198192ABF0E82003C6658 /* DOAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DOAppDelegate.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -724,6 +728,8 @@
0443A9AF2B79D9C10014C933 /* DOPSListItemsController.m */,
8C296BAA2BE049E4007C2AD1 /* DOPSExploitListItemsController.h */,
8C296BAB2BE049E4007C2AD1 /* DOPSExploitListItemsController.m */,
8C6599DC2C555A71000FF57F /* DOPSJetsamListItemsController.h */,
8C6599DA2C555A60000FF57F /* DOPSJetsamListItemsController.m */,
);
path = PSLists;
sourceTree = "<group>";
Expand Down Expand Up @@ -1660,10 +1666,12 @@
files = (
8C609C9E2C19B4270023DD12 /* NSString+Version.m in Sources */,
042479A62B66916B0082581B /* DOHeaderCell.m in Sources */,
8C6599DD2C555A71000FF57F /* DOPSJetsamListItemsController.h in Sources */,
042479A22B66916B0082581B /* DOCreditsViewController.m in Sources */,
042479B32B66916B0082581B /* DODebugLogView.m in Sources */,
042479AF2B66916B0082581B /* DONavigationController.m in Sources */,
04C246AE2B74ACA200E17924 /* DOAppSwitch.m in Sources */,
8C6599DB2C555A60000FF57F /* DOPSJetsamListItemsController.m in Sources */,
042479B22B66916B0082581B /* DOLyricsLogView.m in Sources */,
042479A52B66916B0082581B /* DOCreditsCell.m in Sources */,
8C296BAC2BE049E4007C2AD1 /* DOPSExploitListItemsController.m in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions Application/Dopamine/Jailbreak/DOJailbreaker.m
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ - (void)runWithError:(NSError **)errOut didRemoveJailbreak:(BOOL*)didRemove show
BOOL tweaksEnabled = [[DOPreferenceManager sharedManager] boolPreferenceValueForKey:@"tweakInjectionEnabled" fallback:YES];
BOOL idownloadEnabled = [[DOPreferenceManager sharedManager] boolPreferenceValueForKey:@"idownloadEnabled" fallback:NO];
BOOL appJITEnabled = [[DOPreferenceManager sharedManager] boolPreferenceValueForKey:@"appJITEnabled" fallback:YES];
NSNumber *jetsamMultiplierOption = [[DOPreferenceManager sharedManager] preferenceValueForKey:@"jetsamMultiplier"];

struct utsname systemInfo;
uname(&systemInfo);
Expand All @@ -489,6 +490,7 @@ - (void)runWithError:(NSError **)errOut didRemoveJailbreak:(BOOL*)didRemove show
if (*errOut) return;

gSystemInfo.jailbreakSettings.markAppsAsDebugged = appJITEnabled;
gSystemInfo.jailbreakSettings.jetsamMultiplier = jetsamMultiplierOption ? (jetsamMultiplierOption.doubleValue / 2) : 0;

[[DOUIManager sharedInstance] sendLog:DOLocalizedString(@"Building Phys R/W Primitive") debug:NO];
*errOut = [self buildPhysRWPrimitive];
Expand Down
57 changes: 56 additions & 1 deletion Application/Dopamine/UI/Settings/DOSettingsController.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#import "DOPSExploitListItemsController.h"
#import "DOThemeManager.h"
#import "DOSceneDelegate.h"
#import "DOPSJetsamListItemsController.h"


@interface DOSettingsController ()
Expand Down Expand Up @@ -115,6 +116,32 @@ - (NSArray *)themeNames
return [[DOThemeManager sharedInstance] getAvailableThemeNames];
}

- (NSArray *)jetsamOptionNumbers
{
return @[
@2,
@3,
@4,
@5,
@6,
@7,
@8,
];
}

- (NSArray *)jetsamOptionTitles
{
return @[
@"1x",
@"1.5x",
[NSString stringWithFormat:@"2x (%@)", DOLocalizedString(@"Recommended")],
@"2.5x",
@"3x",
@"3.5x",
@"4x",
];
}

- (id)specifiers
{
if(_specifiers == nil) {
Expand Down Expand Up @@ -213,6 +240,15 @@ - (id)specifiers
[appJitSpecifier setProperty:@YES forKey:@"default"];
[specifiers addObject:appJitSpecifier];

PSSpecifier *jetsamSpecifier = [PSSpecifier preferenceSpecifierNamed:DOLocalizedString(@"Settings_Jetsam_Multiplier") target:self set:@selector(setJetsamMultiplier:specifier:) get:@selector(readJetsamMultiplier:) detail:nil cell:PSLinkListCell edit:nil];
[jetsamSpecifier setProperty:@YES forKey:@"enabled"];
[jetsamSpecifier setProperty:@"jetsamMultiplier" forKey:@"key"];
[jetsamSpecifier setProperty:@4 forKey:@"default"];
jetsamSpecifier.detailControllerClass = [DOPSJetsamListItemsController class];
[jetsamSpecifier setProperty:@"jetsamOptionNumbers" forKey:@"valuesDataSource"];
[jetsamSpecifier setProperty:@"jetsamOptionTitles" forKey:@"titlesDataSource"];
[specifiers addObject:jetsamSpecifier];

if (!envManager.isJailbroken && !envManager.isInstalledThroughTrollStore) {
PSSpecifier *removeJailbreakSwitchSpecifier = [PSSpecifier preferenceSpecifierNamed:DOLocalizedString(@"Button_Remove_Jailbreak") target:self set:@selector(setRemoveJailbreakEnabled:specifier:) get:defGetter detail:nil cell:PSSwitchCell edit:nil];
[removeJailbreakSwitchSpecifier setProperty:@YES forKey:@"enabled"];
Expand Down Expand Up @@ -375,7 +411,7 @@ - (id)readAppJITEnabled:(PSSpecifier *)specifier
{
DOEnvironmentManager *envManager = [DOEnvironmentManager sharedManager];
if (envManager.isJailbroken) {
bool v = jbclient_platform_jbsettings_get_bool("markAppsAsDebugged");
bool v = jbclient_jbsettings_get_bool("markAppsAsDebugged");
return @(v);
}
return [self readPreferenceValue:specifier];
Expand All @@ -390,6 +426,25 @@ - (void)setAppJITEnabled:(id)value specifier:(PSSpecifier *)specifier
}
}

- (id)readJetsamMultiplier:(PSSpecifier *)specifier
{
DOEnvironmentManager *envManager = [DOEnvironmentManager sharedManager];
if (envManager.isJailbroken) {
double v = jbclient_jbsettings_get_double("jetsamMultiplier");
return @((v < 1 || isnan(v)) ? 4 : ceil(v * 2));
}
return [self readPreferenceValue:specifier];
}

- (void)setJetsamMultiplier:(id)value specifier:(PSSpecifier *)specifier
{
[self setPreferenceValue:value specifier:specifier];
DOEnvironmentManager *envManager = [DOEnvironmentManager sharedManager];
if (envManager.isJailbroken) {
jbclient_platform_jbsettings_set_double("jetsamMultiplier", ((NSNumber *)value).doubleValue / 2);
}
}

- (void)setRemoveJailbreakEnabled:(id)value specifier:(PSSpecifier *)specifier
{
[self setPreferenceValue:value specifier:specifier];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// DOPSExploitListItemsControllerViewController.h
// Dopamine
//
// Created by Lars Fröder on 29.04.24.
//

#import "DOPSListItemsController.h"

NS_ASSUME_NONNULL_BEGIN

@interface DOPSJetsamListItemsController : DOPSListItemsController

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// DOPSExploitListItemsControllerViewController.m
// Dopamine
//
// Created by Lars Fröder on 29.04.24.
//

#import "DOPSJetsamListItemsController.h"
#import "DOUIManager.h"

@interface DOPSJetsamListItemsController ()

@end

@implementation DOPSJetsamListItemsController

- (NSArray *)specifiers
{
if (!_specifiers) {
_specifiers = [super specifiers];
PSSpecifier *jetsamDescriptionSpecifier = [PSSpecifier emptyGroupSpecifier];
[jetsamDescriptionSpecifier setProperty:DOLocalizedString(@"Jetsam_Description") forKey:@"footerText"];
[(NSMutableArray *)_specifiers addObject:jetsamDescriptionSpecifier];
}
return _specifiers;
}

@end
2 changes: 2 additions & 0 deletions Application/Dopamine/de.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"Settings_iDownload" = "iDownload (Entwickler-Terminal)";
"Settings_Verbose_Logs" = "Detaillierte Logs";
"Settings_Apps_JIT" = "Erlaube JIT in Apps";
"Settings_Jetsam_Multiplier" = "Jetsam Multiplikator";

// Settings Buttons
"Button_Remove_Jailbreak" = "Jailbreak entfernen";
Expand All @@ -58,6 +59,7 @@
"Section_Actions" = "Aktionen";
"Section_Customization" = "Design";
"Section_Exploits" = "Exploits";
"Jetsam_Description" = "Jetsam ist ein System-Feature, welches Prozesse, die vorgegebene Speicherlimit überschreiten, automatisch beendet. Wenn viele Tweaks installiert wurden, kann es passieren, dass Prozesse direkt nach dem Start beendet werden, was diese in eine Absturzschleife versetzen kann. Hier kann ein Multiplikator gewählt werden, mit welchem jedes Speicherlimit, das vom System gesetzt wird, multipliziert wird. Erhöhe diese Einstellung, falls unterwünschtes Systemverhalten bei einer hohen Anzahl von installierten Tweaks auftritt.";

// Settings Alerts
"Alert_Tweak_Injection_Toggled_Title" = "Userspace-Neustart erforderlich";
Expand Down
4 changes: 3 additions & 1 deletion Application/Dopamine/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@
"Button_Share" = "Share";
"Button_Reboot" = "Reboot";

// Settings Toggles
// Settings Options
"Settings_Tweak_Injection" = "Tweak Injection";
"Settings_iDownload" = "iDownload (Developer Shell)";
"Settings_Verbose_Logs" = "Verbose Logs";
"Settings_Apps_JIT" = "Allow JIT in Apps";
"Settings_Jetsam_Multiplier" = "Jetsam Multiplier";

// Settings Buttons
"Button_Remove_Jailbreak" = "Remove Jailbreak";
Expand All @@ -58,6 +59,7 @@
"Section_Actions" = "Actions";
"Section_Customization" = "Customization";
"Section_Exploits" = "Exploits";
"Jetsam_Description" = "Jetsam is a system feature that will automatically kill processes whose memory usage exceeds a specified limit. When many tweaks are installed, it is possible for this limit to be exceeded right at launch, causing processes to crash loop. Here you can select a multiplier that the memory limit of all processes launched with a memory limit will be multiplied by. Increase this setting when stuff is crash looping or if you encounter weird system behaviour when a large number of tweaks are installed.";

// Settings Alerts
"Alert_Tweak_Injection_Toggled_Title" = "Userspace Reboot Required";
Expand Down
29 changes: 2 additions & 27 deletions BaseBin/launchdhook/src/jbserver/jbdomain_platform.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "jbserver_global.h"
#include "jbsettings.h"

#include <libjailbreak/codesign.h>
#include <libjailbreak/libjailbreak.h>
Expand Down Expand Up @@ -28,24 +29,6 @@ static int platform_stage_jailbreak_update(const char *updateTar)
return 1;
}

static int platform_jbsettings_get(const char *key, xpc_object_t *valueOut)
{
if (!strcmp(key, "markAppsAsDebugged")) {
*valueOut = xpc_bool_create(jbsetting(markAppsAsDebugged));
return 0;
}
return -1;
}

static int platform_jbsettings_set(const char *key, xpc_object_t value)
{
if (!strcmp(key, "markAppsAsDebugged") && xpc_get_type(value) == XPC_TYPE_BOOL) {
gSystemInfo.jailbreakSettings.markAppsAsDebugged = xpc_bool_get_value(value);
return 0;
}
return -1;
}

struct jbserver_domain gPlatformDomain = {
.permissionHandler = platform_domain_allowed,
.actions = {
Expand All @@ -66,17 +49,9 @@ struct jbserver_domain gPlatformDomain = {
{ 0 },
},
},
// JBS_PLATFORM_JBSETTINGS_GET
{
.handler = platform_jbsettings_get,
.args = (jbserver_arg[]){
{ .name = "key", .type = JBS_TYPE_STRING, .out = false },
{ .name = "value", .type = JBS_TYPE_XPC_GENERIC, .out = true },
},
},
// JBS_PLATFORM_JBSETTINGS_SET
{
.handler = platform_jbsettings_set,
.handler = jbsettings_set,
.args = (jbserver_arg[]){
{ .name = "key", .type = JBS_TYPE_STRING, .out = false },
{ .name = "value", .type = JBS_TYPE_XPC_GENERIC, .out = false },
Expand Down
21 changes: 15 additions & 6 deletions BaseBin/launchdhook/src/jbserver/jbdomain_systemwide.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "jbserver_global.h"
#include "jbsettings.h"
#include <libjailbreak/info.h>
#include <sandbox.h>
#include <libproc.h>
Expand Down Expand Up @@ -275,11 +276,11 @@ static int systemwide_fork_fix(audit_token_t *parentToken, uint64_t childPid)
uint64_t parentTask = proc_task(parentProc);
uint64_t parentVmMap = kread_ptr(parentTask + koffsetof(task, map));

uint64_t parentHeader = kread_ptr(parentVmMap + koffsetof(vm_map, hdr));
uint64_t parentEntry = kread_ptr(parentHeader + koffsetof(vm_map_header, links) + koffsetof(vm_map_links, next));
uint64_t parentHeader = kread_ptr(parentVmMap + koffsetof(vm_map, hdr));
uint64_t parentEntry = kread_ptr(parentHeader + koffsetof(vm_map_header, links) + koffsetof(vm_map_links, next));

uint64_t childHeader = kread_ptr(childVmMap + koffsetof(vm_map, hdr));
uint64_t childEntry = kread_ptr(childHeader + koffsetof(vm_map_header, links) + koffsetof(vm_map_links, next));
uint64_t childHeader = kread_ptr(childVmMap + koffsetof(vm_map, hdr));
uint64_t childEntry = kread_ptr(childHeader + koffsetof(vm_map_header, links) + koffsetof(vm_map_links, next));

uint64_t childFirstEntry = childEntry, parentFirstEntry = parentEntry;
do {
Expand All @@ -299,7 +300,7 @@ static int systemwide_fork_fix(audit_token_t *parentToken, uint64_t childPid)
uint64_t childFlags = kread64(childEntry + koffsetof(vm_map_entry, flags));

uint8_t parentProt = VM_FLAGS_GET_PROT(parentFlags), parentMaxProt = VM_FLAGS_GET_MAXPROT(parentFlags);
uint8_t childProt = VM_FLAGS_GET_PROT(childFlags), childMaxProt = VM_FLAGS_GET_MAXPROT(childFlags);
uint8_t childProt = VM_FLAGS_GET_PROT(childFlags), childMaxProt = VM_FLAGS_GET_MAXPROT(childFlags);

if (parentProt != childProt || parentMaxProt != childMaxProt) {
VM_FLAGS_SET_PROT(childFlags, parentProt);
Expand All @@ -308,7 +309,7 @@ static int systemwide_fork_fix(audit_token_t *parentToken, uint64_t childPid)
}

parentEntry = kread_ptr(parentEntry + koffsetof(vm_map_entry, links) + koffsetof(vm_map_links, next));
childEntry = kread_ptr(childEntry + koffsetof(vm_map_entry, links) + koffsetof(vm_map_links, next));
childEntry = kread_ptr(childEntry + koffsetof(vm_map_entry, links) + koffsetof(vm_map_links, next));
}
} while (parentEntry != 0 && childEntry != 0 && parentEntry != parentFirstEntry && childEntry != childFirstEntry);
retval = 0;
Expand Down Expand Up @@ -400,6 +401,14 @@ struct jbserver_domain gSystemwideDomain = {
{ 0 },
},
},
// JBS_SYSTEMWIDE_JBSETTINGS_GET
{
.handler = jbsettings_get,
.args = (jbserver_arg[]){
{ .name = "key", .type = JBS_TYPE_STRING, .out = false },
{ .name = "value", .type = JBS_TYPE_XPC_GENERIC, .out = true },
},
},
{ 0 },
},
};
28 changes: 28 additions & 0 deletions BaseBin/launchdhook/src/jbserver/jbsettings.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "jbsettings.h"
#include <libjailbreak/info.h>

int jbsettings_get(const char *key, xpc_object_t *valueOut)
{
if (!strcmp(key, "markAppsAsDebugged")) {
*valueOut = xpc_bool_create(jbsetting(markAppsAsDebugged));
return 0;
}
else if (!strcmp(key, "jetsamMultiplier")) {
*valueOut = xpc_double_create(jbsetting(jetsamMultiplier));
return 0;
}
return -1;
}

int jbsettings_set(const char *key, xpc_object_t value)
{
if (!strcmp(key, "markAppsAsDebugged") && xpc_get_type(value) == XPC_TYPE_BOOL) {
gSystemInfo.jailbreakSettings.markAppsAsDebugged = xpc_bool_get_value(value);
return 0;
}
else if (!strcmp(key, "jetsamMultiplier") && xpc_get_type(value) == XPC_TYPE_DOUBLE) {
gSystemInfo.jailbreakSettings.jetsamMultiplier = xpc_double_get_value(value);
return 0;
}
return -1;
}
4 changes: 4 additions & 0 deletions BaseBin/launchdhook/src/jbserver/jbsettings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include <xpc/xpc.h>

int jbsettings_get(const char *key, xpc_object_t *valueOut);
int jbsettings_set(const char *key, xpc_object_t value);
2 changes: 1 addition & 1 deletion BaseBin/launchdhook/src/spawn_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ int __posix_spawn_hook(pid_t *restrict pid, const char *restrict path,
}
}

return spawn_hook_common(pid, path, desc, argv, envp, __posix_spawn_orig_wrapper, systemwide_trust_binary, platform_set_process_debugged);
return spawn_hook_common(pid, path, desc, argv, envp, __posix_spawn_orig_wrapper, systemwide_trust_binary, platform_set_process_debugged, jbsetting(jetsamMultiplier));
}

void initSpawnHooks(void)
Expand Down
Loading

0 comments on commit 13ecfbf

Please sign in to comment.