fix(Messenger - Remove Meta AI): Improve patch logic (#5153)
This commit is contained in:
@ -1,16 +1,24 @@
|
||||
package app.revanced.extension.messenger.metaai;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import app.revanced.extension.shared.Logger;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class RemoveMetaAIPatch {
|
||||
private static final Set<Long> loggedIDs = Collections.synchronizedSet(new HashSet<>());
|
||||
|
||||
public static boolean overrideBooleanFlag(long id, boolean value) {
|
||||
// This catches all flag IDs related to Meta AI.
|
||||
// The IDs change slightly with every update,
|
||||
// so to work around this, IDs from different versions were compared
|
||||
// to find what they have in common, which turned out to be those first bits.
|
||||
// TODO: Find the specific flags that we care about and patch the code they control instead.
|
||||
if ((id & 0x7FFFFFC000000000L) == 0x810A8000000000L) {
|
||||
try {
|
||||
if (Long.toString(id).startsWith("REPLACED_BY_PATCH")) {
|
||||
if (loggedIDs.add(id))
|
||||
Logger.printInfo(() -> "Overriding " + id + " from " + value + " to false");
|
||||
|
||||
return false;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Logger.printException(() -> "overrideBooleanFlag failure", ex);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
@ -11,3 +11,15 @@ internal val getMobileConfigBoolFingerprint = fingerprint {
|
||||
classDef.interfaces.contains("Lcom/facebook/mobileconfig/factory/MobileConfigUnsafeContext;")
|
||||
}
|
||||
}
|
||||
|
||||
internal val metaAIKillSwitchCheckFingerprint = fingerprint {
|
||||
strings("SearchAiagentImplementationsKillSwitch")
|
||||
opcodes(Opcode.CONST_WIDE)
|
||||
}
|
||||
|
||||
internal val extensionMethodFingerprint = fingerprint {
|
||||
strings("REPLACED_BY_PATCH")
|
||||
custom { method, classDef ->
|
||||
method.name == EXTENSION_METHOD_NAME && classDef.type == EXTENSION_CLASS_DESCRIPTOR
|
||||
}
|
||||
}
|
||||
|
@ -2,11 +2,14 @@ package app.revanced.patches.messenger.metaai
|
||||
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
|
||||
import app.revanced.patcher.patch.bytecodePatch
|
||||
import app.revanced.patches.messenger.misc.extension.sharedExtensionPatch
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.WideLiteralInstruction
|
||||
|
||||
private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/messenger/metaai/RemoveMetaAIPatch;"
|
||||
internal const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/messenger/metaai/RemoveMetaAIPatch;"
|
||||
internal const val EXTENSION_METHOD_NAME = "overrideBooleanFlag"
|
||||
|
||||
@Suppress("unused")
|
||||
val removeMetaAIPatch = bytecodePatch(
|
||||
@ -25,10 +28,25 @@ val removeMetaAIPatch = bytecodePatch(
|
||||
addInstructions(
|
||||
returnIndex,
|
||||
"""
|
||||
invoke-static { p1, p2, v$returnRegister }, $EXTENSION_CLASS_DESCRIPTOR->overrideBooleanFlag(JZ)Z
|
||||
invoke-static { p1, p2, v$returnRegister }, $EXTENSION_CLASS_DESCRIPTOR->$EXTENSION_METHOD_NAME(JZ)Z
|
||||
move-result v$returnRegister
|
||||
"""
|
||||
)
|
||||
}
|
||||
|
||||
// Extract the common starting digits of Meta AI flag IDs from a flag found in code.
|
||||
val relevantDigits = with(metaAIKillSwitchCheckFingerprint) {
|
||||
method.getInstruction<WideLiteralInstruction>(patternMatch!!.startIndex).wideLiteral
|
||||
}.toString().substring(0, 7)
|
||||
|
||||
// Replace placeholder in the extension method.
|
||||
with(extensionMethodFingerprint) {
|
||||
method.replaceInstruction(
|
||||
stringMatches!!.first().index,
|
||||
"""
|
||||
const-string v1, "$relevantDigits"
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,4 +2,4 @@ package app.revanced.patches.messenger.misc.extension
|
||||
|
||||
import app.revanced.patches.shared.misc.extension.sharedExtensionPatch
|
||||
|
||||
val sharedExtensionPatch = sharedExtensionPatch("messenger", mainActivityOnCreateHook)
|
||||
val sharedExtensionPatch = sharedExtensionPatch("messenger", messengerApplicationOnCreateHook)
|
||||
|
@ -2,6 +2,8 @@ package app.revanced.patches.messenger.misc.extension
|
||||
|
||||
import app.revanced.patches.shared.misc.extension.extensionHook
|
||||
|
||||
internal val mainActivityOnCreateHook = extensionHook {
|
||||
strings("MainActivity_onCreate_begin")
|
||||
internal val messengerApplicationOnCreateHook = extensionHook {
|
||||
custom { method, classDef ->
|
||||
method.name == "onCreate" && classDef.endsWith("/MessengerApplication;")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user