Skip to content

Commit

Permalink
Fix khanhduytran0#195 probably, fix app being signed again right afte…
Browse files Browse the repository at this point in the history
…r install
  • Loading branch information
hugeBlack committed Nov 7, 2024
1 parent 0aacb0d commit 8b1b10e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 12 deletions.
2 changes: 1 addition & 1 deletion LiveContainerSwiftUI/LCSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ struct LCSettingsView: View {
}
} message: {
if folderRemoveCount > 0 {
Text("lc.settings.cleanDataFolderConfirm".localizeWithFormat(folderRemoveCount))
Text("lc.settings.cleanDataFolderConfirm %lld".localizeWithFormat(folderRemoveCount))
} else {
Text("lc.settings.noDataFolderToClean".loc)
}
Expand Down
4 changes: 2 additions & 2 deletions LiveContainerUI/LCAppInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ - (void)preprocessBundleBeforeSiging:(NSURL *)bundleURL completion:(dispatch_blo
- (void)patchExecAndSignIfNeedWithCompletionHandler:(void(^)(NSString* errorInfo))completetionHandler progressHandler:(void(^)(NSProgress* errorInfo))progressHandler forceSign:(BOOL)forceSign {
NSString *appPath = self.bundlePath;
NSString *infoPath = [NSString stringWithFormat:@"%@/Info.plist", appPath];
NSMutableDictionary *info = [NSMutableDictionary dictionaryWithContentsOfFile:infoPath];
NSMutableDictionary *info = _info;
if (!info) {
completetionHandler(@"Info.plist not found");
return;
Expand Down Expand Up @@ -255,7 +255,7 @@ - (void)patchExecAndSignIfNeedWithCompletionHandler:(void(^)(NSString* errorInfo
[NSFileManager.defaultManager removeItemAtPath:tmpExecPath error:nil];

// Save sign ID and restore bundle ID
[info writeToFile:infoPath atomically:YES];
[self save];


if(error) {
Expand Down
32 changes: 32 additions & 0 deletions TPRO.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// by khanhduytran0
#define _COMM_PAGE_START_ADDRESS (0x0000000FFFFFC000ULL)
//#define _COMM_PAGE_TPRO_SUPPORT (_COMM_PAGE_START_ADDRESS + ????)
#define _COMM_PAGE_TPRO_WRITE_ENABLE (_COMM_PAGE_START_ADDRESS + 0x0D0)
//#define _COMM_PAGE_TPRO_WRITE_DISABLE (_COMM_PAGE_START_ADDRESS + 0x0D8)

static inline bool os_thread_self_restrict_tpro_to_rw() {
if (!*(uint64_t*)_COMM_PAGE_TPRO_WRITE_ENABLE) {
// Doesn't have TPRO, skip this
return false;
}
__asm__ __volatile__ (
"mov x0, %0\n"
"ldr x0, [x0]\n"
"msr s3_6_c15_c1_5, x0\n"
"isb sy\n"
:: "r" (_COMM_PAGE_TPRO_WRITE_ENABLE)
: "memory", "x0"
);
return true;
}

/*
inline uint64_t sprr_read() {
uint64_t v;
__asm__ __volatile__(
"isb sy\n"
"mrs %0, s3_6_c15_c1_5\n"
: "=r"(v)::"memory");
return v;
}
*/
22 changes: 13 additions & 9 deletions main.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <signal.h>
#include <sys/mman.h>
#include <stdlib.h>
#include "TPRO.h"

static int (*appMain)(int, char**);
static const char *dyldImageName;
Expand All @@ -22,6 +23,7 @@
NSString *lcAppGroupPath;
NSString* lcAppUrlScheme;
NSBundle* lcMainBundle;
char* dyldMainExecutablePath = 0;

@implementation NSUserDefaults(LiveContainer)
+ (instancetype)lcUserDefaults {
Expand Down Expand Up @@ -124,13 +126,17 @@ static void overwriteExecPath_handler(int signum, siginfo_t* siginfo, void* cont
size_t newLen = strlen(newPath);
// Check if it's long enough...
assert(maxLen >= newLen);

// Make it RW and overwrite now
kern_return_t ret = builtin_vm_protect(mach_task_self(), (mach_vm_address_t)path, maxLen, false, PROT_READ | PROT_WRITE);
if (ret != KERN_SUCCESS) {
ret = builtin_vm_protect(mach_task_self(), (mach_vm_address_t)path, maxLen, false, PROT_READ | PROT_WRITE | VM_PROT_COPY);

// if we don't have TPRO, we will use the old way
if(!os_thread_self_restrict_tpro_to_rw()) {
// Make it RW and overwrite now
kern_return_t ret = builtin_vm_protect(mach_task_self(), (mach_vm_address_t)path, maxLen, false, PROT_READ | PROT_WRITE);
if (ret != KERN_SUCCESS) {
ret = builtin_vm_protect(mach_task_self(), (mach_vm_address_t)path, maxLen, false, PROT_READ | PROT_WRITE | VM_PROT_COPY);
}
assert(ret == KERN_SUCCESS);
}
assert(ret == KERN_SUCCESS);

bzero(path, maxLen);
strncpy(path, newPath, newLen);
}
Expand All @@ -157,10 +163,8 @@ static void overwriteExecPath(NSString *bundlePath) {
char currPath[PATH_MAX];
uint32_t len = PATH_MAX;
_NSGetExecutablePath(currPath, &len);
// trying to overrite config.process.mainExecutablePath will result in app crash and confuse dylb in 18.2+, so we skip it for now
if(@available(iOS 18.2, *)) {

} else if (strncmp(currPath, newPath, newLen)) {
if (strncmp(currPath, newPath, newLen)) {
struct sigaction sa, saOld;
sa.sa_sigaction = overwriteExecPath_handler;
sa.sa_flags = SA_SIGINFO;
Expand Down

0 comments on commit 8b1b10e

Please sign in to comment.