Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: DisableUtfControlCharacterInNickname #1151

Merged
merged 1 commit into from
Aug 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
package wang.allenyou.hook

import android.annotation.SuppressLint
import android.graphics.Canvas
import android.widget.EditText
import android.widget.TextView
import cc.ioctl.util.hookBeforeIfEnabled
import io.github.qauxv.base.annotation.FunctionHookEntry
import io.github.qauxv.base.annotation.UiItemAgentEntry
import io.github.qauxv.dsl.FunctionEntryRouter
import io.github.qauxv.hook.CommonSwitchFunctionHook
import io.github.qauxv.util.Initiator
import io.github.qauxv.util.Log
import io.github.qauxv.util.QQVersion
import io.github.qauxv.util.requireMinQQVersion
import io.github.qauxv.util.xpcompat.XC_MethodHook

@FunctionHookEntry
@UiItemAgentEntry
Expand All @@ -52,29 +52,16 @@ object DisableUtfControlCharacterInNicknameHook : CommonSwitchFunctionHook() {

override fun initOnce(): Boolean {
val textViewClass = Initiator.loadClass("android.widget.TextView")
val onPreDrawMethod = textViewClass.getDeclaredMethod("onPreDraw")
val wrappedTextViewClass = Initiator.loadClass("android.widget.WrappedTextView")
val setWrappedTextMethod = wrappedTextViewClass.getDeclaredMethod("setText", CharSequence::class.java, Initiator.loadClass("android.widget.TextView${'$'}BufferType"))
val modifyHook = fun(hookParam: XC_MethodHook.MethodHookParam){
if (hookParam.args.isEmpty()) {
return
}
if (hookParam.args[0] !is CharSequence) {
return
}
Log.d("${hookParam.args[0]} [[Allenyou-Debug]]")
if (BLACKLIST.map { ch -> (hookParam.args[0] as String).contains(ch)}.isEmpty()) {
return
}
hookParam.args[0] = filterControlCharacter(hookParam.args[0] as CharSequence)
}
hookBeforeIfEnabled(setWrappedTextMethod, modifyHook)
hookBeforeIfEnabled(onPreDrawMethod) {
val onDrawMethod = textViewClass.getDeclaredMethod("onDraw", Canvas::class.java)
hookBeforeIfEnabled(onDrawMethod) {
if (it.thisObject !is TextView) {
return@hookBeforeIfEnabled
}
if (it.thisObject is EditText) {
return@hookBeforeIfEnabled
}
val str = (it.thisObject as TextView).text.toString()
if (BLACKLIST.map { ch -> str.contains(ch)}.isEmpty()) {
if (BLACKLIST.none { ch -> str.contains(ch) }) {
return@hookBeforeIfEnabled
}
(it.thisObject as TextView).text = filterControlCharacter(str)
Expand Down
Loading