From 58e7f815a58ce030055be460680c40601f087104 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Mon, 23 Oct 2023 00:48:01 +0200 Subject: [PATCH] refactor: Move `MethodFingerprintResult` to own file --- .../patcher/fingerprint/MethodFingerprint.kt | 84 ----------------- .../fingerprint/MethodFingerprintResult.kt | 92 +++++++++++++++++++ 2 files changed, 92 insertions(+), 84 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patcher/fingerprint/MethodFingerprintResult.kt diff --git a/src/main/kotlin/app/revanced/patcher/fingerprint/MethodFingerprint.kt b/src/main/kotlin/app/revanced/patcher/fingerprint/MethodFingerprint.kt index 785f714..d1ee5b3 100644 --- a/src/main/kotlin/app/revanced/patcher/fingerprint/MethodFingerprint.kt +++ b/src/main/kotlin/app/revanced/patcher/fingerprint/MethodFingerprint.kt @@ -426,87 +426,3 @@ abstract class MethodFingerprint( } } -/** - * Represents the result of a [MethodFingerprintResult]. - * - * @param method The matching method. - * @param classDef The [ClassDef] that contains the matching [method]. - * @param scanResult The result of scanning for the [MethodFingerprint]. - * @param context The [BytecodeContext] this [MethodFingerprintResult] is attached to, to create proxies. - */ -class MethodFingerprintResult( - val method: Method, - val classDef: ClassDef, - val scanResult: MethodFingerprintScanResult, - internal val context: BytecodeContext -) { - /** - * Returns a mutable clone of [classDef] - * - * Please note, this method allocates a [ClassProxy]. - * Use [classDef] where possible. - */ - @Suppress("MemberVisibilityCanBePrivate") - val mutableClass by lazy { context.proxy(classDef).mutableClass } - - /** - * Returns a mutable clone of [method] - * - * Please note, this method allocates a [ClassProxy]. - * Use [method] where possible. - */ - val mutableMethod by lazy { - mutableClass.methods.first { - MethodUtil.methodSignaturesMatch(it, this.method) - } - } - - /** - * The result of scanning on the [MethodFingerprint]. - * @param patternScanResult The result of the pattern scan. - * @param stringsScanResult The result of the string scan. - */ - class MethodFingerprintScanResult( - val patternScanResult: PatternScanResult?, - val stringsScanResult: StringsScanResult? - ) { - /** - * The result of scanning strings on the [MethodFingerprint]. - * @param matches The list of strings that were matched. - */ - class StringsScanResult(val matches: List) { - /** - * Represents a match for a string at an index. - * @param string The string that was matched. - * @param index The index of the string. - */ - class StringMatch(val string: String, val index: Int) - } - - /** - * The result of a pattern scan. - * @param startIndex The start index of the instructions where to which this pattern matches. - * @param endIndex The end index of the instructions where to which this pattern matches. - * @param warnings A list of warnings considering this [PatternScanResult]. - */ - class PatternScanResult( - val startIndex: Int, - val endIndex: Int, - var warnings: List? = null - ) { - /** - * Represents warnings of the pattern scan. - * @param correctOpcode The opcode the instruction list has. - * @param wrongOpcode The opcode the pattern list of the signature currently has. - * @param instructionIndex The index of the opcode relative to the instruction list. - * @param patternIndex The index of the opcode relative to the pattern list from the signature. - */ - class Warning( - val correctOpcode: Opcode, - val wrongOpcode: Opcode, - val instructionIndex: Int, - val patternIndex: Int, - ) - } - } -} diff --git a/src/main/kotlin/app/revanced/patcher/fingerprint/MethodFingerprintResult.kt b/src/main/kotlin/app/revanced/patcher/fingerprint/MethodFingerprintResult.kt new file mode 100644 index 0000000..5db1a47 --- /dev/null +++ b/src/main/kotlin/app/revanced/patcher/fingerprint/MethodFingerprintResult.kt @@ -0,0 +1,92 @@ +package app.revanced.patcher.fingerprint + +import app.revanced.patcher.data.BytecodeContext +import com.android.tools.smali.dexlib2.Opcode +import com.android.tools.smali.dexlib2.iface.ClassDef +import com.android.tools.smali.dexlib2.iface.Method +import com.android.tools.smali.dexlib2.util.MethodUtil + +/** + * Represents the result of a [MethodFingerprintResult]. + * + * @param method The matching method. + * @param classDef The [ClassDef] that contains the matching [method]. + * @param scanResult The result of scanning for the [MethodFingerprint]. + * @param context The [BytecodeContext] this [MethodFingerprintResult] is attached to, to create proxies. + */ +class MethodFingerprintResult( + val method: Method, + val classDef: ClassDef, + val scanResult: MethodFingerprintScanResult, + internal val context: BytecodeContext +) { + /** + * Returns a mutable clone of [classDef] + * + * Please note, this method allocates a [ClassProxy]. + * Use [classDef] where possible. + */ + @Suppress("MemberVisibilityCanBePrivate") + val mutableClass by lazy { context.proxy(classDef).mutableClass } + + /** + * Returns a mutable clone of [method] + * + * Please note, this method allocates a [ClassProxy]. + * Use [method] where possible. + */ + val mutableMethod by lazy { + mutableClass.methods.first { + MethodUtil.methodSignaturesMatch(it, this.method) + } + } + + /** + * The result of scanning on the [MethodFingerprint]. + * @param patternScanResult The result of the pattern scan. + * @param stringsScanResult The result of the string scan. + */ + class MethodFingerprintScanResult( + val patternScanResult: PatternScanResult?, + val stringsScanResult: StringsScanResult? + ) { + /** + * The result of scanning strings on the [MethodFingerprint]. + * @param matches The list of strings that were matched. + */ + class StringsScanResult(val matches: List) { + /** + * Represents a match for a string at an index. + * @param string The string that was matched. + * @param index The index of the string. + */ + class StringMatch(val string: String, val index: Int) + } + + /** + * The result of a pattern scan. + * @param startIndex The start index of the instructions where to which this pattern matches. + * @param endIndex The end index of the instructions where to which this pattern matches. + * @param warnings A list of warnings considering this [PatternScanResult]. + */ + class PatternScanResult( + val startIndex: Int, + val endIndex: Int, + var warnings: List? = null + ) { + /** + * Represents warnings of the pattern scan. + * @param correctOpcode The opcode the instruction list has. + * @param wrongOpcode The opcode the pattern list of the signature currently has. + * @param instructionIndex The index of the opcode relative to the instruction list. + * @param patternIndex The index of the opcode relative to the pattern list from the signature. + */ + class Warning( + val correctOpcode: Opcode, + val wrongOpcode: Opcode, + val instructionIndex: Int, + val patternIndex: Int, + ) + } + } +} \ No newline at end of file