Skip to content

Commit

Permalink
Add safe mode alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
asdfugil committed Dec 21, 2023
1 parent 35f3fda commit 0713244
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ROOT := $(shell pwd)
MACOSX_SYSROOT = $(shell xcrun -sdk macosx --show-sdk-path)
TARGET_SYSROOT = $(shell xcrun -sdk macosx --show-sdk-path)
TARGET_SYSROOT = $(shell xcrun -sdk iphoneos --show-sdk-path)
CC = xcrun -sdk iphoneos clang
OBJC = $(CC)

Expand Down Expand Up @@ -35,6 +35,7 @@ apple-include:
gsed -E s/'__IOS_PROHIBITED|__TVOS_PROHIBITED|__WATCHOS_PROHIBITED'//g < $(TARGET_SYSROOT)/usr/include/ucontext.h > apple-include/ucontext.h
gsed -E s/'__IOS_PROHIBITED|__TVOS_PROHIBITED|__WATCHOS_PROHIBITED'//g < $(TARGET_SYSROOT)/usr/include/signal.h > apple-include/signal.h
gsed -E /'__API_UNAVAILABLE'/d < $(TARGET_SYSROOT)/usr/include/pthread.h > apple-include/pthread.h
@if [ -f $(TARGET_SYSROOT)/System/Library/Frameworks/CoreFoundation.framework/Headers/CFUserNotification.h ]; then gsed -E 's/API_UNAVAILABLE\(ios, watchos, tvos\)//g' < $(TARGET_SYSROOT)/System/Library/Frameworks/CoreFoundation.framework/Headers/CFUserNotification.h > apple-include/CoreFoundation/CFUserNotification.h; fi
gsed -i -E s/'__API_UNAVAILABLE\(.*\)'// apple-include/IOKit/IOKitLib.h

clean:
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/payload/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ CFLAGS += -isystem $(ROOT)/apple-include -I$(ROOT)/include -Wno-nullability-comp
LDFLAGS += -Wl,-dead_strip -Wno-unused-command-line-argument
OBJDIR = obj
C_SRC = $(wildcard *.c)
LIBS = -framework CoreFoundation -framework IOKit -framework Foundation ../APFS.tbd ../libjailbreak/libjailbreak.a
LIBS = -framework CoreFoundation -framework IOKit -framework Foundation ../libs/APFS.tbd ../libjailbreak/libjailbreak.a
OBJS = $(patsubst %,$(OBJDIR)/%,$(C_SRC:.c=.c.o))

LAUNCHCTL_OBJ = bootstrap.o xpc_helper.o load.o
Expand Down
40 changes: 40 additions & 0 deletions src/payload/loader/launchdaemons.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
#include <errno.h>
#include <string.h>
#include <mach-o/loader.h>
#include <CoreFoundation/CoreFoundation.h>
#include <pthread.h>
#include <dlfcn.h>

mach_port_t (*SBSSpringBoardServerPort)(void);
static CFRunLoopRef loop;

void sb_launched(CFNotificationCenterRef center, void *observer,
CFStringRef name, const void *object, CFDictionaryRef info) {
CFRunLoopStop(loop);
}

int launchdaemons(uint32_t payload_options, uint64_t pflags) {
printf("plooshInit launchdaemons...\n");
Expand All @@ -12,6 +23,33 @@ int launchdaemons(uint32_t payload_options, uint64_t pflags) {
return -1;
}

if (platform == PLATFORM_IOS) {
void *springboardservices = dlopen("/System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices", RTLD_NOW);
if (springboardservices) {
SBSSpringBoardServerPort = dlsym(springboardservices, "SBSSpringBoardServerPort");
if (SBSSpringBoardServerPort && !MACH_PORT_VALID(SBSSpringBoardServerPort())) {
loop = CFRunLoopGetCurrent();
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, &sb_launched, CFSTR("SBSpringBoardDidLaunchNotification"), NULL, 0);
CFRunLoopRun();
}
dlclose(springboardservices);
} else {
fprintf(stderr, "failed to dlopen springboardservices\n");
}
}

if (pflags & palerain_option_safemode) {
CFMutableDictionaryRef dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
if (dict) {
CFDictionarySetValue(dict, kCFUserNotificationAlertHeaderKey, CFSTR("Entered Safe Mode"));
CFDictionarySetValue(dict, kCFUserNotificationAlertMessageKey, CFSTR("palera1n entered safe mode due to a user request"));

CFUserNotificationRef notif = CFUserNotificationCreate(kCFAllocatorDefault, 0, 0, NULL, dict);
CFRelease(dict);
if (notif) CFRelease(notif);
}
}

switch (platform) {
case PLATFORM_IOS:
runCommand((char*[]){ "/cores/binpack/usr/bin/uicache", "-p", "/cores/binpack/Applications/palera1nLoader.app", NULL });
Expand All @@ -27,5 +65,7 @@ int launchdaemons(uint32_t payload_options, uint64_t pflags) {
runCommand((char*[]){ "/usr/bin/uicache", "-a", NULL });
else if (access("/var/jb/usr/bin/uicache", F_OK) == 0)
runCommand((char*[]){ "/var/jb/usr/bin/uicache", "-a", NULL });

printf("plooshInit launchdaemons: Goodbye!\n");
return 0;
}
3 changes: 3 additions & 0 deletions src/payload/loader/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ uint32_t macho_get_platform(const void *buf) {
}

int get_platform() {
static int cached_platform = -1;
if (cached_platform != -1) return cached_platform;
struct stat st;
int ret = stat("/usr/lib/dyld", &st);
if (ret) return ret;
Expand All @@ -59,5 +61,6 @@ int get_platform() {
uint32_t platform = macho_get_platform(dyld_buf);
if (!platform) return -1;
munmap(dyld_buf, st.st_size);
cached_platform = (int)platform;
return (int)platform;
}
2 changes: 1 addition & 1 deletion src/rootfulhooks/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ OBJDIR = obj
C_SRC = $(wildcard *.c)
OBJC_SRC = $(wildcard *.m)
OBJCFLAGS = -fobjc-arc
LIBS = -lobjc -framework Foundation -framework CoreFoundation ../libellekit.tbd
LIBS = -lobjc -framework Foundation -framework CoreFoundation ../libs/libellekit.tbd
OBJS = $(patsubst %,$(OBJDIR)/%,$(OBJC_SRC:.m=.m.o) $(C_SRC:.c=.c.o))

ifeq ($(ASAN),1)
Expand Down
2 changes: 1 addition & 1 deletion src/rootlesshooks/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ OBJDIR = obj
C_SRC = $(wildcard *.c)
OBJC_SRC = $(wildcard *.m)
OBJCFLAGS = -fobjc-arc
LIBS = -lobjc -framework Foundation -framework CoreFoundation ../libellekit.tbd
LIBS = -lobjc -framework Foundation -framework CoreFoundation ../libs/libellekit.tbd
OBJS = $(patsubst %,$(OBJDIR)/%,$(OBJC_SRC:.m=.m.o) $(C_SRC:.c=.c.o))

ifeq ($(ASAN),1)
Expand Down

0 comments on commit 0713244

Please sign in to comment.