From 2b125144ea325d0572136a78d459366477158325 Mon Sep 17 00:00:00 2001 From: Karmaz95 Date: Tue, 17 Dec 2024 02:40:51 +0100 Subject: [PATCH] Uploading service_lookup --- X. NU/custom/mach_ipc/service_lookup.c | 52 ++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 X. NU/custom/mach_ipc/service_lookup.c diff --git a/X. NU/custom/mach_ipc/service_lookup.c b/X. NU/custom/mach_ipc/service_lookup.c new file mode 100644 index 0000000..3485432 --- /dev/null +++ b/X. NU/custom/mach_ipc/service_lookup.c @@ -0,0 +1,52 @@ +#include +#include +#include + +int main(int argc, char *argv[]) { + if (argc != 2) { + printf("Usage: %s \n", argv[0]); + return 1; + } + + const char *service_name = argv[1]; + mach_port_t bootstrap_port, service_port; + kern_return_t kr; + + // Get the bootstrap port + kr = task_get_bootstrap_port(mach_task_self(), &bootstrap_port); + if (kr != KERN_SUCCESS) { + printf("Failed to get bootstrap port: %s\n", mach_error_string(kr)); + return 1; + } + + // Look up the service + kr = bootstrap_look_up(bootstrap_port, service_name, &service_port); + if (kr != KERN_SUCCESS) { + printf("Service '%s' not found: %s\n", service_name, mach_error_string(kr)); + return 1; + } + + // Get port rights information + mach_port_type_t type; + kr = mach_port_type(mach_task_self(), service_port, &type); + if (kr != KERN_SUCCESS) { + printf("Failed to get port type: %s\n", mach_error_string(kr)); + return 1; + } + + printf("Service: %s\n", service_name); + printf("Port: 0x%x\n", service_port); + printf("Rights: "); + if (type & MACH_PORT_TYPE_RECEIVE) printf("RECV "); + if (type & MACH_PORT_TYPE_SEND) printf("SEND "); + if (type & MACH_PORT_TYPE_SEND_ONCE) printf("ONCE "); + if (type & MACH_PORT_TYPE_PORT_SET) printf("SET "); + if (type & MACH_PORT_TYPE_DEAD_NAME) printf("DEAD "); + printf("\n"); + + // Cleanup + mach_port_deallocate(mach_task_self(), service_port); + mach_port_deallocate(mach_task_self(), bootstrap_port); + + return 0; +} \ No newline at end of file