如果安装 Xposed 哪里不会的 可以参考
https://www.52pojie.cn/thread-850885-1-1.html
其实本来我也不是 很想看 安卓 想去复现一下cve 漏洞 至于 pwn 什么的 更是不想看 ~~~~~ 真滴头大
但是吧 安卓这方面感觉有的地方 挺好玩的 然后 就 过来玩一哈
其中这里呢 我是 看着 吾爱的这篇帖子 做的东西 感觉还是 比较好玩的
然后自己也写了一下 代码 来玩
测试 app 代码
package com.example.lenovo.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
public int number = 0;
private Button add = null;
private Button sub = null;
private y Y = new y();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
add = (Button) findViewById(R.id.add);
sub = (Button) findViewById(R.id.sub);
SetLister();
}
private void SetLister() {
OnClick onclick = new OnClick();
add.setOnClickListener(onclick);
sub.setOnClickListener(onclick);
}
private class OnClick implements View.OnClickListener {
@Override
public void onClick(View v) {
if (number >= 1000) {
Toast.makeText(MainActivity.this, "你赢了", Toast.LENGTH_SHORT).show();
}
switch (v.getId()) {
case R.id.sub:
number = Y.sub(number);
Toast.makeText(MainActivity.this, "生命值:"+number, Toast.LENGTH_SHORT).show();
break;
case R.id.add:
number = Y.add(number);
Toast.makeText(MainActivity.this, "生命值:"+number, Toast.LENGTH_SHORT).show();
break;
}
}
}
}
class y
{
public y()
{
super();
}
public int add(int num)
{
num++;
Log.i("add", "num+1");
return num;
}
public int sub(int num)
{
num--;
return num;
}
}
然后xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.lenovo.myapplication.MainActivity">
<Button
android:text="加血"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/add"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<Button
android:text="减血"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/add"
android:layout_alignLeft="@+id/add"
android:layout_alignStart="@+id/add"
android:layout_marginBottom="46dp"
android:id="@+id/sub" />
</RelativeLayout>
然后 hook的话 代码如下
package com.example.xposed_test;
import android.content.SharedPreferences;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;
import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;
import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;
public class HookMain implements IXposedHookLoadPackage {
public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
if(lpparam.packageName.equals("com.example.lenovo.myapplication"))
{
Log.i("调用成功","存在!");
}
else
{
Log.i("调用失败","不存在!");
}
//固定格式
findAndHookMethod(
"com.example.lenovo.myapplication.y", //要hook的包名+类名
lpparam.classLoader, //classLoader固定
"add", //要hook的方法名
int.class,//方法参数 没有就不填
new XC_MethodHook() {
@Override
//方法执行前执行
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
param.args[0] = 10000;
Log.i("beforeHookedMethod","成功充值一万金币");
}
//方法执行后执行,改方法的返回值一定要在方法执行完毕后更改
protected void afterHookedMethod(MethodHookParam param)
throws Throwable {
param.setResult(10000); //param.setResult修改方法的返回值
Log.i("afterHookedMethod","成功充值一万金币");
}
}
);
Log.i("调用失败","失败!");
}
}
然后 效果图
成功 hook 然后 输出的调试信息
然后其实 我一开始 debug 好长时间 我都不知道 自己哪里出了问题 一直不对
后来我才发现
我一开始 y 写在里面了
然后 我 hook的那个 也应该写
.MainActivity.y 把外边那个类包含进来~~~~