You've already forked revanced-patcher
mirror of
https://github.com/revanced/revanced-patcher
synced 2025-09-06 16:38:50 +02:00
Compare commits
181 Commits
v2.5.1
...
v1.0.0-dev
Author | SHA1 | Date | |
---|---|---|---|
![]() |
a06c0db6a7 | ||
![]() |
3f0c740200 | ||
![]() |
545c5c144d | ||
![]() |
0fa529fcdf | ||
![]() |
7573db2575 | ||
![]() |
70ca184cf9 | ||
![]() |
72f16b7785 | ||
![]() |
fc03639b26 | ||
![]() |
88a85f94e7 | ||
![]() |
45a167e785 | ||
![]() |
699d8abf59 | ||
![]() |
b58c718699 | ||
![]() |
266d6810a9 | ||
![]() |
40b1fa43e1 | ||
![]() |
94f9594eed | ||
![]() |
cff58ab180 | ||
![]() |
989646b0b5 | ||
![]() |
5c3fbaee7a | ||
![]() |
08525e9c26 | ||
![]() |
5630e49663 | ||
![]() |
0543122427 | ||
![]() |
0873703056 | ||
![]() |
1a99ecaffe | ||
![]() |
6726884be5 | ||
![]() |
8b4f3947f8 | ||
![]() |
4d74de4061 | ||
![]() |
4fbee7d255 | ||
![]() |
fd9f639605 | ||
![]() |
9084ccc2a2 | ||
![]() |
83a8a48176 | ||
![]() |
66b08f8b3a | ||
![]() |
e286ba5090 | ||
![]() |
e5c054ac2f | ||
![]() |
cb0741d05f | ||
![]() |
38556d61ab | ||
![]() |
ce8021b482 | ||
![]() |
243dba7751 | ||
![]() |
698f759979 | ||
![]() |
1701da3dde | ||
![]() |
37fa9949ec | ||
![]() |
ac36d19693 | ||
![]() |
c245edb0c5 | ||
![]() |
1f7bf3ac6c | ||
![]() |
bfeeaf4435 | ||
![]() |
748d0abad0 | ||
![]() |
569238ab76 | ||
![]() |
23197879b2 | ||
![]() |
305a81793a | ||
![]() |
33f9211f98 | ||
![]() |
864e38c069 | ||
![]() |
659e1087c9 | ||
![]() |
03700ffa51 | ||
![]() |
ae06d826e8 | ||
![]() |
5ca5188fc2 | ||
![]() |
f88c11820d | ||
![]() |
93e81ff047 | ||
![]() |
d49df10a3c | ||
![]() |
04b49b8b66 | ||
![]() |
5ddc63f979 | ||
![]() |
82b1e66d54 | ||
![]() |
fd630cd429 | ||
![]() |
f4a47d4dc8 | ||
![]() |
3bfc24fc16 | ||
![]() |
25bba2c1d8 | ||
![]() |
4dea27e831 | ||
![]() |
a0d6d46217 | ||
![]() |
643a14e664 | ||
![]() |
355e6d82cc | ||
![]() |
df7503b47b | ||
![]() |
a01dded092 | ||
![]() |
9ae95174e6 | ||
![]() |
e161f7fea4 | ||
![]() |
200e3c9fdb | ||
![]() |
f0f34031dd | ||
![]() |
560c485ab0 | ||
![]() |
cc5a414692 | ||
![]() |
c2a334eb3f | ||
![]() |
1b2fbbca26 | ||
![]() |
4458141d6d | ||
![]() |
8544fc4cbc | ||
![]() |
a492808021 | ||
![]() |
0204eee79e | ||
![]() |
4022b8b847 | ||
![]() |
8daf877fac | ||
![]() |
7d38bb0baa | ||
![]() |
5f71a342ac | ||
![]() |
866b03af21 | ||
![]() |
4c1a42b216 | ||
![]() |
264989f488 | ||
![]() |
4281546f69 | ||
![]() |
af4f2396c7 | ||
![]() |
147195647c | ||
![]() |
433914feda | ||
![]() |
622138736d | ||
![]() |
aed4fd9a3c | ||
![]() |
32e645850d | ||
![]() |
e45fc02aae | ||
![]() |
e0d29cf450 | ||
![]() |
2b888e381c | ||
![]() |
f72dd68ec5 | ||
![]() |
3b68d5c65e | ||
![]() |
eed1cfda7b | ||
![]() |
8b70bb4290 | ||
![]() |
dbda641d0c | ||
![]() |
5ae5e98f1f | ||
![]() |
1ba40ab1cb | ||
![]() |
e9c119ebb1 | ||
![]() |
1bd6d1d5b8 | ||
![]() |
4e7378bd79 | ||
![]() |
28ed4793e3 | ||
![]() |
312235b194 | ||
![]() |
6ab21e5891 | ||
![]() |
db8d1150c3 | ||
![]() |
8f778f38fe | ||
![]() |
88a6a27302 | ||
![]() |
a9e4e8ac32 | ||
![]() |
d5e694c306 | ||
![]() |
dde0a22642 | ||
![]() |
9a67aa3ff4 | ||
![]() |
e69708f21e | ||
![]() |
c49071aff7 | ||
![]() |
d15240d033 | ||
![]() |
6767c8fbc1 | ||
![]() |
4543b36616 | ||
![]() |
ec6d462ade | ||
![]() |
84bc7e0dc7 | ||
![]() |
6ad51aad9a | ||
![]() |
b711b8001e | ||
![]() |
12c10d8c64 | ||
![]() |
05e44007d8 | ||
![]() |
dbafe2ab37 | ||
![]() |
45a885dbde | ||
![]() |
78235d1abe | ||
![]() |
aec5eeb597 | ||
![]() |
d98c9eeb30 | ||
![]() |
f8e978af88 | ||
![]() |
86cb053566 | ||
![]() |
c1ccb70de4 | ||
![]() |
bb42fa3c6f | ||
![]() |
2d3c61113d | ||
![]() |
6bc4e7eab7 | ||
![]() |
be51f42710 | ||
![]() |
fa0412985c | ||
![]() |
0048788dd0 | ||
![]() |
47eb493f54 | ||
![]() |
6b1337e4fc | ||
![]() |
f4589db3a9 | ||
![]() |
1af31b2aa3 | ||
![]() |
14f7667156 | ||
![]() |
cd57a8c9a0 | ||
![]() |
0d3beb353d | ||
![]() |
ddef338631 | ||
![]() |
fc4b673087 | ||
![]() |
8d1bb5f3d9 | ||
![]() |
c8a017a4c0 | ||
![]() |
51fb59a43c | ||
![]() |
a78715133c | ||
![]() |
e8f6973938 | ||
![]() |
3cb1e01587 | ||
![]() |
cb4ee207e1 | ||
![]() |
ca6b94d943 | ||
![]() |
6cdb6887d4 | ||
![]() |
ab6453ca8a | ||
![]() |
e8182c17ad | ||
![]() |
49beec9fc6 | ||
![]() |
3ab42a932c | ||
![]() |
4d98cbc9e8 | ||
![]() |
87bbde5e06 | ||
![]() |
8db8893ab1 | ||
![]() |
00c6ab7faf | ||
![]() |
460d62a24c | ||
![]() |
89e4b9f762 | ||
![]() |
a8fd7c00c3 | ||
![]() |
1769132a9e | ||
![]() |
6c0f0823c9 | ||
![]() |
23e897a7a9 | ||
![]() |
7e67daf878 | ||
![]() |
593c83f29f | ||
![]() |
72e123dd01 | ||
![]() |
599a401ed9 | ||
![]() |
3f8500b059 |
24
.github/ISSUE_TEMPLATE/bug-report.md
vendored
24
.github/ISSUE_TEMPLATE/bug-report.md
vendored
@@ -1,24 +0,0 @@
|
|||||||
---
|
|
||||||
name: Bug report
|
|
||||||
about: Create a bug report on the patcher. Do not submit suggestions for patches here.
|
|
||||||
title: 'problem: some problem'
|
|
||||||
labels: bug
|
|
||||||
assignees: oSumAtrIX, Sculas
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 🐞 Issue
|
|
||||||
|
|
||||||
<!-- Describe your issue in detail here -->
|
|
||||||
|
|
||||||
## ⚙ Reproduce
|
|
||||||
|
|
||||||
<!-- Include your environment and steps to reproduce the issue as detailed as possible -->
|
|
||||||
|
|
||||||
## 🛠 Solution
|
|
||||||
|
|
||||||
<!-- If applicable, add a possible solution -->
|
|
||||||
|
|
||||||
## ⚠ Additional context
|
|
||||||
|
|
||||||
<!-- Add any other context about the problem here -->
|
|
24
.github/ISSUE_TEMPLATE/feature_request.md
vendored
24
.github/ISSUE_TEMPLATE/feature_request.md
vendored
@@ -1,24 +0,0 @@
|
|||||||
---
|
|
||||||
name: Feature request
|
|
||||||
about: Suggest a change for the patcher. Do not submit suggestions for patches here.
|
|
||||||
title: 'feat: some feature'
|
|
||||||
labels: feature-request
|
|
||||||
assignees: ''
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 🐞 Issue
|
|
||||||
|
|
||||||
<!-- Explain here, what the current problem is and why it leads you to request a feature change -->
|
|
||||||
|
|
||||||
## ❗ Solution
|
|
||||||
|
|
||||||
<!-- Explain how your current issue can be solved -->
|
|
||||||
|
|
||||||
## ❓ Motivation
|
|
||||||
|
|
||||||
<!-- Explain why your feature should be considered -->
|
|
||||||
|
|
||||||
## ⚠ Additional context
|
|
||||||
|
|
||||||
<!-- Add any other context or screenshots about the feature request here -->
|
|
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@@ -28,6 +28,8 @@ jobs:
|
|||||||
uses: actions/setup-node@v2
|
uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version: "lts/*"
|
node-version: "lts/*"
|
||||||
|
- name: Make gradlew executable
|
||||||
|
run: chmod +x gradlew
|
||||||
- name: Build with Gradle
|
- name: Build with Gradle
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
@@ -7,11 +7,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"plugins": [
|
"plugins": [
|
||||||
["@semantic-release/commit-analyzer", {
|
"@semantic-release/commit-analyzer",
|
||||||
"releaseRules": [
|
|
||||||
{"type": "build", "release": "patch"}
|
|
||||||
]
|
|
||||||
}],
|
|
||||||
"@semantic-release/release-notes-generator",
|
"@semantic-release/release-notes-generator",
|
||||||
"@semantic-release/changelog",
|
"@semantic-release/changelog",
|
||||||
"gradle-semantic-release-plugin",
|
"gradle-semantic-release-plugin",
|
||||||
|
489
CHANGELOG.md
489
CHANGELOG.md
File diff suppressed because it is too large
Load Diff
@@ -1,32 +1,38 @@
|
|||||||
plugins {
|
plugins {
|
||||||
kotlin("jvm") version "1.7.0"
|
kotlin("jvm") version "1.6.21"
|
||||||
java
|
java
|
||||||
`maven-publish`
|
`maven-publish`
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "app.revanced"
|
group = "app.revanced"
|
||||||
|
|
||||||
val githubUsername: String = project.findProperty("gpr.user") as? String ?: System.getenv("GITHUB_ACTOR")
|
|
||||||
val githubPassword: String = project.findProperty("gpr.key") as? String ?: System.getenv("GITHUB_TOKEN")
|
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
maven {
|
maven {
|
||||||
url = uri("https://maven.pkg.github.com/revanced/multidexlib2")
|
url = uri("https://maven.pkg.github.com/revanced/multidexlib2")
|
||||||
credentials {
|
credentials {
|
||||||
username = githubUsername
|
// DO NOT set these variables in the project's gradle.properties.
|
||||||
password = githubPassword
|
// Instead, you should set them in:
|
||||||
|
// Windows: %homepath%\.gradle\gradle.properties
|
||||||
|
// Linux: ~/.gradle/gradle.properties
|
||||||
|
username =
|
||||||
|
project.findProperty("gpr.user") as String? ?: System.getenv("GITHUB_ACTOR") // DO NOT CHANGE!
|
||||||
|
password =
|
||||||
|
project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN") // DO NOT CHANGE!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("xpp3:xpp3:1.1.4c")
|
implementation(kotlin("stdlib"))
|
||||||
implementation("org.smali:smali:2.5.2")
|
|
||||||
implementation("app.revanced:multidexlib2:2.5.2.r2")
|
api("xpp3:xpp3:1.1.4c")
|
||||||
implementation("org.apktool:apktool-lib:2.6.9-SNAPSHOT")
|
api("org.apktool:apktool-lib:2.6.1")
|
||||||
|
api("app.revanced:multidexlib2:2.5.2.r2")
|
||||||
|
api("org.smali:smali:2.5.2")
|
||||||
|
|
||||||
testImplementation(kotlin("test"))
|
testImplementation(kotlin("test"))
|
||||||
|
implementation(kotlin("reflect"))
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
@@ -40,11 +46,14 @@ tasks {
|
|||||||
|
|
||||||
java {
|
java {
|
||||||
withSourcesJar()
|
withSourcesJar()
|
||||||
|
withJavadocJar()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val isGitHubCI = System.getenv("GITHUB_ACTOR") != null
|
||||||
|
|
||||||
publishing {
|
publishing {
|
||||||
repositories {
|
repositories {
|
||||||
if (System.getenv("GITHUB_ACTOR") != null)
|
if (isGitHubCI) {
|
||||||
maven {
|
maven {
|
||||||
name = "GitHubPackages"
|
name = "GitHubPackages"
|
||||||
url = uri("https://maven.pkg.github.com/revanced/revanced-patcher")
|
url = uri("https://maven.pkg.github.com/revanced/revanced-patcher")
|
||||||
@@ -53,12 +62,13 @@ publishing {
|
|||||||
password = System.getenv("GITHUB_TOKEN")
|
password = System.getenv("GITHUB_TOKEN")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
} else {
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
publications {
|
publications {
|
||||||
register<MavenPublication>("gpr") {
|
register<MavenPublication>("gpr") {
|
||||||
from(components["java"])
|
from(components["java"])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,2 +1,2 @@
|
|||||||
kotlin.code.style = official
|
kotlin.code.style = official
|
||||||
version = 2.5.1
|
version = 1.0.0-dev.16
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,19 +0,0 @@
|
|||||||
package app.revanced.patcher
|
|
||||||
|
|
||||||
import app.revanced.patcher.data.Data
|
|
||||||
import app.revanced.patcher.data.PackageMetadata
|
|
||||||
import app.revanced.patcher.data.impl.BytecodeData
|
|
||||||
import app.revanced.patcher.data.impl.ResourceData
|
|
||||||
import app.revanced.patcher.patch.Patch
|
|
||||||
import org.jf.dexlib2.iface.ClassDef
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
data class PatcherData(
|
|
||||||
internal val internalClasses: MutableList<ClassDef>,
|
|
||||||
internal val resourceCacheDirectory: String,
|
|
||||||
val packageMetadata: PackageMetadata
|
|
||||||
) {
|
|
||||||
internal val patches = mutableListOf<Class<out Patch<Data>>>()
|
|
||||||
internal val bytecodeData = BytecodeData(internalClasses)
|
|
||||||
internal val resourceData = ResourceData(File(resourceCacheDirectory))
|
|
||||||
}
|
|
@@ -1,23 +0,0 @@
|
|||||||
package app.revanced.patcher
|
|
||||||
|
|
||||||
import app.revanced.patcher.logging.Logger
|
|
||||||
import app.revanced.patcher.logging.impl.NopLogger
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Options for the [Patcher].
|
|
||||||
* @param inputFile The input file (usually an apk file).
|
|
||||||
* @param resourceCacheDirectory Directory to cache resources.
|
|
||||||
* @param patchResources Weather to use the resource patcher. Resources will still need to be decoded.
|
|
||||||
* @param aaptPath Optional path to a custom aapt binary.
|
|
||||||
* @param frameworkFolderLocation Optional path to a custom framework folder.
|
|
||||||
* @param logger Custom logger implementation for the [Patcher].
|
|
||||||
*/
|
|
||||||
data class PatcherOptions(
|
|
||||||
internal val inputFile: File,
|
|
||||||
internal val resourceCacheDirectory: String,
|
|
||||||
internal val patchResources: Boolean = false,
|
|
||||||
internal val aaptPath: String = "",
|
|
||||||
internal val frameworkFolderLocation: String? = null,
|
|
||||||
internal val logger: Logger = NopLogger
|
|
||||||
)
|
|
@@ -1,16 +0,0 @@
|
|||||||
package app.revanced.patcher
|
|
||||||
|
|
||||||
import app.revanced.patcher.util.dex.DexFile
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The result of a patcher.
|
|
||||||
* @param dexFiles The patched dex files.
|
|
||||||
* @param doNotCompress List of relative paths to files to exclude from compressing.
|
|
||||||
* @param resourceFile File containing resources that need to be extracted into the APK.
|
|
||||||
*/
|
|
||||||
data class PatcherResult(
|
|
||||||
val dexFiles: List<DexFile>,
|
|
||||||
val doNotCompress: List<String>? = null,
|
|
||||||
val resourceFile: File?
|
|
||||||
)
|
|
@@ -1,11 +1,11 @@
|
|||||||
package app.revanced.patcher.annotation
|
package app.revanced.patcher.annotation
|
||||||
|
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
import app.revanced.patcher.patch.base.Patch
|
||||||
import app.revanced.patcher.patch.Patch
|
import app.revanced.patcher.signature.implementation.method.MethodSignature
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Annotation to constrain a [Patch] or [MethodFingerprint] to compatible packages.
|
* Annotation to constrain a [Patch] or [MethodSignature] to compatible packages.
|
||||||
* @param compatiblePackages A list of packages a [Patch] or [MethodFingerprint] is compatible with.
|
* @param compatiblePackages A list of packages a [Patch] or [MethodSignature] is compatible with.
|
||||||
*/
|
*/
|
||||||
@Target(AnnotationTarget.CLASS)
|
@Target(AnnotationTarget.CLASS)
|
||||||
@Retention(AnnotationRetention.RUNTIME)
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
@@ -17,7 +17,7 @@ annotation class Compatibility(
|
|||||||
/**
|
/**
|
||||||
* Annotation to represent packages a patch can be compatible with.
|
* Annotation to represent packages a patch can be compatible with.
|
||||||
* @param name The package identifier name.
|
* @param name The package identifier name.
|
||||||
* @param versions The versions of the package the [Patch] or [MethodFingerprint]is compatible with.
|
* @param versions The versions of the package the [Patch] or [MethodSignature]is compatible with.
|
||||||
*/
|
*/
|
||||||
@Target()
|
@Target()
|
||||||
@Retention(AnnotationRetention.RUNTIME)
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
@@ -1,11 +1,11 @@
|
|||||||
package app.revanced.patcher.annotation
|
package app.revanced.patcher.annotation
|
||||||
|
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
import app.revanced.patcher.patch.base.Patch
|
||||||
import app.revanced.patcher.patch.Patch
|
import app.revanced.patcher.signature.implementation.method.MethodSignature
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Annotation to name a [Patch] or [MethodFingerprint].
|
* Annotation to name a [Patch] or [MethodSignature].
|
||||||
* @param name A suggestive name for the [Patch] or [MethodFingerprint].
|
* @param name A suggestive name for the [Patch] or [MethodSignature].
|
||||||
*/
|
*/
|
||||||
@Target(AnnotationTarget.CLASS)
|
@Target(AnnotationTarget.CLASS)
|
||||||
@Retention(AnnotationRetention.RUNTIME)
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
@@ -15,8 +15,8 @@ annotation class Name(
|
|||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Annotation to describe a [Patch] or [MethodFingerprint].
|
* Annotation to describe a [Patch] or [MethodSignature].
|
||||||
* @param description A description for the [Patch] or [MethodFingerprint].
|
* @param description A description for the [Patch] or [MethodSignature].
|
||||||
*/
|
*/
|
||||||
@Target(AnnotationTarget.CLASS)
|
@Target(AnnotationTarget.CLASS)
|
||||||
@Retention(AnnotationRetention.RUNTIME)
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
@@ -27,8 +27,8 @@ annotation class Description(
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Annotation to version a [Patch] or [MethodFingerprint].
|
* Annotation to version a [Patch] or [MethodSignature].
|
||||||
* @param version The version of a [Patch] or [MethodFingerprint].
|
* @param version The version of a [Patch] or [MethodSignature].
|
||||||
*/
|
*/
|
||||||
@Target(AnnotationTarget.CLASS)
|
@Target(AnnotationTarget.CLASS)
|
||||||
@Retention(AnnotationRetention.RUNTIME)
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
@@ -1,9 +0,0 @@
|
|||||||
package app.revanced.patcher.data
|
|
||||||
|
|
||||||
import app.revanced.patcher.data.impl.BytecodeData
|
|
||||||
import app.revanced.patcher.data.impl.ResourceData
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constraint interface for [BytecodeData] and [ResourceData]
|
|
||||||
*/
|
|
||||||
interface Data
|
|
@@ -1,13 +0,0 @@
|
|||||||
package app.revanced.patcher.data
|
|
||||||
|
|
||||||
import brut.androlib.meta.MetaInfo
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Metadata about a package.
|
|
||||||
*/
|
|
||||||
class PackageMetadata {
|
|
||||||
lateinit var packageName: String
|
|
||||||
lateinit var packageVersion: String
|
|
||||||
|
|
||||||
internal val metaInfo: MetaInfo = MetaInfo()
|
|
||||||
}
|
|
18
src/main/kotlin/app/revanced/patcher/data/PatcherData.kt
Normal file
18
src/main/kotlin/app/revanced/patcher/data/PatcherData.kt
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package app.revanced.patcher.data
|
||||||
|
|
||||||
|
import app.revanced.patcher.data.base.Data
|
||||||
|
import app.revanced.patcher.data.implementation.BytecodeData
|
||||||
|
import app.revanced.patcher.data.implementation.ResourceData
|
||||||
|
import app.revanced.patcher.patch.base.Patch
|
||||||
|
import org.jf.dexlib2.iface.ClassDef
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
internal data class PatcherData(
|
||||||
|
val internalClasses: MutableList<ClassDef>,
|
||||||
|
val resourceCacheDirectory: String
|
||||||
|
) {
|
||||||
|
internal val patches = mutableListOf<Patch<Data>>()
|
||||||
|
|
||||||
|
internal val bytecodeData = BytecodeData(patches, internalClasses)
|
||||||
|
internal val resourceData = ResourceData(File(resourceCacheDirectory))
|
||||||
|
}
|
9
src/main/kotlin/app/revanced/patcher/data/base/Data.kt
Normal file
9
src/main/kotlin/app/revanced/patcher/data/base/Data.kt
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package app.revanced.patcher.data.base
|
||||||
|
|
||||||
|
import app.revanced.patcher.data.implementation.BytecodeData
|
||||||
|
import app.revanced.patcher.data.implementation.ResourceData
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constraint interface for [BytecodeData] and [ResourceData]
|
||||||
|
*/
|
||||||
|
interface Data
|
@@ -1,69 +0,0 @@
|
|||||||
package app.revanced.patcher.data.impl
|
|
||||||
|
|
||||||
import app.revanced.patcher.data.Data
|
|
||||||
import app.revanced.patcher.util.ProxyBackedClassList
|
|
||||||
import app.revanced.patcher.util.method.MethodWalker
|
|
||||||
import org.jf.dexlib2.iface.ClassDef
|
|
||||||
import org.jf.dexlib2.iface.Method
|
|
||||||
|
|
||||||
class BytecodeData(
|
|
||||||
internalClasses: MutableList<ClassDef>
|
|
||||||
) : Data {
|
|
||||||
val classes = ProxyBackedClassList(internalClasses)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Find a class by a given class name.
|
|
||||||
* @param className The name of the class.
|
|
||||||
* @return A proxy for the first class that matches the class name.
|
|
||||||
*/
|
|
||||||
fun findClass(className: String) = findClass { it.type.contains(className) }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Find a class by a given predicate.
|
|
||||||
* @param predicate A predicate to match the class.
|
|
||||||
* @return A proxy for the first class that matches the predicate.
|
|
||||||
*/
|
|
||||||
fun findClass(predicate: (ClassDef) -> Boolean) =
|
|
||||||
// if we already proxied the class matching the predicate...
|
|
||||||
classes.proxies.firstOrNull { predicate(it.immutableClass) } ?:
|
|
||||||
// else resolve the class to a proxy and return it, if the predicate is matching a class
|
|
||||||
classes.find(predicate)?.let { proxy(it) }
|
|
||||||
|
|
||||||
fun proxy(classDef: ClassDef): app.revanced.patcher.util.proxy.ClassProxy {
|
|
||||||
var proxy = this.classes.proxies.find { it.immutableClass.type == classDef.type }
|
|
||||||
if (proxy == null) {
|
|
||||||
proxy = app.revanced.patcher.util.proxy.ClassProxy(classDef)
|
|
||||||
this.classes.add(proxy)
|
|
||||||
}
|
|
||||||
return proxy
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal class MethodNotFoundException(s: String) : Exception(s)
|
|
||||||
|
|
||||||
internal inline fun <reified T> Iterable<T>.find(predicate: (T) -> Boolean): T? {
|
|
||||||
for (element in this) {
|
|
||||||
if (predicate(element)) {
|
|
||||||
return element
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a [MethodWalker] instance for the current [BytecodeData].
|
|
||||||
* @param startMethod The method to start at.
|
|
||||||
* @return A [MethodWalker] instance.
|
|
||||||
*/
|
|
||||||
fun BytecodeData.toMethodWalker(startMethod: Method): MethodWalker {
|
|
||||||
return MethodWalker(this, startMethod)
|
|
||||||
}
|
|
||||||
|
|
||||||
internal inline fun <T> Iterable<T>.findIndexed(predicate: (T) -> Boolean): Pair<T, Int>? {
|
|
||||||
for ((index, element) in this.withIndex()) {
|
|
||||||
if (predicate(element)) {
|
|
||||||
return element to index
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
@@ -1,49 +0,0 @@
|
|||||||
package app.revanced.patcher.data.impl
|
|
||||||
|
|
||||||
import app.revanced.patcher.data.Data
|
|
||||||
import org.w3c.dom.Document
|
|
||||||
import java.io.Closeable
|
|
||||||
import java.io.File
|
|
||||||
import java.io.InputStream
|
|
||||||
import java.io.OutputStream
|
|
||||||
import javax.xml.parsers.DocumentBuilderFactory
|
|
||||||
import javax.xml.transform.TransformerFactory
|
|
||||||
import javax.xml.transform.dom.DOMSource
|
|
||||||
import javax.xml.transform.stream.StreamResult
|
|
||||||
|
|
||||||
class ResourceData(private val resourceCacheDirectory: File) : Data, Iterable<File> {
|
|
||||||
val xmlEditor = XmlFileHolder()
|
|
||||||
|
|
||||||
operator fun get(path: String) = resourceCacheDirectory.resolve(path)
|
|
||||||
|
|
||||||
override fun iterator() = resourceCacheDirectory.walkTopDown().iterator()
|
|
||||||
|
|
||||||
inner class XmlFileHolder {
|
|
||||||
operator fun get(inputStream: InputStream, outputStream: OutputStream) =
|
|
||||||
DomFileEditor(inputStream, lazyOf(outputStream))
|
|
||||||
|
|
||||||
operator fun get(path: String) = DomFileEditor(this@ResourceData[path])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class DomFileEditor internal constructor(
|
|
||||||
private val inputStream: InputStream,
|
|
||||||
private val outputStream: Lazy<OutputStream>,
|
|
||||||
) : Closeable {
|
|
||||||
val file: Document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream)
|
|
||||||
.also(Document::normalize)
|
|
||||||
|
|
||||||
// lazily open an output stream
|
|
||||||
// this is required because when constructing a DomFileEditor the output stream is created along with the input stream, which is not allowed
|
|
||||||
// the workaround is to lazily create the output stream. This way it would be used after the input stream is closed, which happens in the constructor
|
|
||||||
constructor(file: File) : this(file.inputStream(), lazy { file.outputStream() })
|
|
||||||
|
|
||||||
override fun close() {
|
|
||||||
val result = StreamResult(outputStream.value)
|
|
||||||
TransformerFactory.newInstance().newTransformer().transform(DOMSource(file), result)
|
|
||||||
|
|
||||||
inputStream.close()
|
|
||||||
outputStream.value.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -0,0 +1,86 @@
|
|||||||
|
package app.revanced.patcher.data.implementation
|
||||||
|
|
||||||
|
import app.revanced.patcher.data.base.Data
|
||||||
|
import app.revanced.patcher.patch.base.Patch
|
||||||
|
import app.revanced.patcher.patch.implementation.BytecodePatch
|
||||||
|
import app.revanced.patcher.signature.implementation.method.resolver.SignatureResolverResult
|
||||||
|
import app.revanced.patcher.util.ProxyBackedClassList
|
||||||
|
import app.revanced.patcher.util.method.MethodWalker
|
||||||
|
import org.jf.dexlib2.iface.ClassDef
|
||||||
|
import org.jf.dexlib2.iface.Method
|
||||||
|
|
||||||
|
class BytecodeData(
|
||||||
|
// FIXME: ugly solution due to design.
|
||||||
|
// It does not make sense for a BytecodeData instance to have access to the patches
|
||||||
|
private val patches: List<Patch<Data>>,
|
||||||
|
internalClasses: MutableList<ClassDef>
|
||||||
|
) : Data {
|
||||||
|
val classes = ProxyBackedClassList(internalClasses)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find a class by a given class name
|
||||||
|
* @return A proxy for the first class that matches the class name
|
||||||
|
*/
|
||||||
|
fun findClass(className: String) = findClass { it.type.contains(className) }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find a class by a given predicate
|
||||||
|
* @return A proxy for the first class that matches the predicate
|
||||||
|
*/
|
||||||
|
fun findClass(predicate: (ClassDef) -> Boolean): app.revanced.patcher.util.proxy.ClassProxy? {
|
||||||
|
// if we already proxied the class matching the predicate...
|
||||||
|
for (patch in patches) {
|
||||||
|
if (patch !is BytecodePatch) continue
|
||||||
|
for (signature in patch.signatures) {
|
||||||
|
val result = signature.result
|
||||||
|
result ?: continue
|
||||||
|
|
||||||
|
if (predicate(result.definingClassProxy.immutableClass)) return result.definingClassProxy // ...then return that proxy
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// else resolve the class to a proxy and return it, if the predicate is matching a class
|
||||||
|
return classes.find(predicate)?.let {
|
||||||
|
proxy(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class MethodMap : LinkedHashMap<String, SignatureResolverResult>() {
|
||||||
|
override fun get(key: String): SignatureResolverResult {
|
||||||
|
return super.get(key) ?: throw MethodNotFoundException("Method $key was not found in the method cache")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class MethodNotFoundException(s: String) : Exception(s)
|
||||||
|
|
||||||
|
internal inline fun <reified T> Iterable<T>.find(predicate: (T) -> Boolean): T? {
|
||||||
|
for (element in this) {
|
||||||
|
if (predicate(element)) {
|
||||||
|
return element
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun BytecodeData.toMethodWalker(startMethod: Method): MethodWalker {
|
||||||
|
return MethodWalker(this, startMethod)
|
||||||
|
}
|
||||||
|
|
||||||
|
internal inline fun <T> Iterable<T>.findIndexed(predicate: (T) -> Boolean): Pair<T, Int>? {
|
||||||
|
for ((index, element) in this.withIndex()) {
|
||||||
|
if (predicate(element)) {
|
||||||
|
return element to index
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun BytecodeData.proxy(classDef: ClassDef): app.revanced.patcher.util.proxy.ClassProxy {
|
||||||
|
var proxy = this.classes.proxies.find { it.immutableClass.type == classDef.type }
|
||||||
|
if (proxy == null) {
|
||||||
|
proxy = app.revanced.patcher.util.proxy.ClassProxy(classDef)
|
||||||
|
this.classes.proxies.add(proxy)
|
||||||
|
}
|
||||||
|
return proxy
|
||||||
|
}
|
@@ -0,0 +1,48 @@
|
|||||||
|
package app.revanced.patcher.data.implementation
|
||||||
|
|
||||||
|
import app.revanced.patcher.data.base.Data
|
||||||
|
import org.w3c.dom.Document
|
||||||
|
import java.io.Closeable
|
||||||
|
import java.io.File
|
||||||
|
import javax.xml.XMLConstants
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory
|
||||||
|
import javax.xml.transform.TransformerFactory
|
||||||
|
import javax.xml.transform.dom.DOMSource
|
||||||
|
import javax.xml.transform.stream.StreamResult
|
||||||
|
|
||||||
|
class ResourceData(private val resourceCacheDirectory: File) : Data {
|
||||||
|
private fun resolve(path: String) = resourceCacheDirectory.resolve(path)
|
||||||
|
|
||||||
|
fun forEach(action: (File) -> Unit) = resourceCacheDirectory.walkTopDown().forEach(action)
|
||||||
|
fun get(path: String) = resolve(path)
|
||||||
|
|
||||||
|
fun replace(path: String, oldValue: String, newValue: String, oldValueIsRegex: Boolean = false) {
|
||||||
|
// TODO: buffer this somehow
|
||||||
|
val content = resolve(path).readText()
|
||||||
|
|
||||||
|
if (oldValueIsRegex) {
|
||||||
|
content.replace(Regex(oldValue), newValue)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getXmlEditor(path: String) = DomFileEditor(resolve(path))
|
||||||
|
}
|
||||||
|
|
||||||
|
class DomFileEditor internal constructor(private val domFile: File) : Closeable {
|
||||||
|
val file: Document
|
||||||
|
|
||||||
|
init {
|
||||||
|
val factory = DocumentBuilderFactory.newInstance()
|
||||||
|
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true)
|
||||||
|
|
||||||
|
val builder = factory.newDocumentBuilder()
|
||||||
|
|
||||||
|
// this will expectedly throw
|
||||||
|
file = builder.parse(domFile)
|
||||||
|
file.normalize()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun close() = TransformerFactory.newInstance().newTransformer()
|
||||||
|
.transform(DOMSource(file), StreamResult(domFile.outputStream()))
|
||||||
|
}
|
@@ -4,54 +4,29 @@ import app.revanced.patcher.annotation.Compatibility
|
|||||||
import app.revanced.patcher.annotation.Description
|
import app.revanced.patcher.annotation.Description
|
||||||
import app.revanced.patcher.annotation.Name
|
import app.revanced.patcher.annotation.Name
|
||||||
import app.revanced.patcher.annotation.Version
|
import app.revanced.patcher.annotation.Version
|
||||||
import app.revanced.patcher.data.Data
|
import app.revanced.patcher.patch.base.Patch
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
import app.revanced.patcher.signature.implementation.method.MethodSignature
|
||||||
import app.revanced.patcher.patch.Patch
|
import app.revanced.patcher.signature.implementation.method.annotation.FuzzyPatternScanMethod
|
||||||
import kotlin.reflect.KClass
|
import app.revanced.patcher.signature.implementation.method.annotation.MatchingMethod
|
||||||
|
|
||||||
/**
|
private inline fun <reified T : Annotation> Any.firstAnnotation() =
|
||||||
* Recursively find a given annotation on a class.
|
this::class.annotations.first { it is T } as T
|
||||||
* @param targetAnnotation The annotation to find.
|
|
||||||
* @return The annotation.
|
|
||||||
*/
|
|
||||||
private fun <T : Annotation> Class<*>.recursiveAnnotation(targetAnnotation: KClass<T>) =
|
|
||||||
this.findAnnotationRecursively(targetAnnotation.java, mutableSetOf())
|
|
||||||
|
|
||||||
|
private inline fun <reified T : Annotation> Any.recursiveAnnotation() =
|
||||||
private fun <T : Annotation> Class<*>.findAnnotationRecursively(
|
this::class.java.findAnnotationRecursively(T::class.java)!!
|
||||||
targetAnnotation: Class<T>, traversed: MutableSet<Annotation>
|
|
||||||
): T? {
|
|
||||||
val found = this.annotations.firstOrNull { it.annotationClass.java.name == targetAnnotation.name }
|
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST") if (found != null) return found as T
|
|
||||||
|
|
||||||
for (annotation in this.annotations) {
|
|
||||||
if (traversed.contains(annotation)) continue
|
|
||||||
traversed.add(annotation)
|
|
||||||
|
|
||||||
return (annotation.annotationClass.java.findAnnotationRecursively(targetAnnotation, traversed)) ?: continue
|
|
||||||
}
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
object PatchExtensions {
|
object PatchExtensions {
|
||||||
val Class<out Patch<Data>>.patchName: String
|
val Patch<*>.name get() = firstAnnotation<Name>().name
|
||||||
get() = recursiveAnnotation(Name::class)?.name ?: this.javaClass.simpleName
|
val Patch<*>.version get() = firstAnnotation<Version>().version
|
||||||
val Class<out Patch<Data>>.version get() = recursiveAnnotation(Version::class)?.version
|
val Patch<*>.description get() = firstAnnotation<Description>().description
|
||||||
val Class<out Patch<Data>>.include get() = recursiveAnnotation(app.revanced.patcher.patch.annotations.Patch::class)!!.include
|
val Patch<*>.compatiblePackages get() = recursiveAnnotation<Compatibility>().compatiblePackages
|
||||||
val Class<out Patch<Data>>.description get() = recursiveAnnotation(Description::class)?.description
|
|
||||||
val Class<out Patch<Data>>.dependencies get() = recursiveAnnotation(app.revanced.patcher.patch.annotations.Dependencies::class)?.dependencies
|
|
||||||
val Class<out Patch<Data>>.compatiblePackages get() = recursiveAnnotation(Compatibility::class)?.compatiblePackages
|
|
||||||
}
|
}
|
||||||
|
|
||||||
object MethodFingerprintExtensions {
|
object MethodSignatureExtensions {
|
||||||
val MethodFingerprint.name: String
|
val MethodSignature.name get() = firstAnnotation<Name>().name
|
||||||
get() = javaClass.recursiveAnnotation(Name::class)?.name ?: this.javaClass.simpleName
|
val MethodSignature.version get() = firstAnnotation<Version>().version
|
||||||
val MethodFingerprint.version get() = javaClass.recursiveAnnotation(Version::class)?.version ?: "0.0.1"
|
val MethodSignature.description get() = firstAnnotation<Description>().description
|
||||||
val MethodFingerprint.description get() = javaClass.recursiveAnnotation(Description::class)?.description
|
val MethodSignature.compatiblePackages get() = recursiveAnnotation<Compatibility>().compatiblePackages
|
||||||
val MethodFingerprint.compatiblePackages get() = javaClass.recursiveAnnotation(Compatibility::class)?.compatiblePackages
|
val MethodSignature.matchingMethod get() = firstAnnotation<MatchingMethod>()
|
||||||
val MethodFingerprint.matchingMethod get() = javaClass.recursiveAnnotation(app.revanced.patcher.fingerprint.method.annotation.MatchingMethod::class)
|
val MethodSignature.fuzzyThreshold get() = firstAnnotation<FuzzyPatternScanMethod>().threshold
|
||||||
val MethodFingerprint.fuzzyPatternScanMethod get() = javaClass.recursiveAnnotation(app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod::class)
|
|
||||||
val MethodFingerprint.fuzzyScanThreshold get() = fuzzyPatternScanMethod?.threshold ?: 0
|
|
||||||
}
|
}
|
File diff suppressed because it is too large
Load Diff
@@ -1,9 +0,0 @@
|
|||||||
package app.revanced.patcher.fingerprint
|
|
||||||
|
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A ReVanced fingerprint.
|
|
||||||
* Can be a [MethodFingerprint].
|
|
||||||
*/
|
|
||||||
interface Fingerprint
|
|
@@ -1,98 +0,0 @@
|
|||||||
package app.revanced.patcher.fingerprint.method.impl
|
|
||||||
|
|
||||||
import app.revanced.patcher.data.impl.BytecodeData
|
|
||||||
import app.revanced.patcher.data.impl.MethodNotFoundException
|
|
||||||
import app.revanced.patcher.extensions.MethodFingerprintExtensions.name
|
|
||||||
import app.revanced.patcher.extensions.softCompareTo
|
|
||||||
import app.revanced.patcher.fingerprint.Fingerprint
|
|
||||||
import app.revanced.patcher.fingerprint.method.utils.MethodFingerprintUtils
|
|
||||||
import app.revanced.patcher.util.proxy.ClassProxy
|
|
||||||
import org.jf.dexlib2.Opcode
|
|
||||||
import org.jf.dexlib2.iface.ClassDef
|
|
||||||
import org.jf.dexlib2.iface.Method
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents the [MethodFingerprint] for a method.
|
|
||||||
* @param returnType The return type of the method.
|
|
||||||
* @param access The access flags of the method.
|
|
||||||
* @param parameters The parameters of the method.
|
|
||||||
* @param opcodes The list of opcodes of the method.
|
|
||||||
* @param strings A list of strings which a method contains.
|
|
||||||
* @param customFingerprint A custom condition for this fingerprint.
|
|
||||||
* A `null` opcode is equals to an unknown opcode.
|
|
||||||
*/
|
|
||||||
abstract class MethodFingerprint(
|
|
||||||
internal val returnType: String?,
|
|
||||||
internal val access: Int?,
|
|
||||||
internal val parameters: Iterable<String>?,
|
|
||||||
internal val opcodes: Iterable<Opcode?>?,
|
|
||||||
internal val strings: Iterable<String>? = null,
|
|
||||||
internal val customFingerprint: ((methodDef: Method) -> Boolean)? = null
|
|
||||||
) : Fingerprint {
|
|
||||||
/**
|
|
||||||
* The result of the [MethodFingerprint] the [Method].
|
|
||||||
* @throws MethodNotFoundException If the resolution of the [Method] has not happened.
|
|
||||||
*/
|
|
||||||
var result: MethodFingerprintResult? = null
|
|
||||||
get() = field ?: throw Exception("${this.name} has not been resolved yet.")
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents the result of a [MethodFingerprintUtils].
|
|
||||||
* @param method The matching method.
|
|
||||||
* @param classDef The [ClassDef] that contains the matching [method].
|
|
||||||
* @param patternScanResult Opcodes pattern scan result.
|
|
||||||
* @param data The [BytecodeData] this [MethodFingerprintResult] is attached to, to create proxies.
|
|
||||||
*/
|
|
||||||
data class MethodFingerprintResult(
|
|
||||||
val method: Method,
|
|
||||||
val classDef: ClassDef,
|
|
||||||
val patternScanResult: PatternScanResult?,
|
|
||||||
internal val data: BytecodeData
|
|
||||||
) {
|
|
||||||
/**
|
|
||||||
* Returns a mutable clone of [classDef]
|
|
||||||
*
|
|
||||||
* Please note, this method allocates a [ClassProxy].
|
|
||||||
* Use [classDef] where possible.
|
|
||||||
*/
|
|
||||||
val mutableClass by lazy { data.proxy(classDef).resolve() }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a mutable clone of [method]
|
|
||||||
*
|
|
||||||
* Please note, this method allocates a [ClassProxy].
|
|
||||||
* Use [method] where possible.
|
|
||||||
*/
|
|
||||||
val mutableMethod by lazy {
|
|
||||||
mutableClass.methods.first {
|
|
||||||
it.softCompareTo(this.method)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The result of a pattern scan.
|
|
||||||
* @param startIndex The start index of the instructions where to which this pattern matches.
|
|
||||||
* @param endIndex The end index of the instructions where to which this pattern matches.
|
|
||||||
* @param warnings A list of warnings considering this [PatternScanResult].
|
|
||||||
*/
|
|
||||||
data class PatternScanResult(
|
|
||||||
val startIndex: Int,
|
|
||||||
val endIndex: Int,
|
|
||||||
var warnings: List<Warning>? = null
|
|
||||||
) {
|
|
||||||
/**
|
|
||||||
* Represents warnings of the pattern scan.
|
|
||||||
* @param correctOpcode The opcode the instruction list has.
|
|
||||||
* @param wrongOpcode The opcode the pattern list of the signature currently has.
|
|
||||||
* @param instructionIndex The index of the opcode relative to the instruction list.
|
|
||||||
* @param patternIndex The index of the opcode relative to the pattern list from the signature.
|
|
||||||
*/
|
|
||||||
data class Warning(
|
|
||||||
val correctOpcode: Opcode,
|
|
||||||
val wrongOpcode: Opcode,
|
|
||||||
val instructionIndex: Int,
|
|
||||||
val patternIndex: Int,
|
|
||||||
)
|
|
||||||
}
|
|
@@ -1,158 +0,0 @@
|
|||||||
package app.revanced.patcher.fingerprint.method.utils
|
|
||||||
|
|
||||||
import app.revanced.patcher.data.impl.BytecodeData
|
|
||||||
import app.revanced.patcher.extensions.MethodFingerprintExtensions.fuzzyPatternScanMethod
|
|
||||||
import app.revanced.patcher.extensions.MethodFingerprintExtensions.fuzzyScanThreshold
|
|
||||||
import app.revanced.patcher.extensions.parametersEqual
|
|
||||||
import app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod
|
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprintResult
|
|
||||||
import app.revanced.patcher.fingerprint.method.impl.PatternScanResult
|
|
||||||
import org.jf.dexlib2.Opcode
|
|
||||||
import org.jf.dexlib2.iface.ClassDef
|
|
||||||
import org.jf.dexlib2.iface.Method
|
|
||||||
import org.jf.dexlib2.iface.instruction.Instruction
|
|
||||||
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
|
|
||||||
import org.jf.dexlib2.iface.reference.StringReference
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utility class for [MethodFingerprint]
|
|
||||||
*/
|
|
||||||
object MethodFingerprintUtils {
|
|
||||||
/**
|
|
||||||
* Resolve a list of [MethodFingerprint] against a list of [ClassDef].
|
|
||||||
* @param context The classes on which to resolve the [MethodFingerprint].
|
|
||||||
* @param forData The [BytecodeData] to host proxies.
|
|
||||||
* @return True if the resolution was successful, false otherwise.
|
|
||||||
*/
|
|
||||||
fun Iterable<MethodFingerprint>.resolve(forData: BytecodeData, context: Iterable<ClassDef>) {
|
|
||||||
for (fingerprint in this) // For each fingerprint
|
|
||||||
classes@ for (classDef in context) // search through all classes for the fingerprint
|
|
||||||
if (fingerprint.resolve(forData, classDef))
|
|
||||||
break@classes // if the resolution succeeded, continue with the next fingerprint
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resolve a [MethodFingerprint] against a [ClassDef].
|
|
||||||
* @param context The class on which to resolve the [MethodFingerprint].
|
|
||||||
* @param forData The [BytecodeData] to host proxies.
|
|
||||||
* @return True if the resolution was successful, false otherwise.
|
|
||||||
*/
|
|
||||||
fun MethodFingerprint.resolve(forData: BytecodeData, context: ClassDef): Boolean {
|
|
||||||
for (method in context.methods)
|
|
||||||
if (this.resolve(forData, method, context))
|
|
||||||
return true
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resolve a [MethodFingerprint] against a [Method].
|
|
||||||
* @param context The context on which to resolve the [MethodFingerprint].
|
|
||||||
* @param classDef The class of the matching [Method].
|
|
||||||
* @param forData The [BytecodeData] to host proxies.
|
|
||||||
* @return True if the resolution was successful, false otherwise.
|
|
||||||
*/
|
|
||||||
fun MethodFingerprint.resolve(forData: BytecodeData, context: Method, classDef: ClassDef): Boolean {
|
|
||||||
val methodFingerprint = this
|
|
||||||
|
|
||||||
if (methodFingerprint.returnType != null && !context.returnType.startsWith(methodFingerprint.returnType))
|
|
||||||
return false
|
|
||||||
|
|
||||||
if (methodFingerprint.access != null && methodFingerprint.access != context.accessFlags)
|
|
||||||
return false
|
|
||||||
|
|
||||||
|
|
||||||
if (methodFingerprint.parameters != null && !parametersEqual(
|
|
||||||
methodFingerprint.parameters, // TODO: parseParameters()
|
|
||||||
context.parameterTypes
|
|
||||||
)
|
|
||||||
) return false
|
|
||||||
|
|
||||||
if (methodFingerprint.customFingerprint != null && !methodFingerprint.customFingerprint!!(context))
|
|
||||||
return false
|
|
||||||
|
|
||||||
if (methodFingerprint.strings != null) {
|
|
||||||
val implementation = context.implementation ?: return false
|
|
||||||
|
|
||||||
val stringsList = methodFingerprint.strings.toMutableList()
|
|
||||||
|
|
||||||
implementation.instructions.forEach { instruction ->
|
|
||||||
if (instruction.opcode.ordinal != Opcode.CONST_STRING.ordinal) return@forEach
|
|
||||||
|
|
||||||
val string = ((instruction as ReferenceInstruction).reference as StringReference).string
|
|
||||||
val index = stringsList.indexOfFirst { it == string }
|
|
||||||
if (index != -1) stringsList.removeAt(index)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stringsList.isNotEmpty()) return false
|
|
||||||
}
|
|
||||||
|
|
||||||
val patternScanResult = if (methodFingerprint.opcodes != null) {
|
|
||||||
context.implementation?.instructions ?: return false
|
|
||||||
|
|
||||||
context.patternScan(methodFingerprint) ?: return false
|
|
||||||
} else null
|
|
||||||
|
|
||||||
methodFingerprint.result = MethodFingerprintResult(context, classDef, patternScanResult, forData)
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun Method.patternScan(
|
|
||||||
fingerprint: MethodFingerprint
|
|
||||||
): PatternScanResult? {
|
|
||||||
val instructions = this.implementation!!.instructions
|
|
||||||
val fingerprintFuzzyPatternScanThreshold = fingerprint.fuzzyScanThreshold
|
|
||||||
|
|
||||||
val pattern = fingerprint.opcodes!!
|
|
||||||
val instructionLength = instructions.count()
|
|
||||||
val patternLength = pattern.count()
|
|
||||||
|
|
||||||
for (index in 0 until instructionLength) {
|
|
||||||
var patternIndex = 0
|
|
||||||
var threshold = fingerprintFuzzyPatternScanThreshold
|
|
||||||
|
|
||||||
while (index + patternIndex < instructionLength) {
|
|
||||||
val originalOpcode = instructions.elementAt(index + patternIndex).opcode
|
|
||||||
val patternOpcode = pattern.elementAt(patternIndex)
|
|
||||||
|
|
||||||
if (patternOpcode != null && patternOpcode.ordinal != originalOpcode.ordinal) {
|
|
||||||
// reaching maximum threshold (0) means,
|
|
||||||
// the pattern does not match to the current instructions
|
|
||||||
if (threshold-- == 0) break
|
|
||||||
}
|
|
||||||
|
|
||||||
if (patternIndex < patternLength - 1) {
|
|
||||||
// if the entire pattern has not been scanned yet
|
|
||||||
// continue the scan
|
|
||||||
patternIndex++
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// the pattern is valid, generate warnings if fuzzyPatternScanMethod is FuzzyPatternScanMethod
|
|
||||||
val result = PatternScanResult(index, index + patternIndex)
|
|
||||||
if (fingerprint.fuzzyPatternScanMethod !is FuzzyPatternScanMethod) return result
|
|
||||||
result.warnings = result.createWarnings(pattern, instructions)
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun PatternScanResult.createWarnings(
|
|
||||||
pattern: Iterable<Opcode?>, instructions: Iterable<Instruction>
|
|
||||||
) = buildList {
|
|
||||||
for ((patternIndex, instructionIndex) in (this@createWarnings.startIndex until this@createWarnings.endIndex).withIndex()) {
|
|
||||||
val originalOpcode = instructions.elementAt(instructionIndex).opcode
|
|
||||||
val patternOpcode = pattern.elementAt(patternIndex)
|
|
||||||
|
|
||||||
if (patternOpcode == null || patternOpcode.ordinal == originalOpcode.ordinal) continue
|
|
||||||
|
|
||||||
this.add(PatternScanResult.Warning(originalOpcode, patternOpcode, instructionIndex, patternIndex))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private operator fun ClassDef.component1() = this
|
|
||||||
private operator fun ClassDef.component2() = this.methods
|
|
@@ -1,8 +0,0 @@
|
|||||||
package app.revanced.patcher.logging
|
|
||||||
|
|
||||||
interface Logger {
|
|
||||||
fun error(msg: String) {}
|
|
||||||
fun warn(msg: String) {}
|
|
||||||
fun info(msg: String) {}
|
|
||||||
fun trace(msg: String) {}
|
|
||||||
}
|
|
@@ -1,5 +0,0 @@
|
|||||||
package app.revanced.patcher.logging.impl
|
|
||||||
|
|
||||||
import app.revanced.patcher.logging.Logger
|
|
||||||
|
|
||||||
object NopLogger : Logger
|
|
@@ -1,18 +0,0 @@
|
|||||||
package app.revanced.patcher.patch
|
|
||||||
|
|
||||||
import app.revanced.patcher.data.Data
|
|
||||||
import app.revanced.patcher.patch.impl.BytecodePatch
|
|
||||||
import app.revanced.patcher.patch.impl.ResourcePatch
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A ReVanced patch.
|
|
||||||
* Can either be a [ResourcePatch] or a [BytecodePatch].
|
|
||||||
*/
|
|
||||||
abstract class Patch<out T : Data> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The main function of the [Patch] which the patcher will call.
|
|
||||||
*/
|
|
||||||
abstract fun execute(data: @UnsafeVariance T): PatchResult
|
|
||||||
}
|
|
@@ -1,24 +1,9 @@
|
|||||||
package app.revanced.patcher.patch.annotations
|
package app.revanced.patcher.patch.annotations
|
||||||
|
|
||||||
import app.revanced.patcher.data.Data
|
|
||||||
import app.revanced.patcher.patch.Patch
|
|
||||||
import kotlin.reflect.KClass
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Annotation to mark a Class as a patch.
|
* Annotation to mark a Class as a patch.
|
||||||
* @param include If false, the patch should be treated as optional by default.
|
|
||||||
*/
|
*/
|
||||||
@Target(AnnotationTarget.CLASS)
|
@Target(AnnotationTarget.CLASS)
|
||||||
@Retention(AnnotationRetention.RUNTIME)
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
@MustBeDocumented
|
@MustBeDocumented
|
||||||
annotation class Patch(val include: Boolean = true)
|
annotation class Patch
|
||||||
|
|
||||||
/**
|
|
||||||
* Annotation for dependencies of [Patch]es .
|
|
||||||
*/
|
|
||||||
@Target(AnnotationTarget.CLASS)
|
|
||||||
@Retention(AnnotationRetention.RUNTIME)
|
|
||||||
@MustBeDocumented
|
|
||||||
annotation class Dependencies(
|
|
||||||
val dependencies: Array<KClass<out Patch<Data>>> = []
|
|
||||||
)
|
|
18
src/main/kotlin/app/revanced/patcher/patch/base/Patch.kt
Normal file
18
src/main/kotlin/app/revanced/patcher/patch/base/Patch.kt
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package app.revanced.patcher.patch.base
|
||||||
|
|
||||||
|
import app.revanced.patcher.data.base.Data
|
||||||
|
import app.revanced.patcher.patch.implementation.BytecodePatch
|
||||||
|
import app.revanced.patcher.patch.implementation.ResourcePatch
|
||||||
|
import app.revanced.patcher.patch.implementation.misc.PatchResult
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A ReVanced patch.
|
||||||
|
* Can either be a [ResourcePatch] or a [BytecodePatch].
|
||||||
|
*/
|
||||||
|
abstract class Patch<out T : Data> {
|
||||||
|
/**
|
||||||
|
* The main function of the [Patch] which the patcher will call.
|
||||||
|
*/
|
||||||
|
abstract fun execute(data: @UnsafeVariance T): PatchResult // FIXME: remove the UnsafeVariance annotation
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user