Compare commits

..

46 Commits

Author SHA1 Message Date
semantic-release-bot
87c0e05d9c chore(release): 1.2.0-dev.1 [skip ci]
# [1.2.0-dev.1](https://github.com/revanced/revanced-cli/compare/v1.1.6-dev.1...v1.2.0-dev.1) (2022-06-04)

### Features

* add path for `cacheDirectory` and enable resource patching by default ([54c0a03](54c0a03d44))
2022-06-04 00:32:25 +00:00
oSumAtrIX
54c0a03d44 feat: add path for cacheDirectory and enable resource patching by default 2022-06-03 17:51:13 +02:00
semantic-release-bot
bd185133bc chore(release): 1.1.6-dev.1 [skip ci]
## [1.1.6-dev.1](https://github.com/revanced/revanced-cli/compare/v1.1.5...v1.1.6-dev.1) (2022-05-31)

### Bug Fixes

* migrate to latest patcher api changes ([ace70e4](ace70e417f))
2022-05-31 23:55:55 +00:00
oSumAtrIX
ace70e417f fix: migrate to latest patcher api changes 2022-06-01 01:41:24 +02:00
oSumAtrIX
735dbc9149 Merge remote-tracking branch 'origin/dev' into dev 2022-05-29 02:14:44 +02:00
tillnelown
e756ac9920 Removes the uneeded revanced-patches dependency 2022-05-28 18:22:51 +02:00
oSumAtrIX
a4ef47a285 Merge pull request #19 from revanced/dev
chore: bump patcher version
2022-05-27 17:46:15 +02:00
oSumAtrIX
c69170535e chore: bump patcher version 2022-05-27 14:33:22 +02:00
semantic-release-bot
a1bcd1fdaf chore(release): 1.1.5 [skip ci]
## [1.1.5](https://github.com/revanced/revanced-cli/compare/v1.1.4...v1.1.5) (2022-05-27)

### Bug Fixes

* invalid code flow when adding patches ([206f202](206f2029d7))
2022-05-27 10:27:42 +00:00
oSumAtrIX
206f2029d7 fix: invalid code flow when adding patches 2022-05-27 12:25:44 +02:00
semantic-release-bot
04e0027c08 chore(release): 1.1.4 [skip ci]
## [1.1.4](https://github.com/revanced/revanced-cli/compare/v1.1.3...v1.1.4) (2022-05-26)

### Bug Fixes

* migrate from `PatchLoader.load(...)` to `JarPatchBundle(...).loadPatches()` ([cabd32f](cabd32fda4))
2022-05-26 02:26:10 +00:00
oSumAtrIX
e76983e01c chore: update gradlew wrapper 2022-05-26 04:08:29 +02:00
oSumAtrIX
11d67bc1ea chore: update dependencies 2022-05-26 04:08:15 +02:00
oSumAtrIX
cabd32fda4 fix: migrate from PatchLoader.load(...) to JarPatchBundle(...).loadPatches()
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
2022-05-26 01:02:42 +02:00
semantic-release-bot
61235d7c41 chore(release): 1.1.3 [skip ci]
## [1.1.3](https://github.com/revanced/revanced-cli/compare/v1.1.2...v1.1.3) (2022-05-25)

### Bug Fixes

* only accept directories when looking for files in resource patch ([c76da7e](c76da7e5ff))
2022-05-25 22:42:14 +00:00
oSumAtrIX
817154dd66 Merge pull request #18 from danthe1st/main
fix: only accept directories when looking for files in resource patch
2022-05-26 00:40:39 +02:00
danthe1st
c76da7e5ff fix: only accept directories when looking for files in resource patch 2022-05-26 00:31:29 +02:00
oSumAtrIX
d946333c96 Merge remote-tracking branch 'origin/main' 2022-05-24 02:10:15 +02:00
oSumAtrIX
97a036bfbc chore: update kotlin jvm
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
2022-05-24 00:17:02 +02:00
oSumAtrIX
153d8ce746 chore: update dependencies
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
2022-05-23 20:56:22 +02:00
oSumAtrIX
5cd3ea291c refactor: remove unused Patches class
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
2022-05-23 20:35:03 +02:00
semantic-release-bot
c8a5e97f0d chore(release): 1.1.2 [skip ci]
## [1.1.2](https://github.com/revanced/revanced-cli/compare/v1.1.1...v1.1.2) (2022-05-22)

### Bug Fixes

* delete `outputFile` after deploying ([329f8a3](329f8a383f))
2022-05-22 20:39:34 +00:00
oSumAtrIX
329f8a383f fix: delete outputFile after deploying 2022-05-22 22:38:27 +02:00
semantic-release-bot
fb1cd41521 chore(release): 1.1.1 [skip ci]
## [1.1.1](https://github.com/revanced/revanced-cli/compare/v1.1.0...v1.1.1) (2022-05-22)

### Bug Fixes

* breaking changes by `revanced-patcher` dependency ([51d2504](51d250491f))
* wrong use of dependency to `revanced-patches` ([351de6c](351de6cb90))
* wrong use of variable substitution / typo ([81d53b5](81d53b5518)), closes [revanced/revanced-cli#12](https://github.com/revanced/revanced-cli/issues/12)
2022-05-22 15:28:46 +00:00
oSumAtrIX
457c371fb9 Merge branch 'dev'
# Conflicts:
#	CHANGELOG.md
#	gradle.properties
2022-05-22 17:25:38 +02:00
oSumAtrIX
cd58fe5869 Merge pull request #16 from revanced/annotations
fix: support annotated patches
2022-05-22 17:15:56 +02:00
oSumAtrIX
f297f7d1ef add: signature checker and compatibility filters
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
2022-05-22 17:10:43 +02:00
oSumAtrIX
51d250491f fix: breaking changes by revanced-patcher dependency
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
2022-05-22 13:47:45 +02:00
semantic-release-bot
f90205b243 chore(release): 1.1.0-dev.3 [skip ci]
# [1.1.0-dev.3](https://github.com/revanced/revanced-cli/compare/v1.1.0-dev.2...v1.1.0-dev.3) (2022-05-15)

### Bug Fixes

* wrong use of variable substitution / typo ([81d53b5](81d53b5518)), closes [revanced/revanced-cli#12](https://github.com/revanced/revanced-cli/issues/12)
2022-05-15 20:11:14 +00:00
oSumAtrIX
159a169c16 Merge pull request #13 from AzimsTech/dev
fix: wrong use of variable substitution / typo
2022-05-15 22:09:27 +02:00
Wan Muhammad Azims
81d53b5518 fix: wrong use of variable substitution / typo
[revanced/revanced-cli#12](https://github.com/revanced/revanced-cli/issues/12)
2022-05-16 03:45:20 +08:00
semantic-release-bot
aba7965df8 chore(release): 1.1.0-dev.2 [skip ci]
# [1.1.0-dev.2](https://github.com/revanced/revanced-cli/compare/v1.1.0-dev.1...v1.1.0-dev.2) (2022-05-07)

### Bug Fixes

* wrong use of dependency to `revanced-patches` ([351de6c](351de6cb90))
2022-05-07 21:16:55 +00:00
oSumAtrIX
351de6cb90 fix: wrong use of dependency to revanced-patches
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
2022-05-07 23:15:31 +02:00
oSumAtrIX
52dacc16a0 chore: bump project JDK to JDK 17
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
2022-05-07 21:37:24 +02:00
semantic-release-bot
a7493e5e43 chore(release): 1.1.0 [skip ci]
# [1.1.0](https://github.com/revanced/revanced-cli/compare/v1.0.1...v1.1.0) (2022-05-07)

### Bug Fixes

* ClassLoader not working with Java 9+ ([3a11e11](3a11e1135b))
* leftover TODOs ([5b1139c](5b1139ce43))

### Features

* run `release.yml` workflow on branch `dev` ([9a64730](9a6473056b))
2022-05-07 19:26:36 +00:00
oSumAtrIX
46c275feb5 Merge pull request #10 from revanced/dev
feat: support java version 9+
2022-05-07 21:25:28 +02:00
oSumAtrIX
4fe620e84b chore: bump java-version for action setup-java
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
2022-05-07 21:21:44 +02:00
semantic-release-bot
7b1f10a8e9 chore(release): 1.1.0-dev.1 [skip ci]
# [1.1.0-dev.1](https://github.com/revanced/revanced-cli/compare/v1.0.1...v1.1.0-dev.1) (2022-05-07)

### Bug Fixes

* ClassLoader not working with Java 9+ ([3a11e11](3a11e1135b))
* leftover TODOs ([5b1139c](5b1139ce43))

### Features

* run `release.yml` workflow on branch `dev` ([9a64730](9a6473056b))
2022-05-07 19:20:22 +00:00
oSumAtrIX
9a6473056b feat: run release.yml workflow on branch dev
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
2022-05-07 21:19:01 +02:00
oSumAtrIX
a108c92ade Merge pull request #9 from danthe1st/main
fix: ClassLoader not working with Java 9+
2022-05-07 21:15:02 +02:00
oSumAtrIX
5b1139ce43 fix: leftover TODOs
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
2022-05-07 21:13:28 +02:00
danthe1st
3a11e1135b fix: ClassLoader not working with Java 9+ 2022-05-07 21:08:11 +02:00
semantic-release-bot
7a6025a278 chore(release): 1.0.1 [skip ci]
## [1.0.1](https://github.com/revanced/revanced-cli/compare/v1.0.0...v1.0.1) (2022-05-07)

### Bug Fixes

* broken script `CONTENT_UNMOUNT_SCRIPT` ([be53e64](be53e649a7))
* use latest version of patches dependency ([029f1ad](029f1ad722))
2022-05-07 16:16:48 +00:00
oSumAtrIX
f0d79941aa Merge remote-tracking branch 'origin/main' 2022-05-07 18:15:18 +02:00
oSumAtrIX
029f1ad722 fix: use latest version of patches dependency
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
2022-05-07 18:15:02 +02:00
oSumAtrIX
be53e649a7 fix: broken script CONTENT_UNMOUNT_SCRIPT
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
2022-05-07 18:13:14 +02:00
16 changed files with 275 additions and 141 deletions

View File

@@ -1,11 +1,14 @@
name: Release name: Release
on: on:
workflow_dispatch:
push: push:
branches: branches:
- main - main
- dev
pull_request: pull_request:
branches: branches:
- main - main
- dev
jobs: jobs:
release: release:
name: Release name: Release
@@ -18,7 +21,7 @@ jobs:
- name: Setup JDK - name: Setup JDK
uses: actions/setup-java@v2 uses: actions/setup-java@v2
with: with:
java-version: '8' java-version: '17'
distribution: 'adopt' distribution: 'adopt'
cache: gradle cache: gradle
- name: Setup Node.js - name: Setup Node.js

2
.idea/misc.xml generated
View File

@@ -4,7 +4,7 @@
<component name="FrameworkDetectionExcludesConfiguration"> <component name="FrameworkDetectionExcludesConfiguration">
<file type="web" url="file://$PROJECT_DIR$" /> <file type="web" url="file://$PROJECT_DIR$" />
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="azul-1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="azul-17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>

2
.idea/vcs.xml generated
View File

@@ -8,5 +8,7 @@
</component> </component>
<component name="VcsDirectoryMappings"> <component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" /> <mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$/../revanced-patcher" vcs="Git" />
<mapping directory="$PROJECT_DIR$/../revanced-patches" vcs="Git" />
</component> </component>
</project> </project>

View File

@@ -1,3 +1,89 @@
# [1.2.0-dev.1](https://github.com/revanced/revanced-cli/compare/v1.1.6-dev.1...v1.2.0-dev.1) (2022-06-04)
### Features
* add path for `cacheDirectory` and enable resource patching by default ([54c0a03](https://github.com/revanced/revanced-cli/commit/54c0a03d44c8d1b586bc487ee1ca71859d6f0b57))
## [1.1.6-dev.1](https://github.com/revanced/revanced-cli/compare/v1.1.5...v1.1.6-dev.1) (2022-05-31)
### Bug Fixes
* migrate to latest patcher api changes ([ace70e4](https://github.com/revanced/revanced-cli/commit/ace70e417fdf280c7630a5a89a773879fd240e96))
## [1.1.5](https://github.com/revanced/revanced-cli/compare/v1.1.4...v1.1.5) (2022-05-27)
### Bug Fixes
* invalid code flow when adding patches ([206f202](https://github.com/revanced/revanced-cli/commit/206f2029d7498b6474c16a47cbe451c170fdd31f))
## [1.1.4](https://github.com/revanced/revanced-cli/compare/v1.1.3...v1.1.4) (2022-05-26)
### Bug Fixes
* migrate from `PatchLoader.load(...)` to `JarPatchBundle(...).loadPatches()` ([cabd32f](https://github.com/revanced/revanced-cli/commit/cabd32fda41d32616a61ae450c60e1ee7c35bc59))
## [1.1.3](https://github.com/revanced/revanced-cli/compare/v1.1.2...v1.1.3) (2022-05-25)
### Bug Fixes
* only accept directories when looking for files in resource patch ([c76da7e](https://github.com/revanced/revanced-cli/commit/c76da7e5ffa208860eea008dad358e4e3bb3d735))
## [1.1.2](https://github.com/revanced/revanced-cli/compare/v1.1.1...v1.1.2) (2022-05-22)
### Bug Fixes
* delete `outputFile` after deploying ([329f8a3](https://github.com/revanced/revanced-cli/commit/329f8a383fe52f4c2a66075d893c6599d3550bee))
## [1.1.1](https://github.com/revanced/revanced-cli/compare/v1.1.0...v1.1.1) (2022-05-22)
### Bug Fixes
* breaking changes by `revanced-patcher` dependency ([51d2504](https://github.com/revanced/revanced-cli/commit/51d250491f390695aedc64e7ee71a9dcf99d695c))
* wrong use of dependency to `revanced-patches` ([351de6c](https://github.com/revanced/revanced-cli/commit/351de6cb90aa0f2ec93e8b8f6c10d7d312082079))
* wrong use of variable substitution / typo ([81d53b5](https://github.com/revanced/revanced-cli/commit/81d53b5518454e479b7a8f2e9be934bee30702af)), closes [revanced/revanced-cli#12](https://github.com/revanced/revanced-cli/issues/12)
# [1.1.0-dev.3](https://github.com/revanced/revanced-cli/compare/v1.1.0-dev.2...v1.1.0-dev.3) (2022-05-15)
### Bug Fixes
* wrong use of variable substitution / typo ([81d53b5](https://github.com/revanced/revanced-cli/commit/81d53b5518454e479b7a8f2e9be934bee30702af)), closes [revanced/revanced-cli#12](https://github.com/revanced/revanced-cli/issues/12)
# [1.1.0-dev.2](https://github.com/revanced/revanced-cli/compare/v1.1.0-dev.1...v1.1.0-dev.2) (2022-05-07)
### Bug Fixes
* wrong use of dependency to `revanced-patches` ([351de6c](https://github.com/revanced/revanced-cli/commit/351de6cb90aa0f2ec93e8b8f6c10d7d312082079))
# [1.1.0-dev.1](https://github.com/revanced/revanced-cli/compare/v1.0.1...v1.1.0-dev.1) (2022-05-07)
### Bug Fixes
* ClassLoader not working with Java 9+ ([3a11e11](https://github.com/revanced/revanced-cli/commit/3a11e1135bd1e8958dd21247622d549440725ead))
* leftover TODOs ([5b1139c](https://github.com/revanced/revanced-cli/commit/5b1139ce43df1f5c2c848a8209a9e618857031ce))
### Features
* run `release.yml` workflow on branch `dev` ([9a64730](https://github.com/revanced/revanced-cli/commit/9a6473056b940c6df4860dd09c09d7ac61545f7d))
## [1.0.1](https://github.com/revanced/revanced-cli/compare/v1.0.0...v1.0.1) (2022-05-07)
### Bug Fixes
* broken script `CONTENT_UNMOUNT_SCRIPT` ([be53e64](https://github.com/revanced/revanced-cli/commit/be53e649a7a43de70ba2a7227c49b085001066a6))
* use latest version of patches dependency ([029f1ad](https://github.com/revanced/revanced-cli/commit/029f1ad72223e5be6664c2c8810ac35e5807d9a8))
# 1.0.0 (2022-05-07) # 1.0.0 (2022-05-07)

View File

@@ -1,5 +1,5 @@
plugins { plugins {
kotlin("jvm") version "1.6.20" kotlin("jvm") version "1.6.21"
id("com.github.johnrengelman.shadow") version "7.1.2" id("com.github.johnrengelman.shadow") version "7.1.2"
java java
`maven-publish` `maven-publish`
@@ -22,17 +22,15 @@ repositories {
} }
} }
val patchesDependency = "app.revanced:revanced-patches:1.0.0-dev.5"
dependencies { dependencies {
implementation(kotlin("stdlib")) implementation("org.jetbrains.kotlin:kotlin-stdlib:1.6.21")
implementation("app.revanced:revanced-patcher:+") implementation("app.revanced:revanced-patcher:1.0.0-dev.17")
implementation(patchesDependency)
implementation("info.picocli:picocli:+") implementation("info.picocli:picocli:4.6.3")
implementation("me.tongfei:progressbar:+")
implementation("com.github.li-wjohnson:jadb:master-SNAPSHOT") // using a fork instead. implementation("com.github.li-wjohnson:jadb:master-SNAPSHOT") // using a fork instead.
implementation("org.bouncycastle:bcpkix-jdk15on:+") implementation("org.bouncycastle:bcpkix-jdk15on:1.70")
implementation("org.jetbrains.kotlin:kotlin-reflect:1.6.21")
} }
java { java {
@@ -45,9 +43,6 @@ tasks {
dependsOn(shadowJar) dependsOn(shadowJar)
} }
shadowJar { shadowJar {
dependencies {
exclude(dependency(patchesDependency))
}
manifest { manifest {
attributes("Main-Class" to "app.revanced.cli.MainKt") attributes("Main-Class" to "app.revanced.cli.MainKt")
attributes("Implementation-Title" to project.name) attributes("Implementation-Title" to project.name)

View File

@@ -1,2 +1,2 @@
kotlin.code.style = official kotlin.code.style = official
version = 1.0.0 version = 1.2.0-dev.1

View File

@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View File

@@ -1,8 +1,11 @@
package app.revanced.cli package app.revanced.cli
import app.revanced.patch.PatchLoader import app.revanced.patcher.PatcherOptions
import app.revanced.patch.Patches import app.revanced.patcher.annotation.Name
import app.revanced.patcher.util.patch.implementation.JarPatchBundle
import app.revanced.utils.adb.Adb import app.revanced.utils.adb.Adb
import app.revanced.utils.patcher.addPatchesFiltered
import app.revanced.utils.signature.Signature
import picocli.CommandLine.* import picocli.CommandLine.*
import java.io.File import java.io.File
@@ -17,13 +20,13 @@ internal object MainCommand : Runnable {
internal var includedPatches = arrayOf<String>() internal var includedPatches = arrayOf<String>()
@Option(names = ["-p", "--patches"], description = ["One or more bundles of patches"]) @Option(names = ["-p", "--patches"], description = ["One or more bundles of patches"])
internal var patchBundles = arrayOf<File>() internal var patchBundles = arrayOf<String>()
@Option(names = ["-t", "--temp-dir"], description = ["Temporal resource cache directory"], required = true) @Option(names = ["-t", "--temp-dir"], description = ["Temporal resource cache directory"])
internal lateinit var cacheDirectory: String internal var cacheDirectory = "revanced-cache"
@Option(names = ["-r", "--resource-patcher"], description = ["Enable patching resources"]) @Option(names = ["-r", "--resource-patcher"], description = ["Disable patching resources"])
internal var patchResources: Boolean = false internal var disableResourcePatching: Boolean = false
@Option( @Option(
names = ["-c", "--clean"], names = ["-c", "--clean"],
@@ -34,6 +37,9 @@ internal object MainCommand : Runnable {
@Option(names = ["-l", "--list"], description = ["List patches only"]) @Option(names = ["-l", "--list"], description = ["List patches only"])
internal var listOnly: Boolean = false internal var listOnly: Boolean = false
@Option(names = ["-s", "--signature-checker"], description = ["Check signatures of all patches"])
internal var signatureCheck: Boolean = false
@Option(names = ["-m", "--merge"], description = ["One or more dex file containers to merge"]) @Option(names = ["-m", "--merge"], description = ["One or more dex file containers to merge"])
internal var mergeFiles = listOf<File>() internal var mergeFiles = listOf<File>()
@@ -48,37 +54,40 @@ internal object MainCommand : Runnable {
override fun run() { override fun run() {
if (listOnly) { if (listOnly) {
patchBundles.forEach { for (patchBundlePath in patchBundles) for (it in JarPatchBundle(patchBundlePath).loadPatches()) {
PatchLoader.injectPatches(it)
Patches.loadPatches().forEach { // TODO: adjust extension methods to be able to do this
println(it().metadata) val name = (it.annotations.find { it is Name } as? Name)?.name ?: it.simpleName
} println(
"[available] $name"
)
} }
return return
} }
val patcher = app.revanced.patcher.Patcher( val patcher = app.revanced.patcher.Patcher(PatcherOptions(inputFile, cacheDirectory, !disableResourcePatching))
inputFile,
cacheDirectory,
patchResources
)
Patcher.start(patcher) if (signatureCheck) {
patcher.addPatchesFiltered()
if (clean) { Signature.checkSignatures(patcher)
File(cacheDirectory).deleteRecursively() return
} }
val outputFile = File(outputPath) val outputFile = File(outputPath)
var adb: Adb? = null
deploy?.let { deploy?.let {
Adb( adb = Adb(
outputFile, outputFile, patcher.packageName, deploy!!
patcher.packageName, )
deploy!!
).deploy()
} }
Patcher.start(patcher)
if (clean) File(cacheDirectory).deleteRecursively()
adb?.deploy()
if (clean) outputFile.delete() if (clean) outputFile.delete()
} }
} }

View File

@@ -1,26 +1,22 @@
package app.revanced.cli package app.revanced.cli
import app.revanced.patch.PatchLoader
import app.revanced.patch.Patches
import app.revanced.patcher.data.base.Data
import app.revanced.patcher.patch.base.Patch
import app.revanced.utils.filesystem.FileSystemUtils import app.revanced.utils.filesystem.FileSystemUtils
import app.revanced.utils.patcher.addPatchesFiltered
import app.revanced.utils.patcher.applyPatchesPrint
import app.revanced.utils.patcher.mergeFiles
import app.revanced.utils.signing.Signer import app.revanced.utils.signing.Signer
import java.io.File import java.io.File
import java.io.FileFilter
internal class Patcher { internal class Patcher {
internal companion object { internal companion object {
internal fun start(patcher: app.revanced.patcher.Patcher) { internal fun start(patcher: app.revanced.patcher.Patcher) {
// merge files like necessary integrations // merge files like necessary integrations
patcher.addFiles(MainCommand.mergeFiles) patcher.mergeFiles()
// add patches, but filter incompatible or excluded patches // add patches, but filter incompatible or excluded patches
patcher.addPatchesFiltered() patcher.addPatchesFiltered(includeFilter = MainCommand.includedPatches.isNotEmpty())
// apply patches // apply patches
for ((meta, result) in patcher.applyPatches { patcher.applyPatchesPrint()
println("Applying $it.")
}) {
println("Applied ${meta.name}. The result was $result.")
}
// write output file // write output file
val outFile = File(MainCommand.outputPath) val outFile = File(MainCommand.outputPath)
@@ -34,8 +30,9 @@ internal class Patcher {
zipFileSystem.replaceFile(name, data.data) zipFileSystem.replaceFile(name, data.data)
} }
if (MainCommand.patchResources) { if (!MainCommand.disableResourcePatching) {
for (file in File(MainCommand.cacheDirectory).resolve("build/").listFiles().first().listFiles()) { for (file in File(MainCommand.cacheDirectory).resolve("build/").listFiles(FileFilter { it.isDirectory })
?.first()?.listFiles()!!) {
if (!file.isDirectory) { if (!file.isDirectory) {
zipFileSystem.replaceFile(file.name, file.readBytes()) zipFileSystem.replaceFile(file.name, file.readBytes())
continue continue
@@ -49,43 +46,10 @@ internal class Patcher {
// and sign the apk file // and sign the apk file
Signer.signApk(outFile) Signer.signApk(outFile)
println("[done]")
} }
private fun app.revanced.patcher.Patcher.addPatchesFiltered() {
// TODO: get package metadata (outside of this method) for apk file which needs to be patched
val packageName = this.packageName
val packageVersion = this.packageVersion
val checkInclude = MainCommand.includedPatches.isNotEmpty()
MainCommand.patchBundles.forEach { bundle ->
PatchLoader.injectPatches(bundle)
val includedPatches = mutableListOf<Patch<Data>>()
Patches.loadPatches().forEach patch@{
val patch = it()
// TODO: filter out incompatible patches with package metadata
val filterOutPatches = true
if (filterOutPatches && !patch.metadata.compatiblePackages.any { packageMetadata ->
packageMetadata.name == packageName && packageMetadata.versions.any {
it == packageVersion
}
}) {
println("Skipping ${patch.metadata.name} due to incompatibility with current package $packageName.")
return@patch
}
if (checkInclude && !MainCommand.includedPatches.contains(patch.metadata.shortName)) {
return@patch
}
println("Adding ${patch.metadata.name}.")
includedPatches.add(patch)
}
this.addPatches(includedPatches)
}
}
} }
} }

View File

@@ -1,25 +0,0 @@
package app.revanced.patch
import java.io.File
import java.net.URL
import java.net.URLClassLoader
internal class PatchLoader {
internal companion object {
internal fun injectPatches(file: File) {
// This function will fail on Java 9 and above.
try {
val url = file.toURI().toURL()
val classLoader = Thread.currentThread().contextClassLoader as URLClassLoader
val method = URLClassLoader::class.java.getDeclaredMethod("addURL", URL::class.java)
method.isAccessible = true
method.invoke(classLoader, url)
} catch (e: Exception) {
throw Exception(
"Failed to inject patches! The CLI does NOT work on Java 9 and above, please use Java 8!",
e // propagate exception
)
}
}
}
}

View File

@@ -1,15 +0,0 @@
package app.revanced.patch
import app.revanced.patches.Index
internal class Patches {
internal companion object {
// You may ask yourself, "why do this?".
// We do it like this, because we don't want the Index class
// to be loaded while the dependency hasn't been injected yet.
// You can see this as "controlled class loading".
// Whenever this class is loaded (because it is invoked), all the imports
// will be loaded too. We don't want to do this until we've injected the class.
internal fun loadPatches() = Index.patches
}
}

View File

@@ -8,7 +8,7 @@ internal object Constants {
private const val COMMAND_CHMOD_MOUNT = "chmod +x" private const val COMMAND_CHMOD_MOUNT = "chmod +x"
internal const val COMMAND_PID_OF = "pidof -s" internal const val COMMAND_PID_OF = "pidof -s"
internal const val COMMAND_CREATE_DIR = "mkdir -p" internal const val COMMAND_CREATE_DIR = "mkdir -p"
internal const val COMMAND_LOGCAT = "logcat -c && logcat --pid=$($COMMAND_PID_OF $PLACEHOLDER)" internal const val COMMAND_LOGCAT = "logcat -c && logcat | grep AndroidRuntime"
internal const val COMMAND_RESTART = "monkey -p $PLACEHOLDER 1 && kill ${'$'}($COMMAND_PID_OF $PLACEHOLDER)" internal const val COMMAND_RESTART = "monkey -p $PLACEHOLDER 1 && kill ${'$'}($COMMAND_PID_OF $PLACEHOLDER)"
// default mount file name // default mount file name
@@ -42,8 +42,8 @@ internal object Constants {
""" """
#!/system/bin/sh #!/system/bin/sh
stock_path=${'$'}{ pm path $PLACEHOLDER | grep base | sed 's/package://g' } stock_path=${'$'}( pm path $PLACEHOLDER | grep base | sed 's/package://g' )
umount -l $PLACEHOLDER; done< /proc/mounts umount -l ${'$'}stock_path
""".trimIndent() """.trimIndent()
// mount script // mount script
@@ -53,7 +53,7 @@ internal object Constants {
while [ "${'$'}(getprop sys.boot_completed | tr -d '\r')" != "1" ]; do sleep 1; done while [ "${'$'}(getprop sys.boot_completed | tr -d '\r')" != "1" ]; do sleep 1; done
base_path="$PATH_REVANCED_APP" base_path="$PATH_REVANCED_APP"
stock_path=${'$'}{ pm path $PLACEHOLDER | grep base | sed 's/package://g' } stock_path=${'$'}( pm path $PLACEHOLDER | grep base | sed 's/package://g' )
mount -o bind ${'$'}base_path ${'$'}stock_path mount -o bind ${'$'}base_path ${'$'}stock_path
""".trimIndent() """.trimIndent()
} }

View File

@@ -12,10 +12,7 @@ internal class FileSystemUtils(
private var fileSystem: FileSystem private var fileSystem: FileSystem
init { init {
fileSystem = FileSystems.newFileSystem( fileSystem = FileSystems.newFileSystem(file.toPath(), null as ClassLoader?)
file.toPath(),
null
)
} }
private fun deleteDirectory(dirPath: String) { private fun deleteDirectory(dirPath: String) {

View File

@@ -0,0 +1,63 @@
package app.revanced.utils.patcher
import app.revanced.cli.MainCommand
import app.revanced.patcher.Patcher
import app.revanced.patcher.data.base.Data
import app.revanced.patcher.extensions.PatchExtensions.compatiblePackages
import app.revanced.patcher.extensions.PatchExtensions.patchName
import app.revanced.patcher.patch.base.Patch
import app.revanced.patcher.util.patch.implementation.JarPatchBundle
fun Patcher.addPatchesFiltered(
includeFilter: Boolean = false
) {
val packageName = this.packageName
val packageVersion = this.packageVersion
MainCommand.patchBundles.forEach { bundle ->
val includedPatches = mutableListOf<Class<out Patch<Data>>>()
JarPatchBundle(bundle).loadPatches().forEach patch@{ patch ->
val compatiblePackages = patch.compatiblePackages
val patchName = patch.patchName
val prefix = "[skipped] $patchName"
if (includeFilter && !MainCommand.includedPatches.contains(patchName)) {
println(prefix)
return@patch
}
if (compatiblePackages == null) println("$prefix: Missing compatibility annotation. Continuing.")
else compatiblePackages.forEach { compatiblePackage ->
if (compatiblePackage.name != packageName) {
println("$prefix: Package name not matching ${compatiblePackage.name}.")
return@patch
}
if (!compatiblePackage.versions.any { it == packageVersion }) {
println("$prefix: Unsupported version.")
return@patch
}
}
includedPatches.add(patch)
println("[added] $patchName")
}
this.addPatches(includedPatches)
}
}
fun Patcher.applyPatchesPrint() {
this.applyPatches().forEach { (patch, result) ->
if (result.isSuccess) {
println("[success] $patch")
return@forEach
}
println("[error] $patch:")
result.exceptionOrNull()!!.printStackTrace()
}
}
fun Patcher.mergeFiles() {
this.addFiles(MainCommand.mergeFiles)
}

View File

@@ -0,0 +1,55 @@
package app.revanced.utils.signature
import app.revanced.patcher.Patcher
import org.jf.dexlib2.iface.Method
object Signature {
fun checkSignatures(patcher: Patcher) {
TODO()
/**
val failed = mutableListOf<String>()
for (signature in patcher.resolveSignatures()) {
val signatureClass = signature::class.java
val signatureName = signature.name ?: signatureClass.simpleName
if (!signature.resolved) {
failed.add(signatureName)
continue
}
val method = signature.result!!.method
val matchingMethod = signature.matchingMethod ?: MatchingMethod()
println(
"""
[Signature] $signatureName
[Method] ${matchingMethod.definingClass}->${matchingMethod.name}
[Match] ${method.definingClass}->${method.toStr()}
""".trimIndent()
)
signature.fuzzyThreshold.let {
val warnings = signature.result!!.scanResult.warnings!!
println(
"""
[Warnings: ${warnings.count()}]
${warnings.joinToString(separator = "\n") { warning -> "${warning.instructionIndex} / ${warning.patternIndex}: ${warning.wrongOpcode} (expected: ${warning.correctOpcode})" }}
""".trimIndent()
)
}
}
println(
"""
${"=".repeat(50)}
[Failed signatures: ${failed.size}]
${failed.joinToString(separator = "\n") { it }}
""".trimIndent()
)
*/
}
private fun Method.toStr(): String {
return "${this.name}(${this.parameterTypes.joinToString("")})${this.returnType}"
}
}

View File

@@ -91,7 +91,7 @@ object Signer {
(keyStore.getKey(alias, PASSWORD) as PrivateKey) (keyStore.getKey(alias, PASSWORD) as PrivateKey)
) )
val zip = FileSystems.newFileSystem(apkFile.toPath(), null) val zip = FileSystems.newFileSystem(apkFile.toPath(), null as ClassLoader?)
val dig = MessageDigest.getInstance("SHA1") val dig = MessageDigest.getInstance("SHA1")
val digests: MutableMap<String, String> = LinkedHashMap() val digests: MutableMap<String, String> = LinkedHashMap()