标签:
public String sayhello(int num1, int num2 )
{
if (num1 + num2 < 100) {
return "so small than 100!";
}
if (num1 + num2 == 100) {
return "equal 100!";
}
if (num1 + num2 > 100) {
return "so big than 100!";
}
return "error";
}
<meta-data
android:name="xposedmodule"
android:value="true" />
<meta-data
android:name="xposeddescription"
android:value="Easy example" />
<meta-data
android:name="xposedminversion"
android:value="54" />
dependencies {
compile fileTree(dir: ‘libs‘, include: [‘*.jar‘])
testCompile ‘junit:junit:4.12‘
compile ‘com.android.support:appcompat-v7:23.1.1‘
compile files(‘lib/XposedBridgeApi-54.jar‘)
}
dependencies {
compile fileTree(dir: ‘libs‘, include: [‘*.jar‘])
testCompile ‘junit:junit:4.12‘
compile ‘com.android.support:appcompat-v7:23.1.1‘
provided files(‘lib/XposedBridgeApi-54.jar‘)
}
com.bingghost.xposeddemo.XposedHook
public class XposedHook implements IXposedHookLoadPackage {
public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
XposedBridge.log("Loaded app: " + lpparam.packageName);
if (!lpparam.packageName.equals("com.bingghost.simplehelloworld"))
{
return;
}
findAndHookMethod("com.bingghost.simplehelloworld.MainActivity", lpparam.classLoader, "sayhello", int.class, int.class, new XC_MethodHook() {
protected void afterHookedMethod(MethodHookParam param) {
String str = (String) param.getResult();
Log.v("hook after result :", str);
Integer para1 = (Integer) param.args[0]; //获取参数1
Integer para2 = (Integer) param.args[1]; //获取参数2
String s1 = Integer.toString(para1);
String s2 = Integer.toString(para2);
param.setResult("i am new result! after"); //设置返回值
Log.v("hook param1:", s1);
Log.v("hook param2:", s2);
Log.v("hook result:", "i am new result! after");
}
protected void beforeHookedMethod(MethodHookParam param) {
param.setResult("i am new result! before"); //
Integer para1 = (Integer) param.args[0]; //获取参数1
Integer para2 = (Integer) param.args[1]; //获取参数2
String s1 = Integer.toString(para1);
String s2 = Integer.toString(para2);
Log.v("hook before param1:", s1);
Log.v("hook before param2:", s2);
param.args[0] = 100; //设置参数1
param.args[1] = 200; //设置参数2
Log.v("hook", "before hook!");
}
});
}
}
标签:
原文地址:http://www.cnblogs.com/bingghost/p/5208139.html