Skip to content

Commit

Permalink
修复高版本Android中对应用动态加载dex行为的监控
Browse files Browse the repository at this point in the history
  • Loading branch information
imlk0 committed May 6, 2018
1 parent e6927dc commit 2e0eff9
Show file tree
Hide file tree
Showing 16 changed files with 239 additions and 115 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ZjDroid
[![release](https://img.shields.io/badge/download-v1.0.1(2)-brightgreen.svg)](https://github.com/KB5201314/ZjDroid/releases)
[![release](https://img.shields.io/badge/download-v1.0.2(3)-brightgreen.svg)](https://github.com/KB5201314/ZjDroid/releases)

凑齐了ZjDroid的源码,并在原版的基础上进行了一些改进。

Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
minSdkVersion 8
targetSdkVersion 22

versionCode 2
versionName "1.0.1"
versionCode 3
versionName "1.0.2"

multiDexEnabled true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public final class BuildConfig {
public static final String APPLICATION_ID = "com.android.reverse";
public static final String BUILD_TYPE = "debug";
public static final String FLAVOR = "";
public static final int VERSION_CODE = 2;
public static final String VERSION_NAME = "1.0.1";
public static final int VERSION_CODE = 3;
public static final String VERSION_NAME = "1.0.2";
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.reverse"
android:versionCode="2"
android:versionName="1.0.1" >
android:versionCode="3"
android:versionName="1.0.2" >

<uses-sdk
android:minSdkVersion="8"
Expand Down
2 changes: 1 addition & 1 deletion app/build/intermediates/manifests/full/debug/output.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"outputType":{"type":"MERGED_MANIFESTS"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":2,"versionName":"1.0.1","enabled":true,"outputFile":"app-debug.apk","fullName":"debug","baseName":"debug"},"path":"AndroidManifest.xml","properties":{"packageId":"com.android.reverse","split":"","minSdkVersion":"8"}}]
[{"outputType":{"type":"MERGED_MANIFESTS"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":3,"versionName":"1.0.2","enabled":true,"outputFile":"app-debug.apk","fullName":"debug","baseName":"debug"},"path":"AndroidManifest.xml","properties":{"packageId":"com.android.reverse","split":"","minSdkVersion":"8"}}]
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"outputType":{"type":"INSTANT_RUN_MERGED_MANIFESTS"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":2,"versionName":"1.0.1","enabled":true,"outputFile":"app-debug.apk","fullName":"debug","baseName":"debug"},"path":"AndroidManifest.xml","properties":{"packageId":"com.android.reverse","split":"","minSdkVersion":"8"}}]
[{"outputType":{"type":"INSTANT_RUN_MERGED_MANIFESTS"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":3,"versionName":"1.0.2","enabled":true,"outputFile":"app-debug.apk","fullName":"debug","baseName":"debug"},"path":"AndroidManifest.xml","properties":{"packageId":"com.android.reverse","split":"","minSdkVersion":"8"}}]
2 changes: 1 addition & 1 deletion app/build/intermediates/res/debug/output.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"outputType":{"type":"PROCESSED_RES"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":2,"versionName":"1.0.1","enabled":true,"outputFile":"app-debug.apk","fullName":"debug","baseName":"debug"},"path":"resources-debug.ap_","properties":{"packageId":"com.android.reverse","split":"","minSdkVersion":"8"}}]
[{"outputType":{"type":"PROCESSED_RES"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":3,"versionName":"1.0.2","enabled":true,"outputFile":"app-debug.apk","fullName":"debug","baseName":"debug"},"path":"resources-debug.ap_","properties":{"packageId":"com.android.reverse","split":"","minSdkVersion":"8"}}]
Binary file modified app/build/intermediates/res/debug/resources-debug.ap_
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"type":"MAIN","splits":[],"versionCode":2,"versionName":"1.0.1","enabled":true,"outputFile":"app-debug.apk","fullName":"debug","baseName":"debug"}]
[{"type":"MAIN","splits":[],"versionCode":3,"versionName":"1.0.2","enabled":true,"outputFile":"app-debug.apk","fullName":"debug","baseName":"debug"}]
Binary file modified app/release/app-release.apk
Binary file not shown.
2 changes: 1 addition & 1 deletion app/release/output.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":2,"versionName":"1.0.1","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":3,"versionName":"1.0.2","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
139 changes: 97 additions & 42 deletions app/src/main/java/com/android/reverse/apimonitor/AlarmManagerHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,113 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Build;
import android.os.Handler;
import android.os.WorkSource;

import com.android.reverse.hook.HookParam;
import com.android.reverse.util.Logger;
import com.android.reverse.util.RefInvoke;


public class AlarmManagerHook extends ApiMonitorHook {

@Override
public void startHook() {

Method setImplmethod = RefInvoke.findMethodExact(
"android.app.AlarmManager", ClassLoader.getSystemClassLoader(),
"setImpl",int.class,long.class,long.class,long.class,PendingIntent.class,WorkSource.class);
hookhelper.hookMethod(setImplmethod, new AbstractBahaviorHookCallBack() {

@Override
public void descParam(HookParam param) {
Logger.log_behavior("The Alarm Information:");
PendingIntent intent = (PendingIntent) param.args[4];
descPendingIntent(intent);
Logger.log_behavior("TriggerAtMillis = "+param.args[1]);
Logger.log_behavior("windowMillis = "+param.args[2]);
Logger.log_behavior("intervalMillis = "+param.args[3]);

}
});

}

private void descPendingIntent(PendingIntent pintent){
Method getIntentMethod = RefInvoke.findMethodExact(
"android.app.PendingIntent", ClassLoader.getSystemClassLoader(),
"getIntent");
try {
Intent intent = (Intent) getIntentMethod.invoke(pintent, new Object[]{});
ComponentName cn = intent.getComponent();
if(cn != null){
Logger.log_behavior("The ComponentName = "+cn.getPackageName()+"/"+cn.getClassName());
}
Logger.log_behavior("The Intent Action = "+intent.getAction());
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}

}
@Override
public void startHook() {

if (Build.VERSION.SDK_INT >= 24) {

// private void setImpl(@AlarmType int type, long triggerAtMillis, long windowMillis,
// long intervalMillis, int flags, PendingIntent operation, final OnAlarmListener listener,
// String listenerTag, Handler targetHandler, WorkSource workSource,
// AlarmClockInfo alarmClock) {

Method setImplmethod = RefInvoke.findMethodExact(
"android.app.AlarmManager", ClassLoader.getSystemClassLoader(),
"setImpl", int.class, long.class, long.class, long.class, int.class, PendingIntent.class, AlarmManager.OnAlarmListener.class, String.class, Handler.class, WorkSource.class, AlarmManager.AlarmClockInfo.class);
hookhelper.hookMethod(setImplmethod, new AbstractBahaviorHookCallBack() {

@Override
public void descParam(HookParam param) {
Logger.log_behavior("The Alarm Information:");
PendingIntent intent = (PendingIntent) param.args[5];
descPendingIntent(intent);
Logger.log_behavior("TriggerAtMillis = " + param.args[1]);
Logger.log_behavior("windowMillis = " + param.args[2]);
Logger.log_behavior("intervalMillis = " + param.args[3]);
Logger.log_behavior("flags = " + param.args[4]);
Logger.log_behavior("listener.class = " + param.args[6].getClass().getName());
Logger.log_behavior("listenerTag = " + param.args[7]);
Logger.log_behavior("Handler.class = " + param.args[8].getClass().getName());

}
});


} else if (Build.VERSION.SDK_INT > 19) {

Method setImplmethod = RefInvoke.findMethodExact(
"android.app.AlarmManager", ClassLoader.getSystemClassLoader(),
"setImpl", int.class, long.class, long.class, long.class, PendingIntent.class, WorkSource.class, AlarmManager.AlarmClockInfo.class);
hookhelper.hookMethod(setImplmethod, new AbstractBahaviorHookCallBack() {

@Override
public void descParam(HookParam param) {
Logger.log_behavior("The Alarm Information:");
PendingIntent intent = (PendingIntent) param.args[4];
descPendingIntent(intent);
Logger.log_behavior("TriggerAtMillis = " + param.args[1]);
Logger.log_behavior("windowMillis = " + param.args[2]);
Logger.log_behavior("intervalMillis = " + param.args[3]);

}
});
} else {


Method setImplmethod = RefInvoke.findMethodExact(
"android.app.AlarmManager", ClassLoader.getSystemClassLoader(),
"setImpl", int.class, long.class, long.class, long.class, PendingIntent.class, WorkSource.class);
hookhelper.hookMethod(setImplmethod, new AbstractBahaviorHookCallBack() {

@Override
public void descParam(HookParam param) {
Logger.log_behavior("The Alarm Information:");
PendingIntent intent = (PendingIntent) param.args[4];
descPendingIntent(intent);
Logger.log_behavior("TriggerAtMillis = " + param.args[1]);
Logger.log_behavior("windowMillis = " + param.args[2]);
Logger.log_behavior("intervalMillis = " + param.args[3]);

}
});
}

}

private void descPendingIntent(PendingIntent pintent) {
Method getIntentMethod = RefInvoke.findMethodExact(
"android.app.PendingIntent", ClassLoader.getSystemClassLoader(),
"getIntent");
try {
Intent intent = (Intent) getIntentMethod.invoke(pintent, new Object[]{});
ComponentName cn = intent.getComponent();
if (cn != null) {
Logger.log_behavior("The ComponentName = " + cn.getPackageName() + "/" + cn.getClassName());
}
Logger.log_behavior("The Intent Action = " + intent.getAction());
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}

}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.android.reverse.apimonitor;

import android.os.Build;

import java.lang.reflect.Method;


Expand All @@ -9,21 +11,26 @@

public class ConnectivityManagerHook extends ApiMonitorHook {

@Override
public void startHook() {

Method setMobileDataEnabledmethod = RefInvoke.findMethodExact(
"android.net.ConnectivityManager", ClassLoader.getSystemClassLoader(),
"setMobileDataEnabled",boolean.class);
hookhelper.hookMethod(setMobileDataEnabledmethod, new AbstractBahaviorHookCallBack() {

@Override
public void descParam(HookParam param) {
boolean status = (Boolean) param.args[0];
Logger.log("Set MobileDataEnabled = "+status);
}
});

}
@Override
public void startHook() {

if (Build.VERSION.SDK_INT <= 19) {

Method setMobileDataEnabledmethod = RefInvoke.findMethodExact(
"android.net.ConnectivityManager", ClassLoader.getSystemClassLoader(),
"setMobileDataEnabled", boolean.class);
hookhelper.hookMethod(setMobileDataEnabledmethod, new AbstractBahaviorHookCallBack() {

@Override
public void descParam(HookParam param) {
boolean status = (Boolean) param.args[0];
Logger.log("Set MobileDataEnabled = " + status);
}
});

}


}

}
Loading

0 comments on commit 2e0eff9

Please sign in to comment.