diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index d36dd47..59ef1e9 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -10,21 +10,23 @@
-
+
+
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
index a5f05cd..2f42958 100644
--- a/.idea/jarRepositories.xml
+++ b/.idea/jarRepositories.xml
@@ -21,5 +21,15 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index b194a05..d513d83 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -2,7 +2,7 @@
-
+
diff --git a/Plugin/timePlugin/.gitignore b/ASMInject/.gitignore
similarity index 100%
rename from Plugin/timePlugin/.gitignore
rename to ASMInject/.gitignore
diff --git a/ASMInject/build.gradle b/ASMInject/build.gradle
new file mode 100644
index 0000000..8c091a6
--- /dev/null
+++ b/ASMInject/build.gradle
@@ -0,0 +1,45 @@
+plugins {
+ id 'com.android.library'
+ id 'kotlin-android'
+}
+
+android {
+ compileSdkVersion 30
+ buildToolsVersion "30.0.2"
+
+ defaultConfig {
+ minSdkVersion 21
+ targetSdkVersion 30
+ versionCode 1
+ versionName "1.0"
+
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+ consumerProguardFiles "consumer-rules.pro"
+ }
+
+ buildTypes {
+ release {
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
+ }
+ }
+ compileOptions {
+ sourceCompatibility JavaVersion.VERSION_1_8
+ targetCompatibility JavaVersion.VERSION_1_8
+ }
+ kotlinOptions {
+ jvmTarget = '1.8'
+ }
+}
+
+dependencies {
+
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
+ implementation 'androidx.core:core-ktx:1.2.0'
+ implementation 'androidx.appcompat:appcompat:1.1.0'
+ implementation 'com.google.android.material:material:1.1.0'
+ implementation("com.squareup.okhttp3:okhttp:4.9.1")
+ testImplementation 'junit:junit:4.+'
+ androidTestImplementation 'androidx.test.ext:junit:1.1.1'
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
+}
\ No newline at end of file
diff --git a/Plugin/timePlugin/consumer-rules.pro b/ASMInject/consumer-rules.pro
similarity index 100%
rename from Plugin/timePlugin/consumer-rules.pro
rename to ASMInject/consumer-rules.pro
diff --git a/Plugin/timePlugin/proguard-rules.pro b/ASMInject/proguard-rules.pro
similarity index 100%
rename from Plugin/timePlugin/proguard-rules.pro
rename to ASMInject/proguard-rules.pro
diff --git a/ASMInject/src/androidTest/java/com/github/crosswall/inject/ExampleInstrumentedTest.kt b/ASMInject/src/androidTest/java/com/github/crosswall/inject/ExampleInstrumentedTest.kt
new file mode 100644
index 0000000..c11fb8b
--- /dev/null
+++ b/ASMInject/src/androidTest/java/com/github/crosswall/inject/ExampleInstrumentedTest.kt
@@ -0,0 +1,24 @@
+package com.github.crosswall.inject
+
+import androidx.test.platform.app.InstrumentationRegistry
+import androidx.test.ext.junit.runners.AndroidJUnit4
+
+import org.junit.Test
+import org.junit.runner.RunWith
+
+import org.junit.Assert.*
+
+/**
+ * Instrumented test, which will execute on an Android device.
+ *
+ * See [testing documentation](http://d.android.com/tools/testing).
+ */
+@RunWith(AndroidJUnit4::class)
+class ExampleInstrumentedTest {
+ @Test
+ fun useAppContext() {
+ // Context of the app under test.
+ val appContext = InstrumentationRegistry.getInstrumentation().targetContext
+ assertEquals("com.github.crosswall.inject.test", appContext.packageName)
+ }
+}
\ No newline at end of file
diff --git a/ASMInject/src/main/AndroidManifest.xml b/ASMInject/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..298b7b2
--- /dev/null
+++ b/ASMInject/src/main/AndroidManifest.xml
@@ -0,0 +1,5 @@
+
+
+
+
\ No newline at end of file
diff --git a/ASMInject/src/main/java/com/github/crosswall/inject/OkHttpHooker.java b/ASMInject/src/main/java/com/github/crosswall/inject/OkHttpHooker.java
new file mode 100644
index 0000000..a8df7e7
--- /dev/null
+++ b/ASMInject/src/main/java/com/github/crosswall/inject/OkHttpHooker.java
@@ -0,0 +1,44 @@
+package com.github.crosswall.inject;
+
+import com.github.crosswall.inject.http.TimingOKEventListener;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import okhttp3.Dns;
+import okhttp3.EventListener;
+import okhttp3.Interceptor;
+
+public class OkHttpHooker {
+ public static EventListener.Factory globalEventFactory = TimingOKEventListener.FACTORY;
+
+// new EventListener.Factory() {
+// public EventListener create(Call call) {
+// return EventListener.NONE;
+// }
+// };
+
+ public static Dns globalDns = Dns.SYSTEM;
+
+ public static List globalInterceptors = new ArrayList<>();
+
+ public static List globalNetworkInterceptors = new ArrayList<>();
+
+ public static void installEventListenerFactory(EventListener.Factory factory) {
+ globalEventFactory = factory;
+ }
+
+ public static void installDns(Dns dns) {
+ globalDns = dns;
+ }
+
+ public static void installInterceptor(Interceptor interceptor) {
+ if(interceptor != null)
+ globalInterceptors.add(interceptor);
+ }
+
+ public static void installNetworkInterceptors(Interceptor networkInterceptor) {
+ if(networkInterceptor != null)
+ globalNetworkInterceptors.add(networkInterceptor);
+ }
+}
diff --git a/ASMInject/src/main/java/com/github/crosswall/inject/TimingTrace.java b/ASMInject/src/main/java/com/github/crosswall/inject/TimingTrace.java
new file mode 100644
index 0000000..bed728d
--- /dev/null
+++ b/ASMInject/src/main/java/com/github/crosswall/inject/TimingTrace.java
@@ -0,0 +1,23 @@
+package com.github.crosswall.inject;
+
+import android.os.SystemClock;
+import android.util.Log;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class TimingTrace {
+
+ private static final String TAG = "TimingTrace";
+
+ private static Map startMap = new HashMap<>();
+
+ public static void start(String name){
+ startMap.put(name, SystemClock.elapsedRealtimeNanos());
+ }
+
+ public static void end(String name){
+ long cost = SystemClock.elapsedRealtimeNanos() - startMap.get(name);
+ Log.d(TAG,"测试方法耗时====>>> " + name + " ---- " + cost / 1000000.f + "ms");
+ }
+}
diff --git a/ASMInject/src/main/java/com/github/crosswall/inject/http/TimingOKEventListener.java b/ASMInject/src/main/java/com/github/crosswall/inject/http/TimingOKEventListener.java
new file mode 100644
index 0000000..3f42df5
--- /dev/null
+++ b/ASMInject/src/main/java/com/github/crosswall/inject/http/TimingOKEventListener.java
@@ -0,0 +1,66 @@
+package com.github.crosswall.inject.http;
+
+import android.os.SystemClock;
+import android.util.Log;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.Proxy;
+import java.util.concurrent.atomic.AtomicLong;
+
+import okhttp3.Call;
+import okhttp3.EventListener;
+
+public class TimingOKEventListener extends EventListener{
+
+ private static final String TAG = "TimingTrace";
+
+ public static final EventListener.Factory FACTORY = new EventListener.Factory() {
+
+ AtomicLong nextCallId = new AtomicLong(1L);
+
+ @Override
+ public EventListener create(Call call) {
+ long callId = nextCallId.getAndIncrement();
+ return new TimingOKEventListener(callId);
+ }
+
+ };
+
+ private long callId;
+ private long callStartNanos = 0L;
+ private boolean isNewConnection = false;
+
+ public TimingOKEventListener(long callId) {
+ this.callId = callId;
+ }
+
+ @Override
+ public void callStart(Call call) {
+ callStartNanos = SystemClock.elapsedRealtimeNanos();
+ }
+
+ @Override
+ public void connectStart(Call call, InetSocketAddress inetSocketAddress, Proxy proxy) {
+ isNewConnection = true;
+ }
+
+ @Override
+ public void callEnd(Call call) {
+ printResult(true, call);
+ }
+
+ @Override
+ public void callFailed(Call call, IOException ioe) {
+ printResult(false, call);
+ }
+
+ private void printResult(boolean success, Call call) {
+ float elapsed = (SystemClock.elapsedRealtimeNanos() - callStartNanos) / 1000000.f;
+ String from = isNewConnection ? "newest connection" : "pooled connection";
+ String url = call.request().url().toString();
+ String result = String.format("%04d %s Call From %s costs %.3f ms, url %s", callId, success ? "Success" : "Fail", from, elapsed, url);
+ Log.i(TAG, "测试请求耗时====>>>" + result);
+ }
+
+}
diff --git a/ASMInject/src/test/java/com/github/crosswall/inject/ExampleUnitTest.kt b/ASMInject/src/test/java/com/github/crosswall/inject/ExampleUnitTest.kt
new file mode 100644
index 0000000..d88ce22
--- /dev/null
+++ b/ASMInject/src/test/java/com/github/crosswall/inject/ExampleUnitTest.kt
@@ -0,0 +1,17 @@
+package com.github.crosswall.inject
+
+import org.junit.Test
+
+import org.junit.Assert.*
+
+/**
+ * Example local unit test, which will execute on the development machine (host).
+ *
+ * See [testing documentation](http://d.android.com/tools/testing).
+ */
+class ExampleUnitTest {
+ @Test
+ fun addition_isCorrect() {
+ assertEquals(4, 2 + 2)
+ }
+}
\ No newline at end of file
diff --git a/Plugin/ASMHookerPlugin/.gitignore b/Plugin/ASMHookerPlugin/.gitignore
new file mode 100644
index 0000000..42afabf
--- /dev/null
+++ b/Plugin/ASMHookerPlugin/.gitignore
@@ -0,0 +1 @@
+/build
\ No newline at end of file
diff --git a/Plugin/timePlugin/build.gradle b/Plugin/ASMHookerPlugin/build.gradle
similarity index 89%
rename from Plugin/timePlugin/build.gradle
rename to Plugin/ASMHookerPlugin/build.gradle
index 8bedb6d..367464a 100644
--- a/Plugin/timePlugin/build.gradle
+++ b/Plugin/ASMHookerPlugin/build.gradle
@@ -17,6 +17,11 @@ dependencies {
implementation localGroovy()
implementation 'com.android.tools.build:gradle:3.1.0'
implementation 'commons-io:commons-io:2.6'
+
+ implementation 'org.ow2.asm:asm:7.1'
+ implementation 'org.ow2.asm:asm-util:7.1'
+ implementation 'org.ow2.asm:asm-commons:7.1'
+
// implementation 'org.javassist:javassist:3.27.0-GA'
// kapt "com.google.auto.service:auto-service:1.0-rc6"
// implementation 'com.google.auto.service:auto-service:1.0-rc6'
diff --git a/Plugin/ASMHookerPlugin/consumer-rules.pro b/Plugin/ASMHookerPlugin/consumer-rules.pro
new file mode 100644
index 0000000..e69de29
diff --git a/Plugin/ASMHookerPlugin/proguard-rules.pro b/Plugin/ASMHookerPlugin/proguard-rules.pro
new file mode 100644
index 0000000..481bb43
--- /dev/null
+++ b/Plugin/ASMHookerPlugin/proguard-rules.pro
@@ -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
+# http://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
\ No newline at end of file
diff --git a/Plugin/timePlugin/src/androidTest/java/com/github/crosswall/plugin/ExampleInstrumentedTest.kt b/Plugin/ASMHookerPlugin/src/androidTest/java/com/github/crosswall/plugin/ExampleInstrumentedTest.kt
similarity index 100%
rename from Plugin/timePlugin/src/androidTest/java/com/github/crosswall/plugin/ExampleInstrumentedTest.kt
rename to Plugin/ASMHookerPlugin/src/androidTest/java/com/github/crosswall/plugin/ExampleInstrumentedTest.kt
diff --git a/Plugin/timePlugin/src/main/AndroidManifest.xml b/Plugin/ASMHookerPlugin/src/main/AndroidManifest.xml
similarity index 100%
rename from Plugin/timePlugin/src/main/AndroidManifest.xml
rename to Plugin/ASMHookerPlugin/src/main/AndroidManifest.xml
diff --git a/Plugin/timePlugin/src/main/java/com/github/crosswall/plugin/ASMHookerPlugin.kt b/Plugin/ASMHookerPlugin/src/main/java/com/github/crosswall/plugin/ASMHookerPlugin.kt
similarity index 100%
rename from Plugin/timePlugin/src/main/java/com/github/crosswall/plugin/ASMHookerPlugin.kt
rename to Plugin/ASMHookerPlugin/src/main/java/com/github/crosswall/plugin/ASMHookerPlugin.kt
diff --git a/Plugin/timePlugin/src/main/java/com/github/crosswall/plugin/ASMTransformer.kt b/Plugin/ASMHookerPlugin/src/main/java/com/github/crosswall/plugin/ASMTransformer.kt
similarity index 88%
rename from Plugin/timePlugin/src/main/java/com/github/crosswall/plugin/ASMTransformer.kt
rename to Plugin/ASMHookerPlugin/src/main/java/com/github/crosswall/plugin/ASMTransformer.kt
index 93b51db..ce1493e 100644
--- a/Plugin/timePlugin/src/main/java/com/github/crosswall/plugin/ASMTransformer.kt
+++ b/Plugin/ASMHookerPlugin/src/main/java/com/github/crosswall/plugin/ASMTransformer.kt
@@ -2,6 +2,7 @@ package com.github.crosswall.plugin
import com.android.build.api.transform.*
import com.android.build.gradle.internal.pipeline.TransformManager
+import com.github.crosswall.plugin.core.OkHttpClassVisitor
import com.github.crosswall.plugin.core.TimeClassVisitor
import com.github.crosswall.plugin.option.HookerOption
import org.apache.commons.io.FileUtils
@@ -21,7 +22,7 @@ import java.util.jar.JarOutputStream
class ASMTransformer(private val project: Project, private val option: HookerOption) :
Transform() {
- override fun getName(): String = "time-class-transform"
+ override fun getName(): String = "asm-hooker-transform"
override fun getInputTypes(): MutableSet =
TransformManager.CONTENT_CLASS
@@ -71,10 +72,13 @@ class ASMTransformer(private val project: Project, private val option: HookerOpt
//字节码插桩
val clzReader = ClassReader(f.readBytes())
val clzWriter = ClassWriter(clzReader, ClassWriter.COMPUTE_MAXS)
- val cv = TimeClassVisitor(Opcodes.ASM5, clzWriter, option)
+
+ val cv = if (f.name.contains("okhttp3"))
+ OkHttpClassVisitor(Opcodes.ASM6, clzWriter) else TimeClassVisitor(Opcodes.ASM6, clzWriter, option)
clzReader.accept(cv, ClassReader.EXPAND_FRAMES)
val byteArray = clzWriter.toByteArray()
- val fos = FileOutputStream(f.parentFile.absolutePath + File.separator + f.name)
+ val fos =
+ FileOutputStream(f.parentFile.absolutePath + File.separator + f.name)
fos.write(byteArray)
fos.close()
}
@@ -120,7 +124,8 @@ class ASMTransformer(private val project: Project, private val option: HookerOpt
//字节码插桩
val clzReader = ClassReader(IOUtils.toByteArray(inputStream))
val clzWriter = ClassWriter(clzReader, ClassWriter.COMPUTE_MAXS)
- val cv = TimeClassVisitor(Opcodes.ASM5, clzWriter, option)
+ val cv = if (entryName.contains("okhttp3"))
+ OkHttpClassVisitor(Opcodes.ASM6, clzWriter) else TimeClassVisitor(Opcodes.ASM6, clzWriter, option)
clzReader.accept(cv, ClassReader.EXPAND_FRAMES)
val byteArray = clzWriter.toByteArray()
jarOutputStream.write(byteArray)
diff --git a/Plugin/timePlugin/src/main/java/com/github/crosswall/plugin/bean/TraceMethod.kt b/Plugin/ASMHookerPlugin/src/main/java/com/github/crosswall/plugin/bean/TraceMethod.kt
similarity index 100%
rename from Plugin/timePlugin/src/main/java/com/github/crosswall/plugin/bean/TraceMethod.kt
rename to Plugin/ASMHookerPlugin/src/main/java/com/github/crosswall/plugin/bean/TraceMethod.kt
diff --git a/Plugin/timePlugin/src/main/java/com/github/crosswall/plugin/core/GlideClassVisitor.kt b/Plugin/ASMHookerPlugin/src/main/java/com/github/crosswall/plugin/core/GlideClassVisitor.kt
similarity index 100%
rename from Plugin/timePlugin/src/main/java/com/github/crosswall/plugin/core/GlideClassVisitor.kt
rename to Plugin/ASMHookerPlugin/src/main/java/com/github/crosswall/plugin/core/GlideClassVisitor.kt
diff --git a/Plugin/ASMHookerPlugin/src/main/java/com/github/crosswall/plugin/core/OkHttpClassVisitor.kt b/Plugin/ASMHookerPlugin/src/main/java/com/github/crosswall/plugin/core/OkHttpClassVisitor.kt
new file mode 100644
index 0000000..816e1ae
--- /dev/null
+++ b/Plugin/ASMHookerPlugin/src/main/java/com/github/crosswall/plugin/core/OkHttpClassVisitor.kt
@@ -0,0 +1,81 @@
+package com.github.crosswall.plugin.core
+
+import org.objectweb.asm.ClassVisitor
+import org.objectweb.asm.MethodVisitor
+import org.objectweb.asm.Opcodes
+import org.objectweb.asm.commons.AdviceAdapter
+
+
+class OkHttpClassVisitor(api: Int, classVisitor: ClassVisitor?) : ClassVisitor(api, classVisitor) {
+
+ private var className: String? = null
+ override fun visit(
+ version: Int,
+ access: Int,
+ name: String?,
+ signature: String?,
+ superName: String?,
+ interfaces: Array?
+ ) {
+ super.visit(version, access, name, signature, superName, interfaces)
+ className = name
+ // println("$className")
+ }
+
+ override fun visitMethod(
+ access: Int, name: String,
+ desc: String?, signature: String?, exceptions: Array?
+ ): MethodVisitor? {
+// return super.visitMethod(
+// access,
+// name,
+// desc,
+// signature,
+// exceptions
+// )
+ //
+
+ return when{
+ className == "okhttp3/OkHttpClient\$Builder" && name == "" -> {
+ val mv =
+ cv.visitMethod(access, name, desc, signature, exceptions)
+ OkHttpMethodVisitor(api, mv, access, name, desc)
+ }
+ else -> super.visitMethod(access, name, desc, signature, exceptions)
+ }
+ }
+
+
+ inner class OkHttpMethodVisitor(
+ api: Int,
+ mv: MethodVisitor?,
+ access: Int,
+ name: String?,
+ desc: String?
+ ) : AdviceAdapter(api, mv, access, name, desc), Opcodes {
+
+
+ override fun visitInsn(opcode: Int) {
+ if (opcode >= Opcodes.IRETURN && opcode <= Opcodes.RETURN || opcode == Opcodes.ATHROW) {
+
+ mv.visitVarInsn(Opcodes.ALOAD, 0)
+ mv.visitFieldInsn(
+ Opcodes.GETSTATIC,
+ "com/github/crosswall/inject/OkHttpHooker",
+ "globalEventFactory",
+ "Lokhttp3/EventListener\$Factory;"
+ )
+ mv.visitFieldInsn(
+ Opcodes.PUTFIELD,
+ "okhttp3/OkHttpClient\$Builder",
+ "eventListenerFactory",
+ "Lokhttp3/EventListener\$Factory;"
+ )
+
+ }
+ super.visitInsn(opcode)
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/Plugin/timePlugin/src/main/java/com/github/crosswall/plugin/core/TimeClassVisitor.kt b/Plugin/ASMHookerPlugin/src/main/java/com/github/crosswall/plugin/core/TimeClassVisitor.kt
similarity index 99%
rename from Plugin/timePlugin/src/main/java/com/github/crosswall/plugin/core/TimeClassVisitor.kt
rename to Plugin/ASMHookerPlugin/src/main/java/com/github/crosswall/plugin/core/TimeClassVisitor.kt
index f219d4b..c36602c 100644
--- a/Plugin/timePlugin/src/main/java/com/github/crosswall/plugin/core/TimeClassVisitor.kt
+++ b/Plugin/ASMHookerPlugin/src/main/java/com/github/crosswall/plugin/core/TimeClassVisitor.kt
@@ -56,8 +56,6 @@ class TimeClassVisitor(api: Int, clzVisitor: ClassVisitor, private val option: H
)
else -> {
val mv = cv.visitMethod(access, name, desc, signature, exceptions)
-
-
TimeMethodVisitor(api, mv, access, name, desc, className)
}
}
diff --git a/Plugin/timePlugin/src/main/java/com/github/crosswall/plugin/core/TrackClassVisitor.kt b/Plugin/ASMHookerPlugin/src/main/java/com/github/crosswall/plugin/core/TrackClassVisitor.kt
similarity index 100%
rename from Plugin/timePlugin/src/main/java/com/github/crosswall/plugin/core/TrackClassVisitor.kt
rename to Plugin/ASMHookerPlugin/src/main/java/com/github/crosswall/plugin/core/TrackClassVisitor.kt
diff --git a/Plugin/timePlugin/src/main/java/com/github/crosswall/plugin/option/HookerOption.kt b/Plugin/ASMHookerPlugin/src/main/java/com/github/crosswall/plugin/option/HookerOption.kt
similarity index 100%
rename from Plugin/timePlugin/src/main/java/com/github/crosswall/plugin/option/HookerOption.kt
rename to Plugin/ASMHookerPlugin/src/main/java/com/github/crosswall/plugin/option/HookerOption.kt
diff --git a/Plugin/timePlugin/src/main/resources/META-INF/gradle-plugins/asm-hooker-plugin.properties b/Plugin/ASMHookerPlugin/src/main/resources/META-INF/gradle-plugins/asm-hooker-plugin.properties
similarity index 100%
rename from Plugin/timePlugin/src/main/resources/META-INF/gradle-plugins/asm-hooker-plugin.properties
rename to Plugin/ASMHookerPlugin/src/main/resources/META-INF/gradle-plugins/asm-hooker-plugin.properties
diff --git a/Plugin/timePlugin/src/test/java/com/github/crosswall/plugin/ExampleUnitTest.kt b/Plugin/ASMHookerPlugin/src/test/java/com/github/crosswall/plugin/ExampleUnitTest.kt
similarity index 100%
rename from Plugin/timePlugin/src/test/java/com/github/crosswall/plugin/ExampleUnitTest.kt
rename to Plugin/ASMHookerPlugin/src/test/java/com/github/crosswall/plugin/ExampleUnitTest.kt
diff --git a/Plugin/settings.gradle b/Plugin/settings.gradle
index dc08c28..14d9205 100644
--- a/Plugin/settings.gradle
+++ b/Plugin/settings.gradle
@@ -1,2 +1,2 @@
rootProject.name = "Plugin"
-include ':timePlugin'
+include ':ASMHookerPlugin'
\ No newline at end of file
diff --git a/Plugin/timePlugin/src/main/java/com/github/crosswall/plugin/core/OkHttpClassVisitor.kt b/Plugin/timePlugin/src/main/java/com/github/crosswall/plugin/core/OkHttpClassVisitor.kt
deleted file mode 100644
index 263f7a0..0000000
--- a/Plugin/timePlugin/src/main/java/com/github/crosswall/plugin/core/OkHttpClassVisitor.kt
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.github.crosswall.plugin.core
-
-//TODO 占位待完善
-class OkHttpClassVisitor {
-}
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 8df3baf..5257461 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -37,7 +37,7 @@ hookerOption {
test = "hello"
test2 = "world!"
- setBeatClass("com.github.crosswall.app.Test")
+ setBeatClass("com.github.crosswall.inject.TimingTrace")
addPackageList('com.github.crosswall.app')
}
@@ -50,6 +50,8 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
+ implementation("com.squareup.okhttp3:okhttp:4.9.1")
+ implementation project(":ASMInject")
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index b84efdc..9995f27 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -2,6 +2,8 @@
+
+
(R.id.btn_hello).setOnClickListener {
Test2().also {
it.hello()
diff --git a/app/src/main/java/com/github/crosswall/app/test/Test2.java b/app/src/main/java/com/github/crosswall/app/test/Test2.java
index 02741df..1fd13cc 100644
--- a/app/src/main/java/com/github/crosswall/app/test/Test2.java
+++ b/app/src/main/java/com/github/crosswall/app/test/Test2.java
@@ -2,14 +2,29 @@
import android.os.SystemClock;
+import java.io.IOException;
+
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+
public class Test2 {
- public void hello() throws InterruptedException {
- for (int i = 0; i < 1000000; i++) {
+ public void hello(){
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+
+ Request request = new Request.Builder().url("https://api-one.wallstcn.com/apiv1/content/carousel/information-flow?channel=global&limit=5").build();
+ OkHttpClient client = createClient();
+ try {
+ client.newCall(request).execute();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }).start();
- }
- SystemClock.sleep(20);
}
public void world() {
@@ -19,4 +34,10 @@ public void world() {
}
SystemClock.sleep(20);
}
+
+
+ private OkHttpClient createClient(){
+ OkHttpClient.Builder builder = new OkHttpClient.Builder();
+ return builder.build();
+ }
}
diff --git a/build.gradle b/build.gradle
index 959f17f..2813521 100644
--- a/build.gradle
+++ b/build.gradle
@@ -4,6 +4,8 @@ buildscript {
repositories {
google()
jcenter()
+ mavenCentral()
+ maven { url "https://dl.bintray.com/thelasterstar/maven/" }
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.3"
@@ -16,13 +18,15 @@ buildscript {
plugins {
// 这个 id 就是在 versionPlugin 文件夹下 build.gradle 文件内定义的id
- id "asm-hooker-plugin" apply false
+ id "asm-hooker-plugin"
}
allprojects {
repositories {
google()
jcenter()
+ mavenCentral()
+ maven { url "https://dl.bintray.com/thelasterstar/maven/" }
}
}
diff --git a/settings.gradle b/settings.gradle
index 4e59305..3fee68a 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -1,3 +1,4 @@
include ':app'
+include ':ASMInject'
includeBuild('./Plugin')
rootProject.name = "ASMPluginTest"
\ No newline at end of file