From 3cd5ee34c783ff8091ac725590fa649b6c4ded71 Mon Sep 17 00:00:00 2001
From: fengyuecanzhu <1021300691@qq.com>
Date: Tue, 29 Mar 2022 21:44:10 +0800
Subject: [PATCH] fix dynamic
---
.idea/gradle.xml | 1 +
app/src/test/java/Test.java | 2 +-
dynamic/build.gradle | 2 +-
.../main/java/xyz/fycz/dynamic/AppLoadImpl.kt | 73 +++++++++++++------
4 files changed, 53 insertions(+), 25 deletions(-)
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index 976a899..2dc7e53 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -19,5 +19,6 @@
+
\ No newline at end of file
diff --git a/app/src/test/java/Test.java b/app/src/test/java/Test.java
index 168db9f..b9c03bd 100644
--- a/app/src/test/java/Test.java
+++ b/app/src/test/java/Test.java
@@ -117,7 +117,7 @@ public class Test {
@org.junit.Test
public void md5(){
- File file = new File("D:\\Java\\AndroidSdk\\build-tools\\29.0.3\\dynamic_v1.0.2.dex");
+ File file = new File("D:\\Java\\AndroidSdk\\build-tools\\29.0.3\\dynamic-test.dex");
System.out.println(MD5Utils.INSTANCE.getFileMD5s(file, 32));
}
}
diff --git a/dynamic/build.gradle b/dynamic/build.gradle
index 27227fc..9dfa1bb 100644
--- a/dynamic/build.gradle
+++ b/dynamic/build.gradle
@@ -5,7 +5,7 @@ plugins {
android {
compileSdkVersion 29
-
+ buildToolsVersion '29.0.3'
defaultConfig {
minSdkVersion 21
targetSdkVersion 29
diff --git a/dynamic/src/main/java/xyz/fycz/dynamic/AppLoadImpl.kt b/dynamic/src/main/java/xyz/fycz/dynamic/AppLoadImpl.kt
index d10ca33..21b898c 100644
--- a/dynamic/src/main/java/xyz/fycz/dynamic/AppLoadImpl.kt
+++ b/dynamic/src/main/java/xyz/fycz/dynamic/AppLoadImpl.kt
@@ -2,19 +2,66 @@ package xyz.fycz.dynamic
import android.app.AlertDialog
import android.content.Context
+import android.content.DialogInterface
import android.os.Bundle
import me.fycz.maple.MapleBridge
import me.fycz.maple.MapleUtils
import me.fycz.maple.MethodHook
-import me.fycz.maple.MethodReplacement
/**
* @author fengyue
* @date 2022/3/29 11:59
*/
class AppLoadImpl : IAppLoader {
+ val spuName = "FYReader_plugin"
+
override fun onLoad(appParam: AppParam) {
- /*try {
+ announce(appParam, "风月读书插件测试",
+ "2022-03-23\n当你看到这条消息时,表示插件成功加载", "2022-03-30")
+ }
+
+ private fun announce(appParam: AppParam, title: String, msg: String, key: String) {
+ try {
+ MapleUtils.findAndHookMethod(
+ "xyz.fycz.myreader.ui.activity.MainActivity",
+ appParam.classLoader,
+ "onCreate",
+ Bundle::class.java,
+ object : MethodHook() {
+ override fun afterHookedMethod(param: MapleBridge.MethodHookParam) {
+ val context = param.thisObject as Context
+ val spu = context.getSharedPreferences(spuName, Context.MODE_PRIVATE)
+ val hasRead = spu.getBoolean(key, false)
+ if (!hasRead) {
+ AlertDialog.Builder(context)
+ .setTitle(title)
+ .setMessage(msg)
+ .setPositiveButton("我知道了") { _, _ ->
+ spu.edit().run {
+ putBoolean(key, true)
+ apply()
+ }
+ }.create().show()
+ MapleUtils.callStaticMethod(
+ MapleUtils.findClass(
+ "xyz.fycz.myreader.util.utils.AdUtils",
+ appParam.classLoader
+ ),"adRecord",
+ arrayOf(String::class.java, String::class.java),
+ "plugin", "success"
+ )
+ }
+ }
+ }
+ )
+ } catch (e: Exception) {
+ e.printStackTrace()
+ MapleUtils.log(e)
+ }
+ }
+
+ /*fun noAd(appParam: AppParam) {
+ try {
MapleUtils.findAndHookMethod(
"xyz.fycz.myreader.util.utils.AdUtils",
appParam.classLoader,
@@ -37,25 +84,5 @@ class AppLoadImpl : IAppLoader {
e.printStackTrace()
MapleUtils.log(e)
}
-
- try {
- MapleUtils.findAndHookMethod(
- "xyz.fycz.myreader.ui.activity.MainActivity",
- appParam.classLoader,
- "onCreate",
- Bundle::class.java,
- object : MethodHook() {
- override fun afterHookedMethod(param: MapleBridge.MethodHookParam) {
- AlertDialog.Builder(param.thisObject as Context)
- .setTitle("风月读书插件")
- .setMessage("此消息由风月读书插件提供")
- .create().show()
- }
- }
- )
- } catch (e: Exception) {
- e.printStackTrace()
- MapleUtils.log(e)
- }*/
- }
+ }*/
}
\ No newline at end of file