refactor: use apktool fork

also fixed some compilation issues
This commit is contained in:
Lucaskyy 2022-05-24 17:43:43 +02:00 committed by oSumAtrIX
parent 839a5ef22a
commit 5a96f2d99f
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
4 changed files with 27 additions and 19 deletions

View File

@ -8,29 +8,31 @@ group = "app.revanced"
repositories { repositories {
mavenCentral() mavenCentral()
maven { listOf("multidexlib2", "Apktool").forEach { repo ->
url = uri("https://maven.pkg.github.com/revanced/multidexlib2") maven {
credentials { url = uri("https://maven.pkg.github.com/revanced/$repo")
// DO NOT set these variables in the project's gradle.properties. credentials {
// Instead, you should set them in: // DO NOT set these variables in the project's gradle.properties.
// Windows: %homepath%\.gradle\gradle.properties // Instead, you should set them in:
// Linux: ~/.gradle/gradle.properties // Windows: %homepath%\.gradle\gradle.properties
username = project.findProperty("gpr.user") as String? ?: System.getenv("GITHUB_ACTOR") // DO NOT CHANGE! // Linux: ~/.gradle/gradle.properties
password = project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN") // DO NOT CHANGE! username = project.findProperty("gpr.user") as String? ?: System.getenv("GITHUB_ACTOR") // DO NOT CHANGE!
password = project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN") // DO NOT CHANGE!
}
} }
} }
} }
dependencies { dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.6.21") implementation(kotlin("stdlib"))
api("xpp3:xpp3:1.1.4c") api("xpp3:xpp3:1.1.4c")
api("org.apktool:apktool-lib:2.6.1") api("org.apktool:apktool-lib:2.6.2-SNAPSHOT")
api("app.revanced:multidexlib2:2.5.2.r2") api("app.revanced:multidexlib2:2.5.2.r2")
api("org.smali:smali:2.5.2") api("org.smali:smali:2.5.2")
testImplementation("org.jetbrains.kotlin:kotlin-test:1.6.21") testImplementation(kotlin("test"))
implementation("org.jetbrains.kotlin:kotlin-reflect:1.6.21") implementation(kotlin("reflect"))
} }
tasks { tasks {

View File

@ -5,6 +5,7 @@ import app.revanced.patcher.data.PatcherData
import app.revanced.patcher.data.base.Data import app.revanced.patcher.data.base.Data
import app.revanced.patcher.data.implementation.findIndexed import app.revanced.patcher.data.implementation.findIndexed
import app.revanced.patcher.extensions.findAnnotationRecursively import app.revanced.patcher.extensions.findAnnotationRecursively
import app.revanced.patcher.extensions.nullOutputStream
import app.revanced.patcher.patch.base.Patch import app.revanced.patcher.patch.base.Patch
import app.revanced.patcher.patch.implementation.BytecodePatch import app.revanced.patcher.patch.implementation.BytecodePatch
import app.revanced.patcher.patch.implementation.ResourcePatch import app.revanced.patcher.patch.implementation.ResourcePatch
@ -28,7 +29,6 @@ import org.jf.dexlib2.iface.ClassDef
import org.jf.dexlib2.iface.DexFile import org.jf.dexlib2.iface.DexFile
import org.jf.dexlib2.writer.io.MemoryDataStore import org.jf.dexlib2.writer.io.MemoryDataStore
import java.io.File import java.io.File
import java.io.OutputStream
val NAMER = BasicDexFileNamer() val NAMER = BasicDexFileNamer()
@ -41,7 +41,8 @@ val NAMER = BasicDexFileNamer()
class Patcher( class Patcher(
inputFile: File, inputFile: File,
// TODO: maybe a file system in memory is better. Could cause high memory usage. // TODO: maybe a file system in memory is better. Could cause high memory usage.
private val resourceCacheDirectory: String, private val patchResources: Boolean = false private val resourceCacheDirectory: String,
private val patchResources: Boolean = false
) { ) {
val packageVersion: String val packageVersion: String
val packageName: String val packageName: String
@ -51,7 +52,6 @@ class Patcher(
private val opcodes: Opcodes private val opcodes: Opcodes
private var signaturesResolved = false private var signaturesResolved = false
init { init {
val extFileInput = ExtFile(inputFile) val extFileInput = ExtFile(inputFile)
val outDir = File(resourceCacheDirectory) val outDir = File(resourceCacheDirectory)
@ -85,7 +85,7 @@ class Patcher(
XmlPullStreamDecoder( XmlPullStreamDecoder(
axmlParser, AndrolibResources().resXmlSerializer axmlParser, AndrolibResources().resXmlSerializer
).decodeManifest( ).decodeManifest(
extFileInput.directory.getFileInput("AndroidManifest.xml"), OutputStream.nullOutputStream() extFileInput.directory.getFileInput("AndroidManifest.xml"), nullOutputStream
) )
} }

View File

@ -9,6 +9,7 @@ import org.jf.dexlib2.iface.reference.MethodReference
import org.jf.dexlib2.immutable.ImmutableMethod import org.jf.dexlib2.immutable.ImmutableMethod
import org.jf.dexlib2.immutable.ImmutableMethodImplementation import org.jf.dexlib2.immutable.ImmutableMethodImplementation
import org.jf.dexlib2.util.MethodUtil import org.jf.dexlib2.util.MethodUtil
import java.io.OutputStream
/** /**
* Recursively find a given annotation on a class * Recursively find a given annotation on a class
@ -105,4 +106,9 @@ internal fun parametersEqual(
) )
} }
} }
} }
internal val nullOutputStream: OutputStream =
object : OutputStream() {
override fun write(b: Int) {}
}

View File

@ -19,7 +19,7 @@ object PatchLoader {
val entry = entries.nextElement() val entry = entries.nextElement()
if (!entry.name.endsWith(".class") || entry.name.contains("$")) continue if (!entry.name.endsWith(".class") || entry.name.contains("$")) continue
val clazz = classLoader.loadClass(entry.realName.replace('/', '.').replace(".class", "")) val clazz = classLoader.loadClass(entry.name.replace('/', '.').replace(".class", ""))
if (!clazz.isAnnotationPresent(app.revanced.patcher.patch.annotations.Patch::class.java)) continue if (!clazz.isAnnotationPresent(app.revanced.patcher.patch.annotations.Patch::class.java)) continue