Skip to content
Open
1 change: 1 addition & 0 deletions patches/api/patches.api
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public final class app/revanced/patches/all/misc/connectivity/location/hide/Hide

public final class app/revanced/patches/all/misc/connectivity/telephony/sim/spoof/SpoofSimCountryPatchKt {
public static final fun getSpoofSimCountryPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
public static final fun getSpoofSimProviderPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
}

public final class app/revanced/patches/all/misc/connectivity/wifi/spoof/SpoofWifiPatchKt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patcher.patch.stringOption
import app.revanced.patcher.patch.intOption
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patches.all.misc.transformation.transformInstructionsPatch
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
import com.android.tools.smali.dexlib2.immutable.reference.ImmutableMethodReference
import com.android.tools.smali.dexlib2.util.MethodUtil
import java.util.*
import java.util.Locale
import java.util.regex.Pattern

@Suppress("unused")
val spoofSimCountryPatch = bytecodePatch(
name = "Spoof SIM country",
description = "Spoofs country information returned by the SIM card provider.",
val spoofSimProviderPatch = bytecodePatch(
name = "Spoof SIM provider",
description = "Spoofs information about the SIM card provider.",
use = false,
) {
val countries = Locale.getISOCountries().associateBy { Locale("", it).displayCountry }
Expand All @@ -39,11 +41,38 @@ val spoofSimCountryPatch = bytecodePatch(
"Network ISO country code",
)

val networkOperator by intOption(
key = "networkOperator",
title = "MCC+MNC network operator code",
description = "The 5 or 6 digits MCC+MNC (Mobile Country Code + Mobile Network Code) of the network operator.",
validator = { it: Int? -> it == null || Pattern.matches("[0-9]{5,6}", it.toString()) }
)

val networkOperatorName by stringOption(
key = "networkOperatorName",
title = "Network operator name",
description = "The full name of the network operator.",
)

val simCountryIso by isoCountryPatchOption(
"simCountryIso",
"SIM ISO country code",
)

val simOperator by intOption(
key = "simOperator",
title = "MCC+MNC SIM operator code",
description = "The 5 or 6 digits MCC+MNC (Mobile Country Code + Mobile Network Code) of the SIM operator.",
validator = { it: Int? -> it == null || Pattern.matches("[0-9]{5,6}", it.toString()) }
)

val simOperatorName by stringOption(
key = "simOperatorName",
title = "SIM operator name",
description = "The full name of the SIM operator.",
)


dependsOn(
transformInstructionsPatch(
filterMap = { _, _, instruction, instructionIndex ->
Expand All @@ -55,28 +84,31 @@ val spoofSimCountryPatch = bytecodePatch(
MethodUtil.methodSignaturesMatch(reference, search.reference)
} ?: return@transformInstructionsPatch null

val iso = when (match) {
MethodCall.NetworkCountryIso -> networkCountryIso
MethodCall.SimCountryIso -> simCountryIso
}?.lowercase()

iso?.let { instructionIndex to it }
},
transform = { mutableMethod, entry: Pair<Int, String> ->
transformMethodCall(entry, mutableMethod)
val replacement = when (match) {
MethodCall.NetworkCountryIso -> networkCountryIso?.lowercase()
MethodCall.NetworkOperator -> networkOperator?.toString()
MethodCall.NetworkOperatorName -> networkOperatorName
MethodCall.SimCountryIso -> simCountryIso?.lowercase()
MethodCall.SimOperator -> simOperator?.toString()
MethodCall.SimOperatorName -> simOperatorName
}
replacement?.let { instructionIndex to it }
},
transform = ::transformMethodCall,
),
)
}

private fun transformMethodCall(
entry: Pair<Int, String>,
mutableMethod: MutableMethod,
entry: Pair<Int, String>,
) {
val (instructionIndex, methodCallValue) = entry

// Get the register which would have contained the return value
val register = mutableMethod.getInstruction<OneRegisterInstruction>(instructionIndex + 1).registerA

// Replace the move-result instruction with our fake value
mutableMethod.replaceInstruction(
instructionIndex + 1,
"const-string v$register, \"$methodCallValue\"",
Expand All @@ -94,6 +126,22 @@ private enum class MethodCall(
"Ljava/lang/String;",
),
),
NetworkOperator(
ImmutableMethodReference(
"Landroid/telephony/TelephonyManager;",
"getNetworkOperator",
emptyList(),
"Ljava/lang/String;",
),
),
NetworkOperatorName(
ImmutableMethodReference(
"Landroid/telephony/TelephonyManager;",
"getNetworkOperatorName",
emptyList(),
"Ljava/lang/String;",
),
),
SimCountryIso(
ImmutableMethodReference(
"Landroid/telephony/TelephonyManager;",
Expand All @@ -102,4 +150,26 @@ private enum class MethodCall(
"Ljava/lang/String;",
),
),
SimOperator(
ImmutableMethodReference(
"Landroid/telephony/TelephonyManager;",
"getSimOperator",
emptyList(),
"Ljava/lang/String;",
),
),
SimOperatorName(
ImmutableMethodReference(
"Landroid/telephony/TelephonyManager;",
"getSimOperatorName",
emptyList(),
"Ljava/lang/String;",
),
),
}

@Deprecated("Patch was renamed", ReplaceWith("spoofSimProviderPatch"))
@Suppress("unused")
val spoofSimCountryPatch = bytecodePatch {
dependsOn(spoofSimProviderPatch)
}
Loading