mirror of
https://github.com/revanced/revanced-patcher
synced 2024-11-20 16:19:21 +01:00
Refactor code, add YTVersion, ElementType and signatures for 17.03.38
"signatures" package will be moved to Signatures repository soon.
This commit is contained in:
parent
6a3e913a3c
commit
8ab86312bf
@ -1,25 +1,26 @@
|
||||
package net.revanced.patcher
|
||||
|
||||
import net.revanced.patcher.sigscan.Sig
|
||||
import net.revanced.patcher.sigscan.SigScanner
|
||||
import org.jf.dexlib2.Opcode
|
||||
import net.revanced.patcher.version.YTVersion
|
||||
import org.jf.dexlib2.DexFileFactory
|
||||
import java.io.File
|
||||
import java.lang.reflect.Modifier
|
||||
|
||||
class Patcher {
|
||||
companion object {
|
||||
/**
|
||||
* Invokes the patcher on the given input file.
|
||||
*
|
||||
* @param input the input file
|
||||
* @param output the output file
|
||||
*/
|
||||
fun invoke(input: File, output: File) {
|
||||
SigScanner(Sig(
|
||||
arrayOf(Opcode.ADD_INT),
|
||||
Modifier.PUBLIC or Modifier.STATIC,
|
||||
String.Companion::class
|
||||
)).scan(emptyArray())
|
||||
}
|
||||
/**
|
||||
* Creates a patcher.
|
||||
*
|
||||
* @param input the input dex file
|
||||
* @param output the output dex file
|
||||
* @param version the YT version of this dex file
|
||||
*/
|
||||
class Patcher(private val input: File, private val output: File, private val version: YTVersion) {
|
||||
// setting opcodes to null causes it to autodetect, perfect!
|
||||
private val dexFile = DexFileFactory.loadDexFile(input, null)
|
||||
|
||||
/**
|
||||
* Runs the patcher.
|
||||
*/
|
||||
fun run() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,15 @@
|
||||
package net.revanced.patcher.signatures
|
||||
|
||||
class ElementType private constructor() {
|
||||
companion object {
|
||||
const val Void = "()V"
|
||||
const val Boolean = "()Z"
|
||||
const val Byte = "()B"
|
||||
const val Char = "()C"
|
||||
const val Short = "()S"
|
||||
const val Int = "()I"
|
||||
const val Long = "()J"
|
||||
const val Float = "()F"
|
||||
const val Double = "()D"
|
||||
}
|
||||
}
|
@ -1,18 +1,32 @@
|
||||
package net.revanced.patcher.sigscan
|
||||
package net.revanced.patcher.signatures
|
||||
|
||||
import org.jf.dexlib2.Opcode
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
data class Sig(
|
||||
/**
|
||||
* An ASM signature.
|
||||
*
|
||||
* ```
|
||||
* Signature(
|
||||
* arrayOf(Opcode.ADD_INT),
|
||||
* Modifier.PUBLIC or Modifier.STATIC,
|
||||
* "Ljava/lang/String;"
|
||||
* )
|
||||
* ```
|
||||
*
|
||||
* @param opcodes the opcode signature
|
||||
* @param attributes the modifiers of the method you are searching for
|
||||
* @param returnType the return type of the method as string, see: https://stackoverflow.com/a/9909370
|
||||
*/
|
||||
data class Signature(
|
||||
val opcodes: Array<Opcode>,
|
||||
val attributes: Int,
|
||||
val returnType: KClass<*>
|
||||
val returnType: String
|
||||
) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as Sig
|
||||
other as Signature
|
||||
|
||||
if (!opcodes.contentEquals(other.opcodes)) return false
|
||||
if (attributes != other.attributes) return false
|
@ -0,0 +1,5 @@
|
||||
package net.revanced.patcher.signatures
|
||||
|
||||
interface SignatureSupplier {
|
||||
fun signatures(): Array<Signature>
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package net.revanced.patcher.signatures.v17_03_38
|
||||
|
||||
import net.revanced.patcher.signatures.SignatureSupplier
|
||||
import net.revanced.patcher.signatures.ElementType
|
||||
import net.revanced.patcher.signatures.Signature
|
||||
import java.lang.reflect.Modifier
|
||||
|
||||
import org.jf.dexlib2.Opcode.*
|
||||
|
||||
class Sigs: SignatureSupplier {
|
||||
override fun signatures(): Array<Signature> {
|
||||
return arrayOf(
|
||||
// public static aT(Landroid/content/Context;I)Z
|
||||
Signature(
|
||||
arrayOf(
|
||||
IF_LT, // if-lt p0, p1, :cond_1
|
||||
CONST_4, // const/4 p0, 0x1
|
||||
// TODO(Inject):
|
||||
// invoke-static {p0}, Lfi/razerman/youtube/XGlobals;->getOverride(Z)Z
|
||||
// move-result p0
|
||||
RETURN, // return p0
|
||||
// :cond_1
|
||||
CONST_4, // const/4 p0, 0x0
|
||||
// TODO(Inject):
|
||||
// invoke-static {p0}, Lfi/razerman/youtube/XGlobals;->getOverride(Z)Z
|
||||
// move-result p0
|
||||
RETURN, // return p0
|
||||
),
|
||||
Modifier.PUBLIC or Modifier.STATIC,
|
||||
ElementType.Boolean
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
@ -1,8 +1,9 @@
|
||||
package net.revanced.patcher.sigscan
|
||||
|
||||
import net.revanced.patcher.signatures.Signature
|
||||
import org.jf.dexlib2.iface.ClassDef
|
||||
|
||||
class SigScanner (sig: Sig) {
|
||||
class SignatureScanner(signature: Signature) {
|
||||
fun scan(classes: Array<ClassDef>) {
|
||||
|
||||
}
|
26
src/main/kotlin/net/revanced/patcher/version/YTVersion.kt
Normal file
26
src/main/kotlin/net/revanced/patcher/version/YTVersion.kt
Normal file
@ -0,0 +1,26 @@
|
||||
package net.revanced.patcher.version
|
||||
|
||||
import net.revanced.patcher.signatures.SignatureSupplier
|
||||
import net.revanced.patcher.signatures.v17_03_38.Sigs
|
||||
|
||||
enum class YTVersion(
|
||||
val versionNumber: Triple<Int, Int, Int>,
|
||||
val sigs: SignatureSupplier
|
||||
) {
|
||||
V17_03_38(
|
||||
Triple(17, 3, 38),
|
||||
Sigs()
|
||||
);
|
||||
|
||||
companion object {
|
||||
private val vm: Map<Triple<Int, Int, Int>, YTVersion> = buildMap {
|
||||
values().forEach {
|
||||
this[it.versionNumber] = it
|
||||
}
|
||||
}
|
||||
|
||||
fun versionFor(versionNumber: Triple<Int, Int, Int>): YTVersion? {
|
||||
return vm[versionNumber]
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user