Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bmax121 committed Apr 26, 2018
0 parents commit a693a45
Show file tree
Hide file tree
Showing 98 changed files with 3,308 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
Binary file added .idea/caches/build_file_checksums.ser
Binary file not shown.
29 changes: 29 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 60 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
29 changes: 29 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 26
defaultConfig {
applicationId "com.bmax.budhook"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile project(path: ':library')
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# https://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.bmax.budhook;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="https://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("com.bmax.budhook", appContext.getPackageName());
}
}
22 changes: 22 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="https://schemas.android.com/apk/res/android"
package="com.bmax.budhook">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
114 changes: 114 additions & 0 deletions app/src/main/java/com/bmax/budhook/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package com.bmax.budhook;

import android.Manifest;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import java.lang.reflect.Method;

import bmax.budhook.BudHelpers;
import dalvik.system.DexClassLoader;

public class MainActivity extends AppCompatActivity {
public static final String TAG = "budhook";

private static final int REQUEST_EXTERNAL_STORAGE = 1;
private static String[] PERMISSIONS_STORAGE = {
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE};


private Button btn_test ;
private Button btn_hook ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

btn_hook = (Button) findViewById(R.id.btn_hook);
btn_test = (Button) findViewById(R.id.btn_test);

int permission = ActivityCompat.checkSelfPermission(this,
Manifest.permission.READ_EXTERNAL_STORAGE);

if (permission != PackageManager.PERMISSION_GRANTED) {
//如果应用程序没有权限,则会提示用户授予权限
ActivityCompat.requestPermissions(this, PERMISSIONS_STORAGE,
REQUEST_EXTERNAL_STORAGE);
}



BudHelpers.init(getBaseContext());


ClassLoader classLoader = getClassLoader();

final DexClassLoader dexClassLoader = new DexClassLoader("/sdcard/appplugin-debug.apk",
getCodeCacheDir().getAbsolutePath(), null, classLoader);

Log.d(TAG,dexClassLoader.toString());

btn_hook.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

try {
Class demo = Class.forName("bmax.budhook.demo.BudHookDemo", true, dexClassLoader);

Method startHook = demo.getMethod("startHook",ClassLoader.class);

startHook.invoke(null,getClassLoader());

} catch (Exception e) {
e.printStackTrace();
}

}
});

btn_test.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
runTestFun(MainActivity.this);
}
});

}

public static void runTestFun(MainActivity thiz){


test1(1,2,'c');


long ret = thiz.test2("test2 arg1","test2 arg2","test2 arg3","test2 arg4","test2 arg5",new TestClass("constructor test"));
Log.d(TAG,"test2 ret" + Long.toString(ret));

try {
thiz.test3("def");
} catch (Throwable e) {
Log.d(TAG,e.toString());
}
}

public static void test1(int arg1,double arg2,char arg3){
Log.d(TAG,"arg1:" + arg1 + " arg2:" + arg2 +" arg3:" + arg3);
}

public long test2(String arg1,String arg2,String arg3,String arg4,String arg5,TestClass arg6){

return 1111;
}

public void test3(Object a) throws Exception{
Log.d(TAG,"origin call test3" );
throw new Exception("origin exception");
}

}
18 changes: 18 additions & 0 deletions app/src/main/java/com/bmax/budhook/TestClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.bmax.budhook;

import android.util.Log;

/**
* Created by bmax on 2018/4/13.
*/

public class TestClass {

public TestClass(String s){
Log.d("budhook","origin call constructor");
}
@Override
public String toString(){
return "origin TestClass toString()";
}
}
Loading

0 comments on commit a693a45

Please sign in to comment.