diff -ur coreutils-7.4/src/su.c coreutils-7.4+iPhone/src/su.c --- coreutils-7.4/src/su.c 2009-04-24 02:50:28.000000000 -1000 +++ coreutils-7.4+iPhone/src/su.c 2018-07-26 13:20:56.000000000 -1000 @@ -52,6 +52,7 @@ #include #include #include +#include /* Hide any system prototype for getusershell. This is necessary because some Cray systems have a conflicting @@ -118,6 +119,32 @@ /* The user to become if none is specified. */ #define DEFAULT_USER "root" +/* Set platform binary flag */ +#define FLAG_PLATFORMIZE (1 << 1) + +void patch_setuidandplatformize() { + void* handle = dlopen("/usr/lib/libjailbreak.dylib", RTLD_LAZY); + if (!handle) return; + + // Reset errors + dlerror(); + + typedef void (*fix_setuid_prt_t)(pid_t pid); + fix_setuid_prt_t setuidptr = (fix_setuid_prt_t)dlsym(handle, "jb_oneshot_fix_setuid_now"); + + typedef void (*fix_entitle_prt_t)(pid_t pid, uint32_t what); + fix_entitle_prt_t entitleptr = (fix_entitle_prt_t)dlsym(handle, "jb_oneshot_entitle_now"); + + setuidptr(getpid()); + + const char *dlsym_error = dlerror(); + if (dlsym_error) { + return; + } + + entitleptr(getpid(), FLAG_PLATFORMIZE); +} + char *crypt (char const *key, char const *salt); char *getusershell (void); void endusershell (void); @@ -403,6 +432,9 @@ int main (int argc, char **argv) { + patch_setuidandplatformize(); + if (geteuid() != 0) + seteuid(0); int optc; const char *new_user = DEFAULT_USER; char *command = NULL;