Skip to content

Commit

Permalink
telegram: auto uncheck share phone number
Browse files Browse the repository at this point in the history
  • Loading branch information
5ec1cff committed Jun 7, 2024
1 parent 524e6da commit 90fd9b8
Showing 1 changed file with 34 additions and 14 deletions.
48 changes: 34 additions & 14 deletions app/src/main/java/five/ec1cff/myinjector/TelegramHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ import de.robv.android.xposed.XposedHelpers
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam
import java.util.WeakHashMap

fun View.findView(predicate: (View) -> Boolean): View? {
if (predicate(this)) return this
if (this is ViewGroup) {
for (i in 0 until childCount) {
val v = getChildAt(i).findView(predicate)
if (v != null) return v
}
}
return null
}

class TelegramHandler : IXposedHookLoadPackage {
companion object {
private const val TAG = "TelegramHandler"
Expand All @@ -41,6 +52,26 @@ class TelegramHandler : IXposedHookLoadPackage {
hookContactPermission(lpparam)
// hookUserProfileShowId(lpparam)
hookAutoCheckDeleteMessagesOptionAlso(lpparam)
hookAutoUncheckSharePhoneNum(lpparam)
}

private fun hookAutoUncheckSharePhoneNum(lpparam: LoadPackageParam) = runCatching {
XposedBridge.hookAllMethods(
XposedHelpers.findClass("org.telegram.ui.ContactAddActivity", lpparam.classLoader),
"createView",
object : XC_MethodHook() {
override fun afterHookedMethod(param: MethodHookParam) {
val checkBox =
XposedHelpers.getObjectField(param.thisObject, "checkBoxCell") as? View
?: return
if (XposedHelpers.callMethod(checkBox, "isChecked") == true) {
checkBox.performClick()
}
}
}
)
}.onFailure {
Log.e(TAG, "hookAutoUncheckSharePhoneNum: failed", it)
}

private fun hookAutoCheckDeleteMessagesOptionAlso(lpparam: LoadPackageParam) =
Expand Down Expand Up @@ -84,21 +115,10 @@ class TelegramHandler : IXposedHookLoadPackage {
?: return

// TODO: find the checkbox correctly
fun find(v: View): View? {
if (checkBoxCellClass.isInstance(v)) {
if (XposedHelpers.callMethod(v, "isChecked") == false)
return v
}
if (v is ViewGroup) {
for (i in 0 until v.childCount) {
val retVal = find(v.getChildAt(i))
if (retVal != null) return retVal
}
}
return null
val v = root.findView {
checkBoxCellClass.isInstance(it) &&
XposedHelpers.callMethod(it, "isChecked") == false
}

val v = find(root)
Log.d(TAG, "beforeHookedMethod: found view: $v")
v?.performClick()
}
Expand Down

0 comments on commit 90fd9b8

Please sign in to comment.