X-Git-Url: https://git.saurik.com/cydia.git/blobdiff_plain/cf769c11b99abf71df6bf9528c8bf9956c7e18e0..87d58a906a7660760a9f2b2321fb99e72cdf551b:/cydo.cpp diff --git a/cydo.cpp b/cydo.cpp index 6d33f948..d6e6f758 100644 --- a/cydo.cpp +++ b/cydo.cpp @@ -28,6 +28,8 @@ #include +#include + #include typedef Function LaunchDataIterator; @@ -39,12 +41,6 @@ void launch_data_dict_iterate(launch_data_t data, LaunchDataIterator code) { } int main(int argc, char *argv[]) { - auto log(fopen("/tmp/cydia.log", "a+")); - fprintf(log, "cydo:"); - for (int arg(1); arg < argc; ++arg) - fprintf(log, " %s", argv[arg]); - fprintf(log, "\n"); - auto request(launch_data_new_string(LAUNCH_KEY_GETJOBS)); auto response(launch_msg(request)); launch_data_free(request); @@ -56,8 +52,14 @@ int main(int argc, char *argv[]) { auto cydia(false); + struct stat correct; + if (lstat("/Applications/Cydia.app/Cydia", &correct) == -1) { + fprintf(stderr, "you have no arms left"); + return EX_NOPERM; + } + launch_data_dict_iterate(response, [=, &cydia](const char *name, launch_data_t value) { - if (launch_data_get_type(response) != LAUNCH_DATA_DICTIONARY) + if (launch_data_get_type(value) != LAUNCH_DATA_DICTIONARY) return; auto integer(launch_data_dict_lookup(value, LAUNCH_JOBKEY_PID)); @@ -70,7 +72,7 @@ int main(int argc, char *argv[]) { auto variables(launch_data_dict_lookup(value, LAUNCH_JOBKEY_ENVIRONMENTVARIABLES)); if (variables != NULL && launch_data_get_type(variables) == LAUNCH_DATA_DICTIONARY) { - bool dyld(false); + auto dyld(false); launch_data_dict_iterate(variables, [&dyld](const char *name, launch_data_t value) { if (strncmp(name, "DYLD_", 5) == 0) @@ -98,19 +100,19 @@ int main(int argc, char *argv[]) { if (program == NULL) return; - fprintf(log, "%lld %s\n", pid, program); - if (strcmp(program, "/Applications/Cydia.app/Cydia") == 0) + struct stat check; + if (lstat(program, &check) == -1) + return; + + if (correct.st_dev == check.st_dev && correct.st_ino == check.st_ino) cydia = true; }); if (!cydia) { - fprintf(stderr, "thou shalt not pass\n"); + fprintf(stderr, "none shall pass\n"); return EX_NOPERM; } - fflush(log); - fclose(log); - setuid(0); setgid(0);