Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

Commit

Permalink
适配多个旧版本至24.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
GangJust committed Mar 17, 2023
1 parent b2d205d commit 3f7541b
Show file tree
Hide file tree
Showing 7 changed files with 298 additions and 232 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "com.freegang.fplus"
minSdk 21
targetSdk 33
versionCode 3
versionName "1.0.2"
versionCode 4
versionName "1.0.3"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/assets/update.log
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ v1.0.1
关注页未获取到基本信息

v1.0.2
更换评论区图片的判断逻辑
适配抖音24.6.0
更换评论区图片的判断逻辑

v1.0.3
适配抖音24.0.0、24.1.0、24.2.0、24.3.0
修复评论区图片24.4.0无法保存情况
174 changes: 126 additions & 48 deletions core/src/main/java/com/freegang/douyin/HAbsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.freegang.douyin.model.DeAweme
import com.freegang.douyin.model.ImageUrlStruct
import com.freegang.xpler.R
import com.freegang.xpler.databinding.HookAppbarLayoutBinding
import com.freegang.xpler.utils.app.KAppVersionUtils.appVersionName
import com.freegang.xpler.utils.json.KJSONUtils.getStringOrDefault
import com.freegang.xpler.utils.json.KJSONUtils.isEmpties
import com.freegang.xpler.utils.json.KJSONUtils.parseJSON
Expand All @@ -38,15 +39,18 @@ class HAbsActivity(
lpparam: XC_LoadPackage.LoadPackageParam,
) : BaseHook(lpparam) {
private var primaryClipChangedListener: ClipboardManager.OnPrimaryClipChangedListener? = null
val config: Config //get, 确保获取时已经有值
get() = Config.get()

override fun onHook() {
val config = Config.get()

lpparam.hookClass(AbsActivity::class.java)
.method("onCreate", Bundle::class.java) {
onAfter {
if (!config.isEmoji) return@onAfter
getCommentImage(this)
val absActivity = thisObject as AbsActivity
if (absActivity !is DetailActivity) return@onAfter
hookComment(absActivity)
}
}
.method("onResume") {
Expand Down Expand Up @@ -91,20 +95,7 @@ class HAbsActivity(
//val sortUrl = shareText.substring(urlIndexOf)
//mainLogic(absActivity, sortUrl, config)

if (absActivity is DetailActivity || absActivity is MainActivity) {
val methods = absActivity.findMethodsByReturnType(Aweme::class.java)
if (methods.isNotEmpty()) {
var aweme = methods.first().call(absActivity)
if (aweme == null) {
val curFragment = absActivity.findMethod("getCurFragment", *arrayOf<Any>())?.call(absActivity)
val curFragmentMethods = curFragment?.findMethodsByReturnType(Aweme::class.java) ?: listOf()
if (curFragmentMethods.isNotEmpty()) {
aweme = curFragmentMethods.first().call(curFragment!!)
}
}
DownloadLogic(this@HAbsActivity, absActivity, aweme, config.isOwnerDir)
}
}
hookActivity(absActivity)
}
clipboardManager.addPrimaryClipChangedListener(primaryClipChangedListener)
}
Expand All @@ -116,58 +107,145 @@ class HAbsActivity(
clipboardManager.removePrimaryClipChangedListener(primaryClipChangedListener)
}

// 获取评论区图片
private fun getCommentImage(it: XC_MethodHook.MethodHookParam) {
val absActivity = it.thisObject as AbsActivity
if (absActivity !is DetailActivity) return
private fun hookActivity(absActivity: AbsActivity) {
hookActivityAt1(absActivity)
hookActivityAt2(absActivity)
}

launch {
delay(200L)
private fun hookActivityAt1(absActivity: AbsActivity) {
val versions = listOf("24.0.0", "24.1.0", "24.2.0")
if (!versions.contains(absActivity.appVersionName)) return

//获取内容
var urlList: List<String> = listOf()
if (absActivity is MainActivity) {
val methods = absActivity.findMethodsByReturnType(Aweme::class.java)
if (methods.isNotEmpty()) {
val aweme = methods.first().call(absActivity) ?: return@launch
var aweme = methods.first().call(absActivity)
if (aweme == null) {
val curFragment = absActivity.findMethod("getCurFragment", *arrayOf<Any>())?.call(absActivity)
val curFragmentMethods = curFragment?.findMethodsByReturnType(Aweme::class.java) ?: listOf()
if (curFragmentMethods.isNotEmpty()) {
aweme = curFragmentMethods.first().call(curFragment!!)
}
}
DownloadLogic(this@HAbsActivity, absActivity, aweme, config.isOwnerDir)
}
}

//如果是评论区的评论, 则获取图片
val commentFeedOuterAweme = aweme.getObjectField<Any>("commentFeedOuterAweme")
if (commentFeedOuterAweme != null) {
val image = aweme.getObjectField<List<Any>>("images")?.first() ?: return@launch
urlList = image.getObjectField<List<String>>("urlList") ?: return@launch
if (absActivity is DetailActivity) {
val any1 = absActivity.getObjectField<Any>("LIZJ") ?: return
val methods = any1.findMethodsByReturnType(Aweme::class.java)
if (methods.isNotEmpty()) {
val aweme = methods.first().call(any1)
DownloadLogic(this@HAbsActivity, absActivity, aweme, config.isOwnerDir)
}
}
}

private fun hookActivityAt2(absActivity: AbsActivity) {
val versions = listOf("24.2.0", "24.3.0", "24.4.0", "24.5.0", "24.6.0")
if (!versions.contains(absActivity.appVersionName)) return

if (absActivity is DetailActivity || absActivity is MainActivity) {
val methods = absActivity.findMethodsByReturnType(Aweme::class.java)
if (methods.isNotEmpty()) {
var aweme = methods.first().call(absActivity)
if (aweme == null) {
val curFragment = absActivity.findMethod("getCurFragment", *arrayOf<Any>())?.call(absActivity)
val curFragmentMethods = curFragment?.findMethodsByReturnType(Aweme::class.java) ?: listOf()
if (curFragmentMethods.isNotEmpty()) {
aweme = curFragmentMethods.first().call(curFragment!!)
}
}
DownloadLogic(this@HAbsActivity, absActivity, aweme, config.isOwnerDir)
}
}
}

// 获取评论区图片
private fun hookComment(absActivity: AbsActivity) {
launch {
delay(200L)

if (urlList.isEmpty()) return@launch
hookCommentAt1(absActivity)
hookCommentAt2(absActivity)
}
}

//重新构建顶部操作栏
val contentView: View = absActivity.window.decorView.findViewById(android.R.id.content)
val outViews = ArrayList<View>()
contentView.findViewsWithText(outViews, "返回", View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION)
val backBtn = outViews.first { it.contentDescription.equals("返回") }
private fun hookCommentAt1(absActivity: AbsActivity) {
val versions = listOf("24.0.0", "24.1.0", "24.2.0")

//清空旧视图
val viewGroup = backBtn.parent as ViewGroup
viewGroup.removeAllViews()
if (!versions.contains(absActivity.appVersionName)) return
var urlList: List<String> = listOf()

//重新构建视图
val appbar = KResourceUtils.inflateView<RelativeLayout>(viewGroup.context, R.layout.hook_appbar_layout)
val binding = HookAppbarLayoutBinding.bind(appbar)
binding.backBtn.setOnClickListener {
backBtn.performClick()
val any1 = absActivity.getObjectField<Any>("LIZJ") ?: return
val methods = any1.findMethodsByReturnType(Aweme::class.java)
if (methods.isNotEmpty()) {
val aweme = methods.first().call(any1) ?: return
val aid = aweme.getObjectField<Any>("aid")
if (aid != null && "$aid".contains("-|[a-z]".toRegex())) {
val image = aweme.getObjectField<List<Any>>("images")?.first() ?: return
urlList = image.getObjectField<List<String>>("urlList") ?: listOf()
}
binding.saveBtn.setOnClickListener {
SaveLogic(this@HAbsActivity, it.context, urlList)
}

if (urlList.isEmpty()) return
rebuildCommentTopBarView(absActivity, urlList)
}

private fun hookCommentAt2(absActivity: AbsActivity) {
val versions = listOf("24.2.0", "24.3.0", "24.4.0", "24.5.0", "24.6.0")
if (!versions.contains(absActivity.appVersionName)) return

var urlList: List<String> = listOf()
val methods = absActivity.findMethodsByReturnType(Aweme::class.java)
if (methods.isNotEmpty()) {
val aweme = methods.first().call(absActivity) ?: return
// 如果是评论区的评论, 则获取图片
// 24.2.0, 24.3.0, 24.4.0
val commentFeedOuterCid = aweme.getObjectField<Any>("commentFeedOuterCid")
if (commentFeedOuterCid != null) {
val image = aweme.getObjectField<List<Any>>("images")?.first() ?: return
urlList = image.getObjectField<List<String>>("urlList") ?: listOf()
}

// 24.5.0, 24.6.0
val commentFeedOuterAweme = aweme.getObjectField<Any>("commentFeedOuterAweme")
if (commentFeedOuterAweme != null) {
val image = aweme.getObjectField<List<Any>>("images")?.first() ?: return
urlList = image.getObjectField<List<String>>("urlList") ?: listOf()
}
viewGroup.addView(appbar)
}
if (urlList.isEmpty()) return
rebuildCommentTopBarView(absActivity, urlList)
}

// 重新构建评论区顶部操作栏
private fun rebuildCommentTopBarView(absActivity: AbsActivity, urlList: List<String> = listOf()) {
val contentView: View = absActivity.window.decorView.findViewById(android.R.id.content)
val outViews = ArrayList<View>()
contentView.findViewsWithText(outViews, "返回", View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION)
val backBtn = outViews.first { it.contentDescription.equals("返回") }

//清空旧视图
val viewGroup = backBtn.parent as ViewGroup
viewGroup.removeAllViews()

//重新构建视图
val appbar = KResourceUtils.inflateView<RelativeLayout>(viewGroup.context, R.layout.hook_appbar_layout)
val binding = HookAppbarLayoutBinding.bind(appbar)
binding.backBtn.setOnClickListener {
backBtn.performClick()
}
binding.saveBtn.setOnClickListener {
SaveLogic(this@HAbsActivity, it.context, urlList)
}
viewGroup.addView(appbar)
}

///// @Deprecated
// 获取接口中的视频信息
@Deprecated("Deprecated")
private fun mainLogic(absActivity: AbsActivity, sortUrl: String, config: Config) {
private fun mainLogic(absActivity: AbsActivity, sortUrl: String) {
launch {
try {
val originUrl = getOriginalUrl(sortUrl)
Expand Down
11 changes: 9 additions & 2 deletions core/src/main/java/com/freegang/douyin/HMainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.freegang.base.BaseHook
import com.freegang.config.Config
import com.freegang.xpler.utils.app.KAppVersionUtils.appVersionCode
import com.freegang.xpler.utils.app.KAppVersionUtils.appVersionName
import com.freegang.xpler.utils.io.KStorageUtils.hasOperationStorage
import com.freegang.xpler.xp.hookClass
import com.freegang.xpler.xp.thisActivity
import com.ss.android.ugc.aweme.main.MainActivity
Expand All @@ -21,7 +20,15 @@ class HMainActivity(
) : BaseHook(lpparam) {

//当前适配版本列表
private val supportVersions = listOf("24.4.0", "24.5.0", "24.6.0")
private val supportVersions = listOf(
"24.0.0",
"24.1.0",
"24.2.0",
"24.3.0",
"24.4.0",
"24.5.0",
"24.6.0",
)

override fun onHook() {
val config = Config.get()
Expand Down
42 changes: 21 additions & 21 deletions core/src/main/java/com/freegang/xpler/utils/app/KAppVersionUtils.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.freegang.xpler.utils.app

import android.app.Application
import android.content.Context
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.os.Build
Expand All @@ -11,27 +11,27 @@ object KAppVersionUtils {
/**
* 返回某个App的版本名
*
* @param application application
* @param context Context
* @param packageName 包名(需要App已安装)
* @return String
*/
@JvmStatic
@JvmOverloads
fun getVersionName(application: Application, packageName: String = application.packageName): String {
return getPackageInfo(application, packageName).versionName
fun getVersionName(context: Context, packageName: String = context.packageName): String {
return getPackageInfo(context, packageName).versionName
}

/**
* 返回某个App的版本号
*
* @param application application
* @param context Context
* @param packageName 包名(需要App已安装)
* @return Long
*/
@JvmStatic
@JvmOverloads
fun getVersionCode(application: Application, packageName: String = application.packageName): Long {
val packageInfo = getPackageInfo(application, packageName)
fun getVersionCode(context: Context, packageName: String = context.packageName): Long {
val packageInfo = getPackageInfo(context, packageName)
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
packageInfo.longVersionCode
} else {
Expand All @@ -42,38 +42,38 @@ object KAppVersionUtils {
/**
* 返回某个App的基本信息
*
* @param application application
* @param context Context
* @param packageName 包名(需要App已安装)
* @return PackageInfo
*/
@JvmStatic
@JvmOverloads
fun getPackageInfo(application: Application, packageName: String = application.packageName): PackageInfo {
return application.packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES)
fun getPackageInfo(context: Context, packageName: String = context.packageName): PackageInfo {
return context.packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES)
}

/**
* 返回某个Apk的版本名
*
* @param application application
* @param context Context
* @param apkFile apk文件路径
* @return String
*/
@JvmStatic
fun getApkVersionName(application: Application, apkFile: File): String? {
return getApkPackageInfo(application, apkFile)?.versionName
fun getApkVersionName(context: Context, apkFile: File): String? {
return getApkPackageInfo(context, apkFile)?.versionName
}

/**
* 返回某个Apk的版本号
*
* @param application application
* @param context Context
* @param apkFile apk文件路径
* @return Long
*/
@JvmStatic
fun getApkVersionCode(application: Application, apkFile: File): Long? {
val packageInfo = getApkPackageInfo(application, apkFile)
fun getApkVersionCode(context: Context, apkFile: File): Long? {
val packageInfo = getApkPackageInfo(context, apkFile)
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
packageInfo?.longVersionCode
} else {
Expand All @@ -84,13 +84,13 @@ object KAppVersionUtils {
/**
* 返回某个Apk的基本信息
*
* @param application application
* @param context Context
* @param apkFile apk文件路径
* @return PackageInfo
*/
@JvmStatic
fun getApkPackageInfo(application: Application, apkFile: File): PackageInfo? {
return application.packageManager.getPackageArchiveInfo(apkFile.absolutePath, PackageManager.GET_ACTIVITIES)
fun getApkPackageInfo(context: Context, apkFile: File): PackageInfo? {
return context.packageManager.getPackageArchiveInfo(apkFile.absolutePath, PackageManager.GET_ACTIVITIES)
}

/**
Expand All @@ -108,9 +108,9 @@ object KAppVersionUtils {
}

///
val Application.appVersionName
val Context.appVersionName
get() = getVersionName(this)

val Application.appVersionCode
val Context.appVersionCode
get() = getVersionCode(this)
}
Loading

0 comments on commit 3f7541b

Please sign in to comment.