From 195c97b3e2fecc62d78780bee0446d62c1f9b3ad Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Thu, 2 Jul 2015 13:41:10 -0700 Subject: Use launch.h to verify cydo was launched by Cydia. --- cydo.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/cydo.cpp b/cydo.cpp index 485d647..49e419a 100644 --- a/cydo.cpp +++ b/cydo.cpp @@ -1,7 +1,63 @@ +#include +#include + +#include #include #include +#include + +#include + +typedef Function LaunchDataIterator; + +void launch_data_dict_iterate(launch_data_t data, LaunchDataIterator code) { + launch_data_dict_iterate(data, [](launch_data_t value, const char *name, void *baton) { + (*static_cast(baton))(name, value); + }, &code); +} + int main(int argc, char *argv[]) { + auto request(launch_data_new_string(LAUNCH_KEY_GETJOBS)); + auto response(launch_msg(request)); + launch_data_free(request); + + _assert(response != NULL); + _assert(launch_data_get_type(response) == LAUNCH_DATA_DICTIONARY); + + int parent(getppid()); + + bool cydia(false); + + launch_data_dict_iterate(response, [=, &cydia](const char *name, launch_data_t value) { + if (launch_data_get_type(response) != LAUNCH_DATA_DICTIONARY) + return; + + auto integer(launch_data_dict_lookup(value, LAUNCH_JOBKEY_PID)); + if (integer == NULL || launch_data_get_type(integer) != LAUNCH_DATA_INTEGER) + return; + + auto pid(launch_data_get_integer(integer)); + if (pid != parent) + return; + + auto string(launch_data_dict_lookup(value, LAUNCH_JOBKEY_PROGRAM)); + if (string == NULL || launch_data_get_type(string) != LAUNCH_DATA_STRING) + return; + + auto program(launch_data_get_string(string)); + if (program == NULL) + return; + + if (strcmp(program, "/Applications/Cydia.app/Cydia") == 0) + cydia = true; + }); + + if (!cydia) { + fprintf(stderr, "thou shalt not pass\n"); + return EX_NOPERM; + } + setuid(0); setgid(0); -- cgit v1.2.3