You've already forked revanced-patcher
mirror of
https://github.com/revanced/revanced-patcher
synced 2025-09-10 05:30:49 +02:00
Compare commits
30 Commits
v20.0.0
...
feat/impro
Author | SHA1 | Date | |
---|---|---|---|
![]() |
e41504bd99 | ||
![]() |
aa472eb985 | ||
![]() |
35b85b2c29 | ||
![]() |
f62e952514 | ||
![]() |
635d23c9b7 | ||
![]() |
5a0e3841ff | ||
![]() |
cfb459b832 | ||
![]() |
2096306107 | ||
![]() |
92eaba8081 | ||
![]() |
7be0cd8548 | ||
![]() |
ab624f04f6 | ||
![]() |
21b5c079fb | ||
![]() |
5024204046 | ||
![]() |
a44802ef4e | ||
![]() |
4c1c34ad01 | ||
![]() |
b2aecb726d | ||
![]() |
851f9c7885 | ||
![]() |
ea6fc70caa | ||
![]() |
a2875d1d64 | ||
![]() |
2be6e97817 | ||
![]() |
348d0070e7 | ||
![]() |
d53aacdad4 | ||
![]() |
f1615b7ab5 | ||
![]() |
ffb1d880d7 | ||
![]() |
e95f13ae3e | ||
![]() |
e1b984d601 | ||
![]() |
c2dc29e061 | ||
![]() |
69f2f20fd9 | ||
![]() |
525beda18e | ||
![]() |
73d3cbf4ff |
5
.github/workflows/release.yml
vendored
5
.github/workflows/release.yml
vendored
@@ -10,6 +10,9 @@ on:
|
||||
jobs:
|
||||
release:
|
||||
name: Release
|
||||
permissions:
|
||||
contents: write
|
||||
packages: write
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
@@ -46,5 +49,5 @@ jobs:
|
||||
|
||||
- name: Release
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.REPOSITORY_PUSH_ACCESS }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: npm exec semantic-release
|
||||
|
@@ -23,7 +23,8 @@
|
||||
"assets": [
|
||||
"CHANGELOG.md",
|
||||
"gradle.properties"
|
||||
]
|
||||
],
|
||||
"message": "chore: Release v${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
|
||||
}
|
||||
],
|
||||
[
|
||||
|
58
CHANGELOG.md
58
CHANGELOG.md
@@ -1,3 +1,61 @@
|
||||
## [20.0.2](https://github.com/ReVanced/revanced-patcher/compare/v20.0.1...v20.0.2) (2024-10-17)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Make it work on Android 12 and lower by using existing APIs ([#312](https://github.com/ReVanced/revanced-patcher/issues/312)) ([a44802e](https://github.com/ReVanced/revanced-patcher/commit/a44802ef4ebf59ae47213854ba761c81dadc51f3))
|
||||
|
||||
## [20.0.2-dev.1](https://github.com/ReVanced/revanced-patcher/compare/v20.0.1...v20.0.2-dev.1) (2024-10-15)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Make it work on Android 12 and lower by using existing APIs ([#312](https://github.com/ReVanced/revanced-patcher/issues/312)) ([a44802e](https://github.com/ReVanced/revanced-patcher/commit/a44802ef4ebf59ae47213854ba761c81dadc51f3))
|
||||
|
||||
## [20.0.1](https://github.com/ReVanced/revanced-patcher/compare/v20.0.0...v20.0.1) (2024-10-13)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Check for class type exactly instead of with contains ([#310](https://github.com/ReVanced/revanced-patcher/issues/310)) ([69f2f20](https://github.com/ReVanced/revanced-patcher/commit/69f2f20fd99162f91cd9c531dfe47d00d3152ead))
|
||||
* Make it work on Android by not using APIs from JVM unavailable to Android. ([2be6e97](https://github.com/ReVanced/revanced-patcher/commit/2be6e97817437f40e17893dfff3bea2cd4c3ff9e))
|
||||
* Use non-nullable type for options ([ea6fc70](https://github.com/ReVanced/revanced-patcher/commit/ea6fc70caab055251ad4d0d3f1b5cf53865abb85))
|
||||
|
||||
|
||||
### Performance Improvements
|
||||
|
||||
* Free memory earlier and remove negligible lookup maps ([d53aacd](https://github.com/ReVanced/revanced-patcher/commit/d53aacdad4ed3750ddae526fb307577ea36e6171))
|
||||
|
||||
## [20.0.1-dev.5](https://github.com/ReVanced/revanced-patcher/compare/v20.0.1-dev.4...v20.0.1-dev.5) (2024-10-11)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Use non-nullable type for options ([ea6fc70](https://github.com/ReVanced/revanced-patcher/commit/ea6fc70caab055251ad4d0d3f1b5cf53865abb85))
|
||||
|
||||
## [20.0.1-dev.4](https://github.com/ReVanced/revanced-patcher/compare/v20.0.1-dev.3...v20.0.1-dev.4) (2024-10-07)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Make it work on Android by not using APIs from JVM unavailable to Android. ([2be6e97](https://github.com/ReVanced/revanced-patcher/commit/2be6e97817437f40e17893dfff3bea2cd4c3ff9e))
|
||||
|
||||
## [20.0.1-dev.3](https://github.com/ReVanced/revanced-patcher/compare/v20.0.1-dev.2...v20.0.1-dev.3) (2024-10-03)
|
||||
|
||||
|
||||
### Performance Improvements
|
||||
|
||||
* Free memory earlier and remove negligible lookup maps ([d53aacd](https://github.com/ReVanced/revanced-patcher/commit/d53aacdad4ed3750ddae526fb307577ea36e6171))
|
||||
|
||||
## [20.0.1-dev.2](https://github.com/ReVanced/revanced-patcher/compare/v20.0.1-dev.1...v20.0.1-dev.2) (2024-10-01)
|
||||
|
||||
## [20.0.1-dev.1](https://github.com/ReVanced/revanced-patcher/compare/v20.0.0...v20.0.1-dev.1) (2024-09-18)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Check for class type exactly instead of with contains ([#310](https://github.com/ReVanced/revanced-patcher/issues/310)) ([69f2f20](https://github.com/ReVanced/revanced-patcher/commit/69f2f20fd99162f91cd9c531dfe47d00d3152ead))
|
||||
|
||||
# [20.0.0](https://github.com/ReVanced/revanced-patcher/compare/v19.3.1...v20.0.0) (2024-08-06)
|
||||
|
||||
|
||||
|
@@ -1,7 +1,4 @@
|
||||
public final class app/revanced/patcher/Fingerprint {
|
||||
public final fun getMatch ()Lapp/revanced/patcher/Match;
|
||||
public final fun match (Lapp/revanced/patcher/patch/BytecodePatchContext;Lcom/android/tools/smali/dexlib2/iface/ClassDef;)Z
|
||||
public final fun match (Lapp/revanced/patcher/patch/BytecodePatchContext;Lcom/android/tools/smali/dexlib2/iface/Method;)Z
|
||||
}
|
||||
|
||||
public final class app/revanced/patcher/FingerprintBuilder {
|
||||
@@ -18,20 +15,17 @@ public final class app/revanced/patcher/FingerprintBuilder {
|
||||
|
||||
public final class app/revanced/patcher/FingerprintKt {
|
||||
public static final fun fingerprint (ILkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/Fingerprint;
|
||||
public static final fun fingerprint (Lapp/revanced/patcher/patch/BytecodePatchBuilder;ILkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/BytecodePatchBuilder$InvokedFingerprint;
|
||||
public static synthetic fun fingerprint$default (ILkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/Fingerprint;
|
||||
public static synthetic fun fingerprint$default (Lapp/revanced/patcher/patch/BytecodePatchBuilder;ILkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/BytecodePatchBuilder$InvokedFingerprint;
|
||||
}
|
||||
|
||||
public abstract interface annotation class app/revanced/patcher/InternalApi : java/lang/annotation/Annotation {
|
||||
}
|
||||
|
||||
public final class app/revanced/patcher/Match {
|
||||
public fun <init> (Lcom/android/tools/smali/dexlib2/iface/Method;Lcom/android/tools/smali/dexlib2/iface/ClassDef;Lapp/revanced/patcher/Match$PatternMatch;Ljava/util/List;Lapp/revanced/patcher/patch/BytecodePatchContext;)V
|
||||
public final fun getClassDef ()Lcom/android/tools/smali/dexlib2/iface/ClassDef;
|
||||
public final fun getMethod ()Lcom/android/tools/smali/dexlib2/iface/Method;
|
||||
public final fun getMutableClass ()Lapp/revanced/patcher/util/proxy/mutableTypes/MutableClass;
|
||||
public final fun getMutableMethod ()Lapp/revanced/patcher/util/proxy/mutableTypes/MutableMethod;
|
||||
public final fun getClassDef ()Lapp/revanced/patcher/util/proxy/mutableTypes/MutableClass;
|
||||
public final fun getMethod ()Lapp/revanced/patcher/util/proxy/mutableTypes/MutableMethod;
|
||||
public final fun getOriginalClassDef ()Lcom/android/tools/smali/dexlib2/iface/ClassDef;
|
||||
public final fun getOriginalMethod ()Lcom/android/tools/smali/dexlib2/iface/Method;
|
||||
public final fun getPatternMatch ()Lapp/revanced/patcher/Match$PatternMatch;
|
||||
public final fun getStringMatches ()Ljava/util/List;
|
||||
}
|
||||
@@ -63,8 +57,8 @@ public final class app/revanced/patcher/Patcher : java/io/Closeable {
|
||||
}
|
||||
|
||||
public final class app/revanced/patcher/PatcherConfig {
|
||||
public fun <init> (Ljava/io/File;Ljava/io/File;Ljava/lang/String;Ljava/lang/String;Z)V
|
||||
public synthetic fun <init> (Ljava/io/File;Ljava/io/File;Ljava/lang/String;Ljava/lang/String;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public fun <init> (Ljava/io/File;Ljava/io/File;Ljava/lang/String;Ljava/lang/String;)V
|
||||
public synthetic fun <init> (Ljava/io/File;Ljava/io/File;Ljava/lang/String;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
}
|
||||
|
||||
public final class app/revanced/patcher/PatcherContext : java/io/Closeable {
|
||||
@@ -135,30 +129,27 @@ public final class app/revanced/patcher/extensions/InstructionExtensions {
|
||||
}
|
||||
|
||||
public final class app/revanced/patcher/patch/BytecodePatch : app/revanced/patcher/patch/Patch {
|
||||
public final fun getExtension ()Ljava/io/InputStream;
|
||||
public final fun getFingerprints ()Ljava/util/Set;
|
||||
public final fun getExtensionInputStream ()Ljava/util/function/Supplier;
|
||||
public fun toString ()Ljava/lang/String;
|
||||
}
|
||||
|
||||
public final class app/revanced/patcher/patch/BytecodePatchBuilder : app/revanced/patcher/patch/PatchBuilder {
|
||||
public synthetic fun build$revanced_patcher ()Lapp/revanced/patcher/patch/Patch;
|
||||
public final fun extendWith (Ljava/lang/String;)Lapp/revanced/patcher/patch/BytecodePatchBuilder;
|
||||
public final fun getExtension ()Ljava/io/InputStream;
|
||||
public final fun invoke (Lapp/revanced/patcher/Fingerprint;)Lapp/revanced/patcher/patch/BytecodePatchBuilder$InvokedFingerprint;
|
||||
public final fun setExtension (Ljava/io/InputStream;)V
|
||||
}
|
||||
|
||||
public final class app/revanced/patcher/patch/BytecodePatchBuilder$InvokedFingerprint {
|
||||
public final fun getValue (Ljava/lang/Void;Lkotlin/reflect/KProperty;)Lapp/revanced/patcher/Match;
|
||||
public final fun getExtensionInputStream ()Ljava/util/function/Supplier;
|
||||
public final fun setExtensionInputStream (Ljava/util/function/Supplier;)V
|
||||
}
|
||||
|
||||
public final class app/revanced/patcher/patch/BytecodePatchContext : app/revanced/patcher/patch/PatchContext, java/io/Closeable {
|
||||
public final fun classBy (Lkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/util/proxy/ClassProxy;
|
||||
public final fun classByType (Ljava/lang/String;)Lapp/revanced/patcher/util/proxy/ClassProxy;
|
||||
public fun close ()V
|
||||
public synthetic fun get ()Ljava/lang/Object;
|
||||
public fun get ()Ljava/util/Set;
|
||||
public final fun getClasses ()Lapp/revanced/patcher/util/ProxyClassList;
|
||||
public final fun getMatch (Lapp/revanced/patcher/Fingerprint;)Lapp/revanced/patcher/Match;
|
||||
public final fun getValue (Lapp/revanced/patcher/Fingerprint;Ljava/lang/Void;Lkotlin/reflect/KProperty;)Lapp/revanced/patcher/Match;
|
||||
public final fun match (Lapp/revanced/patcher/Fingerprint;Lcom/android/tools/smali/dexlib2/iface/ClassDef;)Lapp/revanced/patcher/Match;
|
||||
public final fun match (Lapp/revanced/patcher/Fingerprint;Lcom/android/tools/smali/dexlib2/iface/Method;)Lapp/revanced/patcher/Match;
|
||||
public final fun navigate (Lcom/android/tools/smali/dexlib2/iface/Method;)Lapp/revanced/patcher/util/MethodNavigator;
|
||||
public final fun proxy (Lcom/android/tools/smali/dexlib2/iface/ClassDef;)Lapp/revanced/patcher/util/proxy/ClassProxy;
|
||||
}
|
||||
@@ -286,7 +277,7 @@ public final class app/revanced/patcher/patch/Options : java/util/Map, kotlin/jv
|
||||
}
|
||||
|
||||
public abstract class app/revanced/patcher/patch/Patch {
|
||||
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;ZLjava/util/Set;Ljava/util/Set;Ljava/util/Set;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;ZLjava/util/Set;Ljava/util/Set;Ljava/util/Set;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public final fun execute (Lapp/revanced/patcher/patch/PatchContext;)V
|
||||
public final fun finalize (Lapp/revanced/patcher/patch/PatchContext;)V
|
||||
public final fun getCompatiblePackages ()Ljava/util/Set;
|
||||
@@ -303,13 +294,13 @@ public abstract class app/revanced/patcher/patch/PatchBuilder {
|
||||
public final fun compatibleWith ([Ljava/lang/String;)V
|
||||
public final fun compatibleWith ([Lkotlin/Pair;)V
|
||||
public final fun dependsOn ([Lapp/revanced/patcher/patch/Patch;)V
|
||||
public final fun execute (Lkotlin/jvm/functions/Function2;)V
|
||||
public final fun finalize (Lkotlin/jvm/functions/Function2;)V
|
||||
public final fun execute (Lkotlin/jvm/functions/Function1;)V
|
||||
public final fun finalize (Lkotlin/jvm/functions/Function1;)V
|
||||
protected final fun getCompatiblePackages ()Ljava/util/Set;
|
||||
protected final fun getDependencies ()Ljava/util/Set;
|
||||
protected final fun getDescription ()Ljava/lang/String;
|
||||
protected final fun getExecutionBlock ()Lkotlin/jvm/functions/Function2;
|
||||
protected final fun getFinalizeBlock ()Lkotlin/jvm/functions/Function2;
|
||||
protected final fun getExecutionBlock ()Lkotlin/jvm/functions/Function1;
|
||||
protected final fun getFinalizeBlock ()Lkotlin/jvm/functions/Function1;
|
||||
protected final fun getName ()Ljava/lang/String;
|
||||
protected final fun getOptions ()Ljava/util/Set;
|
||||
protected final fun getUse ()Z
|
||||
@@ -317,8 +308,8 @@ public abstract class app/revanced/patcher/patch/PatchBuilder {
|
||||
public final fun invoke (Ljava/lang/String;[Ljava/lang/String;)Lkotlin/Pair;
|
||||
protected final fun setCompatiblePackages (Ljava/util/Set;)V
|
||||
protected final fun setDependencies (Ljava/util/Set;)V
|
||||
protected final fun setExecutionBlock (Lkotlin/jvm/functions/Function2;)V
|
||||
protected final fun setFinalizeBlock (Lkotlin/jvm/functions/Function2;)V
|
||||
protected final fun setExecutionBlock (Lkotlin/jvm/functions/Function1;)V
|
||||
protected final fun setFinalizeBlock (Lkotlin/jvm/functions/Function1;)V
|
||||
}
|
||||
|
||||
public abstract interface class app/revanced/patcher/patch/PatchContext : java/util/function/Supplier {
|
||||
|
@@ -89,9 +89,9 @@ val patcherResult = Patcher(PatcherConfig(apkFile = File("some.apk"))).use { pat
|
||||
runBlocking {
|
||||
patcher().collect { patchResult ->
|
||||
if (patchResult.exception != null)
|
||||
logger.info("\"${patchResult.patch}\" failed:\n${patchResult.exception}")
|
||||
logger.info { "\"${patchResult.patch}\" failed:\n${patchResult.exception}" }
|
||||
else
|
||||
logger.info("\"${patchResult.patch}\" succeeded")
|
||||
logger.info { "\"${patchResult.patch}\" succeeded" }
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -72,6 +72,10 @@ To start developing patches with ReVanced Patcher, you must prepare a developmen
|
||||
|
||||
Throughout the documentation, [ReVanced Patches](https://github.com/revanced/revanced-patches) will be used as an example project.
|
||||
|
||||
> [!NOTE]
|
||||
> To start a fresh project,
|
||||
> you can use the [ReVanced Patches template](https://github.com/revanced/revanced-patches-template).
|
||||
|
||||
1. Clone the repository
|
||||
|
||||
```bash
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -76,23 +76,23 @@ val disableAdsPatch = bytecodePatch(
|
||||
) {
|
||||
compatibleWith("com.some.app"("1.0.0"))
|
||||
|
||||
// Resource patch disables ads by patching resource files.
|
||||
// Patches can depend on other patches, executing them first.
|
||||
dependsOn(disableAdsResourcePatch)
|
||||
|
||||
// Precompiled DEX file to be merged into the patched app.
|
||||
// Merge precompiled DEX files into the patched app, before the patch is executed.
|
||||
extendWith("disable-ads.rve")
|
||||
|
||||
// Fingerprint to find the method to patch.
|
||||
val showAdsMatch by showAdsFingerprint {
|
||||
// More about fingerprints on the next page of the documentation.
|
||||
}
|
||||
|
||||
// Business logic of the patch to disable ads in the app.
|
||||
execute {
|
||||
// Fingerprint to find the method to patch.
|
||||
val showAdsMatch by showAdsFingerprint {
|
||||
// More about fingerprints on the next page of the documentation.
|
||||
}
|
||||
|
||||
// In the method that shows ads,
|
||||
// call DisableAdsPatch.shouldDisableAds() from the extension (precompiled DEX file)
|
||||
// to enable or disable ads.
|
||||
showAdsMatch.mutableMethod.addInstructions(
|
||||
showAdsMatch.method.addInstructions(
|
||||
0,
|
||||
"""
|
||||
invoke-static {}, LDisableAdsPatch;->shouldDisableAds()Z
|
||||
@@ -146,10 +146,10 @@ loadPatchesJar(patches).apply {
|
||||
The type of an option can be obtained from the `type` property of the option:
|
||||
|
||||
```kt
|
||||
option.type // The KType of the option.
|
||||
option.type // The KType of the option. Captures the full type information of the option.
|
||||
```
|
||||
|
||||
Options can be declared outside of a patch and added to a patch manually:
|
||||
Options can be declared outside a patch and added to a patch manually:
|
||||
|
||||
```kt
|
||||
val option = stringOption(key = "option")
|
||||
@@ -183,11 +183,9 @@ and use it in a patch:
|
||||
```kt
|
||||
val patch = bytecodePatch(name = "Complex patch") {
|
||||
extendWith("complex-patch.rve")
|
||||
|
||||
val match by methodFingerprint()
|
||||
|
||||
|
||||
execute {
|
||||
match.mutableMethod.addInstructions(0, "invoke-static { }, LComplexPatch;->doSomething()V")
|
||||
fingerprint.match!!.mutableMethod.addInstructions(0, "invoke-static { }, LComplexPatch;->doSomething()V")
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@@ -96,21 +96,21 @@ Example of patches:
|
||||
@Surpress("unused")
|
||||
val bytecodePatch = bytecodePatch {
|
||||
execute {
|
||||
// TODO
|
||||
// More about this on the next page of the documentation.
|
||||
}
|
||||
}
|
||||
|
||||
@Surpress("unused")
|
||||
val rawResourcePatch = rawResourcePatch {
|
||||
execute {
|
||||
// TODO
|
||||
execute {
|
||||
// More about this on the next page of the documentation.
|
||||
}
|
||||
}
|
||||
|
||||
@Surpress("unused")
|
||||
val resourcePatch = rawResourcePatch {
|
||||
execute {
|
||||
// TODO
|
||||
val resourcePatch = resourcePatch {
|
||||
execute {
|
||||
// More about this on the next page of the documentation.
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@@ -4,13 +4,11 @@ A handful of APIs are available to make patch development easier and more effici
|
||||
|
||||
## 📙 Overview
|
||||
|
||||
1. 👹 Mutate classes with `context.proxy(ClassDef)`
|
||||
2. 🔍 Find and proxy existing classes with `classBy(Predicate)` and `classByType(String)`
|
||||
3. 🏃 Easily access referenced methods recursively by index with `MethodNavigator`
|
||||
4. 🔨 Make use of extension functions from `BytecodeUtils` and `ResourceUtils` with certain applications
|
||||
(Available in ReVanced Patches)
|
||||
5. 💾 Read and write (decoded) resources with `ResourcePatchContext.get(Path, Boolean)`
|
||||
6. 📃 Read and write DOM files using `ResourcePatchContext.document`
|
||||
1. 👹 Create mutable replacements of classes with `proxy(ClassDef)`
|
||||
2. 🔍 Find and create mutable replaces with `classBy(Predicate)`
|
||||
3. 🏃 Navigate method calls recursively by index with `navigate(Method).at(index)`
|
||||
4. 💾 Read and write resource files with `get(Path, Boolean)`
|
||||
5. 📃 Read and write DOM files using `document`
|
||||
|
||||
### 🧰 APIs
|
||||
|
||||
|
@@ -1,3 +1,3 @@
|
||||
org.gradle.parallel = true
|
||||
org.gradle.caching = true
|
||||
version = 20.0.0
|
||||
version = 20.0.2
|
||||
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
8
gradle/wrapper/gradle-wrapper.properties
vendored
8
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,8 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
|
||||
distributionSha256Sum=9631d53cf3e74bfa726893aee1f8994fee4e060c401335946dba2156f440f24c
|
||||
distributionSha256Sum=d725d707bfabd4dfdc958c624003b3c80accc03f7037b5122c4b1d0ef15cecab
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dist
|
||||
zipStorePath=wrapper/dists
|
||||
|
22
gradlew
vendored
22
gradlew
vendored
@@ -15,6 +15,8 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
@@ -55,7 +57,7 @@
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
@@ -83,7 +85,9 @@ done
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
|
||||
' "$PWD" ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
@@ -144,7 +148,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC3045
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
@@ -152,7 +156,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC3045
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
@@ -201,11 +205,11 @@ fi
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
# double quotes to make sure that they get re-expanded; and
|
||||
# * put everything else in single quotes, so that it's not re-expanded.
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
|
22
gradlew.bat
vendored
22
gradlew.bat
vendored
@@ -13,6 +13,8 @@
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
@rem SPDX-License-Identifier: Apache-2.0
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
@@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
|
2972
package-lock.json
generated
2972
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -3,7 +3,7 @@
|
||||
"@saithodev/semantic-release-backmerge": "^4.0.1",
|
||||
"@semantic-release/changelog": "^6.0.3",
|
||||
"@semantic-release/git": "^10.0.1",
|
||||
"gradle-semantic-release-plugin": "^1.9.1",
|
||||
"semantic-release": "^23.0.2"
|
||||
"gradle-semantic-release-plugin": "^1.10.1",
|
||||
"semantic-release": "^24.1.2"
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -91,20 +91,14 @@ class Patcher(private val config: PatcherConfig) : Closeable {
|
||||
}.also { executedPatches[this] = it }
|
||||
}
|
||||
|
||||
// Prevent from decoding the app manifest twice if it is not needed.
|
||||
// Prevent decoding the app manifest twice if it is not needed.
|
||||
if (config.resourceMode != ResourcePatchContext.ResourceMode.NONE) {
|
||||
context.resourceContext.decodeResources(config.resourceMode)
|
||||
}
|
||||
|
||||
logger.info("Merging extensions")
|
||||
logger.info("Initializing lookup maps")
|
||||
|
||||
context.executablePatches.forEachRecursively { patch ->
|
||||
if (patch is BytecodePatch && patch.extension != null) {
|
||||
context.bytecodeContext.merge(patch.extension)
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize lookup maps.
|
||||
// Accessing the lazy lookup maps to initialize them.
|
||||
context.bytecodeContext.lookupMaps
|
||||
|
||||
logger.info("Executing patches")
|
||||
|
@@ -12,15 +12,12 @@ import java.util.logging.Logger
|
||||
* @param temporaryFilesPath A path to a folder to store temporary files in.
|
||||
* @param aaptBinaryPath A path to a custom aapt binary.
|
||||
* @param frameworkFileDirectory A path to the directory to cache the framework file in.
|
||||
* @param multithreadingDexFileWriter Whether to use multiple threads for writing dex files.
|
||||
* This has impact on memory usage and performance.
|
||||
*/
|
||||
class PatcherConfig(
|
||||
internal val apkFile: File,
|
||||
private val temporaryFilesPath: File = File("revanced-temporary-files"),
|
||||
aaptBinaryPath: String? = null,
|
||||
frameworkFileDirectory: String? = null,
|
||||
internal val multithreadingDexFileWriter: Boolean = false,
|
||||
) {
|
||||
private val logger = Logger.getLogger(PatcherConfig::class.java.name)
|
||||
|
||||
|
@@ -1,8 +1,6 @@
|
||||
package app.revanced.patcher.patch
|
||||
|
||||
import app.revanced.patcher.InternalApi
|
||||
import app.revanced.patcher.PatcherConfig
|
||||
import app.revanced.patcher.PatcherResult
|
||||
import app.revanced.patcher.*
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.instructionsOrNull
|
||||
import app.revanced.patcher.util.ClassMerger.merge
|
||||
import app.revanced.patcher.util.MethodNavigator
|
||||
@@ -21,9 +19,9 @@ import lanchon.multidexlib2.MultiDexIO
|
||||
import lanchon.multidexlib2.RawDexIO
|
||||
import java.io.Closeable
|
||||
import java.io.FileFilter
|
||||
import java.io.InputStream
|
||||
import java.util.*
|
||||
import java.util.logging.Logger
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
/**
|
||||
* A context for patches containing the current state of the bytecode.
|
||||
@@ -54,57 +52,73 @@ class BytecodePatchContext internal constructor(private val config: PatcherConfi
|
||||
).also { opcodes = it.opcodes }.classes.toMutableList(),
|
||||
)
|
||||
|
||||
/**
|
||||
* The match for this [Fingerprint]. Null if unmatched.
|
||||
*/
|
||||
val Fingerprint.match get() = match(this@BytecodePatchContext)
|
||||
|
||||
/**
|
||||
* Match using a [ClassDef].
|
||||
*
|
||||
* @param classDef The class to match against.
|
||||
* @return The [Match] if a match was found or if the fingerprint is already matched to a method, null otherwise.
|
||||
*/
|
||||
fun Fingerprint.match(classDef: ClassDef) = match(this@BytecodePatchContext, classDef)
|
||||
|
||||
/**
|
||||
* Match using a [Method].
|
||||
* The class is retrieved from the method.
|
||||
*
|
||||
* @param method The method to match against.
|
||||
* @return The [Match] if a match was found or if the fingerprint is already matched to a method, null otherwise.
|
||||
*/
|
||||
fun Fingerprint.match(method: Method) = match(this@BytecodePatchContext, method)
|
||||
|
||||
/**
|
||||
* Get the match for this [Fingerprint].
|
||||
*
|
||||
* @throws IllegalStateException If the [Fingerprint] has not been matched.
|
||||
*/
|
||||
operator fun Fingerprint.getValue(nothing: Nothing?, property: KProperty<*>): Match = _match
|
||||
?: throw PatchException("No fingerprint match to delegate to \"${property.name}\".")
|
||||
|
||||
/**
|
||||
* The lookup maps for methods and the class they are a member of from the [classes].
|
||||
*/
|
||||
internal val lookupMaps by lazy { LookupMaps(classes) }
|
||||
|
||||
/**
|
||||
* A map for lookup by [merge].
|
||||
*/
|
||||
internal val classesByType = mutableMapOf<String, ClassDef>().apply {
|
||||
classes.forEach { classDef -> put(classDef.type, classDef) }
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge an extension to [classes].
|
||||
* Merge the extension of [bytecodePatch] into the [BytecodePatchContext].
|
||||
* If no extension is present, the function will return early.
|
||||
*
|
||||
* @param extensionInputStream The input stream of the extension to merge.
|
||||
* @param bytecodePatch The [BytecodePatch] to merge the extension of.
|
||||
*/
|
||||
internal fun merge(extensionInputStream: InputStream) {
|
||||
val extension = extensionInputStream.readAllBytes()
|
||||
internal fun mergeExtension(bytecodePatch: BytecodePatch) {
|
||||
bytecodePatch.extensionInputStream?.get()?.use { extensionStream ->
|
||||
RawDexIO.readRawDexFile(extensionStream, 0, null).classes.forEach { classDef ->
|
||||
val existingClass = lookupMaps.classesByType[classDef.type] ?: run {
|
||||
logger.fine { "Adding class \"$classDef\"" }
|
||||
|
||||
RawDexIO.readRawDexFile(extension, 0, null).classes.forEach { classDef ->
|
||||
val existingClass = classesByType[classDef.type] ?: run {
|
||||
logger.fine("Adding class \"$classDef\"")
|
||||
classes += classDef
|
||||
lookupMaps.classesByType[classDef.type] = classDef
|
||||
|
||||
classes += classDef
|
||||
classesByType[classDef.type] = classDef
|
||||
|
||||
return@forEach
|
||||
}
|
||||
|
||||
logger.fine("Class \"$classDef\" exists already. Adding missing methods and fields.")
|
||||
|
||||
existingClass.merge(classDef, this@BytecodePatchContext).let { mergedClass ->
|
||||
// If the class was merged, replace the original class with the merged class.
|
||||
if (mergedClass === existingClass) {
|
||||
return@let
|
||||
return@forEach
|
||||
}
|
||||
|
||||
classes -= existingClass
|
||||
classes += mergedClass
|
||||
}
|
||||
}
|
||||
}
|
||||
logger.fine { "Class \"$classDef\" exists already. Adding missing methods and fields." }
|
||||
|
||||
/**
|
||||
* Find a class by its type using a contains check.
|
||||
*
|
||||
* @param type The type of the class.
|
||||
* @return A proxy for the first class that matches the type.
|
||||
*/
|
||||
fun classByType(type: String) = classBy { type in it.type }
|
||||
existingClass.merge(classDef, this@BytecodePatchContext).let { mergedClass ->
|
||||
// If the class was merged, replace the original class with the merged class.
|
||||
if (mergedClass === existingClass) {
|
||||
return@let
|
||||
}
|
||||
|
||||
classes -= existingClass
|
||||
classes += mergedClass
|
||||
}
|
||||
}
|
||||
} ?: logger.fine("No extension to merge")
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a class with a predicate.
|
||||
@@ -144,6 +158,9 @@ class BytecodePatchContext internal constructor(private val config: PatcherConfi
|
||||
override fun get(): Set<PatcherResult.PatchedDexFile> {
|
||||
logger.info("Compiling patched dex files")
|
||||
|
||||
// Free up memory before compiling the dex files.
|
||||
lookupMaps.close()
|
||||
|
||||
val patchedDexFileResults =
|
||||
config.patchedFiles.resolve("dex").also {
|
||||
it.deleteRecursively() // Make sure the directory is empty.
|
||||
@@ -151,7 +168,7 @@ class BytecodePatchContext internal constructor(private val config: PatcherConfi
|
||||
}.apply {
|
||||
MultiDexIO.writeDexFile(
|
||||
true,
|
||||
if (config.multithreadingDexFileWriter) -1 else 1,
|
||||
-1,
|
||||
this,
|
||||
BasicDexFileNamer(),
|
||||
object : DexFile {
|
||||
@@ -161,7 +178,7 @@ class BytecodePatchContext internal constructor(private val config: PatcherConfi
|
||||
override fun getOpcodes() = this@BytecodePatchContext.opcodes
|
||||
},
|
||||
DexIO.DEFAULT_MAX_DEX_POOL_SIZE,
|
||||
) { _, entryName, _ -> logger.info("Compiled $entryName") }
|
||||
) { _, entryName, _ -> logger.info { "Compiled $entryName" } }
|
||||
}.listFiles(FileFilter { it.isFile })!!.map {
|
||||
PatcherResult.PatchedDexFile(it.name, it.inputStream())
|
||||
}.toSet()
|
||||
@@ -177,47 +194,21 @@ class BytecodePatchContext internal constructor(private val config: PatcherConfi
|
||||
* @param classes The list of classes to create the lookup maps from.
|
||||
*/
|
||||
internal class LookupMaps internal constructor(classes: List<ClassDef>) : Closeable {
|
||||
/**
|
||||
* Classes associated by their type.
|
||||
*/
|
||||
internal val classesByType = classes.associateBy { it.type }.toMutableMap()
|
||||
|
||||
/**
|
||||
* All methods and the class they are a member of.
|
||||
*/
|
||||
internal val allMethods = MethodClassPairs()
|
||||
|
||||
/**
|
||||
* Methods associated by its access flags, return type and parameter.
|
||||
*/
|
||||
internal val methodsBySignature = MethodClassPairsLookupMap()
|
||||
|
||||
/**
|
||||
* Methods associated by strings referenced in it.
|
||||
*/
|
||||
internal val methodsByStrings = MethodClassPairsLookupMap()
|
||||
|
||||
// Lookup map for fast checking if a class exists by its type.
|
||||
val classesByType = mutableMapOf<String, ClassDef>().apply {
|
||||
classes.forEach { classDef -> put(classDef.type, classDef) }
|
||||
}
|
||||
|
||||
init {
|
||||
classes.forEach { classDef ->
|
||||
classDef.methods.forEach { method ->
|
||||
val methodClassPair: MethodClassPair = method to classDef
|
||||
|
||||
// For fingerprints with no access or return type specified.
|
||||
allMethods += methodClassPair
|
||||
|
||||
val accessFlagsReturnKey = method.accessFlags.toString() + method.returnType.first()
|
||||
|
||||
// Add <access><returnType> as the key.
|
||||
methodsBySignature[accessFlagsReturnKey] = methodClassPair
|
||||
|
||||
// Add <access><returnType>[parameters] as the key.
|
||||
methodsBySignature[
|
||||
buildString {
|
||||
append(accessFlagsReturnKey)
|
||||
appendParameters(method.parameterTypes)
|
||||
},
|
||||
] = methodClassPair
|
||||
|
||||
// Add strings contained in the method as the key.
|
||||
method.instructionsOrNull?.forEach instructions@{ instruction ->
|
||||
if (instruction.opcode != Opcode.CONST_STRING && instruction.opcode != Opcode.CONST_STRING_JUMBO) {
|
||||
@@ -258,15 +249,13 @@ class BytecodePatchContext internal constructor(private val config: PatcherConfi
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
allMethods.clear()
|
||||
methodsBySignature.clear()
|
||||
methodsByStrings.clear()
|
||||
classesByType.clear()
|
||||
}
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
lookupMaps.close()
|
||||
classesByType.clear()
|
||||
classes.clear()
|
||||
}
|
||||
}
|
||||
|
@@ -231,7 +231,7 @@ fun intOption(
|
||||
title: String? = null,
|
||||
description: String? = null,
|
||||
required: Boolean = false,
|
||||
validator: Option<Int?>.(Int?) -> Boolean = { true },
|
||||
validator: Option<Int>.(Int?) -> Boolean = { true },
|
||||
) = option(
|
||||
key,
|
||||
default,
|
||||
@@ -264,7 +264,7 @@ fun PatchBuilder<*>.intOption(
|
||||
title: String? = null,
|
||||
description: String? = null,
|
||||
required: Boolean = false,
|
||||
validator: Option<Int?>.(Int?) -> Boolean = { true },
|
||||
validator: Option<Int>.(Int?) -> Boolean = { true },
|
||||
) = option(
|
||||
key,
|
||||
default,
|
||||
@@ -297,7 +297,7 @@ fun booleanOption(
|
||||
title: String? = null,
|
||||
description: String? = null,
|
||||
required: Boolean = false,
|
||||
validator: Option<Boolean?>.(Boolean?) -> Boolean = { true },
|
||||
validator: Option<Boolean>.(Boolean?) -> Boolean = { true },
|
||||
) = option(
|
||||
key,
|
||||
default,
|
||||
@@ -330,7 +330,7 @@ fun PatchBuilder<*>.booleanOption(
|
||||
title: String? = null,
|
||||
description: String? = null,
|
||||
required: Boolean = false,
|
||||
validator: Option<Boolean?>.(Boolean?) -> Boolean = { true },
|
||||
validator: Option<Boolean>.(Boolean?) -> Boolean = { true },
|
||||
) = option(
|
||||
key,
|
||||
default,
|
||||
@@ -363,7 +363,7 @@ fun floatOption(
|
||||
title: String? = null,
|
||||
description: String? = null,
|
||||
required: Boolean = false,
|
||||
validator: Option<Float?>.(Float?) -> Boolean = { true },
|
||||
validator: Option<Float>.(Float?) -> Boolean = { true },
|
||||
) = option(
|
||||
key,
|
||||
default,
|
||||
@@ -396,7 +396,7 @@ fun PatchBuilder<*>.floatOption(
|
||||
title: String? = null,
|
||||
description: String? = null,
|
||||
required: Boolean = false,
|
||||
validator: Option<Float?>.(Float?) -> Boolean = { true },
|
||||
validator: Option<Float>.(Float?) -> Boolean = { true },
|
||||
) = option(
|
||||
key,
|
||||
default,
|
||||
@@ -429,7 +429,7 @@ fun longOption(
|
||||
title: String? = null,
|
||||
description: String? = null,
|
||||
required: Boolean = false,
|
||||
validator: Option<Long?>.(Long?) -> Boolean = { true },
|
||||
validator: Option<Long>.(Long?) -> Boolean = { true },
|
||||
) = option(
|
||||
key,
|
||||
default,
|
||||
@@ -462,7 +462,7 @@ fun PatchBuilder<*>.longOption(
|
||||
title: String? = null,
|
||||
description: String? = null,
|
||||
required: Boolean = false,
|
||||
validator: Option<Long?>.(Long?) -> Boolean = { true },
|
||||
validator: Option<Long>.(Long?) -> Boolean = { true },
|
||||
) = option(
|
||||
key,
|
||||
default,
|
||||
|
@@ -2,7 +2,6 @@
|
||||
|
||||
package app.revanced.patcher.patch
|
||||
|
||||
import app.revanced.patcher.Fingerprint
|
||||
import app.revanced.patcher.Patcher
|
||||
import app.revanced.patcher.PatcherContext
|
||||
import dalvik.system.DexClassLoader
|
||||
@@ -10,9 +9,12 @@ import lanchon.multidexlib2.BasicDexFileNamer
|
||||
import lanchon.multidexlib2.MultiDexIO
|
||||
import java.io.File
|
||||
import java.io.InputStream
|
||||
import java.lang.reflect.Member
|
||||
import java.lang.reflect.Method
|
||||
import java.lang.reflect.Modifier
|
||||
import java.net.URLClassLoader
|
||||
import java.util.function.Supplier
|
||||
import java.util.jar.JarFile
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
typealias PackageName = String
|
||||
typealias VersionName = String
|
||||
@@ -43,10 +45,10 @@ sealed class Patch<C : PatchContext<*>>(
|
||||
val dependencies: Set<Patch<*>>,
|
||||
val compatiblePackages: Set<Package>?,
|
||||
options: Set<Option<*>>,
|
||||
private val executeBlock: Patch<C>.(C) -> Unit,
|
||||
private val executeBlock: (C) -> Unit,
|
||||
// Must be internal and nullable, so that Patcher.invoke can check,
|
||||
// if a patch has a finalizing block in order to not emit it twice.
|
||||
internal var finalizeBlock: (Patch<C>.(C) -> Unit)?,
|
||||
internal var finalizeBlock: ((C) -> Unit)?,
|
||||
) {
|
||||
/**
|
||||
* The options of the patch.
|
||||
@@ -54,35 +56,35 @@ sealed class Patch<C : PatchContext<*>>(
|
||||
val options = Options(options)
|
||||
|
||||
/**
|
||||
* Runs the execution block of the patch.
|
||||
* Called by [Patcher].
|
||||
* Calls the execution block of the patch.
|
||||
* This function is called by [Patcher.invoke].
|
||||
*
|
||||
* @param context The [PatcherContext] to get the [PatchContext] from to execute the patch with.
|
||||
*/
|
||||
internal abstract fun execute(context: PatcherContext)
|
||||
|
||||
/**
|
||||
* Runs the execution block of the patch.
|
||||
* Calls the execution block of the patch.
|
||||
*
|
||||
* @param context The [PatchContext] to execute the patch with.
|
||||
*/
|
||||
fun execute(context: C) = executeBlock(context)
|
||||
|
||||
/**
|
||||
* Runs the finalizing block of the patch.
|
||||
* Called by [Patcher].
|
||||
* Calls the finalizing block of the patch.
|
||||
* This function is called by [Patcher.invoke].
|
||||
*
|
||||
* @param context The [PatcherContext] to get the [PatchContext] from to finalize the patch with.
|
||||
*/
|
||||
internal abstract fun finalize(context: PatcherContext)
|
||||
|
||||
/**
|
||||
* Runs the finalizing block of the patch.
|
||||
* Calls the finalizing block of the patch.
|
||||
*
|
||||
* @param context The [PatchContext] to finalize the patch with.
|
||||
*/
|
||||
fun finalize(context: C) {
|
||||
finalizeBlock?.invoke(this, context)
|
||||
finalizeBlock?.invoke(context)
|
||||
}
|
||||
|
||||
override fun toString() = name ?: "Patch"
|
||||
@@ -124,8 +126,7 @@ internal fun Iterable<Patch<*>>.forEachRecursively(
|
||||
* If null, the patch is compatible with all packages.
|
||||
* @param dependencies Other patches this patch depends on.
|
||||
* @param options The options of the patch.
|
||||
* @param fingerprints The fingerprints that are resolved before the patch is executed.
|
||||
* @property extension An input stream of the extension resource this patch uses.
|
||||
* @property extensionInputStream Getter for the extension input stream of the patch.
|
||||
* An extension is a precompiled DEX file that is merged into the patched app before this patch is executed.
|
||||
* @param executeBlock The execution block of the patch.
|
||||
* @param finalizeBlock The finalizing block of the patch. Called after all patches have been executed,
|
||||
@@ -140,10 +141,9 @@ class BytecodePatch internal constructor(
|
||||
compatiblePackages: Set<Package>?,
|
||||
dependencies: Set<Patch<*>>,
|
||||
options: Set<Option<*>>,
|
||||
val fingerprints: Set<Fingerprint>,
|
||||
val extension: InputStream?,
|
||||
executeBlock: Patch<BytecodePatchContext>.(BytecodePatchContext) -> Unit,
|
||||
finalizeBlock: (Patch<BytecodePatchContext>.(BytecodePatchContext) -> Unit)?,
|
||||
val extensionInputStream: Supplier<InputStream>?,
|
||||
executeBlock: (BytecodePatchContext) -> Unit,
|
||||
finalizeBlock: ((BytecodePatchContext) -> Unit)?,
|
||||
) : Patch<BytecodePatchContext>(
|
||||
name,
|
||||
description,
|
||||
@@ -155,8 +155,7 @@ class BytecodePatch internal constructor(
|
||||
finalizeBlock,
|
||||
) {
|
||||
override fun execute(context: PatcherContext) = with(context.bytecodeContext) {
|
||||
fingerprints.forEach { it.match(this) }
|
||||
|
||||
mergeExtension(this@BytecodePatch)
|
||||
execute(this)
|
||||
}
|
||||
|
||||
@@ -189,8 +188,8 @@ class RawResourcePatch internal constructor(
|
||||
compatiblePackages: Set<Package>?,
|
||||
dependencies: Set<Patch<*>>,
|
||||
options: Set<Option<*>>,
|
||||
executeBlock: Patch<ResourcePatchContext>.(ResourcePatchContext) -> Unit,
|
||||
finalizeBlock: (Patch<ResourcePatchContext>.(ResourcePatchContext) -> Unit)?,
|
||||
executeBlock: (ResourcePatchContext) -> Unit,
|
||||
finalizeBlock: ((ResourcePatchContext) -> Unit)?,
|
||||
) : Patch<ResourcePatchContext>(
|
||||
name,
|
||||
description,
|
||||
@@ -232,8 +231,8 @@ class ResourcePatch internal constructor(
|
||||
compatiblePackages: Set<Package>?,
|
||||
dependencies: Set<Patch<*>>,
|
||||
options: Set<Option<*>>,
|
||||
executeBlock: Patch<ResourcePatchContext>.(ResourcePatchContext) -> Unit,
|
||||
finalizeBlock: (Patch<ResourcePatchContext>.(ResourcePatchContext) -> Unit)?,
|
||||
executeBlock: (ResourcePatchContext) -> Unit,
|
||||
finalizeBlock: ((ResourcePatchContext) -> Unit)?,
|
||||
) : Patch<ResourcePatchContext>(
|
||||
name,
|
||||
description,
|
||||
@@ -278,8 +277,8 @@ sealed class PatchBuilder<C : PatchContext<*>>(
|
||||
protected var dependencies = mutableSetOf<Patch<*>>()
|
||||
protected val options = mutableSetOf<Option<*>>()
|
||||
|
||||
protected var executionBlock: (Patch<C>.(C) -> Unit) = { }
|
||||
protected var finalizeBlock: (Patch<C>.(C) -> Unit)? = null
|
||||
protected var executionBlock: ((C) -> Unit) = { }
|
||||
protected var finalizeBlock: ((C) -> Unit)? = null
|
||||
|
||||
/**
|
||||
* Add an option to the patch.
|
||||
@@ -338,7 +337,7 @@ sealed class PatchBuilder<C : PatchContext<*>>(
|
||||
*
|
||||
* @param block The execution block of the patch.
|
||||
*/
|
||||
fun execute(block: Patch<C>.(C) -> Unit) {
|
||||
fun execute(block: C.() -> Unit) {
|
||||
executionBlock = block
|
||||
}
|
||||
|
||||
@@ -347,7 +346,7 @@ sealed class PatchBuilder<C : PatchContext<*>>(
|
||||
*
|
||||
* @param block The finalizing block of the patch.
|
||||
*/
|
||||
fun finalize(block: Patch<C>.(C) -> Unit) {
|
||||
fun finalize(block: C.() -> Unit) {
|
||||
finalizeBlock = block
|
||||
}
|
||||
|
||||
@@ -376,8 +375,7 @@ private fun <B : PatchBuilder<*>> B.buildPatch(block: B.() -> Unit = {}) = apply
|
||||
* If null, the patch is named "Patch" and will not be loaded by [PatchLoader].
|
||||
* @param description The description of the patch.
|
||||
* @param use Weather or not the patch should be used.
|
||||
* @property fingerprints The fingerprints that are resolved before the patch is executed.
|
||||
* @property extension An input stream of the extension resource this patch uses.
|
||||
* @property extensionInputStream Getter for the extension input stream of the patch.
|
||||
* An extension is a precompiled DEX file that is merged into the patched app before this patch is executed.
|
||||
*
|
||||
* @constructor Create a new [BytecodePatchBuilder] builder.
|
||||
@@ -387,27 +385,9 @@ class BytecodePatchBuilder internal constructor(
|
||||
description: String?,
|
||||
use: Boolean,
|
||||
) : PatchBuilder<BytecodePatchContext>(name, description, use) {
|
||||
private val fingerprints = mutableSetOf<Fingerprint>()
|
||||
|
||||
/**
|
||||
* Add the fingerprint to the patch.
|
||||
*
|
||||
* @return A wrapper for the fingerprint with the ability to delegate the match to the fingerprint.
|
||||
*/
|
||||
operator fun Fingerprint.invoke() = InvokedFingerprint(also { fingerprints.add(it) })
|
||||
|
||||
class InvokedFingerprint internal constructor(private val fingerprint: Fingerprint) {
|
||||
// The reason getValue isn't extending the Fingerprint class is
|
||||
// because delegating makes only sense if the fingerprint was previously added to the patch by invoking it.
|
||||
// It may be likely to forget invoking it. By wrapping the fingerprint into this class,
|
||||
// the compiler will throw an error if the fingerprint was not invoked if attempting to delegate the match.
|
||||
operator fun getValue(nothing: Nothing?, property: KProperty<*>) = fingerprint.match
|
||||
?: throw PatchException("No fingerprint match to delegate to \"${property.name}\".")
|
||||
}
|
||||
|
||||
// Must be internal for the inlined function "extendWith".
|
||||
@PublishedApi
|
||||
internal var extension: InputStream? = null
|
||||
internal var extensionInputStream: Supplier<InputStream>? = null
|
||||
|
||||
// Inlining is necessary to get the class loader that loaded the patch
|
||||
// to load the extension from the resources.
|
||||
@@ -418,8 +398,11 @@ class BytecodePatchBuilder internal constructor(
|
||||
*/
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun extendWith(extension: String) = apply {
|
||||
this.extension = object {}.javaClass.classLoader.getResourceAsStream(extension)
|
||||
?: throw PatchException("Extension \"$extension\" not found")
|
||||
val classLoader = object {}.javaClass.classLoader
|
||||
|
||||
extensionInputStream = Supplier {
|
||||
classLoader.getResourceAsStream(extension) ?: throw PatchException("Extension \"$extension\" not found")
|
||||
}
|
||||
}
|
||||
|
||||
override fun build() = BytecodePatch(
|
||||
@@ -429,8 +412,7 @@ class BytecodePatchBuilder internal constructor(
|
||||
compatiblePackages,
|
||||
dependencies,
|
||||
options,
|
||||
fingerprints,
|
||||
extension,
|
||||
extensionInputStream,
|
||||
executionBlock,
|
||||
finalizeBlock,
|
||||
)
|
||||
@@ -636,7 +618,7 @@ sealed class PatchLoader private constructor(
|
||||
*/
|
||||
private val Class<*>.patchFields
|
||||
get() = fields.filter { field ->
|
||||
field.type.isPatch && field.canAccess(null)
|
||||
field.type.isPatch && field.canAccess()
|
||||
}.map { field ->
|
||||
field.get(null) as Patch<*>
|
||||
}
|
||||
@@ -646,7 +628,7 @@ sealed class PatchLoader private constructor(
|
||||
*/
|
||||
private val Class<*>.patchMethods
|
||||
get() = methods.filter { method ->
|
||||
method.returnType.isPatch && method.parameterCount == 0 && method.canAccess(null)
|
||||
method.returnType.isPatch && method.parameterCount == 0 && method.canAccess()
|
||||
}.map { method ->
|
||||
method.invoke(null) as Patch<*>
|
||||
}
|
||||
@@ -670,6 +652,12 @@ sealed class PatchLoader private constructor(
|
||||
it.name != null
|
||||
}.toSet()
|
||||
}
|
||||
|
||||
private fun Member.canAccess(): Boolean {
|
||||
if (this is Method && parameterCount != 0) return false
|
||||
|
||||
return Modifier.isStatic(modifiers) && Modifier.isPublic(modifiers)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -60,7 +60,7 @@ internal object ClassMerger {
|
||||
|
||||
if (missingMethods.isEmpty()) return this
|
||||
|
||||
logger.fine("Found ${missingMethods.size} missing methods")
|
||||
logger.fine { "Found ${missingMethods.size} missing methods" }
|
||||
|
||||
return asMutableClass().apply {
|
||||
methods.addAll(missingMethods.map { it.toMutable() })
|
||||
@@ -80,7 +80,7 @@ internal object ClassMerger {
|
||||
|
||||
if (missingFields.isEmpty()) return this
|
||||
|
||||
logger.fine("Found ${missingFields.size} missing fields")
|
||||
logger.fine { "Found ${missingFields.size} missing fields" }
|
||||
|
||||
return asMutableClass().apply {
|
||||
fields.addAll(missingFields.map { it.toMutable() })
|
||||
@@ -100,7 +100,7 @@ internal object ClassMerger {
|
||||
context.traverseClassHierarchy(this) {
|
||||
if (accessFlags.isPublic()) return@traverseClassHierarchy
|
||||
|
||||
logger.fine("Publicizing ${this.type}")
|
||||
logger.fine { "Publicizing ${this.type}" }
|
||||
|
||||
accessFlags = accessFlags.toPublic()
|
||||
}
|
||||
@@ -124,7 +124,7 @@ internal object ClassMerger {
|
||||
|
||||
if (brokenFields.isEmpty()) return this
|
||||
|
||||
logger.fine("Found ${brokenFields.size} broken fields")
|
||||
logger.fine { "Found ${brokenFields.size} broken fields" }
|
||||
|
||||
/**
|
||||
* Make a field public.
|
||||
@@ -153,7 +153,7 @@ internal object ClassMerger {
|
||||
|
||||
if (brokenMethods.isEmpty()) return this
|
||||
|
||||
logger.fine("Found ${brokenMethods.size} methods")
|
||||
logger.fine { "Found ${brokenMethods.size} methods" }
|
||||
|
||||
/**
|
||||
* Make a method public.
|
||||
@@ -179,7 +179,9 @@ internal object ClassMerger {
|
||||
callback: MutableClass.() -> Unit,
|
||||
) {
|
||||
callback(targetClass)
|
||||
this.classByType(targetClass.superclass ?: return)?.mutableClass?.let {
|
||||
|
||||
targetClass.superclass ?: return
|
||||
this.classBy { targetClass.superclass == it.type }?.mutableClass?.let {
|
||||
traverseClassHierarchy(it, callback)
|
||||
}
|
||||
}
|
||||
|
@@ -3,19 +3,21 @@ package app.revanced.patcher
|
||||
import app.revanced.patcher.patch.*
|
||||
import app.revanced.patcher.patch.BytecodePatchContext.LookupMaps
|
||||
import app.revanced.patcher.util.ProxyClassList
|
||||
import com.android.tools.smali.dexlib2.iface.ClassDef
|
||||
import com.android.tools.smali.dexlib2.iface.Method
|
||||
import com.android.tools.smali.dexlib2.immutable.ImmutableClassDef
|
||||
import com.android.tools.smali.dexlib2.immutable.ImmutableMethod
|
||||
import io.mockk.every
|
||||
import io.mockk.just
|
||||
import io.mockk.mockk
|
||||
import io.mockk.runs
|
||||
import jdk.internal.module.ModuleBootstrap.patcher
|
||||
import kotlinx.coroutines.flow.toList
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.assertDoesNotThrow
|
||||
import org.junit.jupiter.api.assertAll
|
||||
import java.util.logging.Logger
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNull
|
||||
import kotlin.test.assertTrue
|
||||
import kotlin.test.*
|
||||
|
||||
internal object PatcherTest {
|
||||
private lateinit var patcher: Patcher
|
||||
@@ -149,19 +151,15 @@ internal object PatcherTest {
|
||||
@Test
|
||||
fun `throws if unmatched fingerprint match is delegated`() {
|
||||
val patch = bytecodePatch {
|
||||
// Fingerprint can never match.
|
||||
val match by fingerprint { }
|
||||
// Manually add the fingerprint.
|
||||
app.revanced.patcher.fingerprint { }()
|
||||
|
||||
execute {
|
||||
// Fingerprint can never match.
|
||||
val match by fingerprint { }
|
||||
|
||||
// Throws, because the fingerprint can't be matched.
|
||||
match.patternMatch
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(2, patch.fingerprints.size)
|
||||
|
||||
assertTrue(
|
||||
patch().exception != null,
|
||||
"Expected an exception because the fingerprint can't match.",
|
||||
@@ -170,43 +168,6 @@ internal object PatcherTest {
|
||||
|
||||
@Test
|
||||
fun `matches fingerprint`() {
|
||||
mockClassWithMethod()
|
||||
|
||||
val patches = setOf(bytecodePatch { fingerprint { this returns "V" } })
|
||||
|
||||
assertNull(
|
||||
patches.first().fingerprints.first().match,
|
||||
"Expected fingerprint to be matched before execution.",
|
||||
)
|
||||
|
||||
patches()
|
||||
|
||||
assertDoesNotThrow("Expected fingerprint to be matched.") {
|
||||
assertEquals(
|
||||
"V",
|
||||
patches.first().fingerprints.first().match!!.method.returnType,
|
||||
"Expected fingerprint to be matched.",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private operator fun Set<Patch<*>>.invoke(): List<PatchResult> {
|
||||
every { patcher.context.executablePatches } returns toMutableSet()
|
||||
every { patcher.context.bytecodeContext.lookupMaps } returns LookupMaps(patcher.context.bytecodeContext.classes)
|
||||
|
||||
return runBlocking { patcher().toList() }
|
||||
}
|
||||
|
||||
private operator fun Patch<*>.invoke() = setOf(this)().first()
|
||||
|
||||
private fun Any.setPrivateField(field: String, value: Any) {
|
||||
this::class.java.getDeclaredField(field).apply {
|
||||
this.isAccessible = true
|
||||
set(this@setPrivateField, value)
|
||||
}
|
||||
}
|
||||
|
||||
private fun mockClassWithMethod() {
|
||||
every { patcher.context.bytecodeContext.classes } returns ProxyClassList(
|
||||
mutableListOf(
|
||||
ImmutableClassDef(
|
||||
@@ -232,6 +193,50 @@ internal object PatcherTest {
|
||||
),
|
||||
),
|
||||
)
|
||||
every { with(patcher.context.bytecodeContext) { any<Fingerprint>().match } } answers { callOriginal() }
|
||||
every { with(patcher.context.bytecodeContext) { any<Fingerprint>().match(any<ClassDef>()) } } answers { callOriginal() }
|
||||
every { with(patcher.context.bytecodeContext) { any<Fingerprint>().match(any<Method>()) } } answers { callOriginal() }
|
||||
every { patcher.context.bytecodeContext.classBy(any()) } answers { callOriginal() }
|
||||
every { patcher.context.bytecodeContext.proxy(any()) } answers { callOriginal() }
|
||||
|
||||
val fingerprint = fingerprint { returns("V") }
|
||||
val fingerprint2 = fingerprint { returns("V") }
|
||||
val fingerprint3 = fingerprint { returns("V") }
|
||||
|
||||
val patches = setOf(
|
||||
bytecodePatch {
|
||||
execute {
|
||||
fingerprint.match(classes.first().methods.first())
|
||||
fingerprint2.match(classes.first())
|
||||
fingerprint3.match
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
patches()
|
||||
|
||||
assertAll(
|
||||
"Expected fingerprints to match.",
|
||||
{ assertNotNull(fingerprint._match) },
|
||||
{ assertNotNull(fingerprint2._match) },
|
||||
{ assertNotNull(fingerprint3._match) },
|
||||
)
|
||||
}
|
||||
|
||||
private operator fun Set<Patch<*>>.invoke(): List<PatchResult> {
|
||||
every { patcher.context.executablePatches } returns toMutableSet()
|
||||
every { patcher.context.bytecodeContext.lookupMaps } returns LookupMaps(patcher.context.bytecodeContext.classes)
|
||||
every { with(patcher.context.bytecodeContext) { mergeExtension(any<BytecodePatch>()) } } just runs
|
||||
|
||||
return runBlocking { patcher().toList() }
|
||||
}
|
||||
|
||||
private operator fun Patch<*>.invoke() = setOf(this)().first()
|
||||
|
||||
private fun Any.setPrivateField(field: String, value: Any) {
|
||||
this::class.java.getDeclaredField(field).apply {
|
||||
this.isAccessible = true
|
||||
set(this@setPrivateField, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package app.revanced.patcher.patch
|
||||
|
||||
import app.revanced.patcher.fingerprint
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@@ -24,23 +23,6 @@ internal object PatchTest {
|
||||
assertEquals("compatible.package", patch.compatiblePackages!!.first().first)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `can create patch with fingerprints`() {
|
||||
val externalFingerprint = fingerprint {}
|
||||
|
||||
val patch = bytecodePatch(name = "Test") {
|
||||
val externalFingerprintMatch by externalFingerprint()
|
||||
val internalFingerprintMatch by fingerprint {}
|
||||
|
||||
execute {
|
||||
externalFingerprintMatch.method
|
||||
internalFingerprintMatch.method
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(2, patch.fingerprints.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `can create patch with dependencies`() {
|
||||
val patch = bytecodePatch(name = "Test") {
|
||||
|
Reference in New Issue
Block a user