新增JNI文件并导入so库
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.10.2)
# Declares and names the project.
project("native-lib")
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
add_library( # Sets the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
native-lib.cpp
)
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log)
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
native-lib
# Links the target library to the log library
# included in the NDK.
${log-lib})
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
version "3.10.2"
}
}
内部类
类加载器
package com.sam.myapplicationcj;
import android.util.Log;
import com.virjar.ratel.api.rposed.IRposedHookLoadPackage;
import com.virjar.ratel.api.rposed.RC_MethodHook;
import com.virjar.ratel.api.rposed.RposedHelpers;
import com.virjar.ratel.api.rposed.callbacks.RC_LoadPackage;
public class HookMethodEntry implements IRposedHookLoadPackage {
private static final String TAG = "yuanrenxue->";
@Override
public void handleLoadPackage(RC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
if (lpparam.packageName.equals("com.yuanrenxue.course4")) {
Log.d(TAG, "handleLoadPackage: hook method start success");
RposedHelpers.findAndHookMethod("com.yuanrenxue.course4.MysteryBox", lpparam.classLoader, "staticMethod", String.class, int.class, new RC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
Log.d(TAG, "beforeHookedMethod: args[0] = " + param.args[0] + ", args[1]" + param.args[1]);
param.args[0] = "静态方法修改后的第一个参数";
param.args[1] = 1000;
}
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
Object result = param.getResult();
Log.d(TAG, "afterHookedMethod: " + result);
param.setResult("我是修改之后的静态方法返回值");
}
});
Class<?> MysteryBoxClass = lpparam.classLoader.loadClass("com.yuanrenxue.course4.MysteryBox");
RposedHelpers.findAndHookMethod(MysteryBoxClass, "instanceMethod", String.class, int.class, new RC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
Log.d(TAG, "beforeHookedMethod实例方法: args[0]" + param.args[0] + ", args[1] " + param.args[1]);
param.args[0] = "实例方法修改后的第一个参数";
param.args[1] = 2000;
}
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
param.setResult("我是实例方法修改后的返回值");
}
});
RposedHelpers.findAndHookMethod("com.yuanrenxue.course4.MysteryBox$InnerClass", lpparam.classLoader, "innerClassMethod", String.class, int.class, new RC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
Log.d(TAG, "beforeHookedMethod内部类: args[0]" + param.args[0] + ", args[1] " + param.args[1]);
}
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
Log.d(TAG, "afterHookedMethod: " + param.getResult());
}
});
RposedHelpers.findAndHookMethod("com.yuanrenxue.course4.MainActivity", lpparam.classLoader, "nativeMethod", new RC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
Log.d(TAG, "beforeHookedMethod: " + param.args.length);
}
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
Log.d(TAG, "afterHookedMethod: " + param.getResult());
param.setResult("我是修改之后native方法的返回值");
}
});
}
}
}
PS
|