generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tiktok):
sim-spoof
patch (#1088)
Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
- Loading branch information
Showing
4 changed files
with
137 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...in/kotlin/app/revanced/patches/tiktok/misc/spoof/sim/annotations/SpoofSimCompatibility.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package app.revanced.patches.tiktok.misc.spoof.sim.annotations | ||
|
||
import app.revanced.patcher.annotation.Compatibility | ||
import app.revanced.patcher.annotation.Package | ||
|
||
@Compatibility( | ||
[ | ||
Package("com.ss.android.ugc.trill"), | ||
Package("com.zhiliaoapp.musically") | ||
] | ||
) | ||
@Target(AnnotationTarget.CLASS) | ||
@Retention(AnnotationRetention.RUNTIME) | ||
internal annotation class SpoofSimCompatibility |
110 changes: 110 additions & 0 deletions
110
src/main/kotlin/app/revanced/patches/tiktok/misc/spoof/sim/patch/SpoofSimPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package app.revanced.patches.tiktok.misc.spoof.sim.patch | ||
|
||
import app.revanced.extensions.findMutableMethodOf | ||
import app.revanced.patcher.annotation.Description | ||
import app.revanced.patcher.annotation.Name | ||
import app.revanced.patcher.annotation.Version | ||
import app.revanced.patcher.data.BytecodeContext | ||
import app.revanced.patcher.extensions.addInstruction | ||
import app.revanced.patcher.extensions.addInstructions | ||
import app.revanced.patcher.extensions.instruction | ||
import app.revanced.patcher.patch.BytecodePatch | ||
import app.revanced.patcher.patch.PatchResult | ||
import app.revanced.patcher.patch.PatchResultSuccess | ||
import app.revanced.patcher.patch.annotations.DependsOn | ||
import app.revanced.patcher.patch.annotations.Patch | ||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod | ||
import app.revanced.patches.tiktok.misc.integrations.patch.TikTokIntegrationsPatch | ||
import app.revanced.patches.tiktok.misc.settings.fingerprints.SettingsStatusLoadFingerprint | ||
import app.revanced.patches.tiktok.misc.settings.patch.TikTokSettingsPatch | ||
import app.revanced.patches.tiktok.misc.spoof.sim.annotations.SpoofSimCompatibility | ||
import org.jf.dexlib2.Opcode | ||
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction | ||
import org.jf.dexlib2.iface.instruction.formats.Instruction35c | ||
import org.jf.dexlib2.iface.reference.MethodReference | ||
|
||
@Patch(false) | ||
@DependsOn([TikTokIntegrationsPatch::class, TikTokSettingsPatch::class]) | ||
@Name("sim-spoof") | ||
@Description("Spoofs the information which is retrieved from the sim-card.") | ||
@SpoofSimCompatibility | ||
@Version("0.0.1") | ||
class SpoofSimPatch : BytecodePatch() { | ||
private companion object { | ||
val replacements = hashMapOf( | ||
"getSimCountryIso" to "getCountryIso", | ||
"getNetworkCountryIso" to "getCountryIso", | ||
"getSimOperator" to "getOperator", | ||
"getNetworkOperator" to "getOperator", | ||
"getSimOperatorName" to "getOperatorName", | ||
"getNetworkOperatorName" to "getOperatorName" | ||
) | ||
} | ||
|
||
override fun execute(context: BytecodeContext): PatchResult { | ||
// Find all api call to check sim information | ||
buildMap { | ||
context.classes.forEach { classDef -> | ||
classDef.methods.let { methods -> | ||
buildMap methodList@{ | ||
methods.forEach methods@{ method -> | ||
with(method.implementation?.instructions ?: return@methods) { | ||
ArrayDeque<Pair<Int, String>>().also { patchIndices -> | ||
this.forEachIndexed { index, instruction -> | ||
if (instruction.opcode != Opcode.INVOKE_VIRTUAL) return@forEachIndexed | ||
|
||
val methodRef = | ||
(instruction as Instruction35c).reference as MethodReference | ||
if (methodRef.definingClass != "Landroid/telephony/TelephonyManager;") return@forEachIndexed | ||
|
||
replacements[methodRef.name]?.let { replacement -> | ||
patchIndices.add(index to replacement) | ||
} | ||
} | ||
}.also { if (it.isEmpty()) return@methods }.let { patches -> | ||
put(method, patches) | ||
} | ||
} | ||
} | ||
} | ||
}.also { if (it.isEmpty()) return@forEach }.let { methodPatches -> | ||
put(classDef, methodPatches) | ||
} | ||
} | ||
}.forEach { (classDef, methods) -> | ||
with(context.proxy(classDef).mutableClass) { | ||
methods.forEach { (method, patches) -> | ||
with(findMutableMethodOf(method)) { | ||
while (!patches.isEmpty()) { | ||
val (index, replacement) = patches.removeLast() | ||
replaceReference(index, replacement) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Enable patch in settings | ||
with(SettingsStatusLoadFingerprint.result!!.mutableMethod) { | ||
addInstruction( | ||
0, | ||
"invoke-static {}, Lapp/revanced/tiktok/settingsmenu/SettingsStatus;->enableSimSpoof()V" | ||
) | ||
} | ||
|
||
return PatchResultSuccess() | ||
} | ||
|
||
// Patch Android API and return fake sim information | ||
private fun MutableMethod.replaceReference(index: Int, replacement: String) { | ||
val resultReg = (instruction(index + 1) as OneRegisterInstruction).registerA | ||
|
||
addInstructions( | ||
index + 2, | ||
""" | ||
invoke-static {v$resultReg}, Lapp/revanced/tiktok/spoof/sim/SpoofSimPatch;->$replacement(Ljava/lang/String;)Ljava/lang/String; | ||
move-result-object v$resultReg | ||
""" | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters