Skip to content

Commit

Permalink
add hook.getObjectsOfClass and getAssignableClasses based on JVMTI
Browse files Browse the repository at this point in the history
  • Loading branch information
5ec1cff committed Nov 18, 2024
1 parent 64a9e4b commit 135efb8
Show file tree
Hide file tree
Showing 27 changed files with 7,408 additions and 38 deletions.
21 changes: 12 additions & 9 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ android {
}
buildFeatures {
buildConfig = true
prefab = true
}
defaultConfig {
applicationId = "io.github.a13e300.tools.stethox"
Expand All @@ -42,7 +43,8 @@ android {
versionName = "1.0.2"
externalNativeBuild {
cmake {
cppFlags += ""
cppFlags("-std=c++20", "-fno-rtti", "-fno-exceptions")
arguments += "-DANDROID_STL=none"
}
}
}
Expand Down Expand Up @@ -226,13 +228,14 @@ task("generateDefaultOkHttp3Helper") {
}

dependencies {
implementation("androidx.annotation:annotation:1.9.1")
compileOnly("de.robv.android.xposed:api:82")
implementation(libs.annotation)
compileOnly(libs.api)
compileOnly(project(":hidden-api"))
implementation("com.github.5ec1cff.stetho:stetho:1.0-alpha-1")
implementation("com.github.5ec1cff.stetho:stetho-js-rhino:1.0-alpha-1")
implementation("com.github.5ec1cff.stetho:stetho-urlconnection:1.0-alpha-1")
implementation("org.mozilla:rhino:1.7.15-SNAPSHOT")
implementation("com.linkedin.dexmaker:dexmaker:2.28.3")
implementation("org.luckypray:dexkit:2.0.0-rc4")
implementation(libs.stetho)
implementation(libs.stetho.js.rhino)
implementation(libs.stetho.urlconnection)
implementation(libs.rhino)
implementation(libs.dexmaker)
implementation(libs.dexkit)
implementation(libs.cxx)
}
13 changes: 10 additions & 3 deletions app/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
cmake_minimum_required(VERSION 3.22.1)
project("stethox")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20")
add_library(${CMAKE_PROJECT_NAME} SHARED stethox.cpp plt.c classloader.cpp utils.cpp)

target_link_libraries(${CMAKE_PROJECT_NAME} android log)
include_directories(include)

find_package(cxx REQUIRED CONFIG)
link_libraries(cxx::cxx)

add_library(${CMAKE_PROJECT_NAME} SHARED stethox.cpp plt.c classloader.cpp utils.cpp jvmti/stethox_jvmti.cpp)

target_link_libraries(${CMAKE_PROJECT_NAME} log elf_parser maps_scan)
add_subdirectory(elf_parser)
add_subdirectory(maps_scan)
13 changes: 5 additions & 8 deletions app/src/main/cpp/classloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ class ClassLoaderVisitor : public art::SingleRootVisitor {
void VisitRoot(art::mirror::Object *root, const art::RootInfo &info ATTRIBUTE_UNUSED) final {
jobject object = newLocalRef((JNIEnv *) env_, (jobject) root);
if (object != nullptr) {
auto s = (jstring) env_->CallObjectMethod(env_->GetObjectClass(object), toStringMid);
auto c = env_->GetStringUTFChars(s, nullptr);
env_->ReleaseStringUTFChars(s, c);
LOGD("object name %s", c);
if (env_->IsInstanceOf(object, classLoader_)) {
auto s = (jstring) env_->CallObjectMethod(env_->GetObjectClass(object), toStringMid);
auto c = env_->GetStringUTFChars(s, nullptr);
env_->ReleaseStringUTFChars(s, c);
LOGD("object name %s", c);
callback_((jobject) root);
}
deleteLocalRef((JNIEnv *) env_, object);
Expand Down Expand Up @@ -214,9 +214,6 @@ jobjectArray visitClassLoadersByRootVisitor(JNIEnv *env) {
#ifdef DEBUG
LOGI("SweepJniWeakGlobals: %p", SweepJniWeakGlobals);
#endif
if (SweepJniWeakGlobals == nullptr) {
return nullptr;
}

JavaVM *jvm;
env->GetJavaVM(&jvm);
Expand All @@ -229,7 +226,7 @@ jobjectArray visitClassLoadersByRootVisitor(JNIEnv *env) {
ClassLoaderVisitor visitor(env, class_loader_class, callback);
VisitRoots(jvm, &visitor);
}
{
if (SweepJniWeakGlobals != nullptr) {
WeakClassLoaderVisitor visitor(env, class_loader_class, callback);
SweepJniWeakGlobals(jvm, &visitor);
}
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/cpp/elf_parser/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
project(elf_parser)

add_library(elf_parser STATIC
elf_parser.cc
xz-embedded/xz_crc32.c
xz-embedded/xz_crc64.c
xz-embedded/xz_dec_lzma2.c
xz-embedded/xz_dec_stream.c
)
target_include_directories(elf_parser PUBLIC include)
target_include_directories(elf_parser PRIVATE xz-embedded)
Loading

0 comments on commit 135efb8

Please sign in to comment.