Skip to content

Commit

Permalink
refactor: use apktool fork
Browse files Browse the repository at this point in the history
also fixed some compilation issues
  • Loading branch information
Sculas authored and oSumAtrIX committed Jun 5, 2022
1 parent 839a5ef commit 5a96f2d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
28 changes: 15 additions & 13 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,31 @@ group = "app.revanced"

repositories {
mavenCentral()
maven {
url = uri("https://maven.pkg.github.com/revanced/multidexlib2")
credentials {
// DO NOT set these variables in the project's gradle.properties.
// Instead, you should set them in:
// Windows: %homepath%\.gradle\gradle.properties
// Linux: ~/.gradle/gradle.properties
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!
listOf("multidexlib2", "Apktool").forEach { repo ->
maven {
url = uri("https://maven.pkg.github.com/revanced/$repo")
credentials {
// DO NOT set these variables in the project's gradle.properties.
// Instead, you should set them in:
// Windows: %homepath%\.gradle\gradle.properties
// Linux: ~/.gradle/gradle.properties
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 {
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.6.21")
implementation(kotlin("stdlib"))

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("org.smali:smali:2.5.2")

testImplementation("org.jetbrains.kotlin:kotlin-test:1.6.21")
implementation("org.jetbrains.kotlin:kotlin-reflect:1.6.21")
testImplementation(kotlin("test"))
implementation(kotlin("reflect"))
}

tasks {
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/app/revanced/patcher/Patcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import app.revanced.patcher.data.PatcherData
import app.revanced.patcher.data.base.Data
import app.revanced.patcher.data.implementation.findIndexed
import app.revanced.patcher.extensions.findAnnotationRecursively
import app.revanced.patcher.extensions.nullOutputStream
import app.revanced.patcher.patch.base.Patch
import app.revanced.patcher.patch.implementation.BytecodePatch
import app.revanced.patcher.patch.implementation.ResourcePatch
Expand All @@ -28,7 +29,6 @@ import org.jf.dexlib2.iface.ClassDef
import org.jf.dexlib2.iface.DexFile
import org.jf.dexlib2.writer.io.MemoryDataStore
import java.io.File
import java.io.OutputStream

val NAMER = BasicDexFileNamer()

Expand All @@ -41,7 +41,8 @@ val NAMER = BasicDexFileNamer()
class Patcher(
inputFile: File,
// 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 packageName: String
Expand All @@ -51,7 +52,6 @@ class Patcher(
private val opcodes: Opcodes
private var signaturesResolved = false


init {
val extFileInput = ExtFile(inputFile)
val outDir = File(resourceCacheDirectory)
Expand Down Expand Up @@ -85,7 +85,7 @@ class Patcher(
XmlPullStreamDecoder(
axmlParser, AndrolibResources().resXmlSerializer
).decodeManifest(
extFileInput.directory.getFileInput("AndroidManifest.xml"), OutputStream.nullOutputStream()
extFileInput.directory.getFileInput("AndroidManifest.xml"), nullOutputStream
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.jf.dexlib2.iface.reference.MethodReference
import org.jf.dexlib2.immutable.ImmutableMethod
import org.jf.dexlib2.immutable.ImmutableMethodImplementation
import org.jf.dexlib2.util.MethodUtil
import java.io.OutputStream

/**
* Recursively find a given annotation on a class
Expand Down Expand Up @@ -105,4 +106,9 @@ internal fun parametersEqual(
)
}
}
}
}

internal val nullOutputStream: OutputStream =
object : OutputStream() {
override fun write(b: Int) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ object PatchLoader {
val entry = entries.nextElement()
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

Expand Down

0 comments on commit 5a96f2d

Please sign in to comment.