mirror of
https://github.com/ReVanced/revanced-cli.git
synced 2026-01-11 22:06:20 +00:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e126436f3d | ||
|
|
80c11fef73 | ||
|
|
debf0116fb | ||
|
|
29105bab3d | ||
|
|
31853fe539 | ||
|
|
21747d5552 | ||
|
|
ee6aff8fe7 | ||
|
|
f3a3e935a2 | ||
|
|
c272d55e2d | ||
|
|
1781612789 | ||
|
|
3829136c49 | ||
|
|
00145f2bb6 |
22
CHANGELOG.md
22
CHANGELOG.md
@@ -1,3 +1,25 @@
|
||||
## [1.6.3](https://github.com/revanced/revanced-cli/compare/v1.6.2...v1.6.3) (2022-06-21)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* update patcher version ([80c11fe](https://github.com/revanced/revanced-cli/commit/80c11fef734bdba9026e91f95ee0a4a522cbefab))
|
||||
|
||||
## [1.6.2](https://github.com/revanced/revanced-cli/compare/v1.6.1...v1.6.2) (2022-06-21)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* CLI not working ([29105ba](https://github.com/revanced/revanced-cli/commit/29105bab3dabd9d16af6b511caef9727f98afd1a))
|
||||
* improper use of mount variable ([31853fe](https://github.com/revanced/revanced-cli/commit/31853fe5393af04805857b78a54434e1c51e4c8e))
|
||||
|
||||
## [1.6.1](https://github.com/revanced/revanced-cli/compare/v1.6.0...v1.6.1) (2022-06-21)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* remove `-e` from `experimental` option ([3829136](https://github.com/revanced/revanced-cli/commit/3829136c49ddce1dc6b01eda04ce013540b213c2))
|
||||
|
||||
# [1.6.0](https://github.com/revanced/revanced-cli/compare/v1.5.1...v1.6.0) (2022-06-21)
|
||||
|
||||
|
||||
|
||||
@@ -31,7 +31,8 @@ repositories {
|
||||
dependencies {
|
||||
implementation(kotlin("stdlib"))
|
||||
implementation(kotlin("reflect"))
|
||||
implementation("app.revanced:revanced-patcher:1.3.1")
|
||||
|
||||
implementation("app.revanced:revanced-patcher:1.3.4")
|
||||
implementation("info.picocli:picocli:4.6.3")
|
||||
implementation("com.android.tools.build:apksig:7.2.1")
|
||||
implementation("com.github.revanced:jadb:master-SNAPSHOT") // updated fork
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
kotlin.code.style = official
|
||||
version = 1.6.0
|
||||
version = 1.6.3
|
||||
|
||||
@@ -11,10 +11,11 @@ import java.io.File
|
||||
import java.nio.file.Files
|
||||
|
||||
@Command(
|
||||
name = "ReVanced-CLI", version = ["1.0.0"], mixinStandardHelpOptions = true,
|
||||
name = "ReVanced-CLI",
|
||||
version = ["1.0.0"],
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
internal object MainCommand : Runnable {
|
||||
|
||||
@ArgGroup(exclusive = false, multiplicity = "1")
|
||||
lateinit var args: Args
|
||||
|
||||
@@ -47,7 +48,7 @@ internal object MainCommand : Runnable {
|
||||
@Option(names = ["-r", "--resource-patcher"], description = ["Disable patching resources"])
|
||||
var disableResourcePatching: Boolean = false
|
||||
|
||||
@Option(names = ["-e", "--experimental"], description = ["Disable patch version compatibility patch"])
|
||||
@Option(names = ["--experimental"], description = ["Disable patch version compatibility patch"])
|
||||
var experimental: Boolean = false
|
||||
|
||||
@Option(names = ["-m", "--merge"], description = ["One or more dex file containers to merge"])
|
||||
@@ -97,14 +98,15 @@ internal object MainCommand : Runnable {
|
||||
Adb(outputFile, patcher.data.packageMetadata.packageName, args.deploy!!, !args.mount)
|
||||
}
|
||||
|
||||
val patchedFile =
|
||||
if (args.mount) outputFile else File(args.cacheDirectory).resolve("${outputFile.nameWithoutExtension}_raw.apk")
|
||||
val patchedFile = if (args.mount) {
|
||||
File(args.cacheDirectory).resolve("${outputFile.nameWithoutExtension}_raw.apk")
|
||||
} else outputFile
|
||||
|
||||
Patcher.start(patcher, patchedFile)
|
||||
|
||||
println("[aligning & signing]")
|
||||
|
||||
if (args.mount) {
|
||||
if (!args.mount) {
|
||||
Signing.start(
|
||||
patchedFile,
|
||||
outputFile,
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.nio.file.Files
|
||||
|
||||
internal object Patcher {
|
||||
internal fun start(patcher: app.revanced.patcher.Patcher, output: File) {
|
||||
val args = args.pArgs!!
|
||||
val args = args.pArgs!!
|
||||
|
||||
// merge files like necessary integrations
|
||||
patcher.mergeFiles()
|
||||
@@ -23,16 +23,20 @@ internal object Patcher {
|
||||
if (output.exists()) Files.delete(output.toPath())
|
||||
args.inputFile.copyTo(output)
|
||||
|
||||
ZipFileSystemUtils(output).use { fileSystem ->
|
||||
val result = patcher.save()
|
||||
val inputFile = if (!args.disableResourcePatching && result.resourceFile != null) {
|
||||
result.resourceFile
|
||||
} else null
|
||||
ZipFileSystemUtils(inputFile, output).use { fileSystem ->
|
||||
// replace all dex files
|
||||
val result = patcher.save()
|
||||
result.dexFiles.forEach {
|
||||
fileSystem.write(it.name, it.memoryDataStore.data)
|
||||
}
|
||||
|
||||
// write resources
|
||||
if (!args.disableResourcePatching) {
|
||||
fileSystem.writePathRecursively(File(args.cacheDirectory).resolve("build").toPath())
|
||||
// inputFile being null implies resource patching being disabled
|
||||
if (inputFile != null) {
|
||||
// write resources
|
||||
fileSystem.writeInput()
|
||||
fileSystem.uncompress(*result.doNotCompress!!.toTypedArray())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,12 +7,17 @@ import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.util.zip.ZipEntry
|
||||
|
||||
internal class ZipFileSystemUtils(
|
||||
file: File
|
||||
) : Closeable {
|
||||
private var zipFileSystem = FileSystems.newFileSystem(file.toPath(), mapOf("noCompression" to true))
|
||||
internal class ZipFileSystemUtils(input: File?, output: File) : Closeable {
|
||||
private val inFileSystem = if (input != null) {
|
||||
FileSystems.newFileSystem(input.toPath())
|
||||
} else null
|
||||
private val outFileSystem = FileSystems.newFileSystem(output.toPath(), mapOf("noCompression" to true))
|
||||
|
||||
private fun Path.deleteRecursively() {
|
||||
if (!Files.exists(this)) {
|
||||
throw IllegalStateException("File exists in input but not in output, cannot delete")
|
||||
}
|
||||
|
||||
if (Files.isDirectory(this)) {
|
||||
Files.list(this).forEach { path ->
|
||||
path.deleteRecursively()
|
||||
@@ -22,19 +27,25 @@ internal class ZipFileSystemUtils(
|
||||
Files.delete(this)
|
||||
}
|
||||
|
||||
internal fun writePathRecursively(path: Path) {
|
||||
Files.list(path).let { fileStream ->
|
||||
internal fun writeInput() {
|
||||
if (inFileSystem == null) {
|
||||
throw IllegalArgumentException("Input file not set")
|
||||
}
|
||||
val root = inFileSystem.getPath(inFileSystem.separator)
|
||||
|
||||
Files.list(root).close()
|
||||
|
||||
Files.list(root).also { fileStream ->
|
||||
fileStream.forEach { filePath ->
|
||||
val fileSystemPath = filePath.getRelativePath(path)
|
||||
val fileSystemPath = filePath.getRelativePath(root)
|
||||
fileSystemPath.deleteRecursively()
|
||||
}
|
||||
|
||||
fileStream
|
||||
}.close()
|
||||
|
||||
Files.walk(path).let { fileStream ->
|
||||
Files.walk(root).also { fileStream ->
|
||||
// don't include build directory by skipping the root node.
|
||||
fileStream.skip(1).forEach { filePath ->
|
||||
val relativePath = filePath.getRelativePath(path)
|
||||
val relativePath = filePath.getRelativePath(root)
|
||||
|
||||
if (Files.isDirectory(filePath)) {
|
||||
Files.createDirectory(relativePath)
|
||||
@@ -43,17 +54,18 @@ internal class ZipFileSystemUtils(
|
||||
|
||||
Files.copy(filePath, relativePath)
|
||||
}
|
||||
|
||||
fileStream
|
||||
}.close()
|
||||
}
|
||||
|
||||
internal fun write(path: String, content: ByteArray) = Files.write(zipFileSystem.getPath(path), content)
|
||||
internal fun write(path: String, content: ByteArray) = Files.write(outFileSystem.getPath(path), content)
|
||||
|
||||
private fun Path.getRelativePath(path: Path): Path = zipFileSystem.getPath(path.relativize(this).toString())
|
||||
private fun Path.getRelativePath(path: Path): Path = outFileSystem.getPath(path.relativize(this).toString())
|
||||
|
||||
internal fun uncompress(vararg paths: String) =
|
||||
paths.forEach { Files.setAttribute(zipFileSystem.getPath(it), "zip:method", ZipEntry.STORED) }
|
||||
paths.forEach { Files.setAttribute(outFileSystem.getPath(it), "zip:method", ZipEntry.STORED) }
|
||||
|
||||
override fun close() = zipFileSystem.close()
|
||||
override fun close() {
|
||||
inFileSystem?.close()
|
||||
outFileSystem.close()
|
||||
}
|
||||
}
|
||||
@@ -24,13 +24,11 @@ fun Patcher.addPatchesFiltered(
|
||||
|
||||
val prefix = "[skipped] $patchName"
|
||||
|
||||
val args = MainCommand.args.pArgs!!
|
||||
val args = MainCommand.args.pArgs!!
|
||||
|
||||
if (excludePatches) {
|
||||
if (args.excludedPatches.contains(patchName)) {
|
||||
println("$prefix: Explicitly excluded.")
|
||||
return@patch
|
||||
}
|
||||
if (excludePatches && args.excludedPatches.contains(patchName)) {
|
||||
println("$prefix: Explicitly excluded.")
|
||||
return@patch
|
||||
} else if (!patch.include) {
|
||||
println("$prefix: Implicitly excluded.")
|
||||
return@patch
|
||||
@@ -43,7 +41,7 @@ fun Patcher.addPatchesFiltered(
|
||||
return@patch
|
||||
}
|
||||
|
||||
if (!(args.experimental || compatiblePackages.any { it.versions.isEmpty() || it.versions.any { version -> version == packageVersion }})) {
|
||||
if (!(args.experimental || compatiblePackages.any { it.versions.isEmpty() || it.versions.any { version -> version == packageVersion } })) {
|
||||
println("$prefix: The package version is $packageVersion and is incompatible.")
|
||||
return@patch
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user