Skip to content

Commit 43afaf8

Browse files
committed
Add dump_xsc
1 parent 34e76c8 commit 43afaf8

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

launchctl.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ static const struct {
7979
{ "examine", "Runs the specified analysis tool against launchd in a non-reentrant manner.", "[<tool> [arg0, arg1, ... , @PID, ...]]", examine_cmd },
8080
{ "config", "Modifies persistent configuration parameters for launchd domains.", NULL, config_cmd },
8181
{ "dumpstate", "Dumps launchd state to stdout.", NULL, dumpstate_cmd },
82+
{ "dump-xsc", "Dumps launchd XPC string caches to stdout.", "<name>", dump_xsc_cmd },
8283
{ "dumpjpcategory", "Dumps the jetsam properties category for all services.", NULL, dumpjpcategory_cmd },
8384
{ "reboot", "Initiates a system reboot of the specified type.", "[system|halt|obliterate|userspace] [-s]", reboot_cmd },
8485
{ "enter-rem", "Enter into Restricted Execution Mode (REM).", NULL, enter_rem_cmd },

launchctl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ cmd_main print_cmd;
6060
cmd_main print_cache_cmd;
6161
cmd_main print_disabled_cmd;
6262
cmd_main dumpstate_cmd;
63+
cmd_main dump_xsc_cmd;
6364

6465
// env.c
6566
cmd_main setenv_cmd;

print.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,35 @@ dumpstate_cmd(xpc_object_t *msg, int argc, char **argv, char **envp, char **appl
193193

194194
return ret;
195195
}
196+
197+
int
198+
dump_xsc_cmd(xpc_object_t *msg, int argc, char **argv, char **envp, char **apple)
199+
{
200+
int ret = ENOTSUP;
201+
xpc_object_t reply;
202+
vm_address_t addr;
203+
vm_size_t sz = 0xa00000;
204+
205+
if (__builtin_available(macOS 16.0, iOS 19.0, tvOS 19.0, watchOS 12.0, bridgeOS 10.0, *)) {
206+
xpc_object_t dict = xpc_dictionary_create(NULL, NULL, 0);
207+
*msg = dict;
208+
209+
if ((ret = launchctl_setup_xpc_dict_for_service_name("system", dict, NULL)) != 0)
210+
return ret;
211+
212+
if (argc > 1)
213+
xpc_dictionary_set_string(dict, "name", argv[1]);
214+
215+
addr = launchctl_create_shmem(dict, sz);
216+
ret = launchctl_send_xpc_to_launchd(XPC_ROUTINE_DUMP_XSC, dict, &reply);
217+
218+
if (ret)
219+
fprintf(stderr, "State-dump failed with error %d\n", ret);
220+
else
221+
launchctl_print_shmem(reply, addr, sz, stdout);
222+
223+
vm_deallocate(mach_task_self(), addr, sz);
224+
}
225+
226+
return ret;
227+
}

xpc_private.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ enum {
7575
XPC_ROUTINE_EXAMINE = 826,
7676
XPC_ROUTINE_PRINT = 828,
7777
XPC_ROUTINE_DUMPSTATE = 834,
78-
XPC_ROUTINE_DUMPJPCATEGORY = 837
78+
XPC_ROUTINE_DUMPJPCATEGORY = 837,
79+
XPC_ROUTINE_DUMP_XSC = 849,
7980
};
8081

8182
XPC_DECL(xpc_pipe);

0 commit comments

Comments
 (0)