Skip to content

Commit

Permalink
Adapt to the restructure of lsplant
Browse files Browse the repository at this point in the history
Update submodule JingMatrix/LSPlant
  • Loading branch information
JingMatrix committed Mar 7, 2025
1 parent 165ad94 commit b384321
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ jobs:
restore-keys: ${{ runner.os }}
save: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}

- name: Setup Android SDK
uses: android-actions/setup-android@v3

- name: Remove Android's cmake
shell: bash
run: rm -rf $ANDROID_HOME/cmake
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ val androidTargetSdkVersion by extra(35)
val androidMinSdkVersion by extra(27)
val androidBuildToolsVersion by extra("35.0.0")
val androidCompileSdkVersion by extra(35)
val androidCompileNdkVersion by extra("27.1.12297006")
val androidCompileNdkVersion by extra("29.0.13113456")
val androidSourceCompatibility by extra(JavaVersion.VERSION_21)
val androidTargetCompatibility by extra(JavaVersion.VERSION_21)

Expand Down
12 changes: 7 additions & 5 deletions core/src/main/jni/include/framework/androidfw/resource_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <cstdint>
#include "utils/hook_helper.hpp"

using lsplant::operator""_sym;

// @ApiSensitive(Level.MIDDLE)
namespace android {

Expand Down Expand Up @@ -142,11 +144,11 @@ namespace android {

using stringAtRet = expected<StringPiece16, NullOrIOError>;

inline static lsplant::MemberFunction<{"_ZNK7android13ResStringPool8stringAtEjPj",
"_ZNK7android13ResStringPool8stringAtEmPm"}, ResStringPool, stringAtRet (size_t)> stringAtS_;
inline static auto stringAtS_ = ("_ZNK7android13ResStringPool8stringAtEjPj"_sym |
"_ZNK7android13ResStringPool8stringAtEmPm"_sym).as<stringAtRet (ResStringPool::*)(size_t)>;

inline static lsplant::MemberFunction<{"_ZNK7android13ResStringPool8stringAtEj",
"_ZNK7android13ResStringPool8stringAtEm"}, ResStringPool, const char16_t* (size_t, size_t *)> stringAt_;
inline static auto stringAt_ = ("_ZNK7android13ResStringPool8stringAtEj"_sym |
"_ZNK7android13ResStringPool8stringAtEm"_sym).as<const char16_t* (ResStringPool::*)(size_t, size_t *)>;

StringPiece16 stringAt(size_t idx) const {
if (stringAt_) {
Expand All @@ -163,7 +165,7 @@ namespace android {
}

static bool setup(const lsplant::HookHandler &handler) {
return handler.dlsym(stringAt_) || handler.dlsym(stringAtS_);
return handler(stringAt_) || handler(stringAtS_);
}
};

Expand Down
6 changes: 3 additions & 3 deletions core/src/main/jni/src/jni/resources_hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ namespace lspd {
"_ZNK7android12ResXMLParser18getAttributeNameIDEm")))) {
return false;
}
return android::ResStringPool::setup(lsplant::InitInfo {
return android::ResStringPool::setup(InitInfo {
.art_symbol_resolver = [&](auto s) {
return fw.template getSymbAddress(s);
return fw.template getSymbAddress<>(s);
}
});
}
Expand Down Expand Up @@ -111,7 +111,7 @@ namespace lspd {

// @ApiSensitive(Level.MIDDLE)
LSP_DEF_NATIVE_METHOD(jboolean, ResourcesHook, makeInheritable, jclass target_class) {
if (lsplant::MakeClassInheritable(env, target_class)) {
if (MakeClassInheritable(env, target_class)) {
return JNI_TRUE;
}
return JNI_FALSE;
Expand Down
12 changes: 7 additions & 5 deletions core/src/main/jni/src/native_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
* callback will not work.
*/

using lsplant::operator""_sym;

namespace lspd {

std::list<NativeOnModuleLoaded> moduleLoadedCallbacks;
Expand Down Expand Up @@ -91,10 +93,10 @@ namespace lspd {
return false;
}

inline static lsplant::Hooker<"__dl__Z9do_dlopenPKciPK17android_dlextinfoPKv",
void*(const char*, int, const void*, const void*)>
do_dlopen = +[](const char* name, int flags, const void* extinfo, const void* caller_addr) {
auto *handle = do_dlopen(name, flags, extinfo, caller_addr);
inline static auto do_dlopen_ = "__dl__Z9do_dlopenPKciPK17android_dlextinfoPKv"_sym.hook->*[]
<lsplant::Backup auto backup>
(const char* name, int flags, const void* extinfo, const void* caller_addr) static -> void* {
auto *handle = backup(name, flags, extinfo, caller_addr);
std::string ns;
if (name) {
ns = std::string(name);
Expand Down Expand Up @@ -133,6 +135,6 @@ namespace lspd {
};

bool InstallNativeAPI(const lsplant::HookHandler & handler) {
return handler.hook(do_dlopen);
return handler(do_dlopen_);
}
}
1 change: 1 addition & 0 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ OPTION(LSPLANT_BUILD_SHARED OFF)
add_subdirectory(dobby)
add_subdirectory(fmt)
add_subdirectory(lsplant/lsplant/src/main/jni)
target_compile_options(lsplant_static PUBLIC -Wno-gnu-anonymous-struct)
target_compile_definitions(fmt-header-only INTERFACE FMT_USE_LOCALE=0 FMT_USE_FLOAT=0 FMT_USE_DOUBLE=0 FMT_USE_LONG_DOUBLE=0 FMT_USE_BITINT=0)
2 changes: 1 addition & 1 deletion external/lsplant

0 comments on commit b384321

Please sign in to comment.