From ef96ed124e12091dde34124eabd8be9f2bb9280c Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Fri, 16 Jun 2023 04:04:59 +0200 Subject: [PATCH] feat(google-recorder): add `remove-device-restrictions` patch --- .../OnApplicationCreateFingerprint.kt | 12 ++++++ .../patch/RemoveDeviceRestrictions.kt | 42 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/googlerecorder/restrictions/fingereprints/OnApplicationCreateFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/googlerecorder/restrictions/patch/RemoveDeviceRestrictions.kt diff --git a/src/main/kotlin/app/revanced/patches/googlerecorder/restrictions/fingereprints/OnApplicationCreateFingerprint.kt b/src/main/kotlin/app/revanced/patches/googlerecorder/restrictions/fingereprints/OnApplicationCreateFingerprint.kt new file mode 100644 index 00000000..9eb26b8b --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/googlerecorder/restrictions/fingereprints/OnApplicationCreateFingerprint.kt @@ -0,0 +1,12 @@ +package app.revanced.patches.googlerecorder.restrictions.fingereprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint + +object OnApplicationCreateFingerprint : MethodFingerprint( + strings = listOf("com.google.android.feature.PIXEL_2017_EXPERIENCE"), + customFingerprint = custom@{ methodDef, classDef -> + if (methodDef.name != "onCreate") return@custom false + + classDef.type.endsWith("RecorderApplication;") + } +) diff --git a/src/main/kotlin/app/revanced/patches/googlerecorder/restrictions/patch/RemoveDeviceRestrictions.kt b/src/main/kotlin/app/revanced/patches/googlerecorder/restrictions/patch/RemoveDeviceRestrictions.kt new file mode 100644 index 00000000..292d43fc --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/googlerecorder/restrictions/patch/RemoveDeviceRestrictions.kt @@ -0,0 +1,42 @@ +package app.revanced.patches.googlerecorder.restrictions.patch + +import app.revanced.extensions.toErrorResult +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.InstructionExtensions.addInstruction +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.extensions.InstructionExtensions.removeInstructions +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patches.googlerecorder.restrictions.fingereprints.OnApplicationCreateFingerprint +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction + +@Patch +@Name("remove-device-restrictions") +@Description("Removes restrictions from using the app on any device.") +@Version("0.0.1") +class RemoveDeviceRestrictions : BytecodePatch( + listOf(OnApplicationCreateFingerprint) +) { + override fun execute(context: BytecodeContext): PatchResult { + OnApplicationCreateFingerprint.result?.let { + val featureStringIndex = it.scanResult.stringsScanResult!!.matches.first().index + + it.mutableMethod.apply { + // Remove check for device restrictions. + removeInstructions(featureStringIndex - 2, 5) + + val featureAvailableRegister = getInstruction(featureStringIndex).registerA + + // Override "isPixelDevice()" to return true. + addInstruction(featureStringIndex, "const/4 v$featureAvailableRegister, 0x1") + } + } ?: return OnApplicationCreateFingerprint.toErrorResult() + + return PatchResultSuccess() + } +} \ No newline at end of file