dynamic fix 243

pull/21/head
fengyuecanzhu 3 years ago
parent 3cd5ee34c7
commit 7cb9be422f
  1. 1
      .idea/gradle.xml
  2. 5
      .idea/jarRepositories.xml
  3. 6
      .idea/render.experimental.xml
  4. 2
      app/build.gradle
  5. 2
      app/src/main/java/xyz/fycz/myreader/util/utils/PluginUtils.kt
  6. 1
      build.gradle
  7. 6
      dynamic/build.gradle
  8. 18
      dynamic/src/androidTest/java/xyz/fycz/dynamic/ExampleInstrumentedTest.kt
  9. 93
      dynamic/src/main/java/xyz/fycz/dynamic/App243Fix.kt
  10. 49
      dynamic/src/main/java/xyz/fycz/dynamic/AppLoadImpl.kt

@ -19,6 +19,5 @@
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
<option name="offlineMode" value="true" />
</component>
</project>

@ -36,5 +36,10 @@
<option name="name" value="maven3" />
<option name="url" value="http://maven.aliyun.com/nexus/content/repositories/releases/" />
</remote-repository>
<remote-repository>
<option name="id" value="MavenLocal" />
<option name="name" value="MavenLocal" />
<option name="url" value="file:/G:/maven/repository/" />
</remote-repository>
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RenderSettings">
<option name="quality" value="0.4" />
</component>
</project>

@ -153,7 +153,7 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
// androidx
implementation 'androidx.core:core-ktx:1.6.0'
implementation "androidx.core:core-ktx:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
implementation 'androidx.appcompat:appcompat:1.3.1'

@ -48,7 +48,7 @@ object PluginUtils {
} else {
config = oldConfig
}
if (config!!.md5.lowercase(Locale.getDefault())
if (!App.isDebug() && config!!.md5.lowercase(Locale.getDefault())
!= getPluginMD5(config!!)?.lowercase(Locale.getDefault())
) {
downloadPlugin(config!!)

@ -28,6 +28,7 @@ allprojects {
jcenter()
maven { url "https://jitpack.io" }
maven { url 'https://artifact.bytedance.com/repository/pangle'}
mavenLocal()
}
/*gradle.projectsEvaluated {
tasks.withType(JavaCompile) {

@ -30,9 +30,11 @@ android {
}
dependencies {
implementation 'androidx.core:core-ktx:1.6.0'
implementation "androidx.core:core-ktx:$kotlin_version"
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
compileOnly("me.fycz.maple:maple:1.6")
compileOnly("me.fycz.maple:maple:1.7")
compileOnly 'org.greenrobot:greendao:3.3.0'
compileOnly project(":app")
}

@ -2,11 +2,13 @@ package xyz.fycz.dynamic
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import me.fycz.maple.MapleUtils
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
import xyz.fycz.myreader.application.App
/**
* Instrumented test, which will execute on an Android device.
@ -16,9 +18,19 @@ import org.junit.Assert.*
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
fun testFix() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("xyz.fycz.dynamic.test", appContext.packageName)
if (App.getVersionCode() == 243) {
try {
App243Fix.fixGetAllNoLocalSource()
} catch (e: Exception) {
MapleUtils.log(e)
}
try {
App243Fix.fixAdTimeout()
} catch (e: Exception) {
MapleUtils.log(e)
}
}
}
}

@ -0,0 +1,93 @@
package xyz.fycz.dynamic
import android.os.Handler
import me.fycz.maple.MapleBridge
import me.fycz.maple.MapleUtils
import me.fycz.maple.MethodHook
import me.fycz.maple.MethodReplacement
import xyz.fycz.myreader.greendao.DbManager
import xyz.fycz.myreader.greendao.entity.rule.BookSource
import xyz.fycz.myreader.greendao.gen.BookSourceDao
import xyz.fycz.myreader.model.sourceAnalyzer.BookSourceManager
import xyz.fycz.myreader.ui.activity.SplashActivity
import xyz.fycz.myreader.util.SharedPreAdUtils
import xyz.fycz.myreader.util.utils.AdUtils
/**
* @author fengyue
* @date 2022/3/31 9:21
*/
object App243Fix {
private fun getAllNoLocalSource(): List<BookSource> {
return DbManager.getDaoSession().bookSourceDao.queryBuilder()
.where(BookSourceDao.Properties.SourceEName.isNull)
.where(BookSourceDao.Properties.SourceType.isNotNull)
.orderAsc(BookSourceDao.Properties.OrderNum)
.list()
}
fun fixGetAllNoLocalSource() {
MapleUtils.findAndHookMethod(
BookSourceManager::class.java,
"getAllNoLocalSource",
object : MethodReplacement() {
override fun replaceHookedMethod(param: MapleBridge.MethodHookParam): Any {
return getAllNoLocalSource()
}
}
)
}
private fun adTimeOut(param: MapleBridge.MethodHookParam) {
val time = param.args[0] as Int
val obj = param.thisObject
if (time == 0) {
MapleUtils.setStaticIntField(SplashActivity::class.java, "WAIT_INTERVAL", 0)
SharedPreAdUtils.getInstance()
.putLong("splashAdTime", System.currentTimeMillis())
MapleUtils.callMethod(obj, "startNormal")
SharedPreAdUtils.getInstance().putBoolean("adTimeOut", true)
} else {
if (time > 5){
MapleUtils.setIntField(obj, "timeOut", 5)
}
val handler = MapleUtils.getObjectField(obj, "handler") as Handler
val adTimeOutRunnable = MapleUtils.getObjectField(obj, "adTimeOutRunnable") as Runnable
handler.postDelayed(adTimeOutRunnable, 1000)
}
}
fun fixAdTimeout() {
MapleUtils.findAndHookMethod(
SplashActivity::class.java,
"adTimeout",
Int::class.javaPrimitiveType,
object : MethodReplacement() {
override fun replaceHookedMethod(param: MapleBridge.MethodHookParam) {
adTimeOut(param)
}
}
)
MapleUtils.findAndHookMethod(
SplashActivity::class.java,
"countTodayAd",
object : MethodHook(){
override fun afterHookedMethod(param: MapleBridge.MethodHookParam) {
SharedPreAdUtils.getInstance().putBoolean("adTimeOut", false)
}
}
)
MapleUtils.findAndHookMethod(
AdUtils::class.java,
"backSplashAd",
object : MethodHook(){
override fun beforeHookedMethod(param: MapleBridge.MethodHookParam) {
if (SharedPreAdUtils.getInstance().getBoolean("adTimeOut")){
param.result = false
}
}
}
)
}
}

@ -2,22 +2,39 @@ 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 xyz.fycz.myreader.application.App
import xyz.fycz.myreader.util.utils.AdUtils
/**
* @author fengyue
* @date 2022/3/29 11:59
*/
class AppLoadImpl : IAppLoader {
val spuName = "FYReader_plugin"
private val spuName = "FYReader_plugin"
private val spu = App.getmContext().getSharedPreferences(spuName, Context.MODE_PRIVATE)
override fun onLoad(appParam: AppParam) {
announce(appParam, "风月读书插件测试",
"2022-03-23\n当你看到这条消息时,表示插件成功加载", "2022-03-30")
if (App.getVersionCode() == 243) {
val key = "2022-03-31"
try {
App243Fix.fixGetAllNoLocalSource()
fixResult(key, "getAllNoLocalSource", true)
} catch (e: Exception) {
MapleUtils.log(e)
fixResult(key, "getAllNoLocalSource", false)
}
try {
App243Fix.fixAdTimeout()
fixResult(key, "adTimeout", true)
} catch (e: Exception) {
MapleUtils.log(e)
fixResult(key, "adTimeout", false)
}
}
}
private fun announce(appParam: AppParam, title: String, msg: String, key: String) {
@ -30,26 +47,19 @@ class AppLoadImpl : IAppLoader {
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("我知道了") { _, _ ->
}.create().show()
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"
)
AdUtils.adRecord("plugin", "adSuccess")
}
}
}
@ -60,6 +70,17 @@ class AppLoadImpl : IAppLoader {
}
}
private fun fixResult(key: String, name: String, success: Boolean) {
val res = if (success) "Success" else "Failed"
if (!spu.getBoolean("$key-$name-$res", false)) {
AdUtils.adRecord(name, "fx$res")
spu.edit().run {
putBoolean("$key-$name-$res", true)
apply()
}
}
}
/*fun noAd(appParam: AppParam) {
try {
MapleUtils.findAndHookMethod(

Loading…
Cancel
Save