Skip to content

Commit

Permalink
去掉清空方法体
Browse files Browse the repository at this point in the history
  • Loading branch information
Peakmain committed May 18, 2022
1 parent dd6c54f commit 9c3ce50
Show file tree
Hide file tree
Showing 22 changed files with 92 additions and 34 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ monitorPlugin {
"com.peakmain.asmactualcombat.utils.TestUtils",
"com.peakmain.plugin"
]
methodStatus = 3
methodStatus = 2
disableStackMapFrame = false
}
59 changes: 59 additions & 0 deletions app/src/main/java/com/peakmain/asmactualcombat/utils/Utils.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.peakmain.asmactualcombat.utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;

import com.peakmain.ui.utils.LogUtils;

import java.util.Locale;

Expand All @@ -17,6 +21,14 @@
* describe:
*/
public class Utils {
Context mContext;
WifiManager mWifiManager;

public Utils(Context context, WifiManager wifiManager) {
this.mContext = context;
this.mWifiManager = wifiManager;
}

public static String getDeviceId(Context context) {
String tac = "";
TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
Expand Down Expand Up @@ -61,6 +73,53 @@ public static String getMacDefault(Context context) {
return mac;
}

public final WifiInfo getConnectionInfo() {
try {
try {
return mWifiManager.getConnectionInfo();
} catch (Exception e) {
e.printStackTrace();
}
} catch (Throwable var1) {
}

return null;
}

public final WifiInfo getConnectionInfo1() {
try {
try {
if (mWifiManager.getConnectionInfo() != null) {
LogUtils.e("not null");
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (Throwable var1) {
}

return null;
}

public final boolean a(ConnectivityManager var1) {
WifiManager var2;
if ((var2 = this.mWifiManager) == null) {
return false;
} else {
boolean var3 = false;

try {
if (var2.getConnectionInfo()!=null) {
var3 = true;
}
} catch (Throwable var4) {
}

return var3;
}
}


public static String getAndroidId(Context context) {
return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ class MonitorConfig {
public ArrayList<String> whiteList = []
/**
* 隐私方法方法的状态
* @params 1 代表清空方法体
* @params 2 代表替换方法体
* @params 其他都代表 正常情况
* @params 0 代表正常
* @params 其他都代表 替换
*/
public int methodStatus = 0
private MethodFieldUtils.StatusEnum statusEnum = MethodFieldUtils.StatusEnum.METHOD_STATE_NORMAL
Expand All @@ -34,7 +33,7 @@ class MonitorConfig {
'android.support.v4.app.NotificationManagerCompat']
HashSet<String> exceptSet = new HashSet<>()
/**
* 是否禁用开启堆栈分析,默认是禁用com.atour.atourlife
* 是否禁用开启堆栈分析,默认是禁用
*/
public boolean disableStackMapFrame = true
public String interceptPackageName = "com/atour"
Expand All @@ -47,10 +46,8 @@ class MonitorConfig {
for (int i = 0; i < whiteList.size(); i++) {
whiteList.set(i, whiteList.get(i).replace(".", "/"))
}
println(methodStatus)
if (methodStatus == MethodFieldUtils.StatusEnum.METHOD_STATE_CLEAR.value) {
statusEnum = MethodFieldUtils.StatusEnum.METHOD_STATE_CLEAR
} else if (methodStatus == MethodFieldUtils.StatusEnum.METHOD_STATE_REPLACE.value) {
println("当前方法的Status:" + methodStatus)
if (methodStatus == MethodFieldUtils.StatusEnum.METHOD_STATE_REPLACE.value) {
statusEnum = MethodFieldUtils.StatusEnum.METHOD_STATE_REPLACE
} else {
statusEnum = MethodFieldUtils.StatusEnum.METHOD_STATE_NORMAL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import org.objectweb.asm.Opcodes
class MethodFieldUtils {
public static final String PLUGIN_VERSION = "1.0.8"
enum StatusEnum {
METHOD_STATE_NORMAL(1),
METHOD_STATE_CLEAR(2),
METHOD_STATE_REPLACE(3)
METHOD_STATE_NORMAL(0),
METHOD_STATE_REPLACE(1)
private int value

StatusEnum(int value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class MonitorMethodCalledClearAdapter extends MonitorDefalutMethodAdapter {

private int mAccess
private MonitorConfig monitorConfig
private String mDesc
/**
* Constructs a new {@link MonitorMethodCalledClearAdapter}.
*
Expand All @@ -32,23 +33,26 @@ class MonitorMethodCalledClearAdapter extends MonitorDefalutMethodAdapter {
super(mv, access, name, desc)
mClassName = className
mAccess = access
mDesc = desc
this.monitorConfig = monitorConfig
}

@Override
void visitMethodInsn(int opcodeAndSource, String owner, String name, String descriptor, boolean isInterface) {
HashMap<String, MethodCalledBean> methodCalledBeans = MonitorHookMethodConfig.methodCalledBeans
if (!monitorConfig.whiteList.contains(mClassName) && !monitorConfig.exceptSet.contains(mClassName) && methodCalledBeans.containsKey(owner + name + descriptor)) {
//println("调用方法的class:" + mClassName + ",方法的名字:" + name + ",方法的描述符:" + descriptor)
clearMethodBody(mv, mClassName, access, name, descriptor)
println("调用方法的class:" + mClassName + ",方法的名字:" + name + ",方法的描述符:" + descriptor)
clearMethodBody(mv, mClassName, access, name, descriptor,mDesc)
return
}
super.visitMethodInsn(opcodeAndSource, owner, name, descriptor, isInterface);
}


static void clearMethodBody(MethodVisitor mv, String className, int access, String name, String descriptor) {
static void clearMethodBody(MethodVisitor mv, String className, int access, String name, String descriptor,String methodDescriptor) {
Type type = Type.getType(descriptor)
Type methodType = Type.getType(methodDescriptor)
Type methodReturnType = methodType.getReturnType()
Type[] argumentsType = type.getArgumentTypes()
Type returnType = type.getReturnType()
int stackSize = returnType.getSize()
Expand All @@ -57,12 +61,12 @@ class MonitorMethodCalledClearAdapter extends MonitorDefalutMethodAdapter {
localSize += argType.size
}
mv.visitCode()
if (returnType.getSort() == Type.VOID) {
if (methodReturnType.getSort() == Type.VOID) {
mv.visitInsn(RETURN)
} else if (returnType.getSort() >= Type.BOOLEAN && returnType.getSort() <= Type.DOUBLE) {
mv.visitInsn(returnType.getOpcode(ICONST_1))
mv.visitInsn(returnType.getOpcode(IRETURN))
} else if (returnType.getInternalName() == "java/lang/String") {
} else if (methodReturnType.getSort() >= Type.BOOLEAN && methodReturnType.getSort() <= Type.DOUBLE) {
mv.visitInsn(methodReturnType.getOpcode(ICONST_1))
mv.visitInsn(methodReturnType.getOpcode(IRETURN))
} else if (methodReturnType.getInternalName() == "java/lang/String") {
mv.visitLdcInsn("")
mv.visitInsn(ARETURN)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class MonitorMethodCalledReplaceAdapter extends MonitorDefalutMethodAdapter {
HashMap<String, MethodCalledBean> methodReplaceBeans = MonitorHookMethodConfig.methodCalledBeans
String desc = owner + name + descriptor
if (!monitorConfig.whiteList.contains(mClassName) && !monitorConfig.exceptSet.contains(mClassName)&&methodReplaceBeans.containsKey(desc)) {
println("调用方法的class:" + mClassName + ",方法的名字:" + name + ",方法的描述符:" + descriptor)
MethodCalledBean bean = methodReplaceBeans.get(desc)
super.visitMethodInsn(bean.newOpcode, bean.newMethodOwner, bean.newMethodName, bean.newMethodDescriptor.get(descriptor), false)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ class PeakmainVisitor extends ClassVisitor {
MethodVisitor methodVisitor = super.visitMethod(access, name, descriptor, signature, exceptions)
methodVisitor = new MonitorClickAdapter(methodVisitor, access, name, descriptor, mMethodCells, mInterfaces,mMonitorConfig,mClassName)
methodVisitor = new MonitorPrintParametersReturnValueAdapter(methodVisitor, access, name, descriptor, mClassName, classVisitor)
if (mMonitorConfig.getStatusEnum() == MethodFieldUtils.StatusEnum.METHOD_STATE_CLEAR)
methodVisitor = new MonitorMethodCalledClearAdapter(methodVisitor, access, name, descriptor, mClassName, mMonitorConfig)
else if (mMonitorConfig.getStatusEnum() == MethodFieldUtils.StatusEnum.METHOD_STATE_REPLACE) {
if (mMonitorConfig.getStatusEnum() != MethodFieldUtils.StatusEnum.METHOD_STATE_NORMAL) {
methodVisitor = new MonitorMethodCalledReplaceAdapter(methodVisitor, access, name, descriptor, classVisitor,mClassName,mMonitorConfig)
}
if (!mMonitorConfig.disableStackMapFrame)
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
260e793fe7290d33b63458d18ae4579b
aa3d302743bf0d0125e80c7933e12ef3
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0469062f62f7e4723a55c41c4596e43917503709
bb33bdf0292444a4f68911b2e81aeb6b166710b2
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5397cdde9ede71935afdb78c2267d978
9ffd4220993e477a9fc630bfebc781c9
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3ad27a8dc00f94cc5b40ecc1385edca4d01386f9
1477c6e37ceff13ffd3ac10822e53cc1ac6337b6
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
f3ccb3f78f2beae7638dc4ad78f1dc6b
cac97c3ae5be0ec78f886f3cb968286a
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fd5854720b2060019f78227b803b69a29c92e748
eef649de0f4810ba60c657dba1d8595e63a03ccd
Binary file modified repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8ba7250e2778fc021b4da67909cea5e3
71c760bab10c33f06b2a44b960682d88
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7d4af61b767637024eb5446b4158daeb979dfbac
d67a3ab5517114e573367604d41fcb8bbaec0c81
2 changes: 1 addition & 1 deletion repo/com/peakmain/android.plugin/maven-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<versions>
<version>1.0.0</version>
</versions>
<lastUpdated>20220518024611</lastUpdated>
<lastUpdated>20220518064857</lastUpdated>
</versioning>
</metadata>
2 changes: 1 addition & 1 deletion repo/com/peakmain/android.plugin/maven-metadata.xml.md5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0dbc7d90b85a4b7207ce3d98438054dd
fa781a6335847929e9b713610faab9d7
2 changes: 1 addition & 1 deletion repo/com/peakmain/android.plugin/maven-metadata.xml.sha1
Original file line number Diff line number Diff line change
@@ -1 +1 @@
e93efc87ab92469dc8c44e401bb3a87322b80650
a18657fdc1e3e97eb0e5a22a5e2ce0348ca52083

0 comments on commit 9c3ce50

Please sign in to comment.