本帖最后由 苏紫方璇 于 2020-3-15 16:02 编辑
如题,我想hook String类的一个构造函数,看文档说用findAndHookConstructor这个函数来hook,但是测试无效,求问该怎么写才可以hook到。
测试的目标代码
package com.suzi.xposedtest;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
import java.io.UnsupportedEncodingException;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
byte bb[]={'a','b','c','e','f'};
try {
String aa= new String(bb,"UTF-8");
Toast.makeText(this,aa,Toast.LENGTH_LONG).show();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}
我需要hook这里的public String(byte bytes[], String charsetName)
我使用的hook代码
package com.suzi.xposedtest;
import android.util.Log;
import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
public class HookMain implements IXposedHookLoadPackage {
@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
if(!lpparam.packageName.equals("com.suzi.xposedtest")) return;
XposedHelpers.findAndHookConstructor("java.lang.String",lpparam.classLoader, byte[].class, String.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
Log.i("szfx","hook");
}
});
}
}
|