Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…n0#221 khanhduytran0#225 by hooking dlsym(RTLD_MAIN_ONLY,)
  • Loading branch information
hugeBlack committed Dec 25, 2024
1 parent efac495 commit 0ac2312
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export CONFIG_COMMIT = $(shell git log --oneline | sed '2,10000000d' | cut -b 1-
# Build the app
APPLICATION_NAME = LiveContainer

$(APPLICATION_NAME)_FILES = dyld_bypass_validation.m main.m utils.m LCSharedUtils.m NSUserDefaults.m
$(APPLICATION_NAME)_FILES = dyld_bypass_validation.m main.m utils.m LCSharedUtils.m NSUserDefaults.m fishhook/fishhook.c
$(APPLICATION_NAME)_CODESIGN_FLAGS = -Sentitlements.xml
$(APPLICATION_NAME)_CFLAGS = -fobjc-arc
$(APPLICATION_NAME)_LDFLAGS = -e _LiveContainerMain -rpath @loader_path/Frameworks
Expand Down
4 changes: 2 additions & 2 deletions Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>3.1.53</string>
<string>3.1.54</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleSupportedPlatforms</key>
Expand All @@ -61,7 +61,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>3.1.53</string>
<string>3.1.54</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.games</string>
<key>LSApplicationQueriesSchemes</key>
Expand Down
2 changes: 1 addition & 1 deletion control
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: com.kdt.livecontainer
Name: livecontainer
Version: 3.1.53
Version: 3.1.54
Architecture: iphoneos-arm
Description: Run iOS app without actually installing it!
Maintainer: khanhduytran0
Expand Down
18 changes: 18 additions & 0 deletions main.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <sys/mman.h>
#include <stdlib.h>
#include "TPRO.h"
#include "fishhook/fishhook.h"
#include <mach-o/ldsyms.h>

static int (*appMain)(int, char**);
static const char *dyldImageName;
Expand Down Expand Up @@ -193,6 +195,18 @@ static void overwriteExecPath(NSString *bundlePath) {
return (void *)header + entryoff;
}

uint32_t appMainImageIndex = 0;
void* (*orig_dlsym)(void * __handle, const char * __symbol);
void* new_dlsym(void * __handle, const char * __symbol) {
if(__handle == (void*)RTLD_MAIN_ONLY) {
if(strcmp(__symbol, MH_EXECUTE_SYM) == 0) {
return (void*)_dyld_get_image_header(appMainImageIndex);
}
return orig_dlsym(RTLD_DEFAULT, __symbol);
}
return orig_dlsym(__handle, __symbol);
}

static NSString* invokeAppMain(NSString *selectedApp, NSString *selectedContainer, int argc, char *argv[]) {
NSString *appError = nil;
if (!LCSharedUtils.certificatePassword) {
Expand Down Expand Up @@ -378,6 +392,7 @@ static void overwriteExecPath(NSString *bundlePath) {

// Preload executable to bypass RT_NOLOAD
uint32_t appIndex = _dyld_image_count();
appMainImageIndex = appIndex;
void *appHandle = dlopen(*path, RTLD_LAZY|RTLD_GLOBAL|RTLD_FIRST);
const char *dlerr = dlerror();
if (!appHandle || (uint64_t)appHandle > 0xf00000000000 || dlerr) {
Expand All @@ -390,6 +405,9 @@ static void overwriteExecPath(NSString *bundlePath) {
*path = oldPath;
return appError;
}
// hook dlsym to solve RTLD_MAIN_ONLY
rebind_symbols((struct rebinding[1]){{"dlsym", (void *)new_dlsym, (void **)&orig_dlsym}},1);

// Fix dynamic properties of some apps
[NSUserDefaults performSelector:@selector(initialize)];

Expand Down

0 comments on commit 0ac2312

Please sign in to comment.