Skip to content

Commit c1544ed

Browse files
author
DevelopLab
committed
1. Add Reboot Userspace
1 parent 3f22621 commit c1544ed

15 files changed

Lines changed: 223 additions & 11 deletions

DeviceController.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
@interface DeviceController : NSObject
44

55
- (BOOL) RebootDevice;
6+
- (BOOL) RebootUserspace;
67
- (void) Respring;
78

8-
@end
9+
@end

DeviceController.m

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,26 @@ - (BOOL) RebootDevice
3131
return NO;
3232
}
3333

34+
- (BOOL) RebootUserspace
35+
{
36+
NSString *path = [[NSBundle mainBundle] pathForResource:@"RebootUserSpaceHelper" ofType:@""];
37+
38+
NSArray *args = @[]; // 不需要任何额外参数
39+
NSString *stdOut = nil;
40+
NSString *stdErr = nil;
41+
42+
if (path == nil) {
43+
return NO;
44+
}
45+
46+
int result = spawnRoot(path, args, &stdOut, &stdErr);
47+
if (result == 0) {
48+
return YES;
49+
}
50+
51+
return NO;
52+
}
53+
3454
// @See https://github.com/opa334/TrollStore/blob/main/Shared/TSUtil.m#L297
3555
- (void) Respring
3656
{
@@ -257,4 +277,4 @@ void enumerateProcessesUsingBlock(void (^enumerator)(pid_t pid, NSString* execut
257277
free(info);
258278
}
259279

260-
@end
280+
@end

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
TARGET = iOS
2-
ARCHS := arm64
2+
ARCHS = arm64 arm64e
33
TARGET = iphone:clang:latest:14.0
44

55
# TARGET = simulator:clang:latest:14.0
@@ -20,8 +20,9 @@ include $(THEOS_MAKE_PATH)/application.mk
2020
$(APPLICATION_NAME)_CODESIGN_FLAGS = -Sentitlements.plist
2121

2222
# SUBPROJECTS += RebootRootHelper
23+
#SUBPROJECTS += RebootUserSpaceHelper
2324
include $(THEOS_MAKE_PATH)/aggregate.mk
2425

2526
after-package::
2627
@echo "Renaming .ipa to .tipa..."
27-
@mv ./packages/com.developlab.RebootTools_1.2.ipa ./packages/com.developlab.RebootTools_1.2.tipa || echo "No .ipa file found."
28+
@mv ./packages/com.developlab.RebootTools_1.2.1.ipa ./packages/com.developlab.RebootTools_1.2.1.tipa || echo "No .ipa file found."

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
iOS Utils TrollStore App reboot your device
33
**⚠️Need install via TrollStore.**
44
Use system restart code `reboot(0);` is safe and reliable, use it with confidence.
5+
Reboot user space compatible with iOS 14~17.0
56
**Note: This project will NOT release/store files in parts other than the App sandbox, and will NOT include ANY URL Scheme. You can use it with confidence and will not be detected by third-party app on App Stores. For specific issues, please [view](https://bsky.app/profile/opa334.bsky.social/post/3ll7zkia24c2s).**
67

78
**iOS 重启工具**
89
**⚠️需要TrollStore权限**
910
系统级别重启代码`reboot(0);`安全可靠,放心使用
11+
重启用户空间兼容iOS 14~17.0
1012
**注意:本项目不会在除本App沙盒以外的部分释放/存储文件,并且不会包含任何URL Scheme,您可以放心使用,而不会被第三方App Store的检测到,具体问题请[查看](https://bsky.app/profile/opa334.bsky.social/post/3ll7zkia24c2s)**
1113

1214
## Testing

RebootRootHelper/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
TARGET := iphone:clang:latest:7.0
2+
ARCHS = arm64 arm64e
23

34
include $(THEOS)/makefiles/common.mk
45

RebootUserSpaceHelper/Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
TARGET := iphone:clang:latest:7.0
2+
ARCHS = arm64 arm64e
3+
4+
include $(THEOS)/makefiles/common.mk
5+
6+
TOOL_NAME = RebootUserSpaceHelper
7+
8+
RebootUserSpaceHelper_FILES = main.m
9+
RebootUserSpaceHelper_CFLAGS = -fobjc-arc
10+
RebootUserSpaceHelper_CODESIGN_FLAGS = -Sentitlements.plist
11+
RebootUserSpaceHelper_INSTALL_PATH = /usr/local/bin
12+
13+
include $(THEOS_MAKE_PATH)/tool.mk
14+
15+
after-stage::
16+
@echo "Copying file to parent directory..."
17+
cp $(THEOS_STAGING_DIR)/usr/local/bin/$(TOOL_NAME) ../$(TOOL_NAME)/
18+
@echo "Copy completed."
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
2+
<plist version="1.0">
3+
<dict>
4+
<key>platform-application</key>
5+
<true/>
6+
<key>com.apple.private.security.no-container</key>
7+
<true/>
8+
<key>com.apple.private.security.no-sandbox</key>
9+
<true/>
10+
<key>com.apple.private.xpc.launchd.userspace-reboot</key>
11+
<true/>
12+
<key>com.apple.private.xpc.launchd.userspace-reboot-now</key>
13+
<true/>
14+
<key>com.apple.security.exception.mach-lookup.global-name</key>
15+
<array>
16+
<string>com.apple.mmaintenanced</string>
17+
</array>
18+
</dict>
19+
</plist>

RebootUserSpaceHelper/main.m

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#include <unistd.h>
2+
#include <xpc/xpc.h>
3+
#include <dlfcn.h>
4+
#include <sys/utsname.h>
5+
6+
int main() {
7+
8+
// 1. 获取系统版本
9+
struct utsname uts;
10+
uname(&uts);
11+
12+
// 2. Unlink MemoryMaintenance 的 state 文件 必要步骤,否则不会重启
13+
// iOS 15及以上系统的mmaintenanced和iOS 15以下的位置不同,所以必须区分
14+
if (atoi(uts.release) >= 21) {
15+
unlink("/private/var/mobile/Library/MemoryMaintenance/mmaintenanced");
16+
} else {
17+
unlink("/private/var/db/mmaintenanced");
18+
}
19+
20+
21+
// 3. 因为直接XPC编译器不让,所以动态加载 libxpc
22+
void *lib = dlopen("/usr/lib/system/libxpc.dylib", RTLD_LAZY);
23+
if (!lib) {
24+
return -1;
25+
}
26+
27+
// 4. 动态获取函数指针
28+
xpc_connection_t (*p_xpc_connection_create_mach_service)(const char *, dispatch_queue_t, uint64_t) =
29+
dlsym(lib, "xpc_connection_create_mach_service");
30+
xpc_object_t (*p_xpc_dictionary_create)(const char *const *, const xpc_object_t *, size_t) =
31+
dlsym(lib, "xpc_dictionary_create");
32+
void (*p_xpc_dictionary_set_uint64)(xpc_object_t, const char *, uint64_t) =
33+
dlsym(lib, "xpc_dictionary_set_uint64");
34+
void (*p_xpc_connection_set_event_handler)(xpc_connection_t, xpc_handler_t) =
35+
dlsym(lib, "xpc_connection_set_event_handler");
36+
void (*p_xpc_connection_resume)(xpc_connection_t) =
37+
dlsym(lib, "xpc_connection_resume");
38+
xpc_object_t (*p_xpc_connection_send_message_with_reply_sync)(xpc_connection_t, xpc_object_t) =
39+
dlsym(lib, "xpc_connection_send_message_with_reply_sync");
40+
const char *(*p_xpc_copy_description)(xpc_object_t) =
41+
dlsym(lib, "xpc_copy_description");
42+
43+
if (!p_xpc_connection_create_mach_service ||
44+
!p_xpc_dictionary_create ||
45+
!p_xpc_dictionary_set_uint64 ||
46+
!p_xpc_connection_set_event_handler ||
47+
!p_xpc_connection_resume ||
48+
!p_xpc_connection_send_message_with_reply_sync ||
49+
!p_xpc_copy_description) {
50+
51+
dlclose(lib);
52+
return -1;
53+
}
54+
55+
// 5.建立连接
56+
xpc_connection_t conn = p_xpc_connection_create_mach_service("com.apple.mmaintenanced", NULL, 0);
57+
if (!conn) {
58+
dlclose(lib);
59+
return -1;
60+
}
61+
62+
// 简单 event handler,防止崩但记录事件
63+
p_xpc_connection_set_event_handler(conn, ^(xpc_object_t event){});
64+
p_xpc_connection_resume(conn);
65+
66+
// 6. 构造消息 { cmd = 5 }
67+
xpc_object_t msg = p_xpc_dictionary_create(NULL, NULL, 0);
68+
p_xpc_dictionary_set_uint64(msg, "cmd", 5);
69+
70+
// 7. 发送消息并等待同步回复
71+
p_xpc_connection_send_message_with_reply_sync(conn, msg);
72+
73+
dlclose(lib);
74+
return 0;
75+
}

Resources/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@
8282
<key>LSApplicationCategoryType</key>
8383
<string>public.app-category.utilities</string>
8484
<key>CFBundleShortVersionString</key>
85-
<string>1.2</string>
85+
<string>1.2.1</string>
8686
<key>UIApplicationStateRestoration</key>
87-
<false/>
87+
<false/>
8888
</dict>
8989
</plist>

Resources/RebootUserSpaceHelper

132 KB
Binary file not shown.

0 commit comments

Comments
 (0)