Skip to content

Commit

Permalink
build: Bump ReVanced Patcher (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX authored Aug 12, 2024
1 parent 0a2e99c commit 54ae01c
Show file tree
Hide file tree
Showing 10 changed files with 235 additions and 221 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,5 @@ node_modules/
revanced-cache/
options.toml

# Generated by an Android project (such as ReVanced Integrations)
# Generated by Android projects
local.properties
221 changes: 96 additions & 125 deletions docs/1_usage.md
Original file line number Diff line number Diff line change
@@ -1,129 +1,100 @@
# 🛠️ Using ReVanced CLI

Learn how to use ReVanced CLI.
The following examples will show you how to perform basic operations.
You can list patches, patch an app, uninstall, and install an app.

## 🔨 Usage

ReVanced CLI is divided into the following fundamental commands:

- ### 🚀 Show all available options for ReVanced CLI

```bash
java -jar revanced-cli.jar -h
```

- ### 📃 List patches

```bash
java -jar revanced-cli.jar list-patches \
--with-packages \
--with-versions \
--with-options \
revanced-patches.jar [<patch-bundle> ...]
```

- ### ⚙️ Generate options

This will generate an `options.json` file for the patches from a list of supplied patch bundles.
The file can be supplied to ReVanced CLI later on.

```bash
java -jar revanced-cli.jar options \
--path options.json \
--overwrite \
revanced-patches.jar [<patch-bundle> ...]
```

> **ℹ️ Note**
> A default `options.json` file will be automatically created if it does not exist
> without any need for intervention when using the `patch` command.

- ### 💉 Patch an app

You can patch apps by supplying patch bundles and the app to patch.
After patching, ReVanced CLI can install the patched app on your device using two methods:

> **💡 Tip**
> For ReVanced CLI to be able to install the patched app on your device, make sure ADB is working:
>
> ```bash
> adb shell exit
> ```
>
> If you want to mount the patched app on top of the un-patched app, make sure you have root permissions:
>
> ```bash
> adb shell su -c exit
> ```

> **⚠️ Warning**
> Some patches may require integrations
> such as [ReVanced Integrations](https://github.com/revanced/revanced-integrations).
> Supply them with the option `--merge`. ReVanced Patcher will automatically determine if they are necessary.

- #### 👾 Patch an app and install it on your device regularly

```bash
java -jar revanced-cli.jar patch \
--patch-bundle revanced-patches.jar \
-d \
input.apk
```

- #### 👾 Patch an app and mount it on top of the un-patched app with root permissions

> **❗ Caution**
> Ensure that the same app you are patching and mounting over is installed on your device:
>
> ```bash
> adb install app.apk
> ```

```bash
java -jar revanced-cli.jar patch \
--patch-bundle revanced-patches.jar \
--include "Some patch" \
--ii 123 \
--exclude "Some other patch" \
-d \
--mount \
app.apk
```

> **💡 Tip**
> You can use the option `--ii` to include or `--ie` to exclude
> patches by their index in relation to supplied patch bundles,
> similarly to the option `--include` and `--exclude`.
>
> This is useful in case two patches have the same name, and you must include or exclude one.
> The patch index is calculated by the position of the patch in the list of patches
> from patch bundles supplied using the option `--patch-bundle`.
>
> You can list all patches with their indices using the command `list-patches`.
>
> Keep in mind that the indices can change based on the order of the patch bundles supplied,
> as well if the patch bundles are updated because patches can be added or removed.

- ### 🗑️ Uninstall an app

```bash
java -jar revanced-cli.jar utility uninstall \
--package-name <package-name> \
[<device-serial>]
```

> **💡 Tip**
> You can unmount an APK file
> by adding the option `--unmount`.

- ### ️ 📦 Install an app

```bash
java -jar revanced-cli.jar utility install \
-a input.apk \
[<device-serial>]
```

> **💡 Tip**
> You can mount an APK file
> by supplying the app's package name to mount the supplied APK file over the option `--mount`.
## 🚀 Show all commands

```bash
java -jar revanced-cli.jar -h
```

## 📃 List patches

```bash
java -jar revanced-cli.jar list-patches --with-descriptions --with-packages --with-versions --with-options --with-universal-patches revanced-patches.rvp
```

## 💉 Patch an app with the default list of patches

```bash
java -jar revanced-cli.jar patch -b revanced-patches.rvp input.apk
```

You can also use multiple patch bundles:

```bash
java -jar revanced-cli.jar patch -b revanced-patches.rvp -b another-patches.rvp input.apk
```

To manually include or exclude patches, use the options `-i` and `-e`.
Keep in mind the name of the patch must be an exact match.
You can also use the options `--ii` and `--ie` to include or exclude patches by their index
if two patches have the same name.
To know the indices of patches, use the option `--with-indices` when listing patches:

```bash
java -jar revanced-cli.jar list-patches --with-indices revanced-patches.rvp
```

Then you can use the indices to include or exclude patches:

```bash
java -jar revanced-cli.jar patch -b revanced-patches.rvp --ii 123 --ie 456 input.apk
```

> [!TIP]
> You can use the option `-d` to automatically install the patched app after patching.
> Make sure ADB is working:
>
> ```bash
> adb shell exit
> ```
> [!TIP]
> You can use the option `--mount` to mount the patched app on top of the un-patched app.
> Make sure you have root permissions and the same app you are patching and mounting over is installed on your device:
>
> ```bash
> adb shell su -c exit
> adb install input.apk
> ```
## 📦 Install an app manually
```bash
java -jar revanced-cli.jar utility install -a input.apk
```
> [!TIP]
> You can use the option `--mount` to mount the patched app on top of the un-patched app.
> Make sure you have root permissions and the same app you are patching and mounting over is installed on your device:
>
> ```bash
> adb shell su -c exit
> adb install input.apk
> ```
## 🗑️ Uninstall an app manually
Here `<package-name>` is the package name of the app you want to uninstall:
```bash
java -jar revanced-cli.jar utility uninstall --package-name <package-name>
```
If the app is mounted, you need to unmount it by using the option `--unmount`:

```bash
java -jar revanced-cli.jar utility uninstall --package-name <package-name> --unmount
```

> [!TIP]
> By default, the app is installed or uninstalled to the first connected device.
> You can append one or more devices by their serial to install or uninstall an app on your selected choice of devices:
>
> ```bash
> java -jar revanced-cli.jar utility uninstall --package-name <package-name> [<device-serial> ...]
> ```
12 changes: 6 additions & 6 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[versions]
shadow = "8.1.1"
kotlin = "2.0.0"
kotlinx-coroutines-core = "1.8.0"
picocli = "4.7.5"
revanced-patcher = "19.3.1"
revanced-library = "2.3.0"
kotlinx = "1.8.1"
picocli = "4.7.6"
revanced-patcher = "20.0.0"
revanced-library = "3.0.0"

[libraries]
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines-core" }
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx" }
picocli = { module = "info.picocli:picocli", version.ref = "picocli" }
revanced-patcher = { module = "app.revanced:revanced-patcher", version.ref = "revanced-patcher" }
revanced-library = { module = "app.revanced:revanced-library", version.ref = "revanced-library" }
revanced-library = { module = "app.revanced:revanced-library-jvm", version.ref = "revanced-library" }

[plugins]
shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" }
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=544c35d6bd849ae8a5ed0bcea39ba677dc40f49df7d1835561582da2009b961d
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionSha256Sum=d725d707bfabd4dfdc958c624003b3c80accc03f7037b5122c4b1d0ef15cecab
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package app.revanced.cli.command
import app.revanced.library.PackageName
import app.revanced.library.PatchUtils
import app.revanced.library.VersionMap
import app.revanced.patcher.PatchBundleLoader
import app.revanced.patcher.patch.loadPatchesFromJar
import picocli.CommandLine
import java.io.File
import java.util.logging.Logger
Expand All @@ -12,7 +12,7 @@ import java.util.logging.Logger
name = "list-versions",
description = [
"List the most common compatible versions of apps that are compatible " +
"with the patches in the supplied patch bundles.",
"with the patches in the supplied patch bundles.",
],
)
internal class ListCompatibleVersions : Runnable {
Expand All @@ -22,7 +22,7 @@ internal class ListCompatibleVersions : Runnable {
description = ["Paths to patch bundles."],
arity = "1..*",
)
private lateinit var patchBundles: Array<File>
private lateinit var patchBundles: Set<File>

@CommandLine.Option(
names = ["-f", "--filter-package-names"],
Expand All @@ -38,8 +38,6 @@ internal class ListCompatibleVersions : Runnable {
private var countUnusedPatches: Boolean = false

override fun run() {
val patches = PatchBundleLoader.Jar(*patchBundles)

fun VersionMap.buildVersionsString(): String {
if (isEmpty()) return "Any"

Expand All @@ -58,6 +56,8 @@ internal class ListCompatibleVersions : Runnable {
appendLine(versions.buildVersionsString().prependIndent("\t"))
}

val patches = loadPatchesFromJar(patchBundles)

PatchUtils.getMostCommonCompatibleVersions(
patches,
packageNames,
Expand Down
20 changes: 12 additions & 8 deletions src/main/kotlin/app/revanced/cli/command/ListPatchesCommand.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package app.revanced.cli.command

import app.revanced.patcher.PatchBundleLoader
import app.revanced.patcher.patch.Package
import app.revanced.patcher.patch.Patch
import app.revanced.patcher.patch.options.PatchOption
import app.revanced.patcher.patch.loadPatchesFromJar
import picocli.CommandLine.*
import picocli.CommandLine.Help.Visibility.ALWAYS
import java.io.File
import java.util.logging.Logger
import app.revanced.patcher.patch.Option as PatchOption

@Command(
name = "list-patches",
Expand All @@ -19,7 +20,7 @@ internal object ListPatchesCommand : Runnable {
description = ["Paths to patch bundles."],
arity = "1..*",
)
private lateinit var patchBundles: Array<File>
private lateinit var patchBundles: Set<File>

@Option(
names = ["-d", "--with-descriptions"],
Expand Down Expand Up @@ -70,16 +71,19 @@ internal object ListPatchesCommand : Runnable {
private var packageName: String? = null

override fun run() {
fun Patch.CompatiblePackage.buildString() =
buildString {
fun Package.buildString(): String {
val (name, versions) = this

return buildString {
if (withVersions && versions != null) {
appendLine("Package name: $name")
appendLine("Compatible versions:")
append(versions!!.joinToString("\n") { version -> version }.prependIndent("\t"))
append(versions.joinToString("\n") { version -> version }.prependIndent("\t"))
} else {
append("Package name: $name")
}
}
}

fun PatchOption<*>.buildString() =
buildString {
Expand Down Expand Up @@ -126,10 +130,10 @@ internal object ListPatchesCommand : Runnable {
}

fun Patch<*>.filterCompatiblePackages(name: String) =
compatiblePackages?.any { it.name == name }
compatiblePackages?.any { (compatiblePackageName, _) -> compatiblePackageName == name }
?: withUniversalPatches

val patches = PatchBundleLoader.Jar(*patchBundles).withIndex().toList()
val patches = loadPatchesFromJar(patchBundles).withIndex().toList()

val filtered =
packageName?.let { patches.filter { (_, patch) -> patch.filterCompatiblePackages(it) } } ?: patches
Expand Down
Loading

0 comments on commit 54ae01c

Please sign in to comment.