Skip to content

Commit

Permalink
1.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
AXiX-official committed Jun 9, 2024
1 parent aa51cc2 commit 970a4f3
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 117 deletions.
13 changes: 2 additions & 11 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId = "com.axix.assetsideloader"
minSdk = 26
targetSdk = 34
versionCode = 105
versionName = "1.0.5"
versionCode = 106
versionName = "1.0.6"

ndk {
}
Expand All @@ -34,15 +34,6 @@ android {
buildFeatures{
prefab = true
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/cpp/log.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#ifndef IL2CPPBRIDGE_LOG_H
#define IL2CPPBRIDGE_LOG_H
#ifndef AssetSideLoader_LOG_H
#define AssetSideLoader_LOG_H

#include <android/log.h>

#define LOG_TAG "IL2CPP_Bridge"
#define LOG_TAG "AssetSideLoader"
#define LOG_D(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
#define LOG_W(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)
#define LOG_E(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
#define LOG_I(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)

#endif //IL2CPPBRIDGE_LOG_H
#endif //AssetSideLoader_LOG_H
180 changes: 82 additions & 98 deletions app/src/main/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "utf8.h"
#include "il2cpp-class.h"

//------------------------------------------------------------------------------------------------//

#define DO_API(r, n, p) r (*n) p

#include "il2cpp-api-functions.h"
Expand All @@ -29,54 +31,35 @@ void init_il2cpp_api(void *handle) {
#undef DO_API
}

static uint64_t il2cpp_base = 0;
//------------------------------------------------------------------------------------------------//

void* Handle = nullptr;

std::string modDir = "/storage/emulated/0/Android/data/";

void hook_funcs();

typedef int (*il2cpp_init_func)(const char *);
il2cpp_init_func il2cpp_init_origin = nullptr;

int hook_il2cpp_init(const char *domain_name) {
int result = il2cpp_init_origin(domain_name);
DobbyDestroy((void*)hook_il2cpp_init);
LOG_I("il2cpp_init finished with result: %d", result);
if (result == 1){
DobbyDestroy((void*)hook_il2cpp_init);
Handle = xdl_open("libil2cpp.so", 0);
LOG_I("libil2cpp.so handle: %p", Handle);
hook_funcs();
}
return result;
}
std::string pakageName = "";

typedef void* (*dlsym_t)(void* handle, const char* symbol);
std::string modDir = "/storage/emulated/0/Android/data/";

static dlsym_t orig_dlsym = NULL;
//------------------------------------------------------------------------------------------------//

void* my_dlsym(void* handle, const char* symbol){
void* addr = orig_dlsym(handle, symbol);
if (strcmp(symbol, "il2cpp_init") == 0) {
LOG_I("find il2cpp_init: %p", addr);
DobbyDestroy((void*)my_dlsym);
DobbyHook(
(void*)addr,
(void*)hook_il2cpp_init,
(void**)&il2cpp_init_origin
);
void* ReplacePath(std::string path) {
if (path.find("AssetBundles") != std::string::npos) {
std::string modPath = modDir + path.substr(path.find("AssetBundles") + 12);
if (modPath.find(".ys") != std::string::npos) {
//去除.ys后缀
modPath = modPath.substr(0, modPath.find(".ys"));
}
// 判断文件是否存在
std::ifstream file(modPath);
if (file) {
LOG_I("Redirect from: %s", path.c_str());
LOG_I("To: %s", modPath.c_str());
return il2cpp_string_new(modPath.c_str());
}
}
return addr;
return il2cpp_string_new(path.c_str());
}



void il2cpp_api_init(void* handle) {
DobbyHook((void*) dlsym, (void*)my_dlsym, (void**)&orig_dlsym);
//Handle = handle;
}
//------------------------------------------------------------------------------------------------//

std::string Il2CppStringToStdString(void *str) {
const Il2CppChar* chars = il2cpp_string_chars(str);
Expand All @@ -88,29 +71,13 @@ std::string Il2CppStringToStdString(void *str) {
if (length == -1)
break;
}

std::string utf8String;
utf8String.reserve(length);
utf8::unchecked::utf16to8(chars, ptr, std::back_inserter(utf8String));
return utf8String;
}

void * ReplacePath(std::string path) {
if (path.find("AssetBundles") != std::string::npos) {
std::string modPath = modDir + path.substr(path.find("AssetBundles") + 12);
if (modPath.find(".ys") != std::string::npos) {
//去除.ys后缀
modPath = modPath.substr(0, modPath.find(".ys"));
}
// 判断文件是否存在
std::ifstream file(modPath);
if (file) {
LOG_I("Replace with Mod: %s", modPath.c_str());
return il2cpp_string_new(modPath.c_str());
}
}
return il2cpp_string_new(path.c_str());
}
//------------------------------------------------------------------------------------------------//

typedef void* (*LoadFromFile_Internal)(void*, uint32_t, uint64_t);
typedef void* (*LoadFromFileAsync_Internal)(void*, uint32_t, uint64_t);
Expand All @@ -127,66 +94,83 @@ void* Hook_LoadFromFileAsync_Internal(void* path, uint32_t crc, uint64_t offset)
return AssetBundle_LoadFromFileAsync_Internal(ReplacePath(pathStr), crc, offset);
}

void hook_funcs(){
//------------------------------------------------------------------------------------------------//

void hook_funcs(){
LOG_I("Init Il2cpp api...");
init_il2cpp_api(Handle);
LOG_I("hooking...");

modDir += "com.bilibili.azurlane";
modDir += pakageName;
modDir += "/files/mods";
LOG_I("modDir: %s", modDir.c_str());

uint64_t LoadFromFile_Internal_addr = (uint64_t)il2cpp_resolve_icall("UnityEngine.AssetBundle::LoadFromFile_Internal(System.String,System.UInt32,System.UInt64)");
LOG_I("LoadFromFile_Internal_addr: %" PRIx64"", LoadFromFile_Internal_addr);
if (LoadFromFile_Internal_addr) {
LOG_I("LoadFromFile_Internal_addr: %" PRIx64"", LoadFromFile_Internal_addr);
DobbyHook(
(void *)LoadFromFile_Internal_addr,
(void *)Hook_LoadFromFile_Internal,
(void **)&AssetBundle_LoadFromFile_Internal
);
}

uint64_t LoadFromFileAsync_Internal_addr = (uint64_t)il2cpp_resolve_icall("UnityEngine.AssetBundle::LoadFromFileAsync_Internal(System.String,System.UInt32,System.UInt64)");
LOG_I("LoadFromFileAsync_Internal_addr: %" PRIx64"", LoadFromFileAsync_Internal_addr);

DobbyHook(
(void *)LoadFromFile_Internal_addr,
(void *)Hook_LoadFromFile_Internal,
(void **)&AssetBundle_LoadFromFile_Internal
);

DobbyHook(
(void *)LoadFromFileAsync_Internal_addr,
(void *)Hook_LoadFromFileAsync_Internal,
(void **)&AssetBundle_LoadFromFileAsync_Internal
);
if (LoadFromFileAsync_Internal_addr) {
LOG_I("LoadFromFileAsync_Internal_addr: %" PRIx64"", LoadFromFileAsync_Internal_addr);
DobbyHook(
(void *)LoadFromFileAsync_Internal_addr,
(void *)Hook_LoadFromFileAsync_Internal,
(void **)&AssetBundle_LoadFromFileAsync_Internal
);
}
}

typedef void* (*dlopen_t)(const char* filename, int flag);
//------------------------------------------------------------------------------------------------//

static dlopen_t orig_dlopen = NULL;
typedef int (*il2cpp_init_func)(const char *);

il2cpp_init_func il2cpp_init_origin = nullptr;

inline __always_inline
int ends_with(const char *str, const char *suffix)
{
if (!str || !suffix)
return 0;
size_t lenstr = strlen(str);
size_t lensuffix = strlen(suffix);
if (lensuffix > lenstr)
return 0;
return strncmp(str + lenstr - lensuffix, suffix, lensuffix) == 0;
int hook_il2cpp_init(const char *domain_name) {
int result = il2cpp_init_origin(domain_name);
DobbyDestroy((void*)hook_il2cpp_init);
LOG_I("il2cpp_init finished with result: %d", result);
if (result == 1){
DobbyDestroy((void*)hook_il2cpp_init);
Handle = xdl_open("libil2cpp.so", 0);
LOG_I("libil2cpp.so handle: %p", Handle);
hook_funcs();
}
return result;
}

void* my_dlopen(const char* filename, int flag) {
void* handle = orig_dlopen(filename, flag);
// 如果filename以libil2cpp.so结尾
if (ends_with(filename, "libil2cpp.so")) {
LOG_I("libil2cpp.so loaded.");
LOG_I("handle: %p", handle);
LOG_I("flag: %d", flag);
if (flag == 2){
DobbyDestroy((void*)my_dlopen);
il2cpp_api_init(handle);
}
//------------------------------------------------------------------------------------------------//

typedef void* (*dlsym_t)(void* handle, const char* symbol);

static dlsym_t orig_dlsym = nullptr;

void* my_dlsym(void* handle, const char* symbol){
void* addr = orig_dlsym(handle, symbol);
if (strcmp(symbol, "il2cpp_init") == 0) {
LOG_I("symbol il2cpp_init found at: %p", addr);
DobbyDestroy((void*)my_dlsym);
DobbyHook(
(void*)addr,
(void*)hook_il2cpp_init,
(void**)&il2cpp_init_origin
);
}
return handle;
return addr;
}

//------------------------------------------------------------------------------------------------//

extern "C"
JNIEXPORT void JNICALL
Java_com_axix_il2cpp_1bridge_Il2cppBridge_InitHook(JNIEnv *env, jobject thiz) {
il2cpp_api_init(nullptr);
Java_com_axix_assetsideloader_AssetSideLoader_InitHook(JNIEnv *env, jobject thiz, jstring str) {
pakageName = env->GetStringUTFChars(str, NULL);
LOG_D("Hooking dlsym...");
DobbyHook((void*) dlsym, (void*)my_dlsym, (void**)&orig_dlsym);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.axix.assetsideloader

class AssetSideLoader {
external fun InitHook(): Void
external fun InitHook(pakageName: String): Void

companion object {
init {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/axix/assetsideloader/MainHook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import de.robv.android.xposed.callbacks.XC_LoadPackage
class MainHook : IXposedHookLoadPackage {
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
if (lpparam.packageName == "com.bilibili.azurlane") {
Log.i("IL2CPP_Bridge", "Loaded package: ${lpparam.packageName}")
AssetSideLoader().InitHook()
Log.i("AssetSideLoader", "Target application: ${lpparam.packageName} launched")
AssetSideLoader().InitHook("com.bilibili.azurlane")
}
}
}
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<resources>
<string name="app_name">Il2cpp-bridge</string>
<string name="app_name">AssetSideLoader</string>
</resources>
3 changes: 3 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ pluginManagement {
google()
mavenCentral()
gradlePluginPortal()
jcenter()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
jcenter()
}
}

rootProject.name = "AssetSideLoader"
include(":app")

0 comments on commit 970a4f3

Please sign in to comment.