Skip to content

Commit

Permalink
fix: force-vp9-codec patch applied to wrong method
Browse files Browse the repository at this point in the history
  • Loading branch information
inotia00 committed Jan 30, 2023
1 parent 96a55c5 commit 5cee503
Showing 1 changed file with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,29 @@ import org.jf.dexlib2.iface.instruction.ReferenceInstruction
class ForceVP9CodecBytecodePatch : BytecodePatch(
listOf(
LayoutSwitchFingerprint,
Vp9PrimaryFingerprint,
Vp9PropsFingerprint,
Vp9PropsParentFingerprint,
Vp9SecondaryFingerprint
Vp9PropsParentFingerprint
)
) {
override fun execute(context: BytecodeContext): PatchResult {

LayoutSwitchFingerprint.result?.let { parentResult ->
LayoutSwitchFingerprint.result?.classDef?.let { classDef ->
arrayOf(
Vp9PrimaryFingerprint,
Vp9SecondaryFingerprint
).map {
it.also { it.resolve(context, parentResult.classDef) }.result?.injectOverride() ?: return it.toErrorResult()
).forEach { fingerprint ->
fingerprint.also { it.resolve(context, classDef) }.result?.injectOverride() ?: return fingerprint.toErrorResult()
}
} ?: return LayoutSwitchFingerprint.toErrorResult()

Vp9PropsParentFingerprint.result?.let { parentResult ->
Vp9PropsFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.mutableMethod?.let {
it.hookProps("MANUFACTURER", "getManufacturer")
it.hookProps("BRAND", "getBrand")
it.hookProps("MODEL", "getModel")
mapOf(
"MANUFACTURER" to "getManufacturer",
"BRAND" to "getBrand",
"MODEL" to "getModel"
).forEach { (fieldName, descriptor) ->
it.hookProps(fieldName, descriptor)
}
} ?: return Vp9PropsFingerprint.toErrorResult()
} ?: return Vp9PropsParentFingerprint.toErrorResult()

Expand Down Expand Up @@ -92,12 +93,12 @@ class ForceVP9CodecBytecodePatch : BytecodePatch(
}

fun MutableMethod.hookProps(
descriptor: String,
fieldName: String
fieldName: String,
descriptor: String
) {
val insertInstructions = implementation!!.instructions
val targetString = "Landroid/os/Build;->" +
descriptor +
fieldName +
":Ljava/lang/String;"

for ((index, instruction) in insertInstructions.withIndex()) {
Expand All @@ -111,7 +112,7 @@ class ForceVP9CodecBytecodePatch : BytecodePatch(

addInstructions(
index + 1, """
invoke-static {v$register}, $INTEGRATIONS_CLASS_DESCRIPTOR->$fieldName(Ljava/lang/String;)Ljava/lang/String;
invoke-static {v$register}, $INTEGRATIONS_CLASS_DESCRIPTOR->$descriptor(Ljava/lang/String;)Ljava/lang/String;
move-result-object v$register
"""
)
Expand Down

0 comments on commit 5cee503

Please sign in to comment.