Skip to content

Commit d87f36e

Browse files
committed
feat: Add Spoof build info patch
1 parent 4432fe6 commit d87f36e

File tree

3 files changed

+339
-0
lines changed

3 files changed

+339
-0
lines changed

api/revanced-patches.api

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,42 @@ public final class app/revanced/patches/all/location/hide/HideMockLocationPatch
3030
public fun transform (Lapp/revanced/patcher/util/proxy/mutableTypes/MutableMethod;Lkotlin/Pair;)V
3131
}
3232

33+
public abstract class app/revanced/patches/all/misc/build/BaseSpoofBuildInfoPatch : app/revanced/patches/all/misc/transformation/BaseTransformInstructionsPatch {
34+
public fun <init> ()V
35+
public synthetic fun filterMap (Lcom/android/tools/smali/dexlib2/iface/ClassDef;Lcom/android/tools/smali/dexlib2/iface/Method;Lcom/android/tools/smali/dexlib2/iface/instruction/Instruction;I)Ljava/lang/Object;
36+
public fun filterMap (Lcom/android/tools/smali/dexlib2/iface/ClassDef;Lcom/android/tools/smali/dexlib2/iface/Method;Lcom/android/tools/smali/dexlib2/iface/instruction/Instruction;I)Lkotlin/Pair;
37+
protected fun getBoard ()Ljava/lang/String;
38+
protected fun getBootloader ()Ljava/lang/String;
39+
protected fun getBrand ()Ljava/lang/String;
40+
protected fun getCpuAbi ()Ljava/lang/String;
41+
protected fun getCpuAbi2 ()Ljava/lang/String;
42+
protected fun getDevice ()Ljava/lang/String;
43+
protected fun getDisplay ()Ljava/lang/String;
44+
protected fun getFingerprint ()Ljava/lang/String;
45+
protected fun getHardware ()Ljava/lang/String;
46+
protected fun getHost ()Ljava/lang/String;
47+
protected fun getId ()Ljava/lang/String;
48+
protected fun getManufacturer ()Ljava/lang/String;
49+
protected fun getModel ()Ljava/lang/String;
50+
protected fun getOdmSku ()Ljava/lang/String;
51+
protected fun getProduct ()Ljava/lang/String;
52+
protected fun getRadio ()Ljava/lang/String;
53+
protected fun getSerial ()Ljava/lang/String;
54+
protected fun getSku ()Ljava/lang/String;
55+
protected fun getSocManufacturer ()Ljava/lang/String;
56+
protected fun getSocModel ()Ljava/lang/String;
57+
protected fun getTags ()Ljava/lang/String;
58+
protected fun getTime ()Ljava/lang/Long;
59+
protected fun getType ()Ljava/lang/String;
60+
protected fun getUser ()Ljava/lang/String;
61+
public synthetic fun transform (Lapp/revanced/patcher/util/proxy/mutableTypes/MutableMethod;Ljava/lang/Object;)V
62+
public fun transform (Lapp/revanced/patcher/util/proxy/mutableTypes/MutableMethod;Lkotlin/Pair;)V
63+
}
64+
65+
public final class app/revanced/patches/all/misc/build/SpoofBuildInfoPatch : app/revanced/patches/all/misc/build/BaseSpoofBuildInfoPatch {
66+
public fun <init> ()V
67+
}
68+
3369
public final class app/revanced/patches/all/misc/debugging/EnableAndroidDebuggingPatch : app/revanced/patcher/patch/ResourcePatch {
3470
public static final field INSTANCE Lapp/revanced/patches/all/misc/debugging/EnableAndroidDebuggingPatch;
3571
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
package app.revanced.patches.all.misc.build
2+
3+
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
4+
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
5+
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
6+
import app.revanced.patches.all.misc.transformation.BaseTransformInstructionsPatch
7+
import app.revanced.util.getReference
8+
import com.android.tools.smali.dexlib2.iface.ClassDef
9+
import com.android.tools.smali.dexlib2.iface.Method
10+
import com.android.tools.smali.dexlib2.iface.instruction.Instruction
11+
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
12+
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
13+
14+
abstract class BaseSpoofBuildInfoPatch : BaseTransformInstructionsPatch<Pair<Int, Pair<String, String>>>() {
15+
// The build information supported32BitAbis, supported64BitAbis, and supportedAbis are not supported for now,
16+
// because initializing an array in transform is a bit more complex.
17+
18+
protected open val board: String? = null
19+
20+
protected open val bootloader: String? = null
21+
22+
protected open val brand: String? = null
23+
24+
protected open val cpuAbi: String? = null
25+
26+
protected open val cpuAbi2: String? = null
27+
28+
protected open val device: String? = null
29+
30+
protected open val display: String? = null
31+
32+
protected open val fingerprint: String? = null
33+
34+
protected open val hardware: String? = null
35+
36+
protected open val host: String? = null
37+
38+
protected open val id: String? = null
39+
40+
protected open val manufacturer: String? = null
41+
42+
protected open val model: String? = null
43+
44+
protected open val odmSku: String? = null
45+
46+
protected open val product: String? = null
47+
48+
protected open val radio: String? = null
49+
50+
protected open val serial: String? = null
51+
52+
protected open val sku: String? = null
53+
54+
protected open val socManufacturer: String? = null
55+
56+
protected open val socModel: String? = null
57+
58+
protected open val tags: String? = null
59+
60+
protected open val time: Long? = null
61+
62+
protected open val type: String? = null
63+
64+
protected open val user: String? = null
65+
66+
67+
// Lazy, so that patch options above are initialized before they are accessed.
68+
private val replacements: Map<String, Pair<String, String>> by lazy {
69+
buildMap {
70+
if (board != null) put("BOARD", "const-string" to "\"$board\"")
71+
if (bootloader != null) put("BOOTLOADER", "const-string" to "\"$bootloader\"")
72+
if (brand != null) put("BRAND", "const-string" to "\"$brand\"")
73+
if (cpuAbi != null) put("CPU_ABI", "const-string" to "\"$cpuAbi\"")
74+
if (cpuAbi2 != null) put("CPU_ABI2", "const-string" to "\"$cpuAbi2\"")
75+
if (device != null) put("DEVICE", "const-string" to "\"$device\"")
76+
if (display != null) put("DISPLAY", "const-string" to "\"$display\"")
77+
if (fingerprint != null) put("FINGERPRINT", "const-string" to "\"$fingerprint\"")
78+
if (hardware != null) put("HARDWARE", "const-string" to "\"$hardware\"")
79+
if (host != null) put("HOST", "const-string" to "\"$host\"")
80+
if (id != null) put("ID", "const-string" to "\"$id\"")
81+
if (manufacturer != null) put("MANUFACTURER", "const-string" to "\"$manufacturer\"")
82+
if (model != null) put("MODEL", "const-string" to "\"$model\"")
83+
if (odmSku != null) put("ODM_SKU", "const-string" to "\"$odmSku\"")
84+
if (product != null) put("PRODUCT", "const-string" to "\"$product\"")
85+
if (radio != null) put("RADIO", "const-string" to "\"$radio\"")
86+
if (serial != null) put("SERIAL", "const-string" to "\"$serial\"")
87+
if (sku != null) put("SKU", "const-string" to "\"$sku\"")
88+
if (socManufacturer != null) put("SOC_MANUFACTURER", "const-string" to "\"$socManufacturer\"")
89+
if (socModel != null) put("SOC_MODEL", "const-string" to "\"$socModel\"")
90+
if (tags != null) put("TAGS", "const-string" to "\"$tags\"")
91+
if (time != null) put("TIME", "const-wide" to "$time")
92+
if (type != null) put("TYPE", "const-string" to "\"$type\"")
93+
if (user != null) put("USER", "const-string" to "\"$user\"")
94+
}
95+
}
96+
97+
override fun filterMap(
98+
classDef: ClassDef,
99+
method: Method,
100+
instruction: Instruction,
101+
instructionIndex: Int
102+
): Pair<Int, Pair<String, String>>? {
103+
val reference = instruction.getReference<FieldReference>() ?: return null
104+
if (reference.definingClass != BUILD_CLASS_DESCRIPTOR) return null
105+
106+
return replacements[reference.name]?.let { instructionIndex to it }
107+
}
108+
109+
override fun transform(mutableMethod: MutableMethod, entry: Pair<Int, Pair<String, String>>) {
110+
val (index, replacement) = entry
111+
val (opcode, operand) = replacement
112+
val register = mutableMethod.getInstruction<OneRegisterInstruction>(index).registerA
113+
114+
mutableMethod.replaceInstruction(index, "$opcode v$register, $operand")
115+
}
116+
117+
private companion object {
118+
private const val BUILD_CLASS_DESCRIPTOR = "Landroid/os/Build;"
119+
}
120+
}
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
package app.revanced.patches.all.misc.build
2+
3+
import app.revanced.patcher.patch.annotation.Patch
4+
import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.longPatchOption
5+
import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.stringPatchOption
6+
7+
@Patch(
8+
name = "Spoof build info",
9+
description = "Spoof the information about the current build.",
10+
use = false
11+
)
12+
@Suppress("unused")
13+
class SpoofBuildInfoPatch : BaseSpoofBuildInfoPatch() {
14+
override val board by stringPatchOption(
15+
key = "board",
16+
default = null,
17+
title = "Board",
18+
description = "The name of the underlying board, like \"goldfish\"."
19+
)
20+
21+
override val bootloader by stringPatchOption(
22+
key = "bootloader",
23+
default = null,
24+
title = "Bootloader",
25+
description = "The system bootloader version number."
26+
)
27+
28+
override val brand by stringPatchOption(
29+
key = "brand",
30+
default = null,
31+
title = "Brand",
32+
description = "The consumer-visible brand with which the product/hardware will be associated, if any."
33+
)
34+
35+
override val cpuAbi by stringPatchOption(
36+
key = "cpu-abi",
37+
default = null,
38+
title = "CPU ABI",
39+
description = "This field was deprecated in API level 21. Use SUPPORTED_ABIS instead."
40+
)
41+
42+
override val cpuAbi2 by stringPatchOption(
43+
key = "cpu-abi-2",
44+
default = null,
45+
title = "CPU ABI 2",
46+
description = "This field was deprecated in API level 21. Use SUPPORTED_ABIS instead."
47+
)
48+
49+
override val device by stringPatchOption(
50+
key = "device",
51+
default = null,
52+
title = "Device",
53+
description = "The name of the industrial design."
54+
)
55+
56+
override val display by stringPatchOption(
57+
key = "display",
58+
default = null,
59+
title = "Display",
60+
description = "A build ID string meant for displaying to the user."
61+
)
62+
63+
override val fingerprint by stringPatchOption(
64+
key = "fingerprint",
65+
default = null,
66+
title = "Fingerprint",
67+
description = "A string that uniquely identifies this build."
68+
)
69+
70+
override val hardware by stringPatchOption(
71+
key = "hardware",
72+
default = null,
73+
title = "Hardware",
74+
description = "The name of the hardware (from the kernel command line or /proc)."
75+
)
76+
77+
override val host by stringPatchOption(
78+
key = "host",
79+
default = null,
80+
title = "Host",
81+
description = "The host."
82+
)
83+
84+
override val id by stringPatchOption(
85+
key = "id",
86+
default = null,
87+
title = "ID",
88+
description = "Either a changelist number, or a label like \"M4-rc20\"."
89+
)
90+
91+
override val manufacturer by stringPatchOption(
92+
key = "manufacturer",
93+
default = null,
94+
title = "Manufacturer",
95+
description = "The manufacturer of the product/hardware."
96+
)
97+
98+
override val model by stringPatchOption(
99+
key = "model",
100+
default = null,
101+
title = "Model",
102+
description = "The end-user-visible name for the end product."
103+
)
104+
105+
override val odmSku by stringPatchOption(
106+
key = "odm-sku",
107+
default = null,
108+
title = "ODM SKU",
109+
description = "The SKU of the device as set by the original design manufacturer (ODM)."
110+
)
111+
112+
override val product by stringPatchOption(
113+
key = "product",
114+
default = null,
115+
title = "Product",
116+
description = "The name of the overall product."
117+
)
118+
119+
override val radio by stringPatchOption(
120+
key = "radio",
121+
default = null,
122+
title = "Radio",
123+
description = "This field was deprecated in API level 15. " +
124+
"The radio firmware version is frequently not available when this class is initialized, " +
125+
"leading to a blank or \"unknown\" value for this string. Use getRadioVersion() instead."
126+
)
127+
128+
override val serial by stringPatchOption(
129+
key = "serial",
130+
default = null,
131+
title = "Serial",
132+
description = "This field was deprecated in API level 26. Use getSerial() instead."
133+
)
134+
135+
override val sku by stringPatchOption(
136+
key = "sku",
137+
default = null,
138+
title = "SKU",
139+
description = "The SKU of the hardware (from the kernel command line)."
140+
)
141+
142+
override val socManufacturer by stringPatchOption(
143+
key = "soc-manufacturer",
144+
default = null,
145+
title = "SOC Manufacturer",
146+
description = "The manufacturer of the device's primary system-on-chip."
147+
)
148+
149+
override val socModel by stringPatchOption(
150+
key = "soc-model",
151+
default = null,
152+
title = "SOC Model",
153+
description = "The model name of the device's primary system-on-chip."
154+
)
155+
156+
override val tags by stringPatchOption(
157+
key = "tags",
158+
default = null,
159+
title = "Tags",
160+
description = "Comma-separated tags describing the build, like \"unsigned,debug\"."
161+
)
162+
163+
override val time by longPatchOption(
164+
key = "time",
165+
default = null,
166+
title = "Time",
167+
description = "The time at which the build was produced, given in milliseconds since the UNIX epoch."
168+
)
169+
170+
override val type by stringPatchOption(
171+
key = "type",
172+
default = null,
173+
title = "Type",
174+
description = "The type of build, like \"user\" or \"eng\"."
175+
)
176+
177+
override val user by stringPatchOption(
178+
key = "user",
179+
default = null,
180+
title = "User",
181+
description = "The user."
182+
)
183+
}

0 commit comments

Comments
 (0)