forked from khanhduytran0/LiveContainer
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adapt JitStreamer EB 0.2.0, hide lc from dyld api, fix zsign not sign…
…ing FAT binaries
- Loading branch information
Showing
15 changed files
with
176 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// | ||
// Dyld.m | ||
// LiveContainer | ||
// | ||
// Created by s s on 2025/2/7. | ||
// | ||
#include <dlfcn.h> | ||
#include <execinfo.h> | ||
#include <signal.h> | ||
#include <sys/mman.h> | ||
#include <stdlib.h> | ||
#include <mach/mach.h> | ||
#include <mach-o/dyld.h> | ||
#include <mach-o/dyld_images.h> | ||
#include <objc/runtime.h> | ||
#include <mach-o/ldsyms.h> | ||
#import "../fishhook/fishhook.h" | ||
|
||
uint32_t appMainImageIndex = 0; | ||
void* appExecutableHandle = 0; | ||
|
||
void* (*orig_dlsym)(void * __handle, const char * __symbol); | ||
uint32_t (*orig_dyld_image_count)(void); | ||
const struct mach_header* (*orig_dyld_get_image_header)(uint32_t image_index); | ||
intptr_t (*orig_dyld_get_image_vmaddr_slide)(uint32_t image_index); | ||
const char* (*orig_dyld_get_image_name)(uint32_t image_index); | ||
|
||
static inline int translateImageIndex(int origin) { | ||
if(origin == 1) { | ||
return appMainImageIndex; | ||
} | ||
if(origin >= appMainImageIndex) { | ||
return origin + 1; | ||
} | ||
return origin; | ||
} | ||
|
||
|
||
void* hook_dlsym(void * __handle, const char * __symbol) { | ||
if(__handle == (void*)RTLD_MAIN_ONLY) { | ||
if(strcmp(__symbol, MH_EXECUTE_SYM) == 0) { | ||
return (void*)orig_dyld_get_image_header(appMainImageIndex); | ||
} | ||
__handle = appExecutableHandle; | ||
} | ||
|
||
__attribute__((musttail)) return orig_dlsym(__handle, __symbol); | ||
} | ||
|
||
uint32_t hook_dyld_image_count(void) { | ||
return orig_dyld_image_count() - 1; | ||
} | ||
|
||
const struct mach_header* hook_dyld_get_image_header(uint32_t image_index) { | ||
__attribute__((musttail)) return orig_dyld_get_image_header(translateImageIndex(image_index)); | ||
} | ||
|
||
intptr_t hook_dyld_get_image_vmaddr_slide(uint32_t image_index) { | ||
__attribute__((musttail)) return orig_dyld_get_image_vmaddr_slide(translateImageIndex(image_index)); | ||
} | ||
|
||
const char* hook_dyld_get_image_name(uint32_t image_index) { | ||
__attribute__((musttail)) return orig_dyld_get_image_name(translateImageIndex(image_index)); | ||
} | ||
|
||
|
||
|
||
void DyldHooksInit(void) { | ||
// hook dlsym to solve RTLD_MAIN_ONLY, hook other functions to hide LiveContainer itself | ||
rebind_symbols((struct rebinding[5]){ | ||
{"dlsym", (void *)hook_dlsym, (void **)&orig_dlsym}, | ||
{"_dyld_image_count", (void *)hook_dyld_image_count, (void **)&orig_dyld_image_count}, | ||
{"_dyld_get_image_header", (void *)hook_dyld_get_image_header, (void **)&orig_dyld_get_image_header}, | ||
{"_dyld_get_image_vmaddr_slide", (void *)hook_dyld_get_image_vmaddr_slide, (void **)&orig_dyld_get_image_vmaddr_slide}, | ||
{"_dyld_get_image_name", (void *)hook_dyld_get_image_name, (void **)&orig_dyld_get_image_name}, | ||
},5); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#import <Foundation/Foundation.h> | ||
#import "Tweaks.h" | ||
#import <objc/runtime.h> | ||
|
||
@implementation NSString(LiveContainer) | ||
- (NSString *)lc_realpath { | ||
// stringByResolvingSymlinksInPath does not fully resolve symlink, and some apps will cradh without /private prefix | ||
char result[PATH_MAX]; | ||
realpath(self.fileSystemRepresentation, result); | ||
return [NSString stringWithUTF8String:result]; | ||
} | ||
@end | ||
@implementation NSBundle(LiveContainer) | ||
// Built-in initWith* will strip out the /private prefix, which could crash certain apps | ||
// This initializer replicates +[NSBundle mainBundle] to solve this issue (FIXME: may not work) | ||
- (instancetype)initWithPathForMainBundle:(NSString *)path { | ||
self = [self init]; | ||
CFURLRef url = (__bridge CFURLRef)[NSURL fileURLWithPath:path.lc_realpath]; | ||
object_setIvar(self, class_getInstanceVariable(self.class, "_cfBundle"), CFBridgingRelease(CFBundleCreate(NULL, url))); | ||
return self; | ||
} | ||
@end |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// Tweaks.h | ||
// LiveContainer | ||
// | ||
// Created by s s on 2025/2/7. | ||
// | ||
|
||
void swizzle(Class class, SEL originalAction, SEL swizzledAction); | ||
|
||
|
||
void NUDGuestHooksInit(void); | ||
void SecItemGuestHooksInit(void); | ||
void DyldHooksInit(void); | ||
|
||
@interface NSBundle(LiveContainer) | ||
- (instancetype)initWithPathForMainBundle:(NSString *)path; | ||
@end | ||
|
||
|
||
extern uint32_t appMainImageIndex; | ||
extern void* appExecutableHandle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.