Skip to content

Commit 61078b5

Browse files
committed
Fixed bootstrap again
1 parent d87e7e5 commit 61078b5

File tree

23 files changed

+395
-273
lines changed

23 files changed

+395
-273
lines changed

basebin/jbinit/jbinit

0 Bytes
Binary file not shown.

basebin/jbinit/src/launchctl.m

+70-73
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,93 @@
11
#import <Foundation/Foundation.h>
22
#import <xpc/xpc.h>
33

4-
#define ROUTINE_LOAD 800
4+
#define ROUTINE_LOAD 800
55
#define ROUTINE_UNLOAD 801
66

77
struct _os_alloc_once_s {
8-
long once;
9-
void *ptr;
8+
long once;
9+
void *ptr;
1010
};
1111

1212
struct xpc_global_data {
13-
uint64_t a;
14-
uint64_t xpc_flags;
15-
mach_port_t task_bootstrap_port; /* 0x10 */
13+
uint64_t a;
14+
uint64_t xpc_flags;
15+
mach_port_t task_bootstrap_port; /* 0x10 */
1616
#ifndef _64
17-
uint32_t padding;
17+
uint32_t padding;
1818
#endif
19-
xpc_object_t xpc_bootstrap_pipe; /* 0x18 */
20-
// and there's more, but you'll have to wait for MOXiI 2 for those...
21-
// ...
19+
xpc_object_t xpc_bootstrap_pipe; /* 0x18 */
20+
// and there's more, but you'll have to wait for MOXiI 2 for those...
21+
// ...
2222
};
2323

2424
extern struct _os_alloc_once_s _os_alloc_once_table[];
25-
extern void* _os_alloc_once(struct _os_alloc_once_s *slot, size_t sz, os_function_t init);
25+
extern void *_os_alloc_once(struct _os_alloc_once_s *slot, size_t sz,
26+
os_function_t init);
2627

27-
xpc_object_t launchd_xpc_send_message(xpc_object_t xdict)
28-
{
29-
void* pipePtr = NULL;
30-
31-
if(_os_alloc_once_table[1].once == -1)
32-
{
33-
pipePtr = _os_alloc_once_table[1].ptr;
34-
}
35-
else
36-
{
37-
pipePtr = _os_alloc_once(&_os_alloc_once_table[1], 472, NULL);
38-
if (!pipePtr) _os_alloc_once_table[1].once = -1;
39-
}
28+
xpc_object_t launchd_xpc_send_message(xpc_object_t xdict) {
29+
void *pipePtr = NULL;
4030

41-
xpc_object_t xreply = nil;
42-
if (pipePtr) {
43-
struct xpc_global_data* globalData = pipePtr;
44-
xpc_object_t pipe = globalData->xpc_bootstrap_pipe;
45-
if (pipe) {
46-
int err = xpc_pipe_routine_with_flags(pipe, xdict, &xreply, 0);
47-
if (err != 0) {
48-
return nil;
49-
}
50-
}
31+
if (_os_alloc_once_table[1].once == -1) {
32+
pipePtr = _os_alloc_once_table[1].ptr;
33+
} else {
34+
pipePtr = _os_alloc_once(&_os_alloc_once_table[1], 472, NULL);
35+
if (!pipePtr)
36+
_os_alloc_once_table[1].once = -1;
37+
}
38+
39+
xpc_object_t xreply = nil;
40+
if (pipePtr) {
41+
struct xpc_global_data *globalData = pipePtr;
42+
xpc_object_t pipe = globalData->xpc_bootstrap_pipe;
43+
if (pipe) {
44+
int err = xpc_pipe_routine_with_flags(pipe, xdict, &xreply, 0);
45+
if (err != 0) {
46+
return nil;
47+
}
5148
}
52-
return xreply;
49+
}
50+
return xreply;
5351
}
5452

53+
int64_t launchctl_load(const char *plistPath, bool unload) {
54+
xpc_object_t pathArray = xpc_array_create_empty();
55+
xpc_array_set_string(pathArray, XPC_ARRAY_APPEND, plistPath);
56+
57+
xpc_object_t msgDictionary = xpc_dictionary_create_empty();
58+
xpc_dictionary_set_uint64(msgDictionary, "subsystem", 3);
59+
xpc_dictionary_set_uint64(msgDictionary, "handle", 0);
60+
xpc_dictionary_set_uint64(msgDictionary, "type", 1);
61+
xpc_dictionary_set_bool(msgDictionary, "legacy-load", true);
62+
xpc_dictionary_set_bool(msgDictionary, "enable", false);
63+
xpc_dictionary_set_uint64(msgDictionary, "routine",
64+
unload ? ROUTINE_UNLOAD : ROUTINE_LOAD);
65+
xpc_dictionary_set_value(msgDictionary, "paths", pathArray);
66+
67+
xpc_object_t msgReply = launchd_xpc_send_message(msgDictionary);
68+
69+
char *msgReplyDescription = xpc_copy_description(msgReply);
70+
NSLog(@"[jbinit] msgReply = %s\n", msgReplyDescription);
71+
free(msgReplyDescription);
72+
73+
int64_t bootstrapError =
74+
xpc_dictionary_get_int64(msgReply, "bootstrap-error");
75+
if (bootstrapError != 0) {
76+
NSLog(@"[jbinit] bootstrap-error = %s\n",
77+
xpc_strerror((int32_t)bootstrapError));
78+
return bootstrapError;
79+
}
5580

56-
int64_t launchctl_load(const char* plistPath, bool unload)
57-
{
58-
xpc_object_t pathArray = xpc_array_create_empty();
59-
xpc_array_set_string(pathArray, XPC_ARRAY_APPEND, plistPath);
60-
61-
xpc_object_t msgDictionary = xpc_dictionary_create_empty();
62-
xpc_dictionary_set_uint64(msgDictionary, "subsystem", 3);
63-
xpc_dictionary_set_uint64(msgDictionary, "handle", 0);
64-
xpc_dictionary_set_uint64(msgDictionary, "type", 1);
65-
xpc_dictionary_set_bool(msgDictionary, "legacy-load", true);
66-
xpc_dictionary_set_bool(msgDictionary, "enable", false);
67-
xpc_dictionary_set_uint64(msgDictionary, "routine", unload ? ROUTINE_UNLOAD : ROUTINE_LOAD);
68-
xpc_dictionary_set_value(msgDictionary, "paths", pathArray);
69-
70-
xpc_object_t msgReply = launchd_xpc_send_message(msgDictionary);
81+
int64_t error = xpc_dictionary_get_int64(msgReply, "error");
82+
if (error != 0) {
83+
NSLog(@"[jbinit]error = %s\n", xpc_strerror((int32_t)error));
84+
return error;
85+
}
7186

72-
char *msgReplyDescription = xpc_copy_description(msgReply);
73-
printf("msgReply = %s\n", msgReplyDescription);
74-
free(msgReplyDescription);
75-
76-
int64_t bootstrapError = xpc_dictionary_get_int64(msgReply, "bootstrap-error");
77-
if(bootstrapError != 0)
78-
{
79-
printf("bootstrap-error = %s\n", xpc_strerror((int32_t)bootstrapError));
80-
return bootstrapError;
81-
}
82-
83-
int64_t error = xpc_dictionary_get_int64(msgReply, "error");
84-
if(error != 0)
85-
{
86-
printf("error = %s\n", xpc_strerror((int32_t)error));
87-
return error;
88-
}
89-
90-
// launchctl seems to do extra things here
91-
// like getting the audit token via xpc_dictionary_get_audit_token
92-
// or sometimes also getting msgReply["req_pid"] and msgReply["rec_execcnt"]
93-
// but we don't really care about that here
87+
// launchctl seems to do extra things here
88+
// like getting the audit token via xpc_dictionary_get_audit_token
89+
// or sometimes also getting msgReply["req_pid"] and msgReply["rec_execcnt"]
90+
// but we don't really care about that here
9491

95-
return 0;
92+
return 0;
9693
}

basebin/jbinit/src/main.m

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
#import "boot_info.h"
2+
#import "launchctl.h"
13
#import <Foundation/Foundation.h>
24
#import <spawn.h>
3-
#import "launchctl.h"
4-
#import "boot_info.h"
55

6-
int main(int argc, char* argv[])
7-
{
8-
launchctl_load(prebootPath(@"basebin/LaunchDaemons/kr.h4ck.jailbreakd.plist").fileSystemRepresentation, false);
6+
int main(int argc, char *argv[]) {
7+
NSLog(@"[jbinit] Hello, World!");
8+
int ret = launchctl_load(
9+
prebootPath(@"basebin/LaunchDaemons/kr.h4ck.jailbreakd.plist")
10+
.fileSystemRepresentation,
11+
false);
12+
NSLog(@"[jbinit] launchctl_load ret: %d\n", ret);
913

10-
return 0;
14+
return 0;
1115
}

binaries.tar

1.59 MB
Binary file not shown.

binaries/binaries.tc

-22 Bytes
Binary file not shown.

binaries/jbinit

0 Bytes
Binary file not shown.

iosbinpack/binaries.tc

266 Bytes
Binary file not shown.

binaries/tar iosbinpack/tar

File renamed without changes.

iosbinpack/tar.tc

46 Bytes
Binary file not shown.

kfd.xcodeproj/project.pbxproj

+12-12
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
297BA1112A310AE200D1E51A /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 297BA1102A310AE200D1E51A /* Preview Assets.xcassets */; };
1414
6E08ABFC2A9A39B000BF5B0D /* debs in Resources */ = {isa = PBXBuildFile; fileRef = 6E08ABFB2A9A39B000BF5B0D /* debs */; };
1515
6E08ABFE2A9A3B9800BF5B0D /* helpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E08ABFD2A9A3B9800BF5B0D /* helpers.m */; };
16+
6E08AC092A9B87A300BF5B0D /* binaries.tar in Resources */ = {isa = PBXBuildFile; fileRef = 6E08AC082A9B87A300BF5B0D /* binaries.tar */; };
1617
6E75BFA82A8475C70056ABDA /* fun.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E75BFA72A8475C70056ABDA /* fun.m */; };
1718
6E75BFAB2A8476340056ABDA /* krw.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E75BFAA2A8476340056ABDA /* krw.m */; };
1819
6E75BFAE2A847A980056ABDA /* offsets.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E75BFAD2A847A980056ABDA /* offsets.m */; };
@@ -26,10 +27,9 @@
2627
6ECE5B5B2A90662200792D41 /* ipc.c in Sources */ = {isa = PBXBuildFile; fileRef = 6ECE5B5A2A90662200792D41 /* ipc.c */; };
2728
6ECE5B5D2A907DE900792D41 /* iosbinpack in Resources */ = {isa = PBXBuildFile; fileRef = 6ECE5B5C2A907DE900792D41 /* iosbinpack */; };
2829
6ECE5B5F2A907DFE00792D41 /* dropbear.m in Sources */ = {isa = PBXBuildFile; fileRef = 6ECE5B5E2A907DFE00792D41 /* dropbear.m */; };
29-
6ECE5B612A907FC800792D41 /* binaries in Resources */ = {isa = PBXBuildFile; fileRef = 6ECE5B602A907FC800792D41 /* binaries */; };
3030
6ECE5B7E2A9217D000792D41 /* libgeneral_exception.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6ECE5B7C2A9217D000792D41 /* libgeneral_exception.cpp */; };
31-
6ECE5B7F2A9217D000792D41 /* KernelRwWrapper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6ECE5B792A9217CF00792D41 /* KernelRwWrapper.cpp */; };
32-
6ECE5B802A9217D000792D41 /* KernelRW.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6ECE5B782A9217CF00792D41 /* KernelRW.cpp */; };
31+
6ECE5B7F2A9217D000792D41 /* KernelRwWrapper.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6ECE5B792A9217CF00792D41 /* KernelRwWrapper.mm */; };
32+
6ECE5B802A9217D000792D41 /* KernelRW.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6ECE5B782A9217CF00792D41 /* KernelRW.mm */; };
3333
6ECE5B862A9269F000792D41 /* bootstrap.m in Sources */ = {isa = PBXBuildFile; fileRef = 6ECE5B852A9269F000792D41 /* bootstrap.m */; };
3434
6ECE5B892A92F95A00792D41 /* boot_info.m in Sources */ = {isa = PBXBuildFile; fileRef = 6ECE5B882A92F95A00792D41 /* boot_info.m */; };
3535
6ECE5B8C2A944CA700792D41 /* jailbreakd_test.m in Sources */ = {isa = PBXBuildFile; fileRef = 6ECE5B8B2A944CA700792D41 /* jailbreakd_test.m */; };
@@ -83,6 +83,7 @@
8383
6E08ABFB2A9A39B000BF5B0D /* debs */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = debs; sourceTree = SOURCE_ROOT; };
8484
6E08ABFD2A9A3B9800BF5B0D /* helpers.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = helpers.m; sourceTree = "<group>"; };
8585
6E08ABFF2A9A3BA600BF5B0D /* helpers.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = helpers.h; sourceTree = "<group>"; };
86+
6E08AC082A9B87A300BF5B0D /* binaries.tar */ = {isa = PBXFileReference; lastKnownFileType = archive.tar; path = binaries.tar; sourceTree = SOURCE_ROOT; };
8687
6E75BFA72A8475C70056ABDA /* fun.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = fun.m; sourceTree = "<group>"; };
8788
6E75BFA92A8475D30056ABDA /* fun.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = fun.h; sourceTree = "<group>"; };
8889
6E75BFAA2A8476340056ABDA /* krw.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = krw.m; sourceTree = "<group>"; };
@@ -107,11 +108,10 @@
107108
6ECE5B5A2A90662200792D41 /* ipc.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = ipc.c; sourceTree = "<group>"; };
108109
6ECE5B5C2A907DE900792D41 /* iosbinpack */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = iosbinpack; sourceTree = SOURCE_ROOT; };
109110
6ECE5B5E2A907DFE00792D41 /* dropbear.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = dropbear.m; sourceTree = "<group>"; };
110-
6ECE5B602A907FC800792D41 /* binaries */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = binaries; sourceTree = SOURCE_ROOT; };
111111
6ECE5B642A90802100792D41 /* dropbear.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = dropbear.h; sourceTree = "<group>"; };
112112
6ECE5B772A9217CF00792D41 /* KernelRW.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = KernelRW.hpp; sourceTree = "<group>"; };
113-
6ECE5B782A9217CF00792D41 /* KernelRW.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = KernelRW.cpp; sourceTree = "<group>"; };
114-
6ECE5B792A9217CF00792D41 /* KernelRwWrapper.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = KernelRwWrapper.cpp; sourceTree = "<group>"; };
113+
6ECE5B782A9217CF00792D41 /* KernelRW.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = KernelRW.mm; sourceTree = "<group>"; };
114+
6ECE5B792A9217CF00792D41 /* KernelRwWrapper.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = KernelRwWrapper.mm; sourceTree = "<group>"; };
115115
6ECE5B7A2A9217CF00792D41 /* KernelRwWrapper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KernelRwWrapper.h; sourceTree = "<group>"; };
116116
6ECE5B7B2A9217CF00792D41 /* macros.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = macros.h; sourceTree = "<group>"; };
117117
6ECE5B7C2A9217D000792D41 /* libgeneral_exception.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = libgeneral_exception.cpp; sourceTree = "<group>"; };
@@ -264,9 +264,9 @@
264264
297BA1072A310AE100D1E51A /* kfd */ = {
265265
isa = PBXGroup;
266266
children = (
267+
6E08AC082A9B87A300BF5B0D /* binaries.tar */,
267268
6E08ABFB2A9A39B000BF5B0D /* debs */,
268269
6ECE5B902A949F0800792D41 /* unsigned */,
269-
6ECE5B602A907FC800792D41 /* binaries */,
270270
6ECE5B5C2A907DE900792D41 /* iosbinpack */,
271271
297BA10C2A310AE200D1E51A /* Assets.xcassets */,
272272
297BA10A2A310AE100D1E51A /* ContentView.swift */,
@@ -332,10 +332,10 @@
332332
6ECE5B832A92188900792D41 /* common */ = {
333333
isa = PBXGroup;
334334
children = (
335-
6ECE5B782A9217CF00792D41 /* KernelRW.cpp */,
335+
6ECE5B782A9217CF00792D41 /* KernelRW.mm */,
336336
6ECE5B822A92183F00792D41 /* iokit.h */,
337337
6ECE5B772A9217CF00792D41 /* KernelRW.hpp */,
338-
6ECE5B792A9217CF00792D41 /* KernelRwWrapper.cpp */,
338+
6ECE5B792A9217CF00792D41 /* KernelRwWrapper.mm */,
339339
6ECE5B7A2A9217CF00792D41 /* KernelRwWrapper.h */,
340340
6ECE5B7C2A9217D000792D41 /* libgeneral_exception.cpp */,
341341
6ECE5B7D2A9217D000792D41 /* libgeneral_exception.hpp */,
@@ -413,8 +413,8 @@
413413
files = (
414414
6E08ABFC2A9A39B000BF5B0D /* debs in Resources */,
415415
6ECE5B912A949F0800792D41 /* unsigned in Resources */,
416+
6E08AC092A9B87A300BF5B0D /* binaries.tar in Resources */,
416417
297BA1112A310AE200D1E51A /* Preview Assets.xcassets in Resources */,
417-
6ECE5B612A907FC800792D41 /* binaries in Resources */,
418418
297BA10D2A310AE200D1E51A /* Assets.xcassets in Resources */,
419419
6ECE5B5D2A907DE900792D41 /* iosbinpack in Resources */,
420420
);
@@ -446,8 +446,8 @@
446446
297BA1092A310AE100D1E51A /* kfdApp.swift in Sources */,
447447
6E75BFAB2A8476340056ABDA /* krw.m in Sources */,
448448
6ECE5B552A90609100792D41 /* utils.c in Sources */,
449-
6ECE5B802A9217D000792D41 /* KernelRW.cpp in Sources */,
450-
6ECE5B7F2A9217D000792D41 /* KernelRwWrapper.cpp in Sources */,
449+
6ECE5B802A9217D000792D41 /* KernelRW.mm in Sources */,
450+
6ECE5B7F2A9217D000792D41 /* KernelRwWrapper.mm in Sources */,
451451
);
452452
runOnlyForDeploymentPostprocessing = 0;
453453
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1430"
4+
version = "1.7">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "297BA1042A310AE100D1E51A"
18+
BuildableName = "kfd.app"
19+
BlueprintName = "kfd"
20+
ReferencedContainer = "container:kfd.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES"
30+
shouldAutocreateTestPlan = "YES">
31+
</TestAction>
32+
<LaunchAction
33+
buildConfiguration = "Debug"
34+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
35+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
36+
launchStyle = "0"
37+
useCustomWorkingDirectory = "NO"
38+
ignoresPersistentStateOnLaunch = "NO"
39+
debugDocumentVersioning = "YES"
40+
debugServiceExtension = "internal"
41+
allowLocationSimulation = "YES">
42+
<BuildableProductRunnable
43+
runnableDebuggingMode = "0">
44+
<BuildableReference
45+
BuildableIdentifier = "primary"
46+
BlueprintIdentifier = "297BA1042A310AE100D1E51A"
47+
BuildableName = "kfd.app"
48+
BlueprintName = "kfd"
49+
ReferencedContainer = "container:kfd.xcodeproj">
50+
</BuildableReference>
51+
</BuildableProductRunnable>
52+
</LaunchAction>
53+
<ProfileAction
54+
buildConfiguration = "Release"
55+
shouldUseLaunchSchemeArgsEnv = "YES"
56+
savedToolIdentifier = ""
57+
useCustomWorkingDirectory = "NO"
58+
debugDocumentVersioning = "YES">
59+
<BuildableProductRunnable
60+
runnableDebuggingMode = "0">
61+
<BuildableReference
62+
BuildableIdentifier = "primary"
63+
BlueprintIdentifier = "297BA1042A310AE100D1E51A"
64+
BuildableName = "kfd.app"
65+
BlueprintName = "kfd"
66+
ReferencedContainer = "container:kfd.xcodeproj">
67+
</BuildableReference>
68+
</BuildableProductRunnable>
69+
</ProfileAction>
70+
<AnalyzeAction
71+
buildConfiguration = "Debug">
72+
</AnalyzeAction>
73+
<ArchiveAction
74+
buildConfiguration = "Release"
75+
revealArchiveInOrganizer = "YES">
76+
</ArchiveAction>
77+
</Scheme>

0 commit comments

Comments
 (0)