Skip to content

Commit

Permalink
build for roothide
Browse files Browse the repository at this point in the history
Signed-off-by: Lessica <82flex@gmail.com>
  • Loading branch information
Lessica committed Oct 25, 2024
1 parent 26f21c4 commit 68b2233
Show file tree
Hide file tree
Showing 6 changed files with 222 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export PACKAGE_VERSION := 2.4
export PACKAGE_VERSION := 2.5
export ARCHS := arm64 arm64e
export TARGET := iphone:clang:16.5:14.0

Expand Down
6 changes: 6 additions & 0 deletions Preferences/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ BUNDLE_NAME += KayokoPreferences

KayokoPreferences_FILES += $(wildcard Controllers/*.m Cells/*.m ../Manager/*.m)
KayokoPreferences_FILES += $(wildcard ../Utils/*.m)

ifeq ($(THEOS_PACKAGE_SCHEME),roothide)
KayokoPreferences_FILES += ../libroot/dyn.c
endif

KayokoPreferences_CFLAGS += -fobjc-arc
KayokoPreferences_CFLAGS += -I../Manager
KayokoPreferences_CFLAGS += -I../Preferences
KayokoPreferences_CFLAGS += -I../Utils

KayokoPreferences_FRAMEWORKS += UIKit
KayokoPreferences_PRIVATE_FRAMEWORKS += Preferences
KayokoPreferences_INSTALL_PATH := /Library/PreferenceBundles
Expand Down
6 changes: 6 additions & 0 deletions Tweak/Core/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ TWEAK_NAME := KayokoCore
KayokoCore_FILES += KayokoCore.m
KayokoCore_FILES += KayokoCoreLogos.xm
KayokoCore_FILES += $(wildcard ../../Manager/*.m Views/*.m ../../Utils/*.m)

ifeq ($(THEOS_PACKAGE_SCHEME),roothide)
KayokoCore_FILES += ../../libroot/dyn.c
endif

KayokoCore_CFLAGS += -fobjc-arc
KayokoCore_CFLAGS += -I../../Manager
KayokoCore_CFLAGS += -I../../Preferences
KayokoCore_CFLAGS += -I../../Utils

KayokoCore_FRAMEWORKS += UIKit AudioToolbox

include $(THEOS)/makefiles/common.mk
Expand Down
6 changes: 6 additions & 0 deletions Tweak/Helper/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ TWEAK_NAME := KayokoHelper
KayokoHelper_FILES += KayokoHelper.m
KayokoHelper_FILES += KeyokoHelperLogos.xm
KayokoHelper_FILES += $(wildcard ../../Manager/*.m ../../Utils/*.m)

ifeq ($(THEOS_PACKAGE_SCHEME),roothide)
KayokoHelper_FILES += ../../libroot/dyn.c
endif

KayokoHelper_CFLAGS += -fobjc-arc
KayokoHelper_CFLAGS += -I../../Headers
KayokoHelper_CFLAGS += -I../../Preferences
KayokoHelper_CFLAGS += -I../../Manager
KayokoHelper_CFLAGS += -I../../Utils

KayokoHelper_LDFLAGS += -L../../Libraries
KayokoHelper_FRAMEWORKS += UIKit
KayokoHelper_LIBRARIES += sandy
Expand Down
7 changes: 7 additions & 0 deletions devkit/roothide.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

export THEOS=$HOME/theos-roothide
export THEOS_PACKAGE_SCHEME=roothide
export THEOS_DEVICE_IP=127.0.0.1
export THEOS_DEVICE_PORT=58422
export THEOS_DEVICE_SIMULATOR=
196 changes: 196 additions & 0 deletions libroot/dyn.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
#include <stdint.h>
#include <stddef.h>
#include <dispatch/dispatch.h>
#include <dlfcn.h>
#include <sys/param.h>
#include <stdlib.h>
#include <string.h>

#include <libroot.h>

#if THEOS_PACKAGE_SCHEME_ROOTHIDE
#include <roothide.h>
#endif

static const char *(*dyn_get_root_prefix)(void) = NULL;
static const char *(*dyn_get_jbroot_prefix)(void) = NULL;
static const char *(*dyn_get_boot_uuid)(void) = NULL;
static char *(*dyn_jbrootpath)(const char *path, char *resolvedPath) = NULL;
static char *(*dyn_rootfspath)(const char *path, char *resolvedPath) = NULL;

#if TARGET_OS_SIMULATOR

static const char *libroot_get_root_prefix_fallback(void)
{
return IPHONE_SIMULATOR_ROOT;
}

static const char *libroot_get_jbroot_prefix_fallback(void)
{
return IPHONE_SIMULATOR_ROOT;
}

#else

#if THEOS_PACKAGE_SCHEME_ROOTHIDE

static const char *libroot_get_root_prefix_fallback(void)
{
return rootfs("/");
}

static const char *libroot_get_jbroot_prefix_fallback(void)
{
return jbroot("/");
}

#else

#if IPHONEOS_ARM64

static const char *libroot_get_root_prefix_fallback(void)
{
return "";
}

static const char *libroot_get_jbroot_prefix_fallback(void)
{
return "/var/jb";
}

#else

static const char *libroot_get_root_prefix_fallback(void)
{
return "";
}

static const char *libroot_get_jbroot_prefix_fallback(void)
{
if (access("/var/LIY", F_OK) == 0) {
// Legacy support for XinaA15 1.x (For those two people still using it)
// Technically this should be deprecated, but with the libroot solution it's not the hardest thing in the world to maintain
// So I decided to leave it in
return "/var/jb";
}
else {
return "";
}
}

#endif
#endif
#endif

static const char *libroot_get_boot_uuid_fallback(void)
{
return "00000000-0000-0000-0000-000000000000";
}

static char *libroot_rootfspath_fallback(const char *path, char *resolvedPath)
{
if (!path) return NULL;
if (!resolvedPath) resolvedPath = malloc(PATH_MAX);

const char *prefix = libroot_dyn_get_root_prefix();
const char *jbRootPrefix = libroot_dyn_get_jbroot_prefix();
size_t jbRootPrefixLen = strlen(jbRootPrefix);

if (path[0] == '/') {
// This function has two different purposes
// If what we have is a subpath of the jailbreak root, strip the jailbreak root prefix
// Else, add the rootfs prefix
if (!strncmp(path, jbRootPrefix, jbRootPrefixLen)) {
strlcpy(resolvedPath, &path[jbRootPrefixLen], PATH_MAX);
}
else {
strlcpy(resolvedPath, prefix, PATH_MAX);
strlcat(resolvedPath, path, PATH_MAX);
}
}
else {
// Don't modify relative paths
strlcpy(resolvedPath, path, PATH_MAX);
}

return resolvedPath;
}

static char *libroot_jbrootpath_fallback(const char *path, char *resolvedPath)
{
if (!path) return NULL;
if (!resolvedPath) resolvedPath = malloc(PATH_MAX);

const char *prefix = libroot_dyn_get_jbroot_prefix();
bool skipRedirection = path[0] != '/'; // Don't redirect relative paths

#ifndef IPHONEOS_ARM64
// Special case
// On XinaA15 v1: Don't redirect /var/mobile paths to /var/jb/var/mobile
if (!skipRedirection) {
if (access("/var/LIY", F_OK) == 0) {
skipRedirection = strncmp(path, "/var/mobile", 11) == 0;
}
}
#endif

if (!skipRedirection) {
strlcpy(resolvedPath, prefix, PATH_MAX);
strlcat(resolvedPath, path, PATH_MAX);
}
else {
strlcpy(resolvedPath, path, PATH_MAX);
}

return resolvedPath;
}

static void libroot_load(void)
{
static dispatch_once_t onceToken;
dispatch_once (&onceToken, ^{
void *handle = dlopen("@rpath/libroot.dylib", RTLD_NOW);
if (handle) {
dyn_get_root_prefix = dlsym(handle, "libroot_get_root_prefix");
dyn_get_jbroot_prefix = dlsym(handle, "libroot_get_jbroot_prefix");
dyn_get_boot_uuid = dlsym(handle, "libroot_get_boot_uuid");
dyn_jbrootpath = dlsym(handle, "libroot_jbrootpath");
dyn_rootfspath = dlsym(handle, "libroot_rootfspath");
}
if (!dyn_get_root_prefix) dyn_get_root_prefix = libroot_get_root_prefix_fallback;
if (!dyn_get_jbroot_prefix) dyn_get_jbroot_prefix = libroot_get_jbroot_prefix_fallback;
if (!dyn_get_boot_uuid) dyn_get_boot_uuid = libroot_get_boot_uuid_fallback;
if (!dyn_jbrootpath) dyn_jbrootpath = libroot_jbrootpath_fallback;
if (!dyn_rootfspath) dyn_rootfspath = libroot_rootfspath_fallback;
});
}

const char *libroot_dyn_get_root_prefix(void)
{
libroot_load();
return dyn_get_root_prefix();
}

const char *libroot_dyn_get_jbroot_prefix(void)
{
libroot_load();
return dyn_get_jbroot_prefix();
}

const char *libroot_dyn_get_boot_uuid(void)
{
libroot_load();
return dyn_get_boot_uuid();
}

char *libroot_dyn_rootfspath(const char *path, char *resolvedPath)
{
libroot_load();
return dyn_rootfspath(path, resolvedPath);
}

char *libroot_dyn_jbrootpath(const char *path, char *resolvedPath)
{
libroot_load();
return dyn_jbrootpath(path, resolvedPath);
}

0 comments on commit 68b2233

Please sign in to comment.