mirror of
https://github.com/ReVanced/revanced-patcher.git
synced 2026-01-20 09:53:55 +00:00
Compare commits
66 Commits
arsclib-re
...
v14.2.0-de
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
86db64edff | ||
|
|
983563efb6 | ||
|
|
37abb2db99 | ||
|
|
5ba0b47e60 | ||
|
|
e8f2087a6f | ||
|
|
6ce99f5cdf | ||
|
|
13c0c9cdd3 | ||
|
|
58ffdb60d7 | ||
|
|
ba56a6a2ee | ||
|
|
ccccf5b1d2 | ||
|
|
b507ac0a54 | ||
|
|
e985676c2d | ||
|
|
f7f4ba6c55 | ||
|
|
4292f43814 | ||
|
|
30bd4fd9fe | ||
|
|
76de39369d | ||
|
|
88a703ce36 | ||
|
|
5938f6b7ea | ||
|
|
5c0c0d6c37 | ||
|
|
0f15077225 | ||
|
|
273dd8d388 | ||
|
|
1795f376ef | ||
|
|
e7360a7692 | ||
|
|
e1fc86934f | ||
|
|
6b8977f178 | ||
|
|
12c6c73de0 | ||
|
|
db62a1607b | ||
|
|
58bb879ef5 | ||
|
|
254912438a | ||
|
|
0e48918bcc | ||
|
|
783ccf8529 | ||
|
|
8fb2f2dc1d | ||
|
|
2a8cc283c7 | ||
|
|
433fe3af9f | ||
|
|
c2d89c622e | ||
|
|
02d6ff15fe | ||
|
|
f2cb7ee7df | ||
|
|
a2ac44dcc1 | ||
|
|
3cf9d74efa | ||
|
|
d5f89a903f | ||
|
|
496c2242bc | ||
|
|
98fbff87df | ||
|
|
ddb51a1c45 | ||
|
|
8df1155215 | ||
|
|
53f2a61409 | ||
|
|
746544f9d5 | ||
|
|
c65c3df11c | ||
|
|
b29b8f12b3 | ||
|
|
d6945677c4 | ||
|
|
aedf4aea08 | ||
|
|
dc28d414dc | ||
|
|
9755bab298 | ||
|
|
fae4029cfc | ||
|
|
1790f0d706 | ||
|
|
0ba2c51676 | ||
|
|
03cd97b49c | ||
|
|
16a162c1dd | ||
|
|
c9bbcf2bf2 | ||
|
|
86e1bf6078 | ||
|
|
1bca84ef0b | ||
|
|
e0f8e1b71a | ||
|
|
416d69142f | ||
|
|
426807aeaa | ||
|
|
90cb075a97 | ||
|
|
ac2ca8fbd3 | ||
|
|
69e4a49065 |
@@ -7,7 +7,13 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"plugins": [
|
"plugins": [
|
||||||
"@semantic-release/commit-analyzer",
|
[
|
||||||
|
"@semantic-release/commit-analyzer", {
|
||||||
|
"releaseRules": [
|
||||||
|
{ "type": "build", "scope": "Needs bump", "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",
|
||||||
|
|||||||
224
CHANGELOG.md
224
CHANGELOG.md
@@ -1,3 +1,227 @@
|
|||||||
|
# [14.2.0-dev.2](https://github.com/ReVanced/revanced-patcher/compare/v14.2.0-dev.1...v14.2.0-dev.2) (2023-08-26)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* log when merging integrations ([983563e](https://github.com/ReVanced/revanced-patcher/commit/983563efb6d7c8d289464b8bf71a016b8a735630))
|
||||||
|
|
||||||
|
# [14.2.0-dev.1](https://github.com/ReVanced/revanced-patcher/compare/v14.1.0...v14.2.0-dev.1) (2023-08-25)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* load patches in lexicographical order ([e8f2087](https://github.com/ReVanced/revanced-patcher/commit/e8f2087a6ffa6077fb3a6a69e29f3aec72e2fc1b))
|
||||||
|
|
||||||
|
# [14.1.0](https://github.com/ReVanced/revanced-patcher/compare/v14.0.0...v14.1.0) (2023-08-24)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* move version properties file to correct package ([e985676](https://github.com/ReVanced/revanced-patcher/commit/e985676c2d8e5d6cb907d371de30428caaa6da43))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* properly make use of logging facade ([ba56a6a](https://github.com/ReVanced/revanced-patcher/commit/ba56a6a2eef503c0d6cdd846ddce2e1474d8ed1a))
|
||||||
|
|
||||||
|
# [14.1.0-dev.1](https://github.com/ReVanced/revanced-patcher/compare/v14.0.1-dev.1...v14.1.0-dev.1) (2023-08-24)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* properly make use of logging facade ([ba56a6a](https://github.com/ReVanced/revanced-patcher/commit/ba56a6a2eef503c0d6cdd846ddce2e1474d8ed1a))
|
||||||
|
|
||||||
|
## [14.0.1-dev.1](https://github.com/ReVanced/revanced-patcher/compare/v14.0.0...v14.0.1-dev.1) (2023-08-23)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* move version properties file to correct package ([e985676](https://github.com/ReVanced/revanced-patcher/commit/e985676c2d8e5d6cb907d371de30428caaa6da43))
|
||||||
|
|
||||||
|
# [14.0.0](https://github.com/ReVanced/revanced-patcher/compare/v13.0.0...v14.0.0) (2023-08-22)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* log decoding resources after logging deleting resource cache directory ([db62a16](https://github.com/ReVanced/revanced-patcher/commit/db62a1607b4a9d6256b5f5153decb088d9680553))
|
||||||
|
* only emit closed patches that did not throw an exception with the `@Patch` annotation ([5938f6b](https://github.com/ReVanced/revanced-patcher/commit/5938f6b7ea25103a0a1b56ceebe49139bc80c6f5))
|
||||||
|
* supply the parent classloader to `DexClassLoader` ([0f15077](https://github.com/ReVanced/revanced-patcher/commit/0f15077225600b65200022c1a318e504deb472b9))
|
||||||
|
|
||||||
|
|
||||||
|
### Code Refactoring
|
||||||
|
|
||||||
|
* improve structure and public API ([6b8977f](https://github.com/ReVanced/revanced-patcher/commit/6b8977f17854ef0344d868e6391cb18134eceadc))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* do not log instantiation of ReVanced Patcher ([273dd8d](https://github.com/ReVanced/revanced-patcher/commit/273dd8d388f8e9b7436c6d6145a94c12c1fabe55))
|
||||||
|
|
||||||
|
|
||||||
|
### BREAKING CHANGES
|
||||||
|
|
||||||
|
* Various public APIs have been changed. The `Version` annotation has been removed. Patches do not return anything anymore and instead throw `PatchException`. Multiple patch bundles can now be loaded in a single ClassLoader to bypass class loader isolation.
|
||||||
|
|
||||||
|
# [14.0.0-dev.4](https://github.com/ReVanced/revanced-patcher/compare/v14.0.0-dev.3...v14.0.0-dev.4) (2023-08-22)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* only emit closed patches that did not throw an exception with the `@Patch` annotation ([5938f6b](https://github.com/ReVanced/revanced-patcher/commit/5938f6b7ea25103a0a1b56ceebe49139bc80c6f5))
|
||||||
|
|
||||||
|
# [14.0.0-dev.3](https://github.com/ReVanced/revanced-patcher/compare/v14.0.0-dev.2...v14.0.0-dev.3) (2023-08-20)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* supply the parent classloader to `DexClassLoader` ([0f15077](https://github.com/ReVanced/revanced-patcher/commit/0f15077225600b65200022c1a318e504deb472b9))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* do not log instantiation of ReVanced Patcher ([273dd8d](https://github.com/ReVanced/revanced-patcher/commit/273dd8d388f8e9b7436c6d6145a94c12c1fabe55))
|
||||||
|
|
||||||
|
# [14.0.0-dev.2](https://github.com/ReVanced/revanced-patcher/compare/v14.0.0-dev.1...v14.0.0-dev.2) (2023-08-19)
|
||||||
|
|
||||||
|
# [14.0.0-dev.1](https://github.com/ReVanced/revanced-patcher/compare/v13.0.0...v14.0.0-dev.1) (2023-08-18)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* log decoding resources after logging deleting resource cache directory ([db62a16](https://github.com/ReVanced/revanced-patcher/commit/db62a1607b4a9d6256b5f5153decb088d9680553))
|
||||||
|
|
||||||
|
|
||||||
|
### Code Refactoring
|
||||||
|
|
||||||
|
* improve structure and public API ([6b8977f](https://github.com/ReVanced/revanced-patcher/commit/6b8977f17854ef0344d868e6391cb18134eceadc))
|
||||||
|
|
||||||
|
|
||||||
|
### BREAKING CHANGES
|
||||||
|
|
||||||
|
* Various public APIs have been changed. The `Version` annotation has been removed. Patches do not return anything anymore and instead throw `PatchException`. Multiple patch bundles can now be loaded in a single ClassLoader to bypass class loader isolation.
|
||||||
|
|
||||||
|
# [13.0.0](https://github.com/ReVanced/revanced-patcher/compare/v12.1.1...v13.0.0) (2023-08-14)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* decode in correct order ([8fb2f2d](https://github.com/ReVanced/revanced-patcher/commit/8fb2f2dc1d3b9b1e9fd13b39485985d2886d52ae))
|
||||||
|
* disable correct loggers ([c2d89c6](https://github.com/ReVanced/revanced-patcher/commit/c2d89c622e06e58e5042e1a00ef67cee8a246e53))
|
||||||
|
* get framework ids to compile resources ([f2cb7ee](https://github.com/ReVanced/revanced-patcher/commit/f2cb7ee7dffa573c31df497cf235a3f5d120f91f))
|
||||||
|
* only enable logging for ReVanced ([783ccf8](https://github.com/ReVanced/revanced-patcher/commit/783ccf8529f5d16aa463982da6977328306232bb))
|
||||||
|
* set package metadata correctly ([02d6ff1](https://github.com/ReVanced/revanced-patcher/commit/02d6ff15fe87c2352de29749610e9d72db8ba418))
|
||||||
|
|
||||||
|
|
||||||
|
* build(Needs bump)!: Bump dependencies ([d5f89a9](https://github.com/ReVanced/revanced-patcher/commit/d5f89a903f019c199bdb27a50287124fc4b4978e))
|
||||||
|
|
||||||
|
|
||||||
|
### BREAKING CHANGES
|
||||||
|
|
||||||
|
* This bump updates smali, a crucial dependency
|
||||||
|
|
||||||
|
# [13.0.0-dev.3](https://github.com/ReVanced/revanced-patcher/compare/v13.0.0-dev.2...v13.0.0-dev.3) (2023-08-14)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* decode in correct order ([8fb2f2d](https://github.com/ReVanced/revanced-patcher/commit/8fb2f2dc1d3b9b1e9fd13b39485985d2886d52ae))
|
||||||
|
* only enable logging for ReVanced ([783ccf8](https://github.com/ReVanced/revanced-patcher/commit/783ccf8529f5d16aa463982da6977328306232bb))
|
||||||
|
|
||||||
|
# [13.0.0-dev.2](https://github.com/ReVanced/revanced-patcher/compare/v13.0.0-dev.1...v13.0.0-dev.2) (2023-08-12)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* disable correct loggers ([c2d89c6](https://github.com/ReVanced/revanced-patcher/commit/c2d89c622e06e58e5042e1a00ef67cee8a246e53))
|
||||||
|
* get framework ids to compile resources ([f2cb7ee](https://github.com/ReVanced/revanced-patcher/commit/f2cb7ee7dffa573c31df497cf235a3f5d120f91f))
|
||||||
|
* set package metadata correctly ([02d6ff1](https://github.com/ReVanced/revanced-patcher/commit/02d6ff15fe87c2352de29749610e9d72db8ba418))
|
||||||
|
|
||||||
|
# [13.0.0-dev.1](https://github.com/ReVanced/revanced-patcher/compare/v12.1.1...v13.0.0-dev.1) (2023-08-11)
|
||||||
|
|
||||||
|
|
||||||
|
* build(Needs bump)!: Bump dependencies ([d5f89a9](https://github.com/ReVanced/revanced-patcher/commit/d5f89a903f019c199bdb27a50287124fc4b4978e))
|
||||||
|
|
||||||
|
|
||||||
|
### BREAKING CHANGES
|
||||||
|
|
||||||
|
* This bump updates smali, a crucial dependency
|
||||||
|
|
||||||
|
## [12.1.1](https://github.com/ReVanced/revanced-patcher/compare/v12.1.0...v12.1.1) (2023-08-03)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* clear method lookup maps before initializing them ([#210](https://github.com/ReVanced/revanced-patcher/issues/210)) ([746544f](https://github.com/ReVanced/revanced-patcher/commit/746544f9d51d1013bb160075709cd26bffd425b3))
|
||||||
|
|
||||||
|
## [12.1.1-dev.2](https://github.com/ReVanced/revanced-patcher/compare/v12.1.1-dev.1...v12.1.1-dev.2) (2023-08-03)
|
||||||
|
|
||||||
|
## [12.1.1-dev.1](https://github.com/ReVanced/revanced-patcher/compare/v12.1.0...v12.1.1-dev.1) (2023-08-03)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* clear method lookup maps before initializing them ([#210](https://github.com/ReVanced/revanced-patcher/issues/210)) ([746544f](https://github.com/ReVanced/revanced-patcher/commit/746544f9d51d1013bb160075709cd26bffd425b3))
|
||||||
|
|
||||||
|
# [12.1.0](https://github.com/ReVanced/revanced-patcher/compare/v12.0.0...v12.1.0) (2023-08-03)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add `MutableMethod.getInstructions` extension function ([fae4029](https://github.com/ReVanced/revanced-patcher/commit/fae4029cfccfad7aa3dd8f7fbef1c63ee26b85b3))
|
||||||
|
|
||||||
|
# [12.1.0-dev.2](https://github.com/ReVanced/revanced-patcher/compare/v12.1.0-dev.1...v12.1.0-dev.2) (2023-08-03)
|
||||||
|
|
||||||
|
# [12.1.0-dev.1](https://github.com/ReVanced/revanced-patcher/compare/v12.0.0...v12.1.0-dev.1) (2023-08-01)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add `MutableMethod.getInstructions` extension function ([fae4029](https://github.com/ReVanced/revanced-patcher/commit/fae4029cfccfad7aa3dd8f7fbef1c63ee26b85b3))
|
||||||
|
|
||||||
|
# [12.0.0](https://github.com/ReVanced/revanced-patcher/compare/v11.0.4...v12.0.0) (2023-07-30)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* correct access flags of `PackageMetadata` ([416d691](https://github.com/ReVanced/revanced-patcher/commit/416d69142f50dab49c9ea3f027e9d53e4777f257))
|
||||||
|
* set resource table via resource decoder ([e0f8e1b](https://github.com/ReVanced/revanced-patcher/commit/e0f8e1b71a295948b610029c89a48f52762396b6))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* Deprecate `Version` annotation ([c9bbcf2](https://github.com/ReVanced/revanced-patcher/commit/c9bbcf2bf2b0f50ab9100380a3a66c6346ad42ac))
|
||||||
|
* remove `Path` option ([#202](https://github.com/ReVanced/revanced-patcher/issues/202)) ([69e4a49](https://github.com/ReVanced/revanced-patcher/commit/69e4a490659ebc4fb4bf46148634f4b064ef1713))
|
||||||
|
|
||||||
|
|
||||||
|
### BREAKING CHANGES
|
||||||
|
|
||||||
|
* This removes the previously available `Path` option
|
||||||
|
|
||||||
|
# [12.0.0-dev.2](https://github.com/ReVanced/revanced-patcher/compare/v12.0.0-dev.1...v12.0.0-dev.2) (2023-07-28)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* Deprecate `Version` annotation ([400442f](https://github.com/ReVanced/revanced-patcher/commit/400442f70ee56cafd4493b2ce64a294db9836509))
|
||||||
|
|
||||||
|
# [12.0.0-dev.1](https://github.com/ReVanced/revanced-patcher/compare/v11.0.4...v12.0.0-dev.1) (2023-07-26)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* correct access flags of `PackageMetadata` ([416d691](https://github.com/ReVanced/revanced-patcher/commit/416d69142f50dab49c9ea3f027e9d53e4777f257))
|
||||||
|
* set resource table via resource decoder ([e0f8e1b](https://github.com/ReVanced/revanced-patcher/commit/e0f8e1b71a295948b610029c89a48f52762396b6))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* remove `Path` option ([#202](https://github.com/ReVanced/revanced-patcher/issues/202)) ([69e4a49](https://github.com/ReVanced/revanced-patcher/commit/69e4a490659ebc4fb4bf46148634f4b064ef1713))
|
||||||
|
|
||||||
|
|
||||||
|
### BREAKING CHANGES
|
||||||
|
|
||||||
|
* This removes the previously available `Path` option
|
||||||
|
|
||||||
## [11.0.4](https://github.com/revanced/revanced-patcher/compare/v11.0.3...v11.0.4) (2023-07-01)
|
## [11.0.4](https://github.com/revanced/revanced-patcher/compare/v11.0.3...v11.0.4) (2023-07-01)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
42
arsclib-utils/.gitignore
vendored
42
arsclib-utils/.gitignore
vendored
@@ -1,42 +0,0 @@
|
|||||||
.gradle
|
|
||||||
build/
|
|
||||||
!gradle/wrapper/gradle-wrapper.jar
|
|
||||||
!**/src/main/**/build/
|
|
||||||
!**/src/test/**/build/
|
|
||||||
|
|
||||||
### IntelliJ IDEA ###
|
|
||||||
.idea/modules.xml
|
|
||||||
.idea/jarRepositories.xml
|
|
||||||
.idea/compiler.xml
|
|
||||||
.idea/libraries/
|
|
||||||
*.iws
|
|
||||||
*.iml
|
|
||||||
*.ipr
|
|
||||||
out/
|
|
||||||
!**/src/main/**/out/
|
|
||||||
!**/src/test/**/out/
|
|
||||||
|
|
||||||
### Eclipse ###
|
|
||||||
.apt_generated
|
|
||||||
.classpath
|
|
||||||
.factorypath
|
|
||||||
.project
|
|
||||||
.settings
|
|
||||||
.springBeans
|
|
||||||
.sts4-cache
|
|
||||||
bin/
|
|
||||||
!**/src/main/**/bin/
|
|
||||||
!**/src/test/**/bin/
|
|
||||||
|
|
||||||
### NetBeans ###
|
|
||||||
/nbproject/private/
|
|
||||||
/nbbuild/
|
|
||||||
/dist/
|
|
||||||
/nbdist/
|
|
||||||
/.nb-gradle/
|
|
||||||
|
|
||||||
### VS Code ###
|
|
||||||
.vscode/
|
|
||||||
|
|
||||||
### Mac OS ###
|
|
||||||
.DS_Store
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
plugins {
|
|
||||||
kotlin("jvm")
|
|
||||||
`maven-publish`
|
|
||||||
}
|
|
||||||
|
|
||||||
group = "app.revanced"
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation("io.github.reandroid:ARSCLib:1.1.7")
|
|
||||||
}
|
|
||||||
|
|
||||||
java {
|
|
||||||
withSourcesJar()
|
|
||||||
}
|
|
||||||
|
|
||||||
kotlin {
|
|
||||||
jvmToolchain(11)
|
|
||||||
}
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
package app.revanced.arsc
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An exception thrown when there is an error with APK resources.
|
|
||||||
*
|
|
||||||
* @param message The exception message.
|
|
||||||
* @param throwable The corresponding [Throwable].
|
|
||||||
*/
|
|
||||||
sealed class ApkResourceException(message: String, throwable: Throwable? = null) : Exception(message, throwable) {
|
|
||||||
/**
|
|
||||||
* An exception when locking resources.
|
|
||||||
*
|
|
||||||
* @param message The exception message.
|
|
||||||
* @param throwable The corresponding [Throwable].
|
|
||||||
*/
|
|
||||||
class Locked(message: String, throwable: Throwable? = null) : ApkResourceException(message, throwable)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An exception when writing resources.
|
|
||||||
*
|
|
||||||
* @param message The exception message.
|
|
||||||
* @param throwable The corresponding [Throwable].
|
|
||||||
*/
|
|
||||||
class Write(message: String, throwable: Throwable? = null) : ApkResourceException(message, throwable)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An exception when reading resources.
|
|
||||||
*
|
|
||||||
* @param message The exception message.
|
|
||||||
* @param throwable The corresponding [Throwable].
|
|
||||||
*/
|
|
||||||
class Read(message: String, throwable: Throwable? = null) : ApkResourceException(message, throwable)
|
|
||||||
/**
|
|
||||||
* An exception when decoding resources.
|
|
||||||
*
|
|
||||||
* @param message The exception message.
|
|
||||||
* @param throwable The corresponding [Throwable].
|
|
||||||
*/
|
|
||||||
class Decode(message: String, throwable: Throwable? = null) : ApkResourceException(message, throwable)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An exception when encoding resources.
|
|
||||||
*
|
|
||||||
* @param message The exception message.
|
|
||||||
* @param throwable The corresponding [Throwable].
|
|
||||||
*/
|
|
||||||
class Encode(message: String, throwable: Throwable? = null) : ApkResourceException(message, throwable)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An exception thrown when a reference could not be resolved.
|
|
||||||
*
|
|
||||||
* @param reference The invalid reference.
|
|
||||||
* @param throwable The corresponding [Throwable].
|
|
||||||
*/
|
|
||||||
class InvalidReference(reference: String, throwable: Throwable? = null) :
|
|
||||||
ApkResourceException("Failed to resolve: $reference", throwable) {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An exception thrown when a reference could not be resolved.
|
|
||||||
*
|
|
||||||
* @param type The type of the reference.
|
|
||||||
* @param name The name of the reference.
|
|
||||||
* @param throwable The corresponding [Throwable].
|
|
||||||
*/
|
|
||||||
constructor(type: String, name: String, throwable: Throwable? = null) : this("@$type/$name", throwable)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An exception thrown when the Apk file not have a resource table, but was expected to have one.
|
|
||||||
*/
|
|
||||||
class MissingResourceTable : ApkResourceException("Apk does not have a resource table.")
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
@file:Suppress("MemberVisibilityCanBePrivate")
|
|
||||||
|
|
||||||
package app.revanced.arsc.archive
|
|
||||||
|
|
||||||
import app.revanced.arsc.resource.ResourceContainer
|
|
||||||
import com.reandroid.apk.ApkModule
|
|
||||||
import com.reandroid.apk.DexFileInputSource
|
|
||||||
import com.reandroid.archive.InputSource
|
|
||||||
import java.io.File
|
|
||||||
import java.io.Flushable
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A class for reading/writing files in an [ApkModule].
|
|
||||||
*
|
|
||||||
* @param module The [ApkModule] to operate on.
|
|
||||||
*/
|
|
||||||
class Archive(internal val module: ApkModule) : Flushable {
|
|
||||||
val mainPackageResources = ResourceContainer(this, module.tableBlock)
|
|
||||||
|
|
||||||
fun save(output: File) {
|
|
||||||
flush()
|
|
||||||
module.writeApk(output)
|
|
||||||
}
|
|
||||||
fun readDexFiles(): MutableList<DexFileInputSource> = module.listDexFiles()
|
|
||||||
fun write(inputSource: InputSource) = module.apkArchive.add(inputSource) // Overwrites existing files.
|
|
||||||
fun read(name: String): InputSource? = module.apkArchive.getInputSource(name)
|
|
||||||
override fun flush() = mainPackageResources.flush()
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package app.revanced.arsc.logging
|
|
||||||
interface Logger {
|
|
||||||
fun error(msg: String)
|
|
||||||
fun warn(msg: String)
|
|
||||||
fun info(msg: String)
|
|
||||||
fun trace(msg: String)
|
|
||||||
}
|
|
||||||
@@ -1,166 +0,0 @@
|
|||||||
package app.revanced.arsc.resource
|
|
||||||
|
|
||||||
import app.revanced.arsc.ApkResourceException
|
|
||||||
import com.reandroid.arsc.coder.EncodeResult
|
|
||||||
import com.reandroid.arsc.coder.ValueDecoder
|
|
||||||
import com.reandroid.arsc.value.Entry
|
|
||||||
import com.reandroid.arsc.value.ValueType
|
|
||||||
import com.reandroid.arsc.value.array.ArrayBag
|
|
||||||
import com.reandroid.arsc.value.array.ArrayBagItem
|
|
||||||
import com.reandroid.arsc.value.plurals.PluralsBag
|
|
||||||
import com.reandroid.arsc.value.plurals.PluralsBagItem
|
|
||||||
import com.reandroid.arsc.value.plurals.PluralsQuantity
|
|
||||||
import com.reandroid.arsc.value.style.StyleBag
|
|
||||||
import com.reandroid.arsc.value.style.StyleBagItem
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A resource value.
|
|
||||||
*/
|
|
||||||
sealed class Resource {
|
|
||||||
internal abstract fun write(entry: Entry, resources: ResourceContainer)
|
|
||||||
}
|
|
||||||
|
|
||||||
internal val Resource.isComplex get() = when (this) {
|
|
||||||
is Scalar -> false
|
|
||||||
is Complex -> true
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A simple resource.
|
|
||||||
*/
|
|
||||||
open class Scalar internal constructor(private val valueType: ValueType, private val value: Int) : Resource() {
|
|
||||||
protected open fun data(resources: ResourceContainer) = value
|
|
||||||
|
|
||||||
override fun write(entry: Entry, resources: ResourceContainer) {
|
|
||||||
entry.setValueAsRaw(valueType, data(resources))
|
|
||||||
}
|
|
||||||
|
|
||||||
internal open fun toArrayItem(resources: ResourceContainer) = ArrayBagItem.create(valueType, data(resources))
|
|
||||||
internal open fun toStyleItem(resources: ResourceContainer) = StyleBagItem.create(valueType, data(resources))
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A marker class for complex resources.
|
|
||||||
*/
|
|
||||||
sealed class Complex : Resource()
|
|
||||||
|
|
||||||
private fun encoded(encodeResult: EncodeResult?) = encodeResult?.let { Scalar(it.valueType, it.value) }
|
|
||||||
?: throw ApkResourceException.Encode("Failed to encode value")
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Encode a color.
|
|
||||||
*
|
|
||||||
* @param hex The hex value of the color.
|
|
||||||
* @return The encoded [Resource].
|
|
||||||
*/
|
|
||||||
fun color(hex: String) = encoded(ValueDecoder.encodeColor(hex))
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Encode a dimension or fraction.
|
|
||||||
*
|
|
||||||
* @param value The dimension value such as 24dp.
|
|
||||||
* @return The encoded [Resource].
|
|
||||||
*/
|
|
||||||
fun dimension(value: String) = encoded(ValueDecoder.encodeDimensionOrFraction(value))
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Encode a boolean resource.
|
|
||||||
*
|
|
||||||
* @param value The boolean.
|
|
||||||
* @return The encoded [Resource].
|
|
||||||
*/
|
|
||||||
fun boolean(value: Boolean) = Scalar(ValueType.INT_BOOLEAN, if (value) -Int.MAX_VALUE else 0)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Encode a float.
|
|
||||||
*
|
|
||||||
* @param n The number to encode.
|
|
||||||
* @return The encoded [Resource].
|
|
||||||
*/
|
|
||||||
fun float(n: Float) = Scalar(ValueType.FLOAT, n.toBits())
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an integer [Resource].
|
|
||||||
*
|
|
||||||
* @param n The number to encode.
|
|
||||||
* @return The integer [Resource].
|
|
||||||
*/
|
|
||||||
fun integer(n: Int) = Scalar(ValueType.INT_DEC, n)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a reference [Resource].
|
|
||||||
*
|
|
||||||
* @param resourceId The target resource.
|
|
||||||
* @return The reference resource.
|
|
||||||
*/
|
|
||||||
fun reference(resourceId: Int) = Scalar(ValueType.REFERENCE, resourceId)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resolve and create a reference [Resource].
|
|
||||||
*
|
|
||||||
* @see reference
|
|
||||||
* @param ref The reference string to resolve.
|
|
||||||
* @param resourceTable The resource table to resolve the reference with.
|
|
||||||
* @return The reference resource.
|
|
||||||
*/
|
|
||||||
fun reference(resourceTable: ResourceTable, ref: String) = reference(resourceTable.resolve(ref))
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An array [Resource].
|
|
||||||
*
|
|
||||||
* @param elements The elements of the array.
|
|
||||||
*/
|
|
||||||
class Array(private val elements: Collection<Scalar>) : Complex() {
|
|
||||||
override fun write(entry: Entry, resources: ResourceContainer) {
|
|
||||||
ArrayBag.create(entry).addAll(elements.map { it.toArrayItem(resources) })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A style resource.
|
|
||||||
*
|
|
||||||
* @param elements The attributes to override.
|
|
||||||
* @param parent A reference to the parent style.
|
|
||||||
*/
|
|
||||||
class Style(private val elements: Map<String, Scalar>, private val parent: String? = null) : Complex() {
|
|
||||||
override fun write(entry: Entry, resources: ResourceContainer) {
|
|
||||||
val resTable = resources.resourceTable
|
|
||||||
val style = StyleBag.create(entry)
|
|
||||||
parent?.let {
|
|
||||||
style.parentId = resTable.resolve(parent)
|
|
||||||
}
|
|
||||||
|
|
||||||
style.putAll(
|
|
||||||
elements.asIterable().associate {
|
|
||||||
StyleBag.resolve(resTable.encodeMaterials, it.key) to it.value.toStyleItem(resources)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A quantity string [Resource].
|
|
||||||
*
|
|
||||||
* @param elements A map of the quantity to the corresponding string.
|
|
||||||
*/
|
|
||||||
class Plurals(private val elements: Map<String, String>) : Complex() {
|
|
||||||
override fun write(entry: Entry, resources: ResourceContainer) {
|
|
||||||
val plurals = PluralsBag.create(entry)
|
|
||||||
|
|
||||||
plurals.putAll(elements.asIterable().associate { (k, v) ->
|
|
||||||
PluralsQuantity.value(k) to PluralsBagItem.string(resources.getOrCreateString(v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A string [Resource].
|
|
||||||
*
|
|
||||||
* @param value The string value.
|
|
||||||
*/
|
|
||||||
class StringResource(val value: String) : Scalar(ValueType.STRING, 0) {
|
|
||||||
private fun tableString(resources: ResourceContainer) = resources.getOrCreateString(value)
|
|
||||||
|
|
||||||
override fun data(resources: ResourceContainer) = tableString(resources).index
|
|
||||||
override fun toArrayItem(resources: ResourceContainer) = ArrayBagItem.string(tableString(resources))
|
|
||||||
override fun toStyleItem(resources: ResourceContainer) = StyleBagItem.string(tableString(resources))
|
|
||||||
}
|
|
||||||
@@ -1,167 +0,0 @@
|
|||||||
package app.revanced.arsc.resource
|
|
||||||
|
|
||||||
import app.revanced.arsc.ApkResourceException
|
|
||||||
import app.revanced.arsc.archive.Archive
|
|
||||||
import com.reandroid.apk.xmlencoder.EncodeUtil
|
|
||||||
import com.reandroid.arsc.chunk.TableBlock
|
|
||||||
import com.reandroid.arsc.chunk.xml.ResXmlDocument
|
|
||||||
import com.reandroid.arsc.value.Entry
|
|
||||||
import com.reandroid.arsc.value.ResConfig
|
|
||||||
import java.io.Closeable
|
|
||||||
import java.io.File
|
|
||||||
import java.io.Flushable
|
|
||||||
|
|
||||||
class ResourceContainer(private val archive: Archive, internal val tableBlock: TableBlock) : Flushable {
|
|
||||||
private val packageBlock = tableBlock.pickOne() // Pick the main package block.
|
|
||||||
internal lateinit var resourceTable: ResourceTable // TODO: Set this.
|
|
||||||
|
|
||||||
private val lockedResourceFileNames = mutableSetOf<String>()
|
|
||||||
|
|
||||||
private fun lock(resourceFile: ResourceFile) {
|
|
||||||
if (resourceFile.name in lockedResourceFileNames) {
|
|
||||||
throw ApkResourceException.Locked("Resource file ${resourceFile.name} is already locked.")
|
|
||||||
}
|
|
||||||
|
|
||||||
lockedResourceFileNames.add(resourceFile.name)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun unlock(resourceFile: ResourceFile) {
|
|
||||||
lockedResourceFileNames.remove(resourceFile.name)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun <T : ResourceFile> openResource(name: String): ResourceFileEditor<T> {
|
|
||||||
val inputSource = archive.read(name)
|
|
||||||
?: throw ApkResourceException.Read("Resource file $name not found.")
|
|
||||||
|
|
||||||
val resourceFile = when {
|
|
||||||
ResXmlDocument.isResXmlBlock(inputSource.openStream()) -> {
|
|
||||||
val xmlDocument = archive.module
|
|
||||||
.loadResXmlDocument(inputSource)
|
|
||||||
.decodeToXml(resourceTable.entryStore, packageBlock.id)
|
|
||||||
|
|
||||||
ResourceFile.XmlResourceFile(name, xmlDocument)
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> {
|
|
||||||
val bytes = inputSource.openStream().use { it.readAllBytes() }
|
|
||||||
|
|
||||||
ResourceFile.BinaryResourceFile(name, bytes)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
return ResourceFileEditor(resourceFile as T).also {
|
|
||||||
lockedResourceFileNames.add(name)
|
|
||||||
}
|
|
||||||
} catch (e: ClassCastException) {
|
|
||||||
throw ApkResourceException.Decode("Resource file $name is not ${resourceFile::class}.", e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inner class ResourceFileEditor<T : ResourceFile> internal constructor(
|
|
||||||
private val resourceFile: T,
|
|
||||||
) : Closeable {
|
|
||||||
fun use(block: (T) -> Unit) = block(resourceFile)
|
|
||||||
override fun close() {
|
|
||||||
lockedResourceFileNames.remove(resourceFile.name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun flush() {
|
|
||||||
TODO("Not yet implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Open a resource file, creating it if the file does not exist.
|
|
||||||
*
|
|
||||||
* @param path The resource file path.
|
|
||||||
* @return The corresponding [ResourceFiles],
|
|
||||||
*/
|
|
||||||
fun openFile(path: String) = ResourceFiles(createHandle(path), archive)
|
|
||||||
|
|
||||||
private fun getPackageBlock() = packageBlock ?: throw ApkResourceException.MissingResourceTable
|
|
||||||
|
|
||||||
internal fun getOrCreateString(value: String) =
|
|
||||||
tableBlock?.stringPool?.getOrCreate(value) ?: throw ApkResourceException.MissingResourceTable
|
|
||||||
|
|
||||||
private fun Entry.set(resource: Resource) {
|
|
||||||
val existingEntryNameReference = specReference
|
|
||||||
|
|
||||||
// Sets this.specReference if the entry is not yet initialized.
|
|
||||||
// Sets this.specReference to 0 if the resource type of the existing entry changes.
|
|
||||||
ensureComplex(resource.isComplex)
|
|
||||||
|
|
||||||
if (existingEntryNameReference != 0) {
|
|
||||||
// Preserve the entry name by restoring the previous spec block reference (if present).
|
|
||||||
specReference = existingEntryNameReference
|
|
||||||
}
|
|
||||||
|
|
||||||
resource.write(this, this@ResourceContainer)
|
|
||||||
resourceTable.registerChanged(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve an [Entry] from the resource table.
|
|
||||||
*
|
|
||||||
* @param type The resource type.
|
|
||||||
* @param name The resource name.
|
|
||||||
* @param qualifiers The variant to use.
|
|
||||||
*/
|
|
||||||
private fun getEntry(type: String, name: String, qualifiers: String?): Entry? {
|
|
||||||
val resourceId = try {
|
|
||||||
resourceTable.resolve("@$type/$name")
|
|
||||||
} catch (_: ApkResourceException.InvalidReference) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
val config = ResConfig.parse(qualifiers)
|
|
||||||
return tableBlock?.resolveReference(resourceId)?.singleOrNull { it.resConfig == config }
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a [ResourceFiles.Handle] that can be used to open a [ResourceFiles].
|
|
||||||
* This may involve looking it up in the resource table to find the actual location in the archive.
|
|
||||||
*
|
|
||||||
* @param path The path of the resource.
|
|
||||||
*/
|
|
||||||
private fun createHandle(path: String): ResourceFiles.Handle {
|
|
||||||
if (path.startsWith("res/values")) throw ApkResourceException.Decode("Decoding the resource table as a file is not supported")
|
|
||||||
|
|
||||||
var onClose = {}
|
|
||||||
var archivePath = path
|
|
||||||
|
|
||||||
if (tableBlock != null && path.startsWith("res/") && path.count { it == '/' } == 2) {
|
|
||||||
val file = File(path)
|
|
||||||
|
|
||||||
val qualifiers = EncodeUtil.getQualifiersFromResFile(file)
|
|
||||||
val type = EncodeUtil.getTypeNameFromResFile(file)
|
|
||||||
val name = file.nameWithoutExtension
|
|
||||||
|
|
||||||
// The resource file names that the app developers used may have been minified, so we have to resolve it with the resource table.
|
|
||||||
// Example: res/drawable-hdpi/icon.png -> res/4a.png
|
|
||||||
getEntry(type, name, qualifiers)?.resValue?.valueAsString?.let {
|
|
||||||
archivePath = it
|
|
||||||
} ?: run {
|
|
||||||
// An entry for this specific resource file was not found in the resource table, so we have to register it after we save.
|
|
||||||
onClose = { setResource(type, name, StringResource(archivePath), qualifiers) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ResourceFiles.Handle(path, archivePath, onClose)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setResource(type: String, entryName: String, resource: Resource, qualifiers: String? = null) =
|
|
||||||
getPackageBlock().getOrCreate(qualifiers, type, entryName).also { it.set(resource) }.resourceId
|
|
||||||
|
|
||||||
fun setResources(type: String, resources: Map<String, Resource>, configuration: String? = null) {
|
|
||||||
getPackageBlock().getOrCreateSpecTypePair(type).getOrCreateTypeBlock(configuration).apply {
|
|
||||||
resources.forEach { (entryName, resource) -> getOrCreateEntry(entryName).set(resource) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun flush() {
|
|
||||||
packageBlock?.name = archive
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
package app.revanced.arsc.resource
|
|
||||||
|
|
||||||
import app.revanced.arsc.ApkResourceException
|
|
||||||
import app.revanced.arsc.archive.Archive
|
|
||||||
import com.reandroid.archive.InputSource
|
|
||||||
import com.reandroid.xml.XMLDocument
|
|
||||||
import com.reandroid.xml.XMLException
|
|
||||||
import java.io.*
|
|
||||||
|
|
||||||
|
|
||||||
abstract class ResourceFile(val name: String) {
|
|
||||||
internal var realName: String? = null
|
|
||||||
|
|
||||||
class XmlResourceFile(name: String, val document: XMLDocument) : ResourceFile(name)
|
|
||||||
class BinaryResourceFile(name: String, var bytes: ByteArray) : ResourceFile(name)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class ResourceFiles private constructor(
|
|
||||||
) : Closeable {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiate a [ResourceFiles].
|
|
||||||
*
|
|
||||||
* @param handle The [Handle] associated with this file.
|
|
||||||
* @param archive The [Archive] that the file resides in.
|
|
||||||
*/
|
|
||||||
internal constructor(handle: Handle, archive: Archive) : this(
|
|
||||||
handle,
|
|
||||||
archive,
|
|
||||||
try {
|
|
||||||
archive.read(handle.archivePath)
|
|
||||||
} catch (e: XMLException) {
|
|
||||||
throw ApkResourceException.Decode("Failed to decode XML while reading ${handle.virtualPath}", e)
|
|
||||||
} catch (e: IOException) {
|
|
||||||
throw ApkResourceException.Decode("Could not read ${handle.virtualPath}", e)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
const val DEFAULT_BUFFER_SIZE = 1024
|
|
||||||
}
|
|
||||||
|
|
||||||
var contents = readResult?.data ?: ByteArray(0)
|
|
||||||
set(value) {
|
|
||||||
pendingWrite = true
|
|
||||||
field = value
|
|
||||||
}
|
|
||||||
|
|
||||||
val exists = readResult != null
|
|
||||||
|
|
||||||
override fun toString() = handle.virtualPath
|
|
||||||
|
|
||||||
override fun close() {
|
|
||||||
if (pendingWrite) {
|
|
||||||
val path = handle.archivePath
|
|
||||||
|
|
||||||
if (isXmlResource) archive.writeXml(
|
|
||||||
path,
|
|
||||||
try {
|
|
||||||
XMLDocument.load(inputStream())
|
|
||||||
} catch (e: XMLException) {
|
|
||||||
throw ApkResourceException.Encode("Failed to parse XML while writing ${handle.virtualPath}", e)
|
|
||||||
}
|
|
||||||
|
|
||||||
) else archive.writeRaw(path, contents)
|
|
||||||
}
|
|
||||||
|
|
||||||
handle.onClose()
|
|
||||||
|
|
||||||
|
|
||||||
archive.unlock(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun inputStream(): InputStream = ByteArrayInputStream(contents)
|
|
||||||
|
|
||||||
fun outputStream(bufferSize: Int = DEFAULT_BUFFER_SIZE): OutputStream =
|
|
||||||
object : ByteArrayOutputStream(bufferSize) {
|
|
||||||
override fun close() {
|
|
||||||
this@ResourceFiles.contents = if (buf.size > count) buf.copyOf(count) else buf
|
|
||||||
super.close()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param virtualPath The resource file path. Example: /res/drawable-hdpi/icon.png.
|
|
||||||
* @param archivePath The actual file path in the archive. Example: res/4a.png.
|
|
||||||
* @param onClose An action to perform when the file associated with this handle is closed
|
|
||||||
*/
|
|
||||||
internal data class Handle(val virtualPath: String, val archivePath: String, val onClose: () -> Unit)
|
|
||||||
}
|
|
||||||
@@ -1,100 +0,0 @@
|
|||||||
package app.revanced.arsc.resource
|
|
||||||
|
|
||||||
import app.revanced.arsc.ApkResourceException
|
|
||||||
import com.reandroid.apk.xmlencoder.EncodeException
|
|
||||||
import com.reandroid.apk.xmlencoder.EncodeMaterials
|
|
||||||
import com.reandroid.arsc.util.FrameworkTable
|
|
||||||
import com.reandroid.arsc.value.Entry
|
|
||||||
import com.reandroid.common.TableEntryStore
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A high-level API for resolving resources in the resource table, which spans the entire ApkBundle.
|
|
||||||
*/
|
|
||||||
class ResourceTable(base: ResourceContainer, all: Sequence<ResourceContainer>) {
|
|
||||||
private val packageName = base.tableBlock!!.name
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A [TableEntryStore] used to decode XML.
|
|
||||||
*/
|
|
||||||
internal val entryStore = TableEntryStore()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The [EncodeMaterials] to use for resolving resources and encoding XML.
|
|
||||||
*/
|
|
||||||
internal val encodeMaterials: EncodeMaterials = object : EncodeMaterials() {
|
|
||||||
/*
|
|
||||||
Our implementation is more efficient because it does not have to loop through every single entry group
|
|
||||||
when the resource id cannot be found in the TableIdentifier, which does not update when you create a new resource.
|
|
||||||
It also looks at the entire table instead of just the current package.
|
|
||||||
*/
|
|
||||||
override fun resolveLocalResourceId(type: String, name: String) = resolveLocal(type, name)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The resource mappings which are generated when the ApkBundle is created.
|
|
||||||
*/
|
|
||||||
private val tableIdentifier = encodeMaterials.tableIdentifier
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A table of all the resources that have been changed or added.
|
|
||||||
*/
|
|
||||||
private val modifiedResources = HashMap<String, HashMap<String, Int>>()
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resolve a resource id for the specified resource.
|
|
||||||
* Cannot resolve resources from the android framework.
|
|
||||||
*
|
|
||||||
* @param type The type of the resource.
|
|
||||||
* @param name The name of the resource.
|
|
||||||
* @return The id of the resource.
|
|
||||||
*/
|
|
||||||
fun resolveLocal(type: String, name: String) =
|
|
||||||
modifiedResources[type]?.get(name)
|
|
||||||
?: tableIdentifier.get(packageName, type, name)?.resourceId
|
|
||||||
?: throw ApkResourceException.InvalidReference(
|
|
||||||
type,
|
|
||||||
name
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resolve a resource id for the specified resource.
|
|
||||||
*
|
|
||||||
* @param reference The resource reference string.
|
|
||||||
* @return The id of the resource.
|
|
||||||
*/
|
|
||||||
fun resolve(reference: String) = try {
|
|
||||||
encodeMaterials.resolveReference(reference)
|
|
||||||
} catch (e: EncodeException) {
|
|
||||||
throw ApkResourceException.InvalidReference(reference, e)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Notify the [ResourceTable] that an [Entry] has been created or modified.
|
|
||||||
*/
|
|
||||||
internal fun registerChanged(entry: Entry) {
|
|
||||||
modifiedResources.getOrPut(entry.typeName, ::HashMap)[entry.name] = entry.resourceId
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
|
||||||
all.forEach {
|
|
||||||
it.tableBlock?.let { table ->
|
|
||||||
entryStore.add(table)
|
|
||||||
tableIdentifier.load(table)
|
|
||||||
}
|
|
||||||
|
|
||||||
it.resourceTable = this
|
|
||||||
}
|
|
||||||
|
|
||||||
base.also {
|
|
||||||
encodeMaterials.currentPackage = it.tableBlock
|
|
||||||
|
|
||||||
it.tableBlock!!.frameWorks.forEach { fw ->
|
|
||||||
if (fw is FrameworkTable) {
|
|
||||||
entryStore.add(fw)
|
|
||||||
encodeMaterials.addFramework(fw)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
package app.revanced.arsc.xml
|
|
||||||
|
|
||||||
import app.revanced.arsc.resource.ResourceContainer
|
|
||||||
import app.revanced.arsc.resource.boolean
|
|
||||||
import com.reandroid.apk.xmlencoder.EncodeException
|
|
||||||
import com.reandroid.apk.xmlencoder.XMLEncodeSource
|
|
||||||
import com.reandroid.arsc.chunk.xml.ResXmlDocument
|
|
||||||
import com.reandroid.xml.XMLDocument
|
|
||||||
import com.reandroid.xml.XMLElement
|
|
||||||
import com.reandroid.xml.source.XMLDocumentSource
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Archive input source to lazily encode an [XMLDocument] after it has been modified.
|
|
||||||
*
|
|
||||||
* @param name The file name of this input source.
|
|
||||||
* @param document The [XMLDocument] to encode.
|
|
||||||
* @param resources The [ResourceContainer] to use for encoding.
|
|
||||||
*/
|
|
||||||
internal class LazyXMLEncodeSource(
|
|
||||||
name: String,
|
|
||||||
val document: XMLDocument,
|
|
||||||
private val resources: ResourceContainer
|
|
||||||
) : XMLEncodeSource(resources.resourceTable.encodeMaterials, XMLDocumentSource(name, document)) {
|
|
||||||
private var encoded = false
|
|
||||||
|
|
||||||
override fun getResXmlBlock(): ResXmlDocument {
|
|
||||||
if (encoded) return super.getResXmlBlock()
|
|
||||||
|
|
||||||
XMLEncodeSource(resources.resourceTable.encodeMaterials, XMLDocumentSource(name, document))
|
|
||||||
|
|
||||||
fun XMLElement.registerIds() {
|
|
||||||
listAttributes().forEach { attr ->
|
|
||||||
if (!attr.value.startsWith("@+id/")) return@forEach
|
|
||||||
|
|
||||||
val name = attr.value.split('/').last()
|
|
||||||
resources.setResource("id", name, boolean(false))
|
|
||||||
attr.value = "@id/$name"
|
|
||||||
}
|
|
||||||
|
|
||||||
listChildElements().forEach { it.registerIds() }
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle all @+id/id_name references in the document.
|
|
||||||
document.documentElement.registerIds()
|
|
||||||
|
|
||||||
encoded = true
|
|
||||||
|
|
||||||
// This will call XMLEncodeSource.getResXmlBlock(),
|
|
||||||
// which will encode the document if it has not already been encoded.
|
|
||||||
try {
|
|
||||||
return super.getResXmlBlock()
|
|
||||||
} catch (e: EncodeException) {
|
|
||||||
throw EncodeException("Failed to encode $name", e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +1,57 @@
|
|||||||
plugins {
|
plugins {
|
||||||
kotlin("jvm") version "1.8.20" apply false
|
kotlin("jvm") version "1.8.20"
|
||||||
|
`maven-publish`
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "app.revanced"
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation(libs.kotlinx.coroutines.core)
|
||||||
|
implementation(libs.xpp3)
|
||||||
|
implementation(libs.smali)
|
||||||
|
implementation(libs.multidexlib2)
|
||||||
|
implementation(libs.apktool.lib)
|
||||||
|
implementation(libs.kotlin.reflect)
|
||||||
|
|
||||||
|
compileOnly(libs.android)
|
||||||
|
|
||||||
|
testImplementation(libs.kotlin.test)
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks {
|
||||||
|
test {
|
||||||
|
useJUnitPlatform()
|
||||||
|
testLogging {
|
||||||
|
events("PASSED", "SKIPPED", "FAILED")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
processResources {
|
||||||
|
expand("projectVersion" to project.version)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin { jvmToolchain(11) }
|
||||||
|
|
||||||
|
java {
|
||||||
|
withSourcesJar()
|
||||||
|
}
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
maven {
|
||||||
|
name = "GitHubPackages"
|
||||||
|
url = uri("https://maven.pkg.github.com/revanced/revanced-patcher")
|
||||||
|
credentials {
|
||||||
|
username = System.getenv("GITHUB_ACTOR")
|
||||||
|
password = System.getenv("GITHUB_TOKEN")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
publications {
|
||||||
|
create<MavenPublication>("gpr") {
|
||||||
|
from(components["java"])
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
org.gradle.parallel=true
|
org.gradle.parallel = true
|
||||||
org.gradle.caching=true
|
org.gradle.caching = true
|
||||||
kotlin.code.style = official
|
kotlin.code.style = official
|
||||||
version = 11.0.4
|
version = 14.2.0-dev.2
|
||||||
|
|||||||
21
gradle/libs.versions.toml
Normal file
21
gradle/libs.versions.toml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
[versions]
|
||||||
|
android = "4.1.1.4"
|
||||||
|
kotlin-reflect = "1.9.0"
|
||||||
|
apktool-lib = "2.8.2-5"
|
||||||
|
kotlin-test = "1.8.20-RC"
|
||||||
|
kotlinx-coroutines-core = "1.7.1"
|
||||||
|
multidexlib2 = "3.0.3.r2"
|
||||||
|
shadow = "8.1.1"
|
||||||
|
smali = "3.0.3"
|
||||||
|
xpp3 = "1.1.4c"
|
||||||
|
|
||||||
|
|
||||||
|
[libraries]
|
||||||
|
android = { module = "com.google.android:android", version.ref = "android" }
|
||||||
|
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin-reflect" }
|
||||||
|
apktool-lib = { module = "app.revanced:apktool-lib", version.ref = "apktool-lib" }
|
||||||
|
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin-test" }
|
||||||
|
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines-core" }
|
||||||
|
multidexlib2 = { module = "app.revanced:multidexlib2", version.ref = "multidexlib2" }
|
||||||
|
smali = { module = "com.android.tools.smali:smali", version.ref = "smali" }
|
||||||
|
xpp3 = { module = "xpp3:xpp3", version.ref = "xpp3" }
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
plugins {
|
|
||||||
kotlin("jvm")
|
|
||||||
`maven-publish`
|
|
||||||
}
|
|
||||||
|
|
||||||
group = "app.revanced"
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation("xpp3:xpp3:1.1.4c")
|
|
||||||
implementation("app.revanced:smali:2.5.3-a3836654")
|
|
||||||
implementation("app.revanced:multidexlib2:2.5.3-a3836654")
|
|
||||||
implementation("io.github.reandroid:ARSCLib:1.1.7")
|
|
||||||
implementation(project(":arsclib-utils"))
|
|
||||||
|
|
||||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1")
|
|
||||||
implementation("org.jetbrains.kotlin:kotlin-reflect:1.8.20-RC")
|
|
||||||
testImplementation("org.jetbrains.kotlin:kotlin-test:1.8.20-RC")
|
|
||||||
|
|
||||||
compileOnly("com.google.android:android:4.1.1.4")
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks {
|
|
||||||
test {
|
|
||||||
useJUnitPlatform()
|
|
||||||
testLogging {
|
|
||||||
events("PASSED", "SKIPPED", "FAILED")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
processResources {
|
|
||||||
expand("projectVersion" to project.version)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
java {
|
|
||||||
withSourcesJar()
|
|
||||||
}
|
|
||||||
|
|
||||||
kotlin {
|
|
||||||
jvmToolchain(11)
|
|
||||||
}
|
|
||||||
|
|
||||||
publishing {
|
|
||||||
repositories {
|
|
||||||
if (System.getenv("GITHUB_ACTOR") != null)
|
|
||||||
maven {
|
|
||||||
name = "GitHubPackages"
|
|
||||||
url = uri("https://maven.pkg.github.com/revanced/revanced-patcher")
|
|
||||||
credentials {
|
|
||||||
username = System.getenv("GITHUB_ACTOR")
|
|
||||||
password = System.getenv("GITHUB_TOKEN")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
mavenLocal()
|
|
||||||
}
|
|
||||||
publications {
|
|
||||||
register<MavenPublication>("gpr") {
|
|
||||||
from(components["java"])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
rootProject.name = "revanced-patcher"
|
|
||||||
@@ -1,113 +0,0 @@
|
|||||||
package app.revanced.patcher
|
|
||||||
|
|
||||||
import app.revanced.arsc.resource.ResourceContainer
|
|
||||||
import app.revanced.patcher.apk.Apk
|
|
||||||
import app.revanced.patcher.apk.ApkBundle
|
|
||||||
import app.revanced.arsc.resource.ResourceFiles
|
|
||||||
import app.revanced.patcher.util.method.MethodWalker
|
|
||||||
import org.jf.dexlib2.iface.Method
|
|
||||||
import org.w3c.dom.Document
|
|
||||||
import java.io.Closeable
|
|
||||||
import java.io.InputStream
|
|
||||||
import java.io.StringWriter
|
|
||||||
import javax.xml.parsers.DocumentBuilderFactory
|
|
||||||
import javax.xml.transform.TransformerFactory
|
|
||||||
import javax.xml.transform.dom.DOMSource
|
|
||||||
import javax.xml.transform.stream.StreamResult
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A common class to constrain [Context] to [BytecodeContext] and [ResourceContext].
|
|
||||||
* @param apkBundle The [ApkBundle] for this context.
|
|
||||||
*/
|
|
||||||
sealed class Context(val apkBundle: ApkBundle)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A context for the bytecode of an [Apk.Base] file.
|
|
||||||
*
|
|
||||||
* @param apkBundle The [ApkBundle] for this context.
|
|
||||||
*/
|
|
||||||
class BytecodeContext internal constructor(apkBundle: ApkBundle) : Context(apkBundle) {
|
|
||||||
/**
|
|
||||||
* The list of classes.
|
|
||||||
*/
|
|
||||||
val classes = apkBundle.base.bytecodeData.classes
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a [MethodWalker] instance for the current [BytecodeContext].
|
|
||||||
*
|
|
||||||
* @param startMethod The method to start at.
|
|
||||||
* @return A [MethodWalker] instance.
|
|
||||||
*/
|
|
||||||
fun traceMethodCalls(startMethod: Method) = MethodWalker(this, startMethod)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A context for [Apk] file resources.
|
|
||||||
*
|
|
||||||
* @param apkBundle the [ApkBundle] for this context.
|
|
||||||
*/
|
|
||||||
class ResourceContext internal constructor(apkBundle: ApkBundle) : Context(apkBundle) {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Open an [DomFileEditor] for a given DOM file.
|
|
||||||
*
|
|
||||||
* @param inputStream The input stream to read the DOM file from.
|
|
||||||
* @return A [DomFileEditor] instance.
|
|
||||||
*/
|
|
||||||
fun openXmlFile(inputStream: InputStream) = DomFileEditor(inputStream)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Open a [DomFileEditor] for a resource file in the archive.
|
|
||||||
*
|
|
||||||
* @see [ResourceContainer.openFile]
|
|
||||||
* @param path The resource file path.
|
|
||||||
* @return A [DomFileEditor].
|
|
||||||
*/
|
|
||||||
fun ResourceContainer.openXmlFile(path: String) = DomFileEditor(openFile(path))
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrapper for a file that can be edited as a dom document.
|
|
||||||
*
|
|
||||||
* @param inputStream the input stream to read the xml file from.
|
|
||||||
* @param onSave A callback that will be called when the editor is closed to save the file.
|
|
||||||
*/
|
|
||||||
class DomFileEditor internal constructor(
|
|
||||||
private val inputStream: InputStream,
|
|
||||||
private val onSave: ((String) -> Unit)? = null
|
|
||||||
) : Closeable {
|
|
||||||
private var closed: Boolean = false
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The document of the xml file.
|
|
||||||
*/
|
|
||||||
val file: Document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream)
|
|
||||||
.also(Document::normalize)
|
|
||||||
|
|
||||||
internal constructor(file: ResourceFiles) : this(
|
|
||||||
file.inputStream(),
|
|
||||||
{
|
|
||||||
file.contents = it.toByteArray()
|
|
||||||
file.close()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Closes the editor and writes back to the file.
|
|
||||||
*/
|
|
||||||
override fun close() {
|
|
||||||
if (closed) return
|
|
||||||
|
|
||||||
inputStream.close()
|
|
||||||
|
|
||||||
onSave?.let { callback ->
|
|
||||||
// Save the updated file.
|
|
||||||
val writer = StringWriter()
|
|
||||||
TransformerFactory.newInstance().newTransformer().transform(DOMSource(file), StreamResult(writer))
|
|
||||||
callback(writer.toString())
|
|
||||||
}
|
|
||||||
|
|
||||||
closed = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,222 +0,0 @@
|
|||||||
package app.revanced.patcher
|
|
||||||
|
|
||||||
import app.revanced.patcher.apk.Apk
|
|
||||||
import app.revanced.patcher.extensions.PatchExtensions.dependencies
|
|
||||||
import app.revanced.patcher.extensions.PatchExtensions.patchName
|
|
||||||
import app.revanced.patcher.extensions.PatchExtensions.requiresIntegrations
|
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolveUsingLookupMap
|
|
||||||
import app.revanced.patcher.patch.*
|
|
||||||
import app.revanced.patcher.util.VersionReader
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
|
||||||
import kotlinx.coroutines.flow.flow
|
|
||||||
import lanchon.multidexlib2.BasicDexFileNamer
|
|
||||||
import java.io.Closeable
|
|
||||||
import java.io.File
|
|
||||||
import java.util.function.Function
|
|
||||||
|
|
||||||
typealias ExecutedPatchResults = Flow<Pair<String, PatchException?>>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The ReVanced Patcher.
|
|
||||||
* @param options The options for the patcher.
|
|
||||||
* @param patches The patches to use.
|
|
||||||
* @param integrations The integrations to merge if necessary. Must be dex files or dex file container such as ZIP, APK or DEX files.
|
|
||||||
*/
|
|
||||||
class Patcher(private val options: PatcherOptions, patches: Iterable<PatchClass>, integrations: Iterable<File>) :
|
|
||||||
Function<Boolean, ExecutedPatchResults> {
|
|
||||||
private val context = PatcherContext(options, patches.toList(), integrations)
|
|
||||||
private val logger = options.logger
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
/**
|
|
||||||
* The version of the ReVanced Patcher.
|
|
||||||
*/
|
|
||||||
@JvmStatic
|
|
||||||
val version = VersionReader.read()
|
|
||||||
|
|
||||||
@Suppress("SpellCheckingInspection")
|
|
||||||
internal val dexFileNamer = BasicDexFileNamer()
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
|
||||||
/**
|
|
||||||
* Returns true if at least one patches or its dependencies matches the given predicate.
|
|
||||||
*/
|
|
||||||
fun PatchClass.anyRecursively(predicate: (PatchClass) -> Boolean): Boolean =
|
|
||||||
predicate(this) || dependencies?.any { it.java.anyRecursively(predicate) } == true
|
|
||||||
|
|
||||||
// Determine if merging integrations is required.
|
|
||||||
for (patch in context.patches) {
|
|
||||||
if (patch.anyRecursively { it.requiresIntegrations }) {
|
|
||||||
context.integrations.merge = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the patcher.
|
|
||||||
*
|
|
||||||
* @param stopOnError If true, the patches will stop on the first error.
|
|
||||||
* @return A pair of the name of the [Patch] and a [PatchException] if it failed.
|
|
||||||
*/
|
|
||||||
override fun apply(stopOnError: Boolean) = flow {
|
|
||||||
/**
|
|
||||||
* Execute a [Patch] and its dependencies recursively.
|
|
||||||
*
|
|
||||||
* @param patchClass The [Patch] to execute.
|
|
||||||
* @param executedPatches A map of [Patch]es paired to a boolean indicating their success, to prevent infinite recursion.
|
|
||||||
*/
|
|
||||||
suspend fun executePatch(
|
|
||||||
patchClass: PatchClass,
|
|
||||||
executedPatches: HashMap<String, ExecutedPatch>
|
|
||||||
) {
|
|
||||||
val patchName = patchClass.patchName
|
|
||||||
|
|
||||||
// If the patch has already executed silently skip it.
|
|
||||||
if (executedPatches.contains(patchName)) {
|
|
||||||
if (!executedPatches[patchName]!!.success)
|
|
||||||
throw PatchException("'$patchName' did not succeed previously")
|
|
||||||
|
|
||||||
logger.trace("Skipping '$patchName' because it has already been executed")
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Recursively execute all dependency patches.
|
|
||||||
patchClass.dependencies?.forEach { dependencyClass ->
|
|
||||||
val dependency = dependencyClass.java
|
|
||||||
|
|
||||||
try {
|
|
||||||
executePatch(dependency, executedPatches)
|
|
||||||
} catch (throwable: Throwable) {
|
|
||||||
throw PatchException(
|
|
||||||
"'$patchName' depends on '${dependency.patchName}' " +
|
|
||||||
"but the following exception was raised: ${throwable.cause?.stackTraceToString() ?: throwable.message}",
|
|
||||||
throwable
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val isResourcePatch = ResourcePatch::class.java.isAssignableFrom(patchClass)
|
|
||||||
val patchInstance = patchClass.getDeclaredConstructor().newInstance()
|
|
||||||
|
|
||||||
// TODO: implement this in a more polymorphic way.
|
|
||||||
val patchContext = if (isResourcePatch) {
|
|
||||||
context.resourceContext
|
|
||||||
} else {
|
|
||||||
context.bytecodeContext.apply {
|
|
||||||
val bytecodePatch = patchInstance as BytecodePatch
|
|
||||||
bytecodePatch.fingerprints?.resolveUsingLookupMap(context.bytecodeContext)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.trace("Executing '$patchName' of type: ${if (isResourcePatch) "resource" else "bytecode"}")
|
|
||||||
|
|
||||||
var success = false
|
|
||||||
try {
|
|
||||||
patchInstance.execute(patchContext)
|
|
||||||
|
|
||||||
success = true
|
|
||||||
} catch (patchException: PatchException) {
|
|
||||||
throw patchException
|
|
||||||
} catch (throwable: Throwable) {
|
|
||||||
throw PatchException("Unhandled patch exception: ${throwable.message}", throwable)
|
|
||||||
} finally {
|
|
||||||
executedPatches[patchName] = ExecutedPatch(patchInstance, success)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (context.integrations.merge) context.integrations.merge(logger)
|
|
||||||
|
|
||||||
logger.trace("Initialize lookup maps for method MethodFingerprint resolution")
|
|
||||||
|
|
||||||
MethodFingerprint.initializeFingerprintResolutionLookupMaps(context.bytecodeContext)
|
|
||||||
|
|
||||||
logger.info("Executing patches")
|
|
||||||
|
|
||||||
// Key is patch name.
|
|
||||||
LinkedHashMap<String, ExecutedPatch>().apply {
|
|
||||||
context.patches.forEach { patch ->
|
|
||||||
var exception: PatchException? = null
|
|
||||||
|
|
||||||
try {
|
|
||||||
executePatch(patch, this)
|
|
||||||
} catch (patchException: PatchException) {
|
|
||||||
exception = patchException
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: only emit if the patch is not a closeable.
|
|
||||||
// If it is a closeable, this should be done when closing the patch.
|
|
||||||
emit(patch.patchName to exception)
|
|
||||||
|
|
||||||
if (stopOnError && exception != null) return@flow
|
|
||||||
}
|
|
||||||
}.let {
|
|
||||||
it.values
|
|
||||||
.filter(ExecutedPatch::success)
|
|
||||||
.map(ExecutedPatch::patchInstance)
|
|
||||||
.filterIsInstance(Closeable::class.java)
|
|
||||||
.asReversed().forEach { patch ->
|
|
||||||
try {
|
|
||||||
patch.close()
|
|
||||||
} catch (throwable: Throwable) {
|
|
||||||
val patchException =
|
|
||||||
if (throwable is PatchException) throwable
|
|
||||||
else PatchException(throwable)
|
|
||||||
|
|
||||||
val patchName = (patch as Patch<Context>).javaClass.patchName
|
|
||||||
|
|
||||||
logger.error("Failed to close '$patchName': ${patchException.stackTraceToString()}")
|
|
||||||
|
|
||||||
emit(patchName to patchException)
|
|
||||||
|
|
||||||
// This is not failsafe. If a patch throws an exception while closing,
|
|
||||||
// the other patches that depend on it may fail.
|
|
||||||
if (stopOnError) return@flow
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MethodFingerprint.clearFingerprintResolutionLookupMaps()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Finish patching all [Apk]s.
|
|
||||||
*
|
|
||||||
* @return The [PatcherResult] of the [Patcher].
|
|
||||||
*/
|
|
||||||
fun finish(): PatcherResult {
|
|
||||||
val patchResults = buildList {
|
|
||||||
logger.info("Processing patched apks")
|
|
||||||
options.apkBundle.cleanup(options).forEach { result ->
|
|
||||||
if (result.exception != null) {
|
|
||||||
logger.error("Got exception while processing ${result.apk}: ${result.exception.stackTraceToString()}")
|
|
||||||
return@forEach
|
|
||||||
}
|
|
||||||
|
|
||||||
val patch = result.let {
|
|
||||||
when (it.apk) {
|
|
||||||
is Apk.Base -> PatcherResult.Patch.Base(it.apk)
|
|
||||||
is Apk.Split -> PatcherResult.Patch.Split(it.apk)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
add(patch)
|
|
||||||
|
|
||||||
logger.info("Patched ${result.apk}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return PatcherResult(patchResults)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A result of executing a [Patch].
|
|
||||||
*
|
|
||||||
* @param patchInstance The instance of the [Patch] that was executed.
|
|
||||||
* @param success The result of the [Patch].
|
|
||||||
*/
|
|
||||||
internal data class ExecutedPatch(val patchInstance: Patch<Context>, val success: Boolean)
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
package app.revanced.patcher
|
|
||||||
|
|
||||||
import app.revanced.patcher.logging.Logger
|
|
||||||
import app.revanced.patcher.patch.PatchClass
|
|
||||||
import app.revanced.patcher.util.ClassMerger.merge
|
|
||||||
import lanchon.multidexlib2.MultiDexIO
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
class PatcherContext(
|
|
||||||
options: PatcherOptions,
|
|
||||||
internal val patches: List<PatchClass>,
|
|
||||||
integrations: Iterable<File>
|
|
||||||
) {
|
|
||||||
internal val integrations = Integrations(this, integrations)
|
|
||||||
internal val bytecodeContext = BytecodeContext(options.apkBundle)
|
|
||||||
internal val resourceContext = ResourceContext(options.apkBundle)
|
|
||||||
|
|
||||||
internal class Integrations(val context: PatcherContext, private val dexContainers: Iterable<File>) {
|
|
||||||
var merge = false
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Merge integrations.
|
|
||||||
* @param logger A logger.
|
|
||||||
*/
|
|
||||||
fun merge(logger: Logger) {
|
|
||||||
context.bytecodeContext.classes.apply {
|
|
||||||
for (integrations in dexContainers) {
|
|
||||||
logger.info("Merging $integrations")
|
|
||||||
|
|
||||||
for (classDef in MultiDexIO.readDexFile(true, integrations, Patcher.dexFileNamer, null, null).classes) {
|
|
||||||
val type = classDef.type
|
|
||||||
|
|
||||||
val existingClassIndex = this.indexOfFirst { it.type == type }
|
|
||||||
if (existingClassIndex == -1) {
|
|
||||||
logger.trace("Merging type $type")
|
|
||||||
add(classDef)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
logger.trace("Type $type exists. Adding missing methods and fields.")
|
|
||||||
|
|
||||||
get(existingClassIndex).apply {
|
|
||||||
merge(classDef, context.bytecodeContext, logger).let { mergedClass ->
|
|
||||||
if (mergedClass !== this) // referential equality check
|
|
||||||
set(existingClassIndex, mergedClass)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
package app.revanced.patcher
|
|
||||||
|
|
||||||
import app.revanced.patcher.apk.ApkBundle
|
|
||||||
import app.revanced.patcher.logging.Logger
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Options for the [Patcher].
|
|
||||||
* @param apkBundle The [ApkBundle].
|
|
||||||
* @param logger Custom logger implementation for the [Patcher].
|
|
||||||
*/
|
|
||||||
class PatcherOptions(
|
|
||||||
internal val apkBundle: ApkBundle,
|
|
||||||
internal val logger: Logger = Logger.Nop
|
|
||||||
)
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
package app.revanced.patcher
|
|
||||||
|
|
||||||
import app.revanced.patcher.apk.Apk
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The result of a patcher.
|
|
||||||
* @param apkFiles The patched [Apk] files.
|
|
||||||
*/
|
|
||||||
data class PatcherResult(val apkFiles: List<Patch>) {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The result of a patch.
|
|
||||||
*
|
|
||||||
* @param apk The patched [Apk] file.
|
|
||||||
*/
|
|
||||||
sealed class Patch(val apk: Apk) {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The result of a patch of an [Apk.Split] file.
|
|
||||||
*
|
|
||||||
* @param apk The patched [Apk.Split] file.
|
|
||||||
*/
|
|
||||||
class Split(apk: Apk.Split) : Patch(apk)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The result of a patch of an [Apk.Split] file.
|
|
||||||
*
|
|
||||||
* @param apk The patched [Apk.Base] file.
|
|
||||||
*/
|
|
||||||
class Base(apk: Apk.Base) : Patch(apk)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,285 +0,0 @@
|
|||||||
@file:Suppress("MemberVisibilityCanBePrivate")
|
|
||||||
|
|
||||||
package app.revanced.patcher.apk
|
|
||||||
|
|
||||||
import app.revanced.arsc.ApkResourceException
|
|
||||||
import app.revanced.arsc.archive.Archive
|
|
||||||
import app.revanced.patcher.Patcher
|
|
||||||
import app.revanced.patcher.PatcherOptions
|
|
||||||
import app.revanced.patcher.logging.asArscLogger
|
|
||||||
import app.revanced.patcher.util.ProxyBackedClassList
|
|
||||||
import com.reandroid.apk.ApkModule
|
|
||||||
import com.reandroid.apk.xmlencoder.EncodeException
|
|
||||||
import com.reandroid.archive.InputSource
|
|
||||||
import com.reandroid.arsc.chunk.xml.AndroidManifestBlock
|
|
||||||
import com.reandroid.arsc.value.ResConfig
|
|
||||||
import lanchon.multidexlib2.*
|
|
||||||
import org.jf.dexlib2.Opcodes
|
|
||||||
import org.jf.dexlib2.dexbacked.DexBackedDexFile
|
|
||||||
import org.jf.dexlib2.iface.DexFile
|
|
||||||
import org.jf.dexlib2.iface.MultiDexContainer
|
|
||||||
import org.jf.dexlib2.writer.io.MemoryDataStore
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An [Apk] file.
|
|
||||||
*/
|
|
||||||
sealed class Apk private constructor(module: ApkModule) {
|
|
||||||
/**
|
|
||||||
* A wrapper around the zip archive of this [Apk].
|
|
||||||
*
|
|
||||||
* @see Archive
|
|
||||||
*/
|
|
||||||
private val archive = Archive(module)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The metadata of the [Apk].
|
|
||||||
*/
|
|
||||||
val packageMetadata = PackageMetadata(module.androidManifestBlock)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Refresh updated resources and close any open files.
|
|
||||||
*
|
|
||||||
* @param options The [PatcherOptions] of the [Patcher].
|
|
||||||
*/
|
|
||||||
internal open fun cleanup(options: PatcherOptions) {
|
|
||||||
try {
|
|
||||||
archive.cleanup(options.logger.asArscLogger())
|
|
||||||
} catch (e: EncodeException) {
|
|
||||||
throw ApkResourceException.Encode(e.message!!, e)
|
|
||||||
}
|
|
||||||
|
|
||||||
archive.mainPackageResources.refreshPackageName()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write the [Apk] to a file.
|
|
||||||
*
|
|
||||||
* @param output The target file.
|
|
||||||
*/
|
|
||||||
fun write(output: File) = archive.save(output)
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
const val MANIFEST_FILE_NAME = "AndroidManifest.xml"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine the [Module] and [Type] of an [ApkModule].
|
|
||||||
*
|
|
||||||
* @return A [Pair] containing the [Module] and [Type] of the [ApkModule].
|
|
||||||
*/
|
|
||||||
fun ApkModule.identify(): Pair<Module, Type> {
|
|
||||||
val manifestElement = androidManifestBlock.manifestElement
|
|
||||||
return when {
|
|
||||||
isBaseModule -> Module.Main to Type.Base
|
|
||||||
// The module is a base apk for a dynamic feature module if the "isFeatureModule" attribute is set to true.
|
|
||||||
manifestElement.searchAttributeByName("isFeatureModule")?.valueAsBoolean == true -> Module.DynamicFeature(
|
|
||||||
split
|
|
||||||
) to Type.Base
|
|
||||||
|
|
||||||
else -> {
|
|
||||||
val module = manifestElement.searchAttributeByName("configForSplit")
|
|
||||||
?.let { Module.DynamicFeature(it.valueAsString) } ?: Module.Main
|
|
||||||
|
|
||||||
// Examples:
|
|
||||||
// config.xhdpi
|
|
||||||
// df_my_feature.config.en
|
|
||||||
val config = this.split.split(".").last()
|
|
||||||
|
|
||||||
val type = when {
|
|
||||||
// Language splits have a two-letter country code.
|
|
||||||
config.length == 2 -> Type.Language(config)
|
|
||||||
// Library splits use the target CPU architecture.
|
|
||||||
Split.Library.architectures.contains(config) -> Type.Library(config)
|
|
||||||
// Asset splits use the density.
|
|
||||||
ResConfig.Density.valueOf(config) != null -> Type.Asset(config)
|
|
||||||
else -> throw IllegalArgumentException("Invalid split config: $config")
|
|
||||||
}
|
|
||||||
|
|
||||||
module to type
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal inner class BytecodeData {
|
|
||||||
private val opcodes: Opcodes
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The classes and proxied classes of the [Base] apk file.
|
|
||||||
*/
|
|
||||||
val classes: ProxyBackedClassList
|
|
||||||
|
|
||||||
init {
|
|
||||||
MultiDexContainerBackedDexFile(object : MultiDexContainer<DexBackedDexFile> {
|
|
||||||
// Load all dex files from the apk module and create a dex entry for each of them.
|
|
||||||
private val entries = archive.readDexFiles().associateBy { it.name }
|
|
||||||
.mapValues { (name, inputSource) ->
|
|
||||||
BasicDexEntry(
|
|
||||||
this,
|
|
||||||
name,
|
|
||||||
RawDexIO.readRawDexFile(inputSource.openStream(), inputSource.length, null)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getDexEntryNames() = entries.keys.toList()
|
|
||||||
override fun getEntry(entryName: String) = entries[entryName]
|
|
||||||
}).let {
|
|
||||||
opcodes = it.opcodes
|
|
||||||
classes = ProxyBackedClassList(it.classes)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write [classes] to the archive.
|
|
||||||
*/
|
|
||||||
internal fun writeDexFiles() {
|
|
||||||
// Create patched dex files.
|
|
||||||
mutableMapOf<String, MemoryDataStore>().also {
|
|
||||||
val newDexFile = object : DexFile {
|
|
||||||
override fun getClasses() =
|
|
||||||
this@BytecodeData.classes.also(ProxyBackedClassList::applyProxies).toSet()
|
|
||||||
override fun getOpcodes() = this@BytecodeData.opcodes
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write modified dex files.
|
|
||||||
MultiDexIO.writeDexFile(
|
|
||||||
true, -1, // Core count.
|
|
||||||
it, Patcher.dexFileNamer, newDexFile, DexIO.DEFAULT_MAX_DEX_POOL_SIZE, null
|
|
||||||
)
|
|
||||||
}.forEach { (name, store) ->
|
|
||||||
val dexFileInputSource = object : InputSource(name) {
|
|
||||||
override fun openStream() = store.readAt(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
archive.write(dexFileInputSource)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Metadata about an [Apk] file.
|
|
||||||
*
|
|
||||||
* @param packageName The package name of the [Apk] file.
|
|
||||||
* @param packageVersion The package version of the [Apk] file.
|
|
||||||
*/
|
|
||||||
data class PackageMetadata(val packageName: String?, val packageVersion: String?) {
|
|
||||||
internal constructor(manifestBlock: AndroidManifestBlock) : this(
|
|
||||||
manifestBlock.packageName,
|
|
||||||
manifestBlock.versionName
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An [Apk] of type [Split].
|
|
||||||
*
|
|
||||||
* @param config The device configuration associated with this [Split], such as arm64_v8a, en or xhdpi.
|
|
||||||
* @see Apk
|
|
||||||
*/
|
|
||||||
sealed class Split(val config: String, module: ApkModule) : Apk(module) {
|
|
||||||
override fun toString() = "split_config.$config.apk"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The split apk file which contains libraries.
|
|
||||||
*
|
|
||||||
* @see Split
|
|
||||||
*/
|
|
||||||
class Library internal constructor(config: String, module: ApkModule) : Split(config, module) {
|
|
||||||
companion object {
|
|
||||||
/**
|
|
||||||
* A set of all architectures supported by android.
|
|
||||||
*/
|
|
||||||
val architectures = setOf("armeabi_v7a", "arm64_v8a", "x86", "x86_64")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The split apk file which contains language strings.
|
|
||||||
*
|
|
||||||
* @see Split
|
|
||||||
*/
|
|
||||||
class Language internal constructor(config: String, module: ApkModule) : Split(config, module)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The split apk file which contains assets.
|
|
||||||
*
|
|
||||||
* @see Split
|
|
||||||
*/
|
|
||||||
class Asset internal constructor(config: String, module: ApkModule) : Split(config, module)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The base [Apk] file..
|
|
||||||
*
|
|
||||||
* @see Apk
|
|
||||||
*/
|
|
||||||
class Base internal constructor(module: ApkModule) : Apk(module) {
|
|
||||||
/**
|
|
||||||
* Data of the [Base] apk file.
|
|
||||||
*/
|
|
||||||
internal val bytecodeData = BytecodeData()
|
|
||||||
|
|
||||||
override fun toString() = "base.apk"
|
|
||||||
|
|
||||||
override fun cleanup(options: PatcherOptions) {
|
|
||||||
super.cleanup(options)
|
|
||||||
|
|
||||||
options.logger.info("Writing patched dex files")
|
|
||||||
bytecodeData.writeDexFiles()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The module that the [ApkModule] belongs to.
|
|
||||||
*/
|
|
||||||
sealed class Module {
|
|
||||||
/**
|
|
||||||
* The default [Module] that is always installed by software repositories.
|
|
||||||
*/
|
|
||||||
object Main : Module()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A [Module] that can be installed later by software repositories when requested by the application.
|
|
||||||
*
|
|
||||||
* @param name The name of the feature.
|
|
||||||
*/
|
|
||||||
data class DynamicFeature(val name: String) : Module()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type of the [ApkModule].
|
|
||||||
*/
|
|
||||||
sealed class Type {
|
|
||||||
/**
|
|
||||||
* The main Apk of a [Module].
|
|
||||||
*/
|
|
||||||
object Base : Type()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A superclass for all split configuration types.
|
|
||||||
*
|
|
||||||
* @param target The target device configuration.
|
|
||||||
*/
|
|
||||||
sealed class SplitConfig(val target: String) : Type()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The [Type] of an apk containing native libraries.
|
|
||||||
*
|
|
||||||
* @param architecture The target CPU architecture.
|
|
||||||
*/
|
|
||||||
data class Library(val architecture: String) : SplitConfig(architecture)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The [Type] for an Apk containing language resources.
|
|
||||||
*
|
|
||||||
* @param language The target language code.
|
|
||||||
*/
|
|
||||||
data class Language(val language: String) : SplitConfig(language)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The [Type] for an Apk containing assets.
|
|
||||||
*
|
|
||||||
* @param pixelDensity The target screen density.
|
|
||||||
*/
|
|
||||||
data class Asset(val pixelDensity: String) : SplitConfig(pixelDensity)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,105 +0,0 @@
|
|||||||
@file:Suppress("MemberVisibilityCanBePrivate")
|
|
||||||
|
|
||||||
package app.revanced.patcher.apk
|
|
||||||
|
|
||||||
import app.revanced.arsc.ApkResourceException
|
|
||||||
import app.revanced.arsc.resource.ResourceTable
|
|
||||||
import app.revanced.patcher.Patcher
|
|
||||||
import app.revanced.patcher.PatcherOptions
|
|
||||||
import app.revanced.patcher.apk.Apk.Companion.identify
|
|
||||||
import com.reandroid.apk.ApkModule
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An [Apk] file of type [Apk.Split].
|
|
||||||
*
|
|
||||||
* @param files A list of apk files to load.
|
|
||||||
*/
|
|
||||||
class ApkBundle(files: List<File>) : Sequence<Apk> {
|
|
||||||
/**
|
|
||||||
* The [Apk.Base] of this [ApkBundle].
|
|
||||||
*/
|
|
||||||
val base: Apk.Base
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A map containing all the [Apk.Split]s in this bundle associated by their configuration.
|
|
||||||
*/
|
|
||||||
val splits: Map<String, Apk.Split>?
|
|
||||||
|
|
||||||
init {
|
|
||||||
var baseApk: Apk.Base? = null
|
|
||||||
|
|
||||||
splits = buildMap {
|
|
||||||
files.forEach {
|
|
||||||
val apk = ApkModule.loadApkFile(it)
|
|
||||||
val (module, type) = apk.identify()
|
|
||||||
if (module is Apk.Module.DynamicFeature) {
|
|
||||||
return@forEach // Dynamic feature modules are not supported yet.
|
|
||||||
}
|
|
||||||
|
|
||||||
when (type) {
|
|
||||||
Apk.Type.Base -> {
|
|
||||||
if (baseApk != null) {
|
|
||||||
throw IllegalArgumentException("Cannot have more than one base apk")
|
|
||||||
}
|
|
||||||
baseApk = Apk.Base(apk)
|
|
||||||
}
|
|
||||||
|
|
||||||
is Apk.Type.SplitConfig -> {
|
|
||||||
val target = type.target
|
|
||||||
if (this.contains(target)) {
|
|
||||||
throw IllegalArgumentException("Duplicate split: $target")
|
|
||||||
}
|
|
||||||
|
|
||||||
val constructor = when (type) {
|
|
||||||
is Apk.Type.Asset -> Apk.Split::Asset
|
|
||||||
is Apk.Type.Library -> Apk.Split::Library
|
|
||||||
is Apk.Type.Language -> Apk.Split::Language
|
|
||||||
}
|
|
||||||
|
|
||||||
this[target] = constructor(target, apk)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.takeIf { it.isNotEmpty() }
|
|
||||||
|
|
||||||
base = baseApk ?: throw IllegalArgumentException("Base apk not found")
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The [ResourceTable] of this [ApkBundle].
|
|
||||||
*/
|
|
||||||
val resources = ResourceTable(base.resources, map { it.resources })
|
|
||||||
|
|
||||||
override fun iterator() = sequence {
|
|
||||||
yield(base)
|
|
||||||
splits?.values?.let {
|
|
||||||
yieldAll(it)
|
|
||||||
}
|
|
||||||
}.iterator()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Refresh all updated resources in an [ApkBundle].
|
|
||||||
*
|
|
||||||
* @param options The [PatcherOptions] of the [Patcher].
|
|
||||||
* @return A sequence of the [Apk] files which are being refreshed.
|
|
||||||
*/
|
|
||||||
internal fun cleanup(options: PatcherOptions) = map {
|
|
||||||
var exception: ApkResourceException? = null
|
|
||||||
try {
|
|
||||||
it.cleanup(options)
|
|
||||||
} catch (e: ApkResourceException) {
|
|
||||||
exception = e
|
|
||||||
}
|
|
||||||
|
|
||||||
SplitApkResult(it, exception)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The result of writing an [Apk] file.
|
|
||||||
*
|
|
||||||
* @param apk The corresponding [Apk] file.
|
|
||||||
* @param exception The optional [ApkResourceException] when an exception occurred.
|
|
||||||
*/
|
|
||||||
data class SplitApkResult(val apk: Apk, val exception: ApkResourceException? = null)
|
|
||||||
}
|
|
||||||
@@ -1,20 +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) {}
|
|
||||||
|
|
||||||
object Nop : Logger
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Turn a Patcher [Logger] into an [app.revanced.arsc.logging.Logger].
|
|
||||||
*/
|
|
||||||
internal fun Logger.asArscLogger() = object : app.revanced.arsc.logging.Logger {
|
|
||||||
override fun error(msg: String) = this@asArscLogger.error(msg)
|
|
||||||
override fun warn(msg: String) = this@asArscLogger.warn(msg)
|
|
||||||
override fun info(msg: String) = this@asArscLogger.info(msg)
|
|
||||||
override fun trace(msg: String) = this@asArscLogger.error(msg)
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package app.revanced.patcher.util
|
|
||||||
|
|
||||||
internal class ListBackedSet<E>(private val list: MutableList<E>) : MutableSet<E> {
|
|
||||||
override val size get() = list.size
|
|
||||||
override fun add(element: E) = list.add(element)
|
|
||||||
override fun addAll(elements: Collection<E>) = list.addAll(elements)
|
|
||||||
override fun clear() = list.clear()
|
|
||||||
override fun iterator() = list.listIterator()
|
|
||||||
override fun remove(element: E) = list.remove(element)
|
|
||||||
override fun removeAll(elements: Collection<E>) = list.removeAll(elements)
|
|
||||||
override fun retainAll(elements: Collection<E>) = list.retainAll(elements)
|
|
||||||
override fun contains(element: E) = list.contains(element)
|
|
||||||
override fun containsAll(elements: Collection<E>) = list.containsAll(elements)
|
|
||||||
override fun isEmpty() = list.isEmpty()
|
|
||||||
}
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
package app.revanced.patcher.util
|
|
||||||
|
|
||||||
import app.revanced.patcher.util.proxy.ClassProxy
|
|
||||||
import org.jf.dexlib2.iface.ClassDef
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A class that represents a list of classes and proxies.
|
|
||||||
*
|
|
||||||
* @param classes The classes to be backed by proxies.
|
|
||||||
*/
|
|
||||||
class ProxyBackedClassList(classes: Set<ClassDef>) : Iterable<ClassDef> {
|
|
||||||
// A list for pending proxied classes to be added to the current ProxyBackedClassList instance.
|
|
||||||
private val proxiedClasses = mutableListOf<ClassProxy>()
|
|
||||||
private val mutableClasses = classes.toMutableList()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Replace the [mutableClasses]es with their proxies.
|
|
||||||
*/
|
|
||||||
internal fun applyProxies() {
|
|
||||||
proxiedClasses.removeIf { proxy ->
|
|
||||||
// If the proxy is unused, keep it in the proxiedClasses list.
|
|
||||||
if (!proxy.resolved) return@removeIf false
|
|
||||||
|
|
||||||
with(mutableClasses) {
|
|
||||||
remove(proxy.immutableClass)
|
|
||||||
add(proxy.mutableClass)
|
|
||||||
}
|
|
||||||
|
|
||||||
return@removeIf true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Replace a [ClassDef] at a given [index].
|
|
||||||
*
|
|
||||||
* @param index The index of the class to be replaced.
|
|
||||||
* @param classDef The new class to replace the old one.
|
|
||||||
*/
|
|
||||||
operator fun set(index: Int, classDef: ClassDef) {
|
|
||||||
mutableClasses[index] = classDef
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a [ClassDef] at a given [index].
|
|
||||||
*
|
|
||||||
* @param index The index of the class.
|
|
||||||
*/
|
|
||||||
operator fun get(index: Int) = mutableClasses[index]
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Iterator for the classes in [ProxyBackedClassList].
|
|
||||||
*
|
|
||||||
* @return The iterator for the classes.
|
|
||||||
*/
|
|
||||||
override fun iterator() = mutableClasses.iterator()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Proxy a [ClassDef].
|
|
||||||
*
|
|
||||||
* Note: This creates a [ClassProxy] of the [ClassDef], if not already present.
|
|
||||||
*
|
|
||||||
* @return A proxy for the given class.
|
|
||||||
*/
|
|
||||||
fun proxy(classDef: ClassDef) = proxiedClasses
|
|
||||||
.find { it.immutableClass.type == classDef.type } ?: ClassProxy(classDef).also(proxiedClasses::add)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a [ClassDef].
|
|
||||||
*/
|
|
||||||
fun add(classDef: ClassDef) = mutableClasses.add(classDef)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 findClassProxied(className: String) = findClassProxied { 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 findClassProxied(predicate: (ClassDef) -> Boolean) = this.find(predicate)?.let(::proxy)
|
|
||||||
|
|
||||||
val size get() = mutableClasses.size
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
package app.revanced.patcher.util
|
|
||||||
|
|
||||||
import app.revanced.patcher.BytecodeContext
|
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableClass
|
|
||||||
|
|
||||||
object TypeUtil {
|
|
||||||
/**
|
|
||||||
* Traverse the class hierarchy starting from the given root class.
|
|
||||||
*
|
|
||||||
* @param targetClass The class to start traversing the class hierarchy from.
|
|
||||||
* @param callback The function that is called for every class in the hierarchy.
|
|
||||||
*/
|
|
||||||
fun BytecodeContext.traverseClassHierarchy(targetClass: MutableClass, callback: MutableClass.() -> Unit) {
|
|
||||||
callback(targetClass)
|
|
||||||
this.classes.findClassProxied(targetClass.superclass ?: return)?.mutableClass?.let {
|
|
||||||
traverseClassHierarchy(it, callback)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
package app.revanced.patcher.util
|
|
||||||
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
@Deprecated("This class serves no purpose anymore")
|
|
||||||
internal object VersionReader {
|
|
||||||
@JvmStatic
|
|
||||||
private val properties = Properties().apply {
|
|
||||||
load(
|
|
||||||
VersionReader::class.java.getResourceAsStream("/app/revanced/patcher/version.properties")
|
|
||||||
?: throw IllegalStateException("Could not load version.properties")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun read(): String {
|
|
||||||
return properties.getProperty("version") ?: throw IllegalStateException("Version not found")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
@file:Suppress("unused")
|
|
||||||
|
|
||||||
package app.revanced.patcher.util.patch
|
|
||||||
|
|
||||||
import app.revanced.patcher.extensions.AnnotationExtensions.findAnnotationRecursively
|
|
||||||
import app.revanced.patcher.patch.Patch
|
|
||||||
import app.revanced.patcher.patch.PatchClass
|
|
||||||
import dalvik.system.PathClassLoader
|
|
||||||
import org.jf.dexlib2.DexFileFactory
|
|
||||||
import java.io.File
|
|
||||||
import java.net.URLClassLoader
|
|
||||||
import java.util.jar.JarFile
|
|
||||||
import kotlin.streams.toList
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A patch bundle.
|
|
||||||
*
|
|
||||||
* @param fromClasses The classes to get [Patch]es from.
|
|
||||||
*/
|
|
||||||
sealed class PatchBundle private constructor(fromClasses: Iterable<Class<*>>) : Iterable<PatchClass> {
|
|
||||||
private val patches = fromClasses.filter {
|
|
||||||
if (it.isAnnotation) return@filter false
|
|
||||||
|
|
||||||
it.findAnnotationRecursively(app.revanced.patcher.patch.annotations.Patch::class) != null
|
|
||||||
}.map {
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
it as PatchClass
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun iterator() = patches.iterator()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A patch bundle of type [Jar].
|
|
||||||
*
|
|
||||||
* @param patchBundlePath The path to a patch bundle.
|
|
||||||
*/
|
|
||||||
class Jar(private val patchBundlePath: File) : PatchBundle(
|
|
||||||
with(URLClassLoader(arrayOf(patchBundlePath.toURI().toURL()), PatchBundle::class.java.classLoader)) {
|
|
||||||
JarFile(patchBundlePath).stream().filter { it.name.endsWith(".class") }.map {
|
|
||||||
loadClass(
|
|
||||||
it.realName.replace('/', '.').replace(".class", "")
|
|
||||||
)
|
|
||||||
}.toList()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A patch bundle of type [Dex] format.
|
|
||||||
*
|
|
||||||
* @param patchBundlePath The path to a patch bundle of dex format.
|
|
||||||
*/
|
|
||||||
class Dex(private val patchBundlePath: File) : PatchBundle(
|
|
||||||
with(PathClassLoader(patchBundlePath.absolutePath, null, PatchBundle::class.java.classLoader)) {
|
|
||||||
DexFileFactory.loadDexFile(patchBundlePath, null).classes.map { classDef ->
|
|
||||||
classDef.type.substring(1, classDef.length - 1).replace('/', '.')
|
|
||||||
}.map { loadClass(it) }
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,28 +1,22 @@
|
|||||||
pluginManagement {
|
val githubUsername: String = providers.gradleProperty("gpr.user").orNull ?: System.getenv("GITHUB_ACTOR")
|
||||||
repositories {
|
val githubPassword: String = providers.gradleProperty("gpr.key").orNull ?: System.getenv("GITHUB_TOKEN")
|
||||||
mavenCentral()
|
|
||||||
maven {
|
|
||||||
url = uri("https://maven.pkg.github.com/revanced/multidexlib2")
|
|
||||||
credentials {
|
|
||||||
username = providers.gradleProperty("gpr.user").orNull ?: System.getenv("GITHUB_ACTOR")
|
|
||||||
password = providers.gradleProperty("gpr.key").orNull ?: System.getenv("GITHUB_TOKEN")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencyResolutionManagement {
|
dependencyResolutionManagement {
|
||||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
maven {
|
google()
|
||||||
url = uri("https://maven.pkg.github.com/revanced/multidexlib2")
|
mavenLocal()
|
||||||
credentials {
|
listOf("multidexlib2", "apktool").forEach { repo ->
|
||||||
username = providers.gradleProperty("gpr.user").orNull ?: System.getenv("GITHUB_ACTOR")
|
maven {
|
||||||
password = providers.gradleProperty("gpr.key").orNull ?: System.getenv("GITHUB_TOKEN")
|
url = uri("https://maven.pkg.github.com/revanced/$repo")
|
||||||
|
credentials {
|
||||||
|
username = githubUsername
|
||||||
|
password = githubPassword
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
include("revanced-patcher", "arsclib-utils")
|
rootProject.name = "revanced-patcher"
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package app.revanced.patcher
|
||||||
|
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
interface IntegrationsConsumer {
|
||||||
|
fun acceptIntegrations(integrations: List<File>)
|
||||||
|
}
|
||||||
14
src/main/kotlin/app/revanced/patcher/PackageMetadata.kt
Normal file
14
src/main/kotlin/app/revanced/patcher/PackageMetadata.kt
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package app.revanced.patcher
|
||||||
|
|
||||||
|
import brut.androlib.apk.ApkInfo
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Metadata about a package.
|
||||||
|
*/
|
||||||
|
class PackageMetadata internal constructor(internal val apkInfo: ApkInfo) {
|
||||||
|
lateinit var packageName: String
|
||||||
|
internal set
|
||||||
|
|
||||||
|
lateinit var packageVersion: String
|
||||||
|
internal set
|
||||||
|
}
|
||||||
74
src/main/kotlin/app/revanced/patcher/PatchBundleLoader.kt
Normal file
74
src/main/kotlin/app/revanced/patcher/PatchBundleLoader.kt
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
@file:Suppress("unused")
|
||||||
|
|
||||||
|
package app.revanced.patcher
|
||||||
|
|
||||||
|
import app.revanced.patcher.extensions.AnnotationExtensions.findAnnotationRecursively
|
||||||
|
import app.revanced.patcher.extensions.PatchExtensions.patchName
|
||||||
|
import app.revanced.patcher.patch.Patch
|
||||||
|
import app.revanced.patcher.patch.PatchClass
|
||||||
|
import dalvik.system.DexClassLoader
|
||||||
|
import lanchon.multidexlib2.BasicDexFileNamer
|
||||||
|
import lanchon.multidexlib2.MultiDexIO
|
||||||
|
import java.io.File
|
||||||
|
import java.net.URLClassLoader
|
||||||
|
import java.util.jar.JarFile
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A patch bundle.
|
||||||
|
*
|
||||||
|
* @param fromClasses The classes to get [Patch]es from.
|
||||||
|
*/
|
||||||
|
sealed class PatchBundleLoader private constructor(
|
||||||
|
fromClasses: Iterable<Class<*>>
|
||||||
|
) : MutableList<PatchClass> by mutableListOf() {
|
||||||
|
init {
|
||||||
|
fromClasses.filter {
|
||||||
|
if (it.isAnnotation) return@filter false
|
||||||
|
|
||||||
|
it.findAnnotationRecursively(app.revanced.patcher.patch.annotations.Patch::class) != null
|
||||||
|
}.map {
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
it as PatchClass
|
||||||
|
}.sortedBy {
|
||||||
|
it.patchName
|
||||||
|
}.let { addAll(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A [PatchBundleLoader] for JAR files.
|
||||||
|
*
|
||||||
|
* @param patchBundles The path to patch bundles of JAR format.
|
||||||
|
*/
|
||||||
|
class Jar(vararg patchBundles: File) :
|
||||||
|
PatchBundleLoader(with(URLClassLoader(patchBundles.map { it.toURI().toURL() }.toTypedArray())) {
|
||||||
|
patchBundles.flatMap { patchBundle ->
|
||||||
|
// Get the names of all classes in the DEX file.
|
||||||
|
|
||||||
|
JarFile(patchBundle).entries().asSequence()
|
||||||
|
.filter { it.name.endsWith(".class") }
|
||||||
|
.map { it.name.replace('/', '.').replace(".class", "") }
|
||||||
|
.map { loadClass(it) }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A [PatchBundleLoader] for [Dex] files.
|
||||||
|
*
|
||||||
|
* @param patchBundles The path to patch bundles of DEX format.
|
||||||
|
*/
|
||||||
|
class Dex(vararg patchBundles: File) : PatchBundleLoader(with(
|
||||||
|
DexClassLoader(
|
||||||
|
patchBundles.joinToString(File.pathSeparator) { it.absolutePath },
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
PatchBundleLoader::class.java.classLoader
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
patchBundles
|
||||||
|
.flatMap {
|
||||||
|
MultiDexIO.readDexFile(true, it, BasicDexFileNamer(), null, null).classes
|
||||||
|
}
|
||||||
|
.map { classDef -> classDef.type.substring(1, classDef.length - 1) }
|
||||||
|
.map { loadClass(it) }
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package app.revanced.patcher
|
||||||
|
|
||||||
|
import app.revanced.patcher.patch.PatchResult
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import java.util.function.Function
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
interface PatchExecutorFunction : Function<Boolean, Flow<PatchResult>>
|
||||||
236
src/main/kotlin/app/revanced/patcher/Patcher.kt
Normal file
236
src/main/kotlin/app/revanced/patcher/Patcher.kt
Normal file
@@ -0,0 +1,236 @@
|
|||||||
|
package app.revanced.patcher
|
||||||
|
|
||||||
|
import app.revanced.patcher.data.Context
|
||||||
|
import app.revanced.patcher.data.ResourceContext
|
||||||
|
import app.revanced.patcher.extensions.AnnotationExtensions.findAnnotationRecursively
|
||||||
|
import app.revanced.patcher.extensions.PatchExtensions.dependencies
|
||||||
|
import app.revanced.patcher.extensions.PatchExtensions.patchName
|
||||||
|
import app.revanced.patcher.extensions.PatchExtensions.requiresIntegrations
|
||||||
|
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||||
|
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolveUsingLookupMap
|
||||||
|
import app.revanced.patcher.patch.*
|
||||||
|
import kotlinx.coroutines.flow.flow
|
||||||
|
import java.io.Closeable
|
||||||
|
import java.io.File
|
||||||
|
import java.util.function.Supplier
|
||||||
|
import java.util.logging.Level
|
||||||
|
import java.util.logging.LogManager
|
||||||
|
import java.util.logging.Logger
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ReVanced Patcher.
|
||||||
|
*
|
||||||
|
* @param options The options for the patcher.
|
||||||
|
*/
|
||||||
|
class Patcher(
|
||||||
|
private val options: PatcherOptions
|
||||||
|
) : PatchExecutorFunction, PatchesConsumer, IntegrationsConsumer, Supplier<PatcherResult>, Closeable {
|
||||||
|
private val logger = Logger.getLogger(Patcher::class.java.name)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The context of ReVanced [Patcher].
|
||||||
|
* This holds the current state of the patcher.
|
||||||
|
*/
|
||||||
|
val context = PatcherContext(options)
|
||||||
|
|
||||||
|
init {
|
||||||
|
LogManager.getLogManager().let { manager ->
|
||||||
|
// Disable root logger.
|
||||||
|
manager.getLogger("").level = Level.OFF
|
||||||
|
|
||||||
|
// Enable ReVanced logging only.
|
||||||
|
manager.loggerNames
|
||||||
|
.toList()
|
||||||
|
.filter { it.startsWith("app.revanced") }
|
||||||
|
.map { manager.getLogger(it) }
|
||||||
|
.forEach { it.level = Level.INFO }
|
||||||
|
}
|
||||||
|
|
||||||
|
context.resourceContext.decodeResources(ResourceContext.ResourceDecodingMode.MANIFEST_ONLY)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun acceptPatches(patches: List<PatchClass>) {
|
||||||
|
/**
|
||||||
|
* Returns true if at least one patches or its dependencies matches the given predicate.
|
||||||
|
*/
|
||||||
|
fun PatchClass.anyRecursively(predicate: (PatchClass) -> Boolean): Boolean =
|
||||||
|
predicate(this) || dependencies?.any { dependency ->
|
||||||
|
dependency.java.anyRecursively(predicate)
|
||||||
|
} ?: false
|
||||||
|
|
||||||
|
// Determine if resource patching is required.
|
||||||
|
for (patch in patches) {
|
||||||
|
if (patch.anyRecursively { ResourcePatch::class.java.isAssignableFrom(it) }) {
|
||||||
|
options.resourceDecodingMode = ResourceContext.ResourceDecodingMode.FULL
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine if merging integrations is required.
|
||||||
|
for (patch in patches) {
|
||||||
|
if (patch.anyRecursively { it.requiresIntegrations }) {
|
||||||
|
context.bytecodeContext.integrations.merge = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
context.patches.addAll(patches)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add integrations to the [Patcher].
|
||||||
|
*
|
||||||
|
* @param integrations The integrations to add. Must be a DEX file or container of DEX files.
|
||||||
|
*/
|
||||||
|
override fun acceptIntegrations(integrations: List<File>) {
|
||||||
|
context.bytecodeContext.integrations.addAll(integrations)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute [Patch]es that were added to ReVanced [Patcher].
|
||||||
|
*
|
||||||
|
* @param returnOnError If true, ReVanced [Patcher] will return immediately if a [Patch] fails.
|
||||||
|
* @return A pair of the name of the [Patch] and its [PatchResult].
|
||||||
|
*/
|
||||||
|
override fun apply(returnOnError: Boolean) = flow {
|
||||||
|
class ExecutedPatch(val patchInstance: Patch<Context<*>>, val patchResult: PatchResult)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute a [Patch] and its dependencies recursively.
|
||||||
|
*
|
||||||
|
* @param patchClass The [Patch] to execute.
|
||||||
|
* @param executedPatches A map to prevent [Patch]es from being executed twice due to dependencies.
|
||||||
|
* @return The result of executing the [Patch].
|
||||||
|
*/
|
||||||
|
fun executePatch(
|
||||||
|
patchClass: PatchClass,
|
||||||
|
executedPatches: LinkedHashMap<String, ExecutedPatch>
|
||||||
|
): PatchResult {
|
||||||
|
val patchName = patchClass.patchName
|
||||||
|
|
||||||
|
executedPatches[patchName]?.let { executedPatch ->
|
||||||
|
executedPatch.patchResult.exception ?: return executedPatch.patchResult
|
||||||
|
|
||||||
|
// Return a new result with an exception indicating that the patch was not executed previously,
|
||||||
|
// because it is a dependency of another patch that failed.
|
||||||
|
return PatchResult(patchName, PatchException("'$patchName' did not succeed previously"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recursively execute all dependency patches.
|
||||||
|
patchClass.dependencies?.forEach { dependencyClass ->
|
||||||
|
val dependency = dependencyClass.java
|
||||||
|
|
||||||
|
val result = executePatch(dependency, executedPatches)
|
||||||
|
|
||||||
|
result.exception?.let {
|
||||||
|
return PatchResult(
|
||||||
|
patchName,
|
||||||
|
PatchException(
|
||||||
|
"'$patchName' depends on '${dependency.patchName}' that raised an exception: $it"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Implement this in a more polymorphic way.
|
||||||
|
val patchInstance = patchClass.getDeclaredConstructor().newInstance()
|
||||||
|
|
||||||
|
val patchContext = if (patchInstance is BytecodePatch) {
|
||||||
|
patchInstance.fingerprints?.resolveUsingLookupMap(context.bytecodeContext)
|
||||||
|
|
||||||
|
context.bytecodeContext
|
||||||
|
} else {
|
||||||
|
context.resourceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
return try {
|
||||||
|
patchInstance.execute(patchContext)
|
||||||
|
|
||||||
|
PatchResult(patchName)
|
||||||
|
} catch (exception: PatchException) {
|
||||||
|
PatchResult(patchName, exception)
|
||||||
|
} catch (exception: Exception) {
|
||||||
|
PatchResult(patchName, PatchException(exception))
|
||||||
|
}.also { executedPatches[patchName] = ExecutedPatch(patchInstance, it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context.bytecodeContext.integrations.merge) context.bytecodeContext.integrations.flush()
|
||||||
|
|
||||||
|
MethodFingerprint.initializeFingerprintResolutionLookupMaps(context.bytecodeContext)
|
||||||
|
|
||||||
|
// Prevent from decoding the app manifest twice if it is not needed.
|
||||||
|
if (options.resourceDecodingMode == ResourceContext.ResourceDecodingMode.FULL)
|
||||||
|
context.resourceContext.decodeResources(ResourceContext.ResourceDecodingMode.FULL)
|
||||||
|
|
||||||
|
logger.info("Executing patches")
|
||||||
|
|
||||||
|
val executedPatches = LinkedHashMap<String, ExecutedPatch>() // Key is name.
|
||||||
|
|
||||||
|
context.patches.forEach { patch ->
|
||||||
|
val result = executePatch(patch, executedPatches)
|
||||||
|
|
||||||
|
// If the patch failed, or if the patch is not closeable, emit the result.
|
||||||
|
// Results of patches that are closeable will be emitted later.
|
||||||
|
result.exception?.let {
|
||||||
|
emit(result)
|
||||||
|
|
||||||
|
if (returnOnError) return@flow
|
||||||
|
} ?: run {
|
||||||
|
if (executedPatches[result.patchName]!!.patchInstance is Closeable) return@run
|
||||||
|
|
||||||
|
emit(result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
executedPatches.values
|
||||||
|
.filter { it.patchResult.exception == null }
|
||||||
|
.filter { it.patchInstance is Closeable }.asReversed().forEach { executedPatch ->
|
||||||
|
val patchName = executedPatch.patchResult.patchName
|
||||||
|
|
||||||
|
val result = try {
|
||||||
|
(executedPatch.patchInstance as Closeable).close()
|
||||||
|
|
||||||
|
executedPatch.patchResult
|
||||||
|
} catch (exception: PatchException) {
|
||||||
|
PatchResult(patchName, exception)
|
||||||
|
} catch (exception: Exception) {
|
||||||
|
PatchResult(patchName, PatchException(exception))
|
||||||
|
}
|
||||||
|
|
||||||
|
result.exception?.let {
|
||||||
|
emit(
|
||||||
|
PatchResult(
|
||||||
|
patchName,
|
||||||
|
PatchException("'$patchName' raised an exception while being closed: $it")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if (returnOnError) return@flow
|
||||||
|
} ?: run {
|
||||||
|
executedPatch
|
||||||
|
.patchInstance::class
|
||||||
|
.java
|
||||||
|
.findAnnotationRecursively(app.revanced.patcher.patch.annotations.Patch::class)
|
||||||
|
?: return@run
|
||||||
|
|
||||||
|
emit(result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun close() {
|
||||||
|
MethodFingerprint.clearFingerprintResolutionLookupMaps()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compile and save the patched APK file.
|
||||||
|
*
|
||||||
|
* @return The [PatcherResult] containing the patched input files.
|
||||||
|
*/
|
||||||
|
override fun get() = PatcherResult(
|
||||||
|
context.bytecodeContext.get(),
|
||||||
|
context.resourceContext.get(),
|
||||||
|
context.packageMetadata.apkInfo.doNotCompress?.toList()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
37
src/main/kotlin/app/revanced/patcher/PatcherContext.kt
Normal file
37
src/main/kotlin/app/revanced/patcher/PatcherContext.kt
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
package app.revanced.patcher
|
||||||
|
|
||||||
|
import app.revanced.patcher.data.BytecodeContext
|
||||||
|
import app.revanced.patcher.data.ResourceContext
|
||||||
|
import app.revanced.patcher.patch.Patch
|
||||||
|
import app.revanced.patcher.patch.PatchClass
|
||||||
|
import brut.androlib.apk.ApkInfo
|
||||||
|
import brut.directory.ExtFile
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A context for ReVanced [Patcher].
|
||||||
|
*
|
||||||
|
* @param options The [PatcherOptions] used to create this context.
|
||||||
|
*/
|
||||||
|
class PatcherContext internal constructor(options: PatcherOptions) {
|
||||||
|
/**
|
||||||
|
* [PackageMetadata] of the supplied [PatcherOptions.inputFile].
|
||||||
|
*/
|
||||||
|
val packageMetadata = PackageMetadata(ApkInfo(ExtFile(options.inputFile)))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The list of [Patch]es to execute.
|
||||||
|
*/
|
||||||
|
internal val patches = mutableListOf<PatchClass>()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The [ResourceContext] of this [PatcherContext].
|
||||||
|
* This holds the current state of the resources.
|
||||||
|
*/
|
||||||
|
internal val resourceContext = ResourceContext(this, options)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The [BytecodeContext] of this [PatcherContext].
|
||||||
|
* This holds the current state of the bytecode.
|
||||||
|
*/
|
||||||
|
internal val bytecodeContext = BytecodeContext(options)
|
||||||
|
}
|
||||||
73
src/main/kotlin/app/revanced/patcher/PatcherOptions.kt
Normal file
73
src/main/kotlin/app/revanced/patcher/PatcherOptions.kt
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
package app.revanced.patcher
|
||||||
|
|
||||||
|
import app.revanced.patcher.data.ResourceContext
|
||||||
|
import app.revanced.patcher.logging.impl.NopLogger
|
||||||
|
import brut.androlib.Config
|
||||||
|
import java.io.File
|
||||||
|
import java.util.logging.Logger
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options for ReVanced [Patcher].
|
||||||
|
* @param inputFile The input file to patch.
|
||||||
|
* @param resourceCachePath The path to the directory to use for caching resources.
|
||||||
|
* @param aaptBinaryPath The path to a custom aapt binary.
|
||||||
|
* @param frameworkFileDirectory The path to the directory to cache the framework file in.
|
||||||
|
* @param unusedLogger The logger to use for logging.
|
||||||
|
*/
|
||||||
|
data class PatcherOptions
|
||||||
|
@Deprecated("Use the constructor without the logger parameter instead")
|
||||||
|
constructor(
|
||||||
|
internal val inputFile: File,
|
||||||
|
internal val resourceCachePath: File = File("revanced-resource-cache"),
|
||||||
|
internal val aaptBinaryPath: String? = null,
|
||||||
|
internal val frameworkFileDirectory: String? = null,
|
||||||
|
internal val unusedLogger: app.revanced.patcher.logging.Logger = NopLogger
|
||||||
|
) {
|
||||||
|
private val logger = Logger.getLogger(PatcherOptions::class.java.name)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The mode to use for resource decoding.
|
||||||
|
* @see ResourceContext.ResourceDecodingMode
|
||||||
|
*/
|
||||||
|
internal var resourceDecodingMode = ResourceContext.ResourceDecodingMode.MANIFEST_ONLY
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The configuration to use for resource decoding and compiling.
|
||||||
|
*/
|
||||||
|
internal val resourceConfig = Config.getDefaultConfig().apply {
|
||||||
|
useAapt2 = true
|
||||||
|
aaptPath = aaptBinaryPath ?: ""
|
||||||
|
frameworkDirectory = frameworkFileDirectory
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options for ReVanced [Patcher].
|
||||||
|
* @param inputFile The input file to patch.
|
||||||
|
* @param resourceCachePath The path to the directory to use for caching resources.
|
||||||
|
* @param aaptBinaryPath The path to a custom aapt binary.
|
||||||
|
* @param frameworkFileDirectory The path to the directory to cache the framework file in.
|
||||||
|
*/
|
||||||
|
constructor(
|
||||||
|
inputFile: File,
|
||||||
|
resourceCachePath: File = File("revanced-resource-cache"),
|
||||||
|
aaptBinaryPath: String? = null,
|
||||||
|
frameworkFileDirectory: String? = null,
|
||||||
|
) : this(
|
||||||
|
inputFile,
|
||||||
|
resourceCachePath,
|
||||||
|
aaptBinaryPath,
|
||||||
|
frameworkFileDirectory,
|
||||||
|
NopLogger
|
||||||
|
)
|
||||||
|
|
||||||
|
fun recreateResourceCacheDirectory() = resourceCachePath.also {
|
||||||
|
if (it.exists()) {
|
||||||
|
logger.info("Deleting existing resource cache directory")
|
||||||
|
|
||||||
|
if (!it.deleteRecursively())
|
||||||
|
logger.severe("Failed to delete existing resource cache directory")
|
||||||
|
}
|
||||||
|
|
||||||
|
it.mkdirs()
|
||||||
|
}
|
||||||
|
}
|
||||||
23
src/main/kotlin/app/revanced/patcher/PatcherResult.kt
Normal file
23
src/main/kotlin/app/revanced/patcher/PatcherResult.kt
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package app.revanced.patcher
|
||||||
|
|
||||||
|
import java.io.File
|
||||||
|
import java.io.InputStream
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The result of a patcher.
|
||||||
|
* @param dexFiles The patched dex files.
|
||||||
|
* @param resourceFile File containing resources that need to be extracted into the APK.
|
||||||
|
* @param doNotCompress List of relative paths of files to exclude from compressing.
|
||||||
|
*/
|
||||||
|
data class PatcherResult(
|
||||||
|
val dexFiles: List<PatchedDexFile>,
|
||||||
|
val resourceFile: File?,
|
||||||
|
val doNotCompress: List<String>? = null
|
||||||
|
) {
|
||||||
|
/**
|
||||||
|
* Wrapper for dex files.
|
||||||
|
* @param name The original name of the dex file.
|
||||||
|
* @param stream The dex file as [InputStream].
|
||||||
|
*/
|
||||||
|
class PatchedDexFile(val name: String, val stream: InputStream)
|
||||||
|
}
|
||||||
8
src/main/kotlin/app/revanced/patcher/PatchesConsumer.kt
Normal file
8
src/main/kotlin/app/revanced/patcher/PatchesConsumer.kt
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package app.revanced.patcher
|
||||||
|
|
||||||
|
import app.revanced.patcher.patch.PatchClass
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
interface PatchesConsumer {
|
||||||
|
fun acceptPatches(patches: List<PatchClass>)
|
||||||
|
}
|
||||||
@@ -19,14 +19,3 @@ annotation class Name(
|
|||||||
annotation class Description(
|
annotation class Description(
|
||||||
val description: String,
|
val description: String,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Annotation to version a [Patch].
|
|
||||||
* @param version The version of a [Patch].
|
|
||||||
*/
|
|
||||||
@Target(AnnotationTarget.CLASS)
|
|
||||||
@Deprecated("This annotation is deprecated and will be removed in the future.")
|
|
||||||
annotation class Version(
|
|
||||||
val version: String,
|
|
||||||
)
|
|
||||||
157
src/main/kotlin/app/revanced/patcher/data/BytecodeContext.kt
Normal file
157
src/main/kotlin/app/revanced/patcher/data/BytecodeContext.kt
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
package app.revanced.patcher.data
|
||||||
|
|
||||||
|
import app.revanced.patcher.PatcherContext
|
||||||
|
import app.revanced.patcher.PatcherOptions
|
||||||
|
import app.revanced.patcher.PatcherResult
|
||||||
|
import app.revanced.patcher.patch.Patch
|
||||||
|
import app.revanced.patcher.patch.annotations.RequiresIntegrations
|
||||||
|
import app.revanced.patcher.util.ClassMerger.merge
|
||||||
|
import app.revanced.patcher.util.ProxyClassList
|
||||||
|
import app.revanced.patcher.util.method.MethodWalker
|
||||||
|
import app.revanced.patcher.util.proxy.ClassProxy
|
||||||
|
import com.android.tools.smali.dexlib2.Opcodes
|
||||||
|
import com.android.tools.smali.dexlib2.iface.ClassDef
|
||||||
|
import com.android.tools.smali.dexlib2.iface.DexFile
|
||||||
|
import com.android.tools.smali.dexlib2.iface.Method
|
||||||
|
import com.android.tools.smali.dexlib2.writer.io.MemoryDataStore
|
||||||
|
import lanchon.multidexlib2.BasicDexFileNamer
|
||||||
|
import lanchon.multidexlib2.DexIO
|
||||||
|
import lanchon.multidexlib2.MultiDexIO
|
||||||
|
import java.io.File
|
||||||
|
import java.io.Flushable
|
||||||
|
import java.util.logging.Logger
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A context for bytecode.
|
||||||
|
* This holds the current state of the bytecode.
|
||||||
|
*
|
||||||
|
* @param options The [PatcherOptions] used to create this context.
|
||||||
|
*/
|
||||||
|
class BytecodeContext internal constructor(private val options: PatcherOptions) :
|
||||||
|
Context<List<PatcherResult.PatchedDexFile>> {
|
||||||
|
private val logger = Logger.getLogger(BytecodeContext::class.java.name)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [Opcodes] of the supplied [PatcherOptions.inputFile].
|
||||||
|
*/
|
||||||
|
internal lateinit var opcodes: Opcodes
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The list of classes.
|
||||||
|
*/
|
||||||
|
val classes by lazy {
|
||||||
|
ProxyClassList(
|
||||||
|
MultiDexIO.readDexFile(
|
||||||
|
true, options.inputFile, BasicDexFileNamer(), null, null
|
||||||
|
).also { opcodes = it.opcodes }.classes.toMutableSet()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The [Integrations] of this [PatcherContext].
|
||||||
|
*/
|
||||||
|
internal val integrations = Integrations()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Proxy a class.
|
||||||
|
* This will allow the class to be modified.
|
||||||
|
*
|
||||||
|
* @param classDef The class to proxy.
|
||||||
|
* @return A proxy for the class.
|
||||||
|
*/
|
||||||
|
fun proxy(classDef: ClassDef) = this.classes.proxies.find { it.immutableClass.type == classDef.type } ?: let {
|
||||||
|
ClassProxy(classDef).also { this.classes.add(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a [MethodWalker] instance for the current [BytecodeContext].
|
||||||
|
*
|
||||||
|
* @param startMethod The method to start at.
|
||||||
|
* @return A [MethodWalker] instance.
|
||||||
|
*/
|
||||||
|
fun toMethodWalker(startMethod: Method) = MethodWalker(this, startMethod)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The integrations of a [PatcherContext].
|
||||||
|
*/
|
||||||
|
internal inner class Integrations : MutableList<File> by mutableListOf(), Flushable {
|
||||||
|
/**
|
||||||
|
* Whether to merge integrations.
|
||||||
|
* True when any supplied [Patch] is annotated with [RequiresIntegrations].
|
||||||
|
*/
|
||||||
|
var merge = false
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merge integrations into the [BytecodeContext] and flush all [Integrations].
|
||||||
|
*/
|
||||||
|
override fun flush() {
|
||||||
|
if (!merge) return
|
||||||
|
|
||||||
|
logger.info("Merging integrations")
|
||||||
|
|
||||||
|
this@Integrations.forEach { integrations ->
|
||||||
|
MultiDexIO.readDexFile(
|
||||||
|
true,
|
||||||
|
integrations, BasicDexFileNamer(),
|
||||||
|
null,
|
||||||
|
null
|
||||||
|
).classes.forEach classDef@{ classDef ->
|
||||||
|
val existingClass = classes.find { it == classDef } ?: run {
|
||||||
|
logger.fine("Merging $classDef")
|
||||||
|
classes.add(classDef)
|
||||||
|
return@classDef
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.fine("$classDef exists. Adding missing methods and fields.")
|
||||||
|
|
||||||
|
existingClass.merge(classDef, this@BytecodeContext).let { mergedClass ->
|
||||||
|
// If the class was merged, replace the original class with the merged class.
|
||||||
|
if (mergedClass === existingClass) return@let
|
||||||
|
classes.apply { remove(existingClass); add(mergedClass) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
clear()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compile bytecode from the [BytecodeContext].
|
||||||
|
*
|
||||||
|
* @return The compiled bytecode.
|
||||||
|
*/
|
||||||
|
override fun get(): List<PatcherResult.PatchedDexFile> {
|
||||||
|
logger.info("Compiling modified dex files")
|
||||||
|
|
||||||
|
return mutableMapOf<String, MemoryDataStore>().apply {
|
||||||
|
MultiDexIO.writeDexFile(
|
||||||
|
true, -1, // Defaults to amount of available cores.
|
||||||
|
this, BasicDexFileNamer(), object : DexFile {
|
||||||
|
override fun getClasses() = this@BytecodeContext.classes.also(ProxyClassList::replaceClasses)
|
||||||
|
override fun getOpcodes() = this@BytecodeContext.opcodes
|
||||||
|
}, DexIO.DEFAULT_MAX_DEX_POOL_SIZE, null
|
||||||
|
)
|
||||||
|
}.map { PatcherResult.PatchedDexFile(it.key, it.value.readAt(0)) }
|
||||||
|
}
|
||||||
|
}
|
||||||
9
src/main/kotlin/app/revanced/patcher/data/Context.kt
Normal file
9
src/main/kotlin/app/revanced/patcher/data/Context.kt
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package app.revanced.patcher.data
|
||||||
|
|
||||||
|
import java.util.function.Supplier
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A common interface for contexts such as [ResourceContext] and [BytecodeContext].
|
||||||
|
*/
|
||||||
|
|
||||||
|
sealed interface Context<T> : Supplier<T>
|
||||||
160
src/main/kotlin/app/revanced/patcher/data/ResourceContext.kt
Normal file
160
src/main/kotlin/app/revanced/patcher/data/ResourceContext.kt
Normal file
@@ -0,0 +1,160 @@
|
|||||||
|
package app.revanced.patcher.data
|
||||||
|
|
||||||
|
import app.revanced.patcher.PatcherContext
|
||||||
|
import app.revanced.patcher.PatcherOptions
|
||||||
|
import app.revanced.patcher.util.DomFileEditor
|
||||||
|
import brut.androlib.AaptInvoker
|
||||||
|
import brut.androlib.ApkDecoder
|
||||||
|
import brut.androlib.apk.UsesFramework
|
||||||
|
import brut.androlib.res.Framework
|
||||||
|
import brut.androlib.res.ResourcesDecoder
|
||||||
|
import brut.androlib.res.decoder.AndroidManifestResourceParser
|
||||||
|
import brut.androlib.res.decoder.XmlPullStreamDecoder
|
||||||
|
import brut.androlib.res.xml.ResXmlPatcher
|
||||||
|
import brut.directory.ExtFile
|
||||||
|
import java.io.File
|
||||||
|
import java.io.InputStream
|
||||||
|
import java.io.OutputStream
|
||||||
|
import java.nio.file.Files
|
||||||
|
import java.util.logging.Logger
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A context for resources.
|
||||||
|
* This holds the current state of the resources.
|
||||||
|
*
|
||||||
|
* @param context The [PatcherContext] to create the context for.
|
||||||
|
*/
|
||||||
|
class ResourceContext internal constructor(
|
||||||
|
private val context: PatcherContext,
|
||||||
|
private val options: PatcherOptions
|
||||||
|
) : Context<File?>, Iterable<File> {
|
||||||
|
private val logger = Logger.getLogger(ResourceContext::class.java.name)
|
||||||
|
|
||||||
|
val xmlEditor = XmlFileHolder()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decode resources for the patcher.
|
||||||
|
*
|
||||||
|
* @param mode The [ResourceDecodingMode] to use when decoding.
|
||||||
|
*/
|
||||||
|
internal fun decodeResources(mode: ResourceDecodingMode) = with(context.packageMetadata.apkInfo) {
|
||||||
|
// Needed to decode resources.
|
||||||
|
val resourcesDecoder = ResourcesDecoder(options.resourceConfig, this)
|
||||||
|
|
||||||
|
when (mode) {
|
||||||
|
ResourceDecodingMode.FULL -> {
|
||||||
|
val outDir = options.recreateResourceCacheDirectory()
|
||||||
|
|
||||||
|
logger.info("Decoding resources")
|
||||||
|
|
||||||
|
resourcesDecoder.decodeResources(outDir)
|
||||||
|
resourcesDecoder.decodeManifest(outDir)
|
||||||
|
|
||||||
|
// Needed to record uncompressed files.
|
||||||
|
val apkDecoder = ApkDecoder(options.resourceConfig, this)
|
||||||
|
apkDecoder.recordUncompressedFiles(resourcesDecoder.resFileMapping)
|
||||||
|
|
||||||
|
usesFramework = UsesFramework().apply {
|
||||||
|
ids = resourcesDecoder.resTable.listFramePackages().map { it.id }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ResourceDecodingMode.MANIFEST_ONLY -> {
|
||||||
|
logger.info("Decoding app manifest")
|
||||||
|
|
||||||
|
// Decode manually instead of using resourceDecoder.decodeManifest
|
||||||
|
// because it does not support decoding to an OutputStream.
|
||||||
|
XmlPullStreamDecoder(
|
||||||
|
AndroidManifestResourceParser(resourcesDecoder.resTable),
|
||||||
|
resourcesDecoder.resXmlSerializer
|
||||||
|
).decodeManifest(
|
||||||
|
apkFile.directory.getFileInput("AndroidManifest.xml"),
|
||||||
|
// Older Android versions do not support OutputStream.nullOutputStream()
|
||||||
|
object : OutputStream() {
|
||||||
|
override fun write(b: Int) { /* do nothing */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// Get the package name and version from the manifest using the XmlPullStreamDecoder.
|
||||||
|
// XmlPullStreamDecoder.decodeManifest() sets metadata.apkInfo.
|
||||||
|
context.packageMetadata.let { metadata ->
|
||||||
|
metadata.packageName = resourcesDecoder.resTable.packageRenamed
|
||||||
|
versionInfo.let {
|
||||||
|
metadata.packageVersion = it.versionName ?: it.versionCode
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
operator fun get(path: String) = options.resourceCachePath.resolve(path)
|
||||||
|
|
||||||
|
override fun iterator() = options.resourceCachePath.walkTopDown().iterator()
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compile resources from the [ResourceContext].
|
||||||
|
*
|
||||||
|
* @return The compiled resources.
|
||||||
|
*/
|
||||||
|
override fun get(): File? {
|
||||||
|
var resourceFile: File? = null
|
||||||
|
|
||||||
|
if (options.resourceDecodingMode == ResourceDecodingMode.FULL) {
|
||||||
|
logger.info("Compiling modified resources")
|
||||||
|
|
||||||
|
val cacheDirectory = ExtFile(options.resourceCachePath)
|
||||||
|
val aaptFile = cacheDirectory.resolve("aapt_temp_file").also {
|
||||||
|
Files.deleteIfExists(it.toPath())
|
||||||
|
}.also { resourceFile = it }
|
||||||
|
|
||||||
|
try {
|
||||||
|
AaptInvoker(
|
||||||
|
options.resourceConfig, context.packageMetadata.apkInfo
|
||||||
|
).invokeAapt(aaptFile,
|
||||||
|
cacheDirectory.resolve("AndroidManifest.xml").also {
|
||||||
|
ResXmlPatcher.fixingPublicAttrsInProviderAttributes(it)
|
||||||
|
},
|
||||||
|
cacheDirectory.resolve("res"),
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
context.packageMetadata.apkInfo.usesFramework.let { usesFramework ->
|
||||||
|
usesFramework.ids.map { id ->
|
||||||
|
Framework(options.resourceConfig).getFrameworkApk(id, usesFramework.tag)
|
||||||
|
}.toTypedArray()
|
||||||
|
})
|
||||||
|
} finally {
|
||||||
|
cacheDirectory.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return resourceFile
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type of decoding the resources.
|
||||||
|
*/
|
||||||
|
internal enum class ResourceDecodingMode {
|
||||||
|
/**
|
||||||
|
* Decode all resources.
|
||||||
|
*/
|
||||||
|
FULL,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decode the manifest file only.
|
||||||
|
*/
|
||||||
|
MANIFEST_ONLY,
|
||||||
|
}
|
||||||
|
|
||||||
|
inner class XmlFileHolder {
|
||||||
|
operator fun get(inputStream: InputStream) =
|
||||||
|
DomFileEditor(inputStream)
|
||||||
|
|
||||||
|
operator fun get(path: String): DomFileEditor {
|
||||||
|
return DomFileEditor(this@ResourceContext[path])
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package app.revanced.patcher.extensions
|
package app.revanced.patcher.extensions
|
||||||
|
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
||||||
import org.jf.dexlib2.AccessFlags
|
import com.android.tools.smali.dexlib2.AccessFlags
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a label for the instruction at given index.
|
* Create a label for the instruction at given index.
|
||||||
@@ -4,12 +4,12 @@ import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
|||||||
import app.revanced.patcher.util.smali.ExternalLabel
|
import app.revanced.patcher.util.smali.ExternalLabel
|
||||||
import app.revanced.patcher.util.smali.toInstruction
|
import app.revanced.patcher.util.smali.toInstruction
|
||||||
import app.revanced.patcher.util.smali.toInstructions
|
import app.revanced.patcher.util.smali.toInstructions
|
||||||
import org.jf.dexlib2.builder.BuilderInstruction
|
import com.android.tools.smali.dexlib2.builder.BuilderInstruction
|
||||||
import org.jf.dexlib2.builder.BuilderOffsetInstruction
|
import com.android.tools.smali.dexlib2.builder.BuilderOffsetInstruction
|
||||||
import org.jf.dexlib2.builder.Label
|
import com.android.tools.smali.dexlib2.builder.Label
|
||||||
import org.jf.dexlib2.builder.MutableMethodImplementation
|
import com.android.tools.smali.dexlib2.builder.MutableMethodImplementation
|
||||||
import org.jf.dexlib2.builder.instruction.*
|
import com.android.tools.smali.dexlib2.builder.instruction.*
|
||||||
import org.jf.dexlib2.iface.instruction.Instruction
|
import com.android.tools.smali.dexlib2.iface.instruction.Instruction
|
||||||
|
|
||||||
object InstructionExtensions {
|
object InstructionExtensions {
|
||||||
|
|
||||||
@@ -22,8 +22,7 @@ object InstructionExtensions {
|
|||||||
fun MutableMethodImplementation.addInstructions(
|
fun MutableMethodImplementation.addInstructions(
|
||||||
index: Int,
|
index: Int,
|
||||||
instructions: List<BuilderInstruction>
|
instructions: List<BuilderInstruction>
|
||||||
) =
|
) = instructions.asReversed().forEach { addInstruction(index, it) }
|
||||||
instructions.asReversed().forEach { addInstruction(index, it) }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add instructions to a method.
|
* Add instructions to a method.
|
||||||
@@ -321,6 +320,11 @@ object InstructionExtensions {
|
|||||||
* @param T The type of instruction to return.
|
* @param T The type of instruction to return.
|
||||||
* @return The instruction.
|
* @return The instruction.
|
||||||
*/
|
*/
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
fun <T> MutableMethod.getInstruction(index: Int): T = implementation!!.getInstruction<T>(index)
|
fun <T> MutableMethod.getInstruction(index: Int): T = implementation!!.getInstruction<T>(index)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the instructions of a method.
|
||||||
|
* @return The instructions.
|
||||||
|
*/
|
||||||
|
fun MutableMethod.getInstructions(): MutableList<BuilderInstruction> = implementation!!.instructions
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,6 @@ package app.revanced.patcher.extensions
|
|||||||
import app.revanced.patcher.annotation.Compatibility
|
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.extensions.AnnotationExtensions.findAnnotationRecursively
|
import app.revanced.patcher.extensions.AnnotationExtensions.findAnnotationRecursively
|
||||||
import app.revanced.patcher.patch.OptionsContainer
|
import app.revanced.patcher.patch.OptionsContainer
|
||||||
import app.revanced.patcher.patch.Patch
|
import app.revanced.patcher.patch.Patch
|
||||||
@@ -22,13 +21,6 @@ object PatchExtensions {
|
|||||||
val PatchClass.patchName: String
|
val PatchClass.patchName: String
|
||||||
get() = findAnnotationRecursively(Name::class)?.name ?: this.simpleName
|
get() = findAnnotationRecursively(Name::class)?.name ?: this.simpleName
|
||||||
|
|
||||||
/**
|
|
||||||
* The version of a [Patch].
|
|
||||||
*/
|
|
||||||
@Deprecated("This property is deprecated and will be removed in the future.")
|
|
||||||
val PatchClass.version
|
|
||||||
get() = findAnnotationRecursively(Version::class)?.version
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Weather or not a [Patch] should be included.
|
* Weather or not a [Patch] should be included.
|
||||||
*/
|
*/
|
||||||
@@ -1,19 +1,19 @@
|
|||||||
package app.revanced.patcher.fingerprint.method.impl
|
package app.revanced.patcher.fingerprint.method.impl
|
||||||
|
|
||||||
import app.revanced.patcher.BytecodeContext
|
import app.revanced.patcher.data.BytecodeContext
|
||||||
import app.revanced.patcher.extensions.MethodFingerprintExtensions.fuzzyPatternScanMethod
|
import app.revanced.patcher.extensions.MethodFingerprintExtensions.fuzzyPatternScanMethod
|
||||||
import app.revanced.patcher.fingerprint.Fingerprint
|
import app.revanced.patcher.fingerprint.Fingerprint
|
||||||
import app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod
|
import app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod
|
||||||
import app.revanced.patcher.patch.PatchException
|
import app.revanced.patcher.patch.PatchException
|
||||||
import app.revanced.patcher.util.proxy.ClassProxy
|
import app.revanced.patcher.util.proxy.ClassProxy
|
||||||
import org.jf.dexlib2.AccessFlags
|
import com.android.tools.smali.dexlib2.AccessFlags
|
||||||
import org.jf.dexlib2.Opcode
|
import com.android.tools.smali.dexlib2.Opcode
|
||||||
import org.jf.dexlib2.iface.ClassDef
|
import com.android.tools.smali.dexlib2.iface.ClassDef
|
||||||
import org.jf.dexlib2.iface.Method
|
import com.android.tools.smali.dexlib2.iface.Method
|
||||||
import org.jf.dexlib2.iface.instruction.Instruction
|
import com.android.tools.smali.dexlib2.iface.instruction.Instruction
|
||||||
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
|
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
|
||||||
import org.jf.dexlib2.iface.reference.StringReference
|
import com.android.tools.smali.dexlib2.iface.reference.StringReference
|
||||||
import org.jf.dexlib2.util.MethodUtil
|
import com.android.tools.smali.dexlib2.util.MethodUtil
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
private typealias StringMatch = MethodFingerprintResult.MethodFingerprintScanResult.StringsScanResult.StringMatch
|
private typealias StringMatch = MethodFingerprintResult.MethodFingerprintScanResult.StringsScanResult.StringMatch
|
||||||
@@ -99,7 +99,7 @@ abstract class MethodFingerprint(
|
|||||||
methodClassPairs!!.add(methodClassPair)
|
methodClassPairs!!.add(methodClassPair)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (methods.isNotEmpty()) throw PatchException("Map already initialized")
|
if (methods.isNotEmpty()) clearFingerprintResolutionLookupMaps()
|
||||||
|
|
||||||
context.classes.forEach { classDef ->
|
context.classes.forEach { classDef ->
|
||||||
classDef.methods.forEach { method ->
|
classDef.methods.forEach { method ->
|
||||||
@@ -362,18 +362,18 @@ abstract class MethodFingerprint(
|
|||||||
val patternOpcode = pattern.elementAt(patternIndex)
|
val patternOpcode = pattern.elementAt(patternIndex)
|
||||||
|
|
||||||
if (patternOpcode != null && patternOpcode.ordinal != originalOpcode.ordinal) {
|
if (patternOpcode != null && patternOpcode.ordinal != originalOpcode.ordinal) {
|
||||||
// Reaching maximum threshold (0) means,
|
// reaching maximum threshold (0) means,
|
||||||
// the pattern does not match to the current instructions.
|
// the pattern does not match to the current instructions
|
||||||
if (threshold-- == 0) break
|
if (threshold-- == 0) break
|
||||||
}
|
}
|
||||||
|
|
||||||
if (patternIndex < patternLength - 1) {
|
if (patternIndex < patternLength - 1) {
|
||||||
// If the entire pattern has not been scanned yet
|
// if the entire pattern has not been scanned yet
|
||||||
// continue the scan.
|
// continue the scan
|
||||||
patternIndex++
|
patternIndex++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// The pattern is valid, generate warnings if fuzzyPatternScanMethod is FuzzyPatternScanMethod
|
// the pattern is valid, generate warnings if fuzzyPatternScanMethod is FuzzyPatternScanMethod
|
||||||
val result =
|
val result =
|
||||||
MethodFingerprintResult.MethodFingerprintScanResult.PatternScanResult(
|
MethodFingerprintResult.MethodFingerprintScanResult.PatternScanResult(
|
||||||
index,
|
index,
|
||||||
@@ -448,7 +448,7 @@ data class MethodFingerprintResult(
|
|||||||
* Use [classDef] where possible.
|
* Use [classDef] where possible.
|
||||||
*/
|
*/
|
||||||
@Suppress("MemberVisibilityCanBePrivate")
|
@Suppress("MemberVisibilityCanBePrivate")
|
||||||
val mutableClass by lazy { context.classes.proxy(classDef).mutableClass }
|
val mutableClass by lazy { context.proxy(classDef).mutableClass }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a mutable clone of [method]
|
* Returns a mutable clone of [method]
|
||||||
9
src/main/kotlin/app/revanced/patcher/logging/Logger.kt
Normal file
9
src/main/kotlin/app/revanced/patcher/logging/Logger.kt
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package app.revanced.patcher.logging
|
||||||
|
|
||||||
|
@Deprecated("This will be removed in a future release")
|
||||||
|
interface Logger {
|
||||||
|
fun error(msg: String) {}
|
||||||
|
fun warn(msg: String) {}
|
||||||
|
fun info(msg: String) {}
|
||||||
|
fun trace(msg: String) {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package app.revanced.patcher.logging.impl
|
||||||
|
|
||||||
|
import app.revanced.patcher.logging.Logger
|
||||||
|
|
||||||
|
@Deprecated("This will be removed in a future release")
|
||||||
|
object NopLogger : Logger
|
||||||
@@ -1,24 +1,27 @@
|
|||||||
package app.revanced.patcher.patch
|
package app.revanced.patcher.patch
|
||||||
|
|
||||||
import app.revanced.patcher.BytecodeContext
|
import app.revanced.patcher.data.BytecodeContext
|
||||||
import app.revanced.patcher.Context
|
import app.revanced.patcher.data.Context
|
||||||
import app.revanced.patcher.ResourceContext
|
import app.revanced.patcher.data.ResourceContext
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||||
import java.io.Closeable
|
import java.io.Closeable
|
||||||
|
|
||||||
|
typealias PatchClass = Class<out Patch<Context<*>>>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A ReVanced patch.
|
* A ReVanced patch.
|
||||||
*
|
*
|
||||||
* If it implements [Closeable], it will be closed after all patches have been executed.
|
* If it implements [Closeable], it will be closed after all patches have been executed.
|
||||||
* Closing will be done in reverse execution order.
|
* Closing will be done in reverse execution order.
|
||||||
*/
|
*/
|
||||||
sealed interface Patch<out T : Context> {
|
sealed interface Patch<out T : Context<*>> {
|
||||||
/**
|
/**
|
||||||
* The main function of the [Patch] which the patcher will call.
|
* The main function of the [Patch] which the patcher will call.
|
||||||
*
|
*
|
||||||
* @param context The [Context] the patch will work on.
|
* @param context The [Context] the patch will work on.
|
||||||
|
* @return The result of executing the patch.
|
||||||
*/
|
*/
|
||||||
suspend fun execute(context: @UnsafeVariance T)
|
fun execute(context: @UnsafeVariance T)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,9 +37,3 @@ interface ResourcePatch : Patch<ResourceContext>
|
|||||||
abstract class BytecodePatch(
|
abstract class BytecodePatch(
|
||||||
internal val fingerprints: Iterable<MethodFingerprint>? = null
|
internal val fingerprints: Iterable<MethodFingerprint>? = null
|
||||||
) : Patch<BytecodeContext>
|
) : Patch<BytecodeContext>
|
||||||
|
|
||||||
// TODO: populate this everywhere where the alias is not used yet
|
|
||||||
/**
|
|
||||||
* The class type of [Patch].
|
|
||||||
*/
|
|
||||||
typealias PatchClass = Class<out Patch<Context>>
|
|
||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
package app.revanced.patcher.patch
|
package app.revanced.patcher.patch
|
||||||
|
|
||||||
|
import java.nio.file.Path
|
||||||
|
import kotlin.io.path.pathString
|
||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
class NoSuchOptionException(val option: String) : Exception("No such option: $option")
|
class NoSuchOptionException(val option: String) : Exception("No such option: $option")
|
||||||
@@ -77,10 +79,10 @@ class PatchOptions(vararg options: PatchOption<*>) : Iterable<PatchOption<*>> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A [Patch] option.
|
* A [Patch] option.
|
||||||
* @param key Unique identifier of the option. Example: _`settings.microg.enabled`_
|
* @param key Unique identifier of the option. Example: _`settings`_
|
||||||
* @param default The default value of the option.
|
* @param default The default value of the option.
|
||||||
* @param title A human-readable title of the option. Example: _MicroG Settings_
|
* @param title A human-readable title of the option. Example: _Patch Settings_
|
||||||
* @param description A human-readable description of the option. Example: _Settings integration for MicroG._
|
* @param description A human-readable description of the option. Example: _Settings for the patches._
|
||||||
* @param required Whether the option is required.
|
* @param required Whether the option is required.
|
||||||
*/
|
*/
|
||||||
@Suppress("MemberVisibilityCanBePrivate")
|
@Suppress("MemberVisibilityCanBePrivate")
|
||||||
10
src/main/kotlin/app/revanced/patcher/patch/PatchResult.kt
Normal file
10
src/main/kotlin/app/revanced/patcher/patch/PatchResult.kt
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package app.revanced.patcher.patch
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A result of executing a [Patch].
|
||||||
|
*
|
||||||
|
* @param patchName The name of the [Patch].
|
||||||
|
* @param exception The [PatchException] thrown, if any.
|
||||||
|
*/
|
||||||
|
@Suppress("MemberVisibilityCanBePrivate")
|
||||||
|
class PatchResult internal constructor(val patchName: String, val exception: PatchException? = null)
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package app.revanced.patcher.patch.annotations
|
package app.revanced.patcher.patch.annotations
|
||||||
|
|
||||||
import app.revanced.patcher.Context
|
import app.revanced.patcher.data.Context
|
||||||
import app.revanced.patcher.patch.Patch
|
import app.revanced.patcher.patch.Patch
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
@@ -16,12 +16,12 @@ annotation class Patch(val include: Boolean = true)
|
|||||||
*/
|
*/
|
||||||
@Target(AnnotationTarget.CLASS)
|
@Target(AnnotationTarget.CLASS)
|
||||||
annotation class DependsOn(
|
annotation class DependsOn(
|
||||||
val dependencies: Array<KClass<out Patch<Context>>> = [] // TODO: This should be a list of PatchClass instead
|
val dependencies: Array<KClass<out Patch<Context<*>>>> = []
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TODO: Remove this annotation, once integrations are coupled with patches.
|
||||||
/**
|
/**
|
||||||
* Annotation to mark [Patch]es which depend on integrations.
|
* Annotation to mark [Patch]es which depend on integrations.
|
||||||
*/
|
*/
|
||||||
@Target(AnnotationTarget.CLASS)
|
@Target(AnnotationTarget.CLASS)
|
||||||
annotation class RequiresIntegrations // TODO: Remove this annotation and replace it with a proper system
|
annotation class RequiresIntegrations
|
||||||
@@ -1,23 +1,23 @@
|
|||||||
package app.revanced.patcher.util
|
package app.revanced.patcher.util
|
||||||
|
|
||||||
import app.revanced.patcher.BytecodeContext
|
import app.revanced.patcher.data.BytecodeContext
|
||||||
import app.revanced.patcher.extensions.or
|
import app.revanced.patcher.extensions.or
|
||||||
import app.revanced.patcher.logging.Logger
|
|
||||||
import app.revanced.patcher.util.ClassMerger.Utils.asMutableClass
|
import app.revanced.patcher.util.ClassMerger.Utils.asMutableClass
|
||||||
import app.revanced.patcher.util.ClassMerger.Utils.filterAny
|
import app.revanced.patcher.util.ClassMerger.Utils.filterAny
|
||||||
import app.revanced.patcher.util.ClassMerger.Utils.filterNotAny
|
import app.revanced.patcher.util.ClassMerger.Utils.filterNotAny
|
||||||
import app.revanced.patcher.util.ClassMerger.Utils.isPublic
|
import app.revanced.patcher.util.ClassMerger.Utils.isPublic
|
||||||
import app.revanced.patcher.util.ClassMerger.Utils.toPublic
|
import app.revanced.patcher.util.ClassMerger.Utils.toPublic
|
||||||
import app.revanced.patcher.util.TypeUtil.traverseClassHierarchy
|
import app.revanced.patcher.util.ClassMerger.Utils.traverseClassHierarchy
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableClass
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableClass
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableClass.Companion.toMutable
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableClass.Companion.toMutable
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableField
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableField
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableField.Companion.toMutable
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableField.Companion.toMutable
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable
|
||||||
import org.jf.dexlib2.AccessFlags
|
import com.android.tools.smali.dexlib2.AccessFlags
|
||||||
import org.jf.dexlib2.iface.ClassDef
|
import com.android.tools.smali.dexlib2.iface.ClassDef
|
||||||
import org.jf.dexlib2.util.MethodUtil
|
import com.android.tools.smali.dexlib2.util.MethodUtil
|
||||||
|
import java.util.logging.Logger
|
||||||
import kotlin.reflect.KFunction2
|
import kotlin.reflect.KFunction2
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -25,27 +25,28 @@ import kotlin.reflect.KFunction2
|
|||||||
* Note: This will not consider method implementations or if the class is missing a superclass or interfaces.
|
* Note: This will not consider method implementations or if the class is missing a superclass or interfaces.
|
||||||
*/
|
*/
|
||||||
internal object ClassMerger {
|
internal object ClassMerger {
|
||||||
|
private val logger = Logger.getLogger(ClassMerger::class.java.name)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merge a class with [otherClass].
|
* Merge a class with [otherClass].
|
||||||
*
|
*
|
||||||
* @param otherClass The class to merge with
|
* @param otherClass The class to merge with
|
||||||
* @param context The context to traverse the class hierarchy in.
|
* @param context The context to traverse the class hierarchy in.
|
||||||
* @param logger A logger.
|
* @return The merged class or the original class if no merge was needed.
|
||||||
*/
|
*/
|
||||||
fun ClassDef.merge(otherClass: ClassDef, context: BytecodeContext, logger: Logger? = null) = this
|
fun ClassDef.merge(otherClass: ClassDef, context: BytecodeContext) = this
|
||||||
//.fixFieldAccess(otherClass, logger)
|
//.fixFieldAccess(otherClass)
|
||||||
//.fixMethodAccess(otherClass, logger)
|
//.fixMethodAccess(otherClass)
|
||||||
.addMissingFields(otherClass, logger)
|
.addMissingFields(otherClass)
|
||||||
.addMissingMethods(otherClass, logger)
|
.addMissingMethods(otherClass)
|
||||||
.publicize(otherClass, context, logger)
|
.publicize(otherClass, context)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add methods which are missing but existing in [fromClass].
|
* Add methods which are missing but existing in [fromClass].
|
||||||
*
|
*
|
||||||
* @param fromClass The class to add missing methods from.
|
* @param fromClass The class to add missing methods from.
|
||||||
* @param logger A logger.
|
|
||||||
*/
|
*/
|
||||||
private fun ClassDef.addMissingMethods(fromClass: ClassDef, logger: Logger? = null): ClassDef {
|
private fun ClassDef.addMissingMethods(fromClass: ClassDef): ClassDef {
|
||||||
val missingMethods = fromClass.methods.let { fromMethods ->
|
val missingMethods = fromClass.methods.let { fromMethods ->
|
||||||
methods.filterNot { method ->
|
methods.filterNot { method ->
|
||||||
fromMethods.any { fromMethod ->
|
fromMethods.any { fromMethod ->
|
||||||
@@ -56,7 +57,7 @@ internal object ClassMerger {
|
|||||||
|
|
||||||
if (missingMethods.isEmpty()) return this
|
if (missingMethods.isEmpty()) return this
|
||||||
|
|
||||||
logger?.trace("Found ${missingMethods.size} missing methods")
|
logger.fine("Found ${missingMethods.size} missing methods")
|
||||||
|
|
||||||
return asMutableClass().apply {
|
return asMutableClass().apply {
|
||||||
methods.addAll(missingMethods.map { it.toMutable() })
|
methods.addAll(missingMethods.map { it.toMutable() })
|
||||||
@@ -67,16 +68,15 @@ internal object ClassMerger {
|
|||||||
* Add fields which are missing but existing in [fromClass].
|
* Add fields which are missing but existing in [fromClass].
|
||||||
*
|
*
|
||||||
* @param fromClass The class to add missing fields from.
|
* @param fromClass The class to add missing fields from.
|
||||||
* @param logger A logger.
|
|
||||||
*/
|
*/
|
||||||
private fun ClassDef.addMissingFields(fromClass: ClassDef, logger: Logger? = null): ClassDef {
|
private fun ClassDef.addMissingFields(fromClass: ClassDef): ClassDef {
|
||||||
val missingFields = fields.filterNotAny(fromClass.fields) { field, fromField ->
|
val missingFields = fields.filterNotAny(fromClass.fields) { field, fromField ->
|
||||||
fromField.name == field.name
|
fromField.name == field.name
|
||||||
}
|
}
|
||||||
|
|
||||||
if (missingFields.isEmpty()) return this
|
if (missingFields.isEmpty()) return this
|
||||||
|
|
||||||
logger?.trace("Found ${missingFields.size} missing fields")
|
logger.fine("Found ${missingFields.size} missing fields")
|
||||||
|
|
||||||
return asMutableClass().apply {
|
return asMutableClass().apply {
|
||||||
fields.addAll(missingFields.map { it.toMutable() })
|
fields.addAll(missingFields.map { it.toMutable() })
|
||||||
@@ -87,15 +87,14 @@ internal object ClassMerger {
|
|||||||
* Make a class and its super class public recursively.
|
* Make a class and its super class public recursively.
|
||||||
* @param reference The class to check the [AccessFlags] of.
|
* @param reference The class to check the [AccessFlags] of.
|
||||||
* @param context The context to traverse the class hierarchy in.
|
* @param context The context to traverse the class hierarchy in.
|
||||||
* @param logger A logger.
|
|
||||||
*/
|
*/
|
||||||
private fun ClassDef.publicize(reference: ClassDef, context: BytecodeContext, logger: Logger? = null) =
|
private fun ClassDef.publicize(reference: ClassDef, context: BytecodeContext) =
|
||||||
if (reference.accessFlags.isPublic() && !accessFlags.isPublic())
|
if (reference.accessFlags.isPublic() && !accessFlags.isPublic())
|
||||||
this.asMutableClass().apply {
|
this.asMutableClass().apply {
|
||||||
context.traverseClassHierarchy(this) {
|
context.traverseClassHierarchy(this) {
|
||||||
if (accessFlags.isPublic()) return@traverseClassHierarchy
|
if (accessFlags.isPublic()) return@traverseClassHierarchy
|
||||||
|
|
||||||
logger?.trace("Publicizing ${this.type}")
|
logger.fine("Publicizing ${this.type}")
|
||||||
|
|
||||||
accessFlags = accessFlags.toPublic()
|
accessFlags = accessFlags.toPublic()
|
||||||
}
|
}
|
||||||
@@ -106,9 +105,8 @@ internal object ClassMerger {
|
|||||||
* Publicize fields if they are public in [reference].
|
* Publicize fields if they are public in [reference].
|
||||||
*
|
*
|
||||||
* @param reference The class to check the [AccessFlags] of the fields in.
|
* @param reference The class to check the [AccessFlags] of the fields in.
|
||||||
* @param logger A logger.
|
|
||||||
*/
|
*/
|
||||||
private fun ClassDef.fixFieldAccess(reference: ClassDef, logger: Logger? = null): ClassDef {
|
private fun ClassDef.fixFieldAccess(reference: ClassDef): ClassDef {
|
||||||
val brokenFields = fields.filterAny(reference.fields) { field, referenceField ->
|
val brokenFields = fields.filterAny(reference.fields) { field, referenceField ->
|
||||||
if (field.name != referenceField.name) return@filterAny false
|
if (field.name != referenceField.name) return@filterAny false
|
||||||
|
|
||||||
@@ -117,7 +115,7 @@ internal object ClassMerger {
|
|||||||
|
|
||||||
if (brokenFields.isEmpty()) return this
|
if (brokenFields.isEmpty()) return this
|
||||||
|
|
||||||
logger?.trace("Found ${brokenFields.size} broken fields")
|
logger.fine("Found ${brokenFields.size} broken fields")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a field public.
|
* Make a field public.
|
||||||
@@ -135,9 +133,8 @@ internal object ClassMerger {
|
|||||||
* Publicize methods if they are public in [reference].
|
* Publicize methods if they are public in [reference].
|
||||||
*
|
*
|
||||||
* @param reference The class to check the [AccessFlags] of the methods in.
|
* @param reference The class to check the [AccessFlags] of the methods in.
|
||||||
* @param logger A logger.
|
|
||||||
*/
|
*/
|
||||||
private fun ClassDef.fixMethodAccess(reference: ClassDef, logger: Logger? = null): ClassDef {
|
private fun ClassDef.fixMethodAccess(reference: ClassDef): ClassDef {
|
||||||
val brokenMethods = methods.filterAny(reference.methods) { method, referenceMethod ->
|
val brokenMethods = methods.filterAny(reference.methods) { method, referenceMethod ->
|
||||||
if (!MethodUtil.methodSignaturesMatch(method, referenceMethod)) return@filterAny false
|
if (!MethodUtil.methodSignaturesMatch(method, referenceMethod)) return@filterAny false
|
||||||
|
|
||||||
@@ -146,7 +143,7 @@ internal object ClassMerger {
|
|||||||
|
|
||||||
if (brokenMethods.isEmpty()) return this
|
if (brokenMethods.isEmpty()) return this
|
||||||
|
|
||||||
logger?.trace("Found ${brokenMethods.size} methods")
|
logger.fine("Found ${brokenMethods.size} methods")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a method public.
|
* Make a method public.
|
||||||
@@ -161,6 +158,19 @@ internal object ClassMerger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private object Utils {
|
private object Utils {
|
||||||
|
/**
|
||||||
|
* traverse the class hierarchy starting from the given root class
|
||||||
|
*
|
||||||
|
* @param targetClass the class to start traversing the class hierarchy from
|
||||||
|
* @param callback function that is called for every class in the hierarchy
|
||||||
|
*/
|
||||||
|
fun BytecodeContext.traverseClassHierarchy(targetClass: MutableClass, callback: MutableClass.() -> Unit) {
|
||||||
|
callback(targetClass)
|
||||||
|
this.findClass(targetClass.superclass ?: return)?.mutableClass?.let {
|
||||||
|
traverseClassHierarchy(it, callback)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun ClassDef.asMutableClass() = if (this is MutableClass) this else this.toMutable()
|
fun ClassDef.asMutableClass() = if (this is MutableClass) this else this.toMutable()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -180,7 +190,6 @@ internal object ClassMerger {
|
|||||||
/**
|
/**
|
||||||
* Filter [this] on [needles] matching the given [predicate].
|
* Filter [this] on [needles] matching the given [predicate].
|
||||||
*
|
*
|
||||||
* @param this The hay to filter for [needles].
|
|
||||||
* @param needles The needles to filter [this] with.
|
* @param needles The needles to filter [this] with.
|
||||||
* @param predicate The filter.
|
* @param predicate The filter.
|
||||||
* @return The [this] filtered on [needles] matching the given [predicate].
|
* @return The [this] filtered on [needles] matching the given [predicate].
|
||||||
@@ -192,7 +201,6 @@ internal object ClassMerger {
|
|||||||
/**
|
/**
|
||||||
* Filter [this] on [needles] not matching the given [predicate].
|
* Filter [this] on [needles] not matching the given [predicate].
|
||||||
*
|
*
|
||||||
* @param this The hay to filter for [needles].
|
|
||||||
* @param needles The needles to filter [this] with.
|
* @param needles The needles to filter [this] with.
|
||||||
* @param predicate The filter.
|
* @param predicate The filter.
|
||||||
* @return The [this] filtered on [needles] not matching the given [predicate].
|
* @return The [this] filtered on [needles] not matching the given [predicate].
|
||||||
87
src/main/kotlin/app/revanced/patcher/util/DomFileEditor.kt
Normal file
87
src/main/kotlin/app/revanced/patcher/util/DomFileEditor.kt
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
package app.revanced.patcher.util
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper for a file that can be edited as a dom document.
|
||||||
|
*
|
||||||
|
* This constructor does not check for locks to the file when writing.
|
||||||
|
* Use the secondary constructor.
|
||||||
|
*
|
||||||
|
* @param inputStream the input stream to read the xml file from.
|
||||||
|
* @param outputStream the output stream to write the xml file to. If null, the file will be read only.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class DomFileEditor internal constructor(
|
||||||
|
private val inputStream: InputStream,
|
||||||
|
private val outputStream: Lazy<OutputStream>? = null,
|
||||||
|
) : Closeable {
|
||||||
|
// path to the xml file to unlock the resource when closing the editor
|
||||||
|
private var filePath: String? = null
|
||||||
|
private var closed: Boolean = false
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The document of the xml file
|
||||||
|
*/
|
||||||
|
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() }) {
|
||||||
|
// increase the lock
|
||||||
|
locks.merge(file.path, 1, Integer::sum)
|
||||||
|
filePath = file.path
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the editor. Write backs and decreases the lock count.
|
||||||
|
*
|
||||||
|
* Will not write back to the file if the file is still locked.
|
||||||
|
*/
|
||||||
|
override fun close() {
|
||||||
|
if (closed) return
|
||||||
|
|
||||||
|
inputStream.close()
|
||||||
|
|
||||||
|
// if the output stream is not null, do not close it
|
||||||
|
outputStream?.let {
|
||||||
|
// prevent writing to same file, if it is being locked
|
||||||
|
// isLocked will be false if the editor was created through a stream
|
||||||
|
val isLocked = filePath?.let { path ->
|
||||||
|
val isLocked = locks[path]!! > 1
|
||||||
|
// decrease the lock count if the editor was opened for a file
|
||||||
|
locks.merge(path, -1, Integer::sum)
|
||||||
|
isLocked
|
||||||
|
} ?: false
|
||||||
|
|
||||||
|
// if unlocked, write back to the file
|
||||||
|
if (!isLocked) {
|
||||||
|
it.value.use { stream ->
|
||||||
|
val result = StreamResult(stream)
|
||||||
|
TransformerFactory.newInstance().newTransformer().transform(DOMSource(file), result)
|
||||||
|
}
|
||||||
|
|
||||||
|
it.value.close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
closed = true
|
||||||
|
}
|
||||||
|
|
||||||
|
private companion object {
|
||||||
|
// map of concurrent open files
|
||||||
|
val locks = mutableMapOf<String, Int>()
|
||||||
|
}
|
||||||
|
}
|
||||||
33
src/main/kotlin/app/revanced/patcher/util/ProxyClassList.kt
Normal file
33
src/main/kotlin/app/revanced/patcher/util/ProxyClassList.kt
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package app.revanced.patcher.util
|
||||||
|
|
||||||
|
import app.revanced.patcher.util.proxy.ClassProxy
|
||||||
|
import com.android.tools.smali.dexlib2.iface.ClassDef
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class that represents a set of classes and proxies.
|
||||||
|
*
|
||||||
|
* @param classes The classes to be backed by proxies.
|
||||||
|
*/
|
||||||
|
class ProxyClassList internal constructor(classes: MutableSet<ClassDef>) : MutableSet<ClassDef> by classes {
|
||||||
|
internal val proxies = mutableListOf<ClassProxy>()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a [ClassProxy].
|
||||||
|
*/
|
||||||
|
fun add(classProxy: ClassProxy) = proxies.add(classProxy)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace all classes with their mutated versions.
|
||||||
|
*/
|
||||||
|
internal fun replaceClasses() = proxies.removeIf { proxy ->
|
||||||
|
// If the proxy is unused, return false to keep it in the proxies list.
|
||||||
|
if (!proxy.resolved) return@removeIf false
|
||||||
|
|
||||||
|
// If it has been used, replace the original class with the mutable class.
|
||||||
|
remove(proxy.immutableClass)
|
||||||
|
add(proxy.mutableClass)
|
||||||
|
|
||||||
|
// Return true to remove the proxy from the proxies list.
|
||||||
|
return@removeIf true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
package app.revanced.patcher.util.method
|
package app.revanced.patcher.util.method
|
||||||
|
|
||||||
import app.revanced.patcher.BytecodeContext
|
import app.revanced.patcher.data.BytecodeContext
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
||||||
import org.jf.dexlib2.iface.Method
|
import com.android.tools.smali.dexlib2.iface.Method
|
||||||
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
|
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
|
||||||
import org.jf.dexlib2.iface.reference.MethodReference
|
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
|
||||||
import org.jf.dexlib2.util.MethodUtil
|
import com.android.tools.smali.dexlib2.util.MethodUtil
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find a method from another method via instruction offsets.
|
* Find a method from another method via instruction offsets.
|
||||||
@@ -41,7 +41,7 @@ class MethodWalker internal constructor(
|
|||||||
val instruction = instructions.elementAt(offset)
|
val instruction = instructions.elementAt(offset)
|
||||||
|
|
||||||
val newMethod = (instruction as ReferenceInstruction).reference as MethodReference
|
val newMethod = (instruction as ReferenceInstruction).reference as MethodReference
|
||||||
val proxy = bytecodeContext.classes.findClassProxied(newMethod.definingClass)!!
|
val proxy = bytecodeContext.findClass(newMethod.definingClass)!!
|
||||||
|
|
||||||
val methods = if (walkMutable) proxy.mutableClass.methods else proxy.immutableClass.methods
|
val methods = if (walkMutable) proxy.mutableClass.methods else proxy.immutableClass.methods
|
||||||
currentMethod = methods.first {
|
currentMethod = methods.first {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package app.revanced.patcher.util.proxy
|
package app.revanced.patcher.util.proxy
|
||||||
|
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableClass
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableClass
|
||||||
import org.jf.dexlib2.iface.ClassDef
|
import com.android.tools.smali.dexlib2.iface.ClassDef
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A proxy class for a [ClassDef].
|
* A proxy class for a [ClassDef].
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package app.revanced.patcher.util.proxy.mutableTypes
|
package app.revanced.patcher.util.proxy.mutableTypes
|
||||||
|
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableAnnotationElement.Companion.toMutable
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableAnnotationElement.Companion.toMutable
|
||||||
import org.jf.dexlib2.base.BaseAnnotation
|
import com.android.tools.smali.dexlib2.base.BaseAnnotation
|
||||||
import org.jf.dexlib2.iface.Annotation
|
import com.android.tools.smali.dexlib2.iface.Annotation
|
||||||
|
|
||||||
class MutableAnnotation(annotation: Annotation) : BaseAnnotation() {
|
class MutableAnnotation(annotation: Annotation) : BaseAnnotation() {
|
||||||
private val visibility = annotation.visibility
|
private val visibility = annotation.visibility
|
||||||
@@ -2,9 +2,9 @@ package app.revanced.patcher.util.proxy.mutableTypes
|
|||||||
|
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.encodedValue.MutableEncodedValue
|
import app.revanced.patcher.util.proxy.mutableTypes.encodedValue.MutableEncodedValue
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.encodedValue.MutableEncodedValue.Companion.toMutable
|
import app.revanced.patcher.util.proxy.mutableTypes.encodedValue.MutableEncodedValue.Companion.toMutable
|
||||||
import org.jf.dexlib2.base.BaseAnnotationElement
|
import com.android.tools.smali.dexlib2.base.BaseAnnotationElement
|
||||||
import org.jf.dexlib2.iface.AnnotationElement
|
import com.android.tools.smali.dexlib2.iface.AnnotationElement
|
||||||
import org.jf.dexlib2.iface.value.EncodedValue
|
import com.android.tools.smali.dexlib2.iface.value.EncodedValue
|
||||||
|
|
||||||
class MutableAnnotationElement(annotationElement: AnnotationElement) : BaseAnnotationElement() {
|
class MutableAnnotationElement(annotationElement: AnnotationElement) : BaseAnnotationElement() {
|
||||||
private var name = annotationElement.name
|
private var name = annotationElement.name
|
||||||
@@ -4,10 +4,10 @@ import app.revanced.patcher.util.proxy.mutableTypes.MutableAnnotation.Companion.
|
|||||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableField.Companion.toMutable
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableField.Companion.toMutable
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable
|
||||||
import com.google.common.collect.Iterables
|
import com.google.common.collect.Iterables
|
||||||
import org.jf.dexlib2.base.reference.BaseTypeReference
|
import com.android.tools.smali.dexlib2.base.reference.BaseTypeReference
|
||||||
import org.jf.dexlib2.iface.ClassDef
|
import com.android.tools.smali.dexlib2.iface.ClassDef
|
||||||
import org.jf.dexlib2.util.FieldUtil
|
import com.android.tools.smali.dexlib2.util.FieldUtil
|
||||||
import org.jf.dexlib2.util.MethodUtil
|
import com.android.tools.smali.dexlib2.util.MethodUtil
|
||||||
|
|
||||||
class MutableClass(classDef: ClassDef) : ClassDef, BaseTypeReference() {
|
class MutableClass(classDef: ClassDef) : ClassDef, BaseTypeReference() {
|
||||||
// Class
|
// Class
|
||||||
@@ -3,9 +3,9 @@ package app.revanced.patcher.util.proxy.mutableTypes
|
|||||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableAnnotation.Companion.toMutable
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableAnnotation.Companion.toMutable
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.encodedValue.MutableEncodedValue
|
import app.revanced.patcher.util.proxy.mutableTypes.encodedValue.MutableEncodedValue
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.encodedValue.MutableEncodedValue.Companion.toMutable
|
import app.revanced.patcher.util.proxy.mutableTypes.encodedValue.MutableEncodedValue.Companion.toMutable
|
||||||
import org.jf.dexlib2.HiddenApiRestriction
|
import com.android.tools.smali.dexlib2.HiddenApiRestriction
|
||||||
import org.jf.dexlib2.base.reference.BaseFieldReference
|
import com.android.tools.smali.dexlib2.base.reference.BaseFieldReference
|
||||||
import org.jf.dexlib2.iface.Field
|
import com.android.tools.smali.dexlib2.iface.Field
|
||||||
|
|
||||||
class MutableField(field: Field) : Field, BaseFieldReference() {
|
class MutableField(field: Field) : Field, BaseFieldReference() {
|
||||||
private var definingClass = field.definingClass
|
private var definingClass = field.definingClass
|
||||||
@@ -2,10 +2,10 @@ package app.revanced.patcher.util.proxy.mutableTypes
|
|||||||
|
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableAnnotation.Companion.toMutable
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableAnnotation.Companion.toMutable
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethodParameter.Companion.toMutable
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethodParameter.Companion.toMutable
|
||||||
import org.jf.dexlib2.HiddenApiRestriction
|
import com.android.tools.smali.dexlib2.HiddenApiRestriction
|
||||||
import org.jf.dexlib2.base.reference.BaseMethodReference
|
import com.android.tools.smali.dexlib2.base.reference.BaseMethodReference
|
||||||
import org.jf.dexlib2.builder.MutableMethodImplementation
|
import com.android.tools.smali.dexlib2.builder.MutableMethodImplementation
|
||||||
import org.jf.dexlib2.iface.Method
|
import com.android.tools.smali.dexlib2.iface.Method
|
||||||
|
|
||||||
class MutableMethod(method: Method) : Method, BaseMethodReference() {
|
class MutableMethod(method: Method) : Method, BaseMethodReference() {
|
||||||
private var definingClass = method.definingClass
|
private var definingClass = method.definingClass
|
||||||
@@ -13,7 +13,7 @@ class MutableMethod(method: Method) : Method, BaseMethodReference() {
|
|||||||
private var accessFlags = method.accessFlags
|
private var accessFlags = method.accessFlags
|
||||||
private var returnType = method.returnType
|
private var returnType = method.returnType
|
||||||
|
|
||||||
// TODO: Create own mutable MethodImplementation (due to not being able to change members like register count).
|
// Create own mutable MethodImplementation (due to not being able to change members like register count)
|
||||||
private val _implementation by lazy { method.implementation?.let { MutableMethodImplementation(it) } }
|
private val _implementation by lazy { method.implementation?.let { MutableMethodImplementation(it) } }
|
||||||
private val _annotations by lazy { method.annotations.map { annotation -> annotation.toMutable() }.toMutableSet() }
|
private val _annotations by lazy { method.annotations.map { annotation -> annotation.toMutable() }.toMutableSet() }
|
||||||
private val _parameters by lazy { method.parameters.map { parameter -> parameter.toMutable() }.toMutableList() }
|
private val _parameters by lazy { method.parameters.map { parameter -> parameter.toMutable() }.toMutableList() }
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package app.revanced.patcher.util.proxy.mutableTypes
|
package app.revanced.patcher.util.proxy.mutableTypes
|
||||||
|
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableAnnotation.Companion.toMutable
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableAnnotation.Companion.toMutable
|
||||||
import org.jf.dexlib2.base.BaseMethodParameter
|
import com.android.tools.smali.dexlib2.base.BaseMethodParameter
|
||||||
import org.jf.dexlib2.iface.MethodParameter
|
import com.android.tools.smali.dexlib2.iface.MethodParameter
|
||||||
|
|
||||||
// TODO: Finish overriding all members if necessary.
|
// TODO: finish overriding all members if necessary
|
||||||
class MutableMethodParameter(parameter: MethodParameter) : MethodParameter, BaseMethodParameter() {
|
class MutableMethodParameter(parameter: MethodParameter) : MethodParameter, BaseMethodParameter() {
|
||||||
private var type = parameter.type
|
private var type = parameter.type
|
||||||
private var name = parameter.name
|
private var name = parameter.name
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
||||||
|
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableAnnotationElement.Companion.toMutable
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableAnnotationElement.Companion.toMutable
|
||||||
import org.jf.dexlib2.base.value.BaseAnnotationEncodedValue
|
import com.android.tools.smali.dexlib2.base.value.BaseAnnotationEncodedValue
|
||||||
import org.jf.dexlib2.iface.AnnotationElement
|
import com.android.tools.smali.dexlib2.iface.AnnotationElement
|
||||||
import org.jf.dexlib2.iface.value.AnnotationEncodedValue
|
import com.android.tools.smali.dexlib2.iface.value.AnnotationEncodedValue
|
||||||
|
|
||||||
class MutableAnnotationEncodedValue(annotationEncodedValue: AnnotationEncodedValue) : BaseAnnotationEncodedValue(),
|
class MutableAnnotationEncodedValue(annotationEncodedValue: AnnotationEncodedValue) : BaseAnnotationEncodedValue(),
|
||||||
MutableEncodedValue {
|
MutableEncodedValue {
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
||||||
|
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.encodedValue.MutableEncodedValue.Companion.toMutable
|
import app.revanced.patcher.util.proxy.mutableTypes.encodedValue.MutableEncodedValue.Companion.toMutable
|
||||||
import org.jf.dexlib2.base.value.BaseArrayEncodedValue
|
import com.android.tools.smali.dexlib2.base.value.BaseArrayEncodedValue
|
||||||
import org.jf.dexlib2.iface.value.ArrayEncodedValue
|
import com.android.tools.smali.dexlib2.iface.value.ArrayEncodedValue
|
||||||
import org.jf.dexlib2.iface.value.EncodedValue
|
import com.android.tools.smali.dexlib2.iface.value.EncodedValue
|
||||||
|
|
||||||
class MutableArrayEncodedValue(arrayEncodedValue: ArrayEncodedValue) : BaseArrayEncodedValue(), MutableEncodedValue {
|
class MutableArrayEncodedValue(arrayEncodedValue: ArrayEncodedValue) : BaseArrayEncodedValue(), MutableEncodedValue {
|
||||||
private val _value by lazy {
|
private val _value by lazy {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
||||||
|
|
||||||
import org.jf.dexlib2.base.value.BaseBooleanEncodedValue
|
import com.android.tools.smali.dexlib2.base.value.BaseBooleanEncodedValue
|
||||||
import org.jf.dexlib2.iface.value.BooleanEncodedValue
|
import com.android.tools.smali.dexlib2.iface.value.BooleanEncodedValue
|
||||||
|
|
||||||
class MutableBooleanEncodedValue(booleanEncodedValue: BooleanEncodedValue) : BaseBooleanEncodedValue(),
|
class MutableBooleanEncodedValue(booleanEncodedValue: BooleanEncodedValue) : BaseBooleanEncodedValue(),
|
||||||
MutableEncodedValue {
|
MutableEncodedValue {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
||||||
|
|
||||||
import org.jf.dexlib2.base.value.BaseByteEncodedValue
|
import com.android.tools.smali.dexlib2.base.value.BaseByteEncodedValue
|
||||||
import org.jf.dexlib2.iface.value.ByteEncodedValue
|
import com.android.tools.smali.dexlib2.iface.value.ByteEncodedValue
|
||||||
|
|
||||||
class MutableByteEncodedValue(byteEncodedValue: ByteEncodedValue) : BaseByteEncodedValue(), MutableEncodedValue {
|
class MutableByteEncodedValue(byteEncodedValue: ByteEncodedValue) : BaseByteEncodedValue(), MutableEncodedValue {
|
||||||
private var value = byteEncodedValue.value
|
private var value = byteEncodedValue.value
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
||||||
|
|
||||||
import org.jf.dexlib2.base.value.BaseCharEncodedValue
|
import com.android.tools.smali.dexlib2.base.value.BaseCharEncodedValue
|
||||||
import org.jf.dexlib2.iface.value.CharEncodedValue
|
import com.android.tools.smali.dexlib2.iface.value.CharEncodedValue
|
||||||
|
|
||||||
class MutableCharEncodedValue(charEncodedValue: CharEncodedValue) : BaseCharEncodedValue(), MutableEncodedValue {
|
class MutableCharEncodedValue(charEncodedValue: CharEncodedValue) : BaseCharEncodedValue(), MutableEncodedValue {
|
||||||
private var value = charEncodedValue.value
|
private var value = charEncodedValue.value
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
||||||
|
|
||||||
import org.jf.dexlib2.base.value.BaseDoubleEncodedValue
|
import com.android.tools.smali.dexlib2.base.value.BaseDoubleEncodedValue
|
||||||
import org.jf.dexlib2.iface.value.DoubleEncodedValue
|
import com.android.tools.smali.dexlib2.iface.value.DoubleEncodedValue
|
||||||
|
|
||||||
class MutableDoubleEncodedValue(doubleEncodedValue: DoubleEncodedValue) : BaseDoubleEncodedValue(),
|
class MutableDoubleEncodedValue(doubleEncodedValue: DoubleEncodedValue) : BaseDoubleEncodedValue(),
|
||||||
MutableEncodedValue {
|
MutableEncodedValue {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
||||||
|
|
||||||
import org.jf.dexlib2.ValueType
|
import com.android.tools.smali.dexlib2.ValueType
|
||||||
import org.jf.dexlib2.iface.value.*
|
import com.android.tools.smali.dexlib2.iface.value.*
|
||||||
|
|
||||||
interface MutableEncodedValue : EncodedValue {
|
interface MutableEncodedValue : EncodedValue {
|
||||||
companion object {
|
companion object {
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
||||||
|
|
||||||
import org.jf.dexlib2.base.value.BaseEnumEncodedValue
|
import com.android.tools.smali.dexlib2.base.value.BaseEnumEncodedValue
|
||||||
import org.jf.dexlib2.iface.reference.FieldReference
|
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
|
||||||
import org.jf.dexlib2.iface.value.EnumEncodedValue
|
import com.android.tools.smali.dexlib2.iface.value.EnumEncodedValue
|
||||||
|
|
||||||
class MutableEnumEncodedValue(enumEncodedValue: EnumEncodedValue) : BaseEnumEncodedValue(), MutableEncodedValue {
|
class MutableEnumEncodedValue(enumEncodedValue: EnumEncodedValue) : BaseEnumEncodedValue(), MutableEncodedValue {
|
||||||
private var value = enumEncodedValue.value
|
private var value = enumEncodedValue.value
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
||||||
|
|
||||||
import org.jf.dexlib2.ValueType
|
import com.android.tools.smali.dexlib2.ValueType
|
||||||
import org.jf.dexlib2.base.value.BaseFieldEncodedValue
|
import com.android.tools.smali.dexlib2.base.value.BaseFieldEncodedValue
|
||||||
import org.jf.dexlib2.iface.reference.FieldReference
|
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
|
||||||
import org.jf.dexlib2.iface.value.FieldEncodedValue
|
import com.android.tools.smali.dexlib2.iface.value.FieldEncodedValue
|
||||||
|
|
||||||
class MutableFieldEncodedValue(fieldEncodedValue: FieldEncodedValue) : BaseFieldEncodedValue(), MutableEncodedValue {
|
class MutableFieldEncodedValue(fieldEncodedValue: FieldEncodedValue) : BaseFieldEncodedValue(), MutableEncodedValue {
|
||||||
private var value = fieldEncodedValue.value
|
private var value = fieldEncodedValue.value
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
||||||
|
|
||||||
import org.jf.dexlib2.base.value.BaseFloatEncodedValue
|
import com.android.tools.smali.dexlib2.base.value.BaseFloatEncodedValue
|
||||||
import org.jf.dexlib2.iface.value.FloatEncodedValue
|
import com.android.tools.smali.dexlib2.iface.value.FloatEncodedValue
|
||||||
|
|
||||||
class MutableFloatEncodedValue(floatEncodedValue: FloatEncodedValue) : BaseFloatEncodedValue(), MutableEncodedValue {
|
class MutableFloatEncodedValue(floatEncodedValue: FloatEncodedValue) : BaseFloatEncodedValue(), MutableEncodedValue {
|
||||||
private var value = floatEncodedValue.value
|
private var value = floatEncodedValue.value
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
||||||
|
|
||||||
import org.jf.dexlib2.base.value.BaseIntEncodedValue
|
import com.android.tools.smali.dexlib2.base.value.BaseIntEncodedValue
|
||||||
import org.jf.dexlib2.iface.value.IntEncodedValue
|
import com.android.tools.smali.dexlib2.iface.value.IntEncodedValue
|
||||||
|
|
||||||
class MutableIntEncodedValue(intEncodedValue: IntEncodedValue) : BaseIntEncodedValue(), MutableEncodedValue {
|
class MutableIntEncodedValue(intEncodedValue: IntEncodedValue) : BaseIntEncodedValue(), MutableEncodedValue {
|
||||||
private var value = intEncodedValue.value
|
private var value = intEncodedValue.value
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
||||||
|
|
||||||
import org.jf.dexlib2.base.value.BaseLongEncodedValue
|
import com.android.tools.smali.dexlib2.base.value.BaseLongEncodedValue
|
||||||
import org.jf.dexlib2.iface.value.LongEncodedValue
|
import com.android.tools.smali.dexlib2.iface.value.LongEncodedValue
|
||||||
|
|
||||||
class MutableLongEncodedValue(longEncodedValue: LongEncodedValue) : BaseLongEncodedValue(), MutableEncodedValue {
|
class MutableLongEncodedValue(longEncodedValue: LongEncodedValue) : BaseLongEncodedValue(), MutableEncodedValue {
|
||||||
private var value = longEncodedValue.value
|
private var value = longEncodedValue.value
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
||||||
|
|
||||||
import org.jf.dexlib2.base.value.BaseMethodEncodedValue
|
import com.android.tools.smali.dexlib2.base.value.BaseMethodEncodedValue
|
||||||
import org.jf.dexlib2.iface.reference.MethodReference
|
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
|
||||||
import org.jf.dexlib2.iface.value.MethodEncodedValue
|
import com.android.tools.smali.dexlib2.iface.value.MethodEncodedValue
|
||||||
|
|
||||||
class MutableMethodEncodedValue(methodEncodedValue: MethodEncodedValue) : BaseMethodEncodedValue(),
|
class MutableMethodEncodedValue(methodEncodedValue: MethodEncodedValue) : BaseMethodEncodedValue(),
|
||||||
MutableEncodedValue {
|
MutableEncodedValue {
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
||||||
|
|
||||||
import org.jf.dexlib2.base.value.BaseMethodHandleEncodedValue
|
import com.android.tools.smali.dexlib2.base.value.BaseMethodHandleEncodedValue
|
||||||
import org.jf.dexlib2.iface.reference.MethodHandleReference
|
import com.android.tools.smali.dexlib2.iface.reference.MethodHandleReference
|
||||||
import org.jf.dexlib2.iface.value.MethodHandleEncodedValue
|
import com.android.tools.smali.dexlib2.iface.value.MethodHandleEncodedValue
|
||||||
|
|
||||||
class MutableMethodHandleEncodedValue(methodHandleEncodedValue: MethodHandleEncodedValue) :
|
class MutableMethodHandleEncodedValue(methodHandleEncodedValue: MethodHandleEncodedValue) :
|
||||||
BaseMethodHandleEncodedValue(),
|
BaseMethodHandleEncodedValue(),
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
||||||
|
|
||||||
import org.jf.dexlib2.base.value.BaseMethodTypeEncodedValue
|
import com.android.tools.smali.dexlib2.base.value.BaseMethodTypeEncodedValue
|
||||||
import org.jf.dexlib2.iface.reference.MethodProtoReference
|
import com.android.tools.smali.dexlib2.iface.reference.MethodProtoReference
|
||||||
import org.jf.dexlib2.iface.value.MethodTypeEncodedValue
|
import com.android.tools.smali.dexlib2.iface.value.MethodTypeEncodedValue
|
||||||
|
|
||||||
class MutableMethodTypeEncodedValue(methodTypeEncodedValue: MethodTypeEncodedValue) : BaseMethodTypeEncodedValue(),
|
class MutableMethodTypeEncodedValue(methodTypeEncodedValue: MethodTypeEncodedValue) : BaseMethodTypeEncodedValue(),
|
||||||
MutableEncodedValue {
|
MutableEncodedValue {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
||||||
|
|
||||||
import org.jf.dexlib2.base.value.BaseNullEncodedValue
|
import com.android.tools.smali.dexlib2.base.value.BaseNullEncodedValue
|
||||||
import org.jf.dexlib2.iface.value.ByteEncodedValue
|
import com.android.tools.smali.dexlib2.iface.value.ByteEncodedValue
|
||||||
|
|
||||||
class MutableNullEncodedValue : BaseNullEncodedValue(), MutableEncodedValue {
|
class MutableNullEncodedValue : BaseNullEncodedValue(), MutableEncodedValue {
|
||||||
companion object {
|
companion object {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
||||||
|
|
||||||
import org.jf.dexlib2.base.value.BaseShortEncodedValue
|
import com.android.tools.smali.dexlib2.base.value.BaseShortEncodedValue
|
||||||
import org.jf.dexlib2.iface.value.ShortEncodedValue
|
import com.android.tools.smali.dexlib2.iface.value.ShortEncodedValue
|
||||||
|
|
||||||
class MutableShortEncodedValue(shortEncodedValue: ShortEncodedValue) : BaseShortEncodedValue(), MutableEncodedValue {
|
class MutableShortEncodedValue(shortEncodedValue: ShortEncodedValue) : BaseShortEncodedValue(), MutableEncodedValue {
|
||||||
private var value = shortEncodedValue.value
|
private var value = shortEncodedValue.value
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
||||||
|
|
||||||
import org.jf.dexlib2.base.value.BaseStringEncodedValue
|
import com.android.tools.smali.dexlib2.base.value.BaseStringEncodedValue
|
||||||
import org.jf.dexlib2.iface.value.ByteEncodedValue
|
import com.android.tools.smali.dexlib2.iface.value.ByteEncodedValue
|
||||||
import org.jf.dexlib2.iface.value.StringEncodedValue
|
import com.android.tools.smali.dexlib2.iface.value.StringEncodedValue
|
||||||
|
|
||||||
class MutableStringEncodedValue(stringEncodedValue: StringEncodedValue) : BaseStringEncodedValue(),
|
class MutableStringEncodedValue(stringEncodedValue: StringEncodedValue) : BaseStringEncodedValue(),
|
||||||
MutableEncodedValue {
|
MutableEncodedValue {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
|
||||||
|
|
||||||
import org.jf.dexlib2.base.value.BaseTypeEncodedValue
|
import com.android.tools.smali.dexlib2.base.value.BaseTypeEncodedValue
|
||||||
import org.jf.dexlib2.iface.value.TypeEncodedValue
|
import com.android.tools.smali.dexlib2.iface.value.TypeEncodedValue
|
||||||
|
|
||||||
class MutableTypeEncodedValue(typeEncodedValue: TypeEncodedValue) : BaseTypeEncodedValue(), MutableEncodedValue {
|
class MutableTypeEncodedValue(typeEncodedValue: TypeEncodedValue) : BaseTypeEncodedValue(), MutableEncodedValue {
|
||||||
private var value = typeEncodedValue.value
|
private var value = typeEncodedValue.value
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package app.revanced.patcher.util.smali
|
package app.revanced.patcher.util.smali
|
||||||
|
|
||||||
import org.jf.dexlib2.iface.instruction.Instruction
|
import com.android.tools.smali.dexlib2.iface.instruction.Instruction
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class that represents a label for an instruction.
|
* A class that represents a label for an instruction.
|
||||||
@@ -4,14 +4,14 @@ import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
|||||||
import org.antlr.runtime.CommonTokenStream
|
import org.antlr.runtime.CommonTokenStream
|
||||||
import org.antlr.runtime.TokenSource
|
import org.antlr.runtime.TokenSource
|
||||||
import org.antlr.runtime.tree.CommonTreeNodeStream
|
import org.antlr.runtime.tree.CommonTreeNodeStream
|
||||||
import org.jf.dexlib2.AccessFlags
|
import com.android.tools.smali.dexlib2.AccessFlags
|
||||||
import org.jf.dexlib2.Opcodes
|
import com.android.tools.smali.dexlib2.Opcodes
|
||||||
import org.jf.dexlib2.builder.BuilderInstruction
|
import com.android.tools.smali.dexlib2.builder.BuilderInstruction
|
||||||
import org.jf.dexlib2.writer.builder.DexBuilder
|
import com.android.tools.smali.dexlib2.writer.builder.DexBuilder
|
||||||
import org.jf.smali.LexerErrorInterface
|
import com.android.tools.smali.smali.LexerErrorInterface
|
||||||
import org.jf.smali.smaliFlexLexer
|
import com.android.tools.smali.smali.smaliFlexLexer
|
||||||
import org.jf.smali.smaliParser
|
import com.android.tools.smali.smali.smaliParser
|
||||||
import org.jf.smali.smaliTreeWalker
|
import com.android.tools.smali.smali.smaliTreeWalker
|
||||||
import java.io.InputStreamReader
|
import java.io.InputStreamReader
|
||||||
|
|
||||||
private const val METHOD_TEMPLATE = """
|
private const val METHOD_TEMPLATE = """
|
||||||
@@ -0,0 +1,233 @@
|
|||||||
|
package app.revanced.patcher.extensions
|
||||||
|
|
||||||
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
|
||||||
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
||||||
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
|
||||||
|
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
||||||
|
import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction
|
||||||
|
import app.revanced.patcher.extensions.InstructionExtensions.removeInstructions
|
||||||
|
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
|
||||||
|
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstructions
|
||||||
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
||||||
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable
|
||||||
|
import app.revanced.patcher.util.smali.ExternalLabel
|
||||||
|
import com.android.tools.smali.dexlib2.AccessFlags
|
||||||
|
import com.android.tools.smali.dexlib2.Opcode
|
||||||
|
import com.android.tools.smali.dexlib2.builder.BuilderOffsetInstruction
|
||||||
|
import com.android.tools.smali.dexlib2.builder.MutableMethodImplementation
|
||||||
|
import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction21s
|
||||||
|
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
||||||
|
import com.android.tools.smali.dexlib2.immutable.ImmutableMethod
|
||||||
|
import org.junit.jupiter.api.BeforeEach
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
private object InstructionExtensionsTest {
|
||||||
|
private lateinit var testMethod: MutableMethod
|
||||||
|
private lateinit var testMethodImplementation: MutableMethodImplementation
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
fun createTestMethod() = ImmutableMethod(
|
||||||
|
"TestClass;",
|
||||||
|
"testMethod",
|
||||||
|
null,
|
||||||
|
"V",
|
||||||
|
AccessFlags.PUBLIC.value,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
MutableMethodImplementation(16).also { testMethodImplementation = it }.apply {
|
||||||
|
repeat(10) { i -> this.addInstruction(TestInstruction(i)) }
|
||||||
|
},
|
||||||
|
).let { testMethod = it.toMutable() }
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun addInstructionsToImplementationIndexed() = applyToImplementation {
|
||||||
|
addInstructions(5, getTestInstructions(5..6)).also {
|
||||||
|
assertRegisterIs(5, 5)
|
||||||
|
assertRegisterIs(6, 6)
|
||||||
|
|
||||||
|
assertRegisterIs(5, 7)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun addInstructionsToImplementation() = applyToImplementation {
|
||||||
|
addInstructions(getTestInstructions(10..11)).also {
|
||||||
|
assertRegisterIs(10, 10)
|
||||||
|
assertRegisterIs(11, 11)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun removeInstructionsFromImplementationIndexed() = applyToImplementation {
|
||||||
|
removeInstructions(5, 5).also { assertRegisterIs(4, 4) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun removeInstructionsFromImplementation() = applyToImplementation {
|
||||||
|
removeInstructions(0).also { assertRegisterIs(9, 9) }
|
||||||
|
removeInstructions(1).also { assertRegisterIs(1, 0) }
|
||||||
|
removeInstructions(2).also { assertRegisterIs(3, 0) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun replaceInstructionsInImplementationIndexed() = applyToImplementation {
|
||||||
|
replaceInstructions(5, getTestInstructions(0..1)).also {
|
||||||
|
assertRegisterIs(0, 5)
|
||||||
|
assertRegisterIs(1, 6)
|
||||||
|
assertRegisterIs(7, 7)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun addInstructionToMethodIndexed() = applyToMethod {
|
||||||
|
addInstruction(5, TestInstruction(0)).also { assertRegisterIs(0, 5) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun addInstructionToMethod() = applyToMethod {
|
||||||
|
addInstruction(TestInstruction(0)).also { assertRegisterIs(0, 10) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun addSmaliInstructionToMethodIndexed() = applyToMethod {
|
||||||
|
addInstruction(5, getTestSmaliInstruction(0)).also { assertRegisterIs(0, 5) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun addSmaliInstructionToMethod() = applyToMethod {
|
||||||
|
addInstruction(getTestSmaliInstruction(0)).also { assertRegisterIs(0, 10) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun addInstructionsToMethodIndexed() = applyToMethod {
|
||||||
|
addInstructions(5, getTestInstructions(0..1)).also {
|
||||||
|
assertRegisterIs(0, 5)
|
||||||
|
assertRegisterIs(1, 6)
|
||||||
|
|
||||||
|
assertRegisterIs(5, 7)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun addInstructionsToMethod() = applyToMethod {
|
||||||
|
addInstructions(getTestInstructions(0..1)).also {
|
||||||
|
assertRegisterIs(0, 10)
|
||||||
|
assertRegisterIs(1, 11)
|
||||||
|
|
||||||
|
assertRegisterIs(9, 9)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun addSmaliInstructionsToMethodIndexed() = applyToMethod {
|
||||||
|
addInstructionsWithLabels(5, getTestSmaliInstructions(0..1)).also {
|
||||||
|
assertRegisterIs(0, 5)
|
||||||
|
assertRegisterIs(1, 6)
|
||||||
|
|
||||||
|
assertRegisterIs(5, 7)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun addSmaliInstructionsToMethod() = applyToMethod {
|
||||||
|
addInstructions(getTestSmaliInstructions(0..1)).also {
|
||||||
|
assertRegisterIs(0, 10)
|
||||||
|
assertRegisterIs(1, 11)
|
||||||
|
|
||||||
|
assertRegisterIs(9, 9)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun addSmaliInstructionsWithExternalLabelToMethodIndexed() = applyToMethod {
|
||||||
|
val label = ExternalLabel("testLabel", getInstruction(5))
|
||||||
|
|
||||||
|
addInstructionsWithLabels(
|
||||||
|
5,
|
||||||
|
getTestSmaliInstructions(0..1).plus("\n").plus("goto :${label.name}"),
|
||||||
|
label
|
||||||
|
).also {
|
||||||
|
assertRegisterIs(0, 5)
|
||||||
|
assertRegisterIs(1, 6)
|
||||||
|
assertRegisterIs(5, 8)
|
||||||
|
|
||||||
|
val gotoTarget = getInstruction<BuilderOffsetInstruction>(7)
|
||||||
|
.target.location.instruction as OneRegisterInstruction
|
||||||
|
|
||||||
|
assertEquals(5, gotoTarget.registerA)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun removeInstructionFromMethodIndexed() = applyToMethod {
|
||||||
|
removeInstruction(5).also {
|
||||||
|
assertRegisterIs(4, 4)
|
||||||
|
assertRegisterIs(6, 5)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun removeInstructionsFromMethodIndexed() = applyToMethod {
|
||||||
|
removeInstructions(5, 5).also { assertRegisterIs(4, 4) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun removeInstructionsFromMethod() = applyToMethod {
|
||||||
|
removeInstructions(0).also { assertRegisterIs(9, 9) }
|
||||||
|
removeInstructions(1).also { assertRegisterIs(1, 0) }
|
||||||
|
removeInstructions(2).also { assertRegisterIs(3, 0) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun replaceInstructionInMethodIndexed() = applyToMethod {
|
||||||
|
replaceInstruction(5, TestInstruction(0)).also { assertRegisterIs(0, 5) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun replaceInstructionsInMethodIndexed() = applyToMethod {
|
||||||
|
replaceInstructions(5, getTestInstructions(0..1)).also {
|
||||||
|
assertRegisterIs(0, 5)
|
||||||
|
assertRegisterIs(1, 6)
|
||||||
|
assertRegisterIs(7, 7)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun replaceSmaliInstructionsInMethodIndexed() = applyToMethod {
|
||||||
|
replaceInstructions(5, getTestSmaliInstructions(0..1)).also {
|
||||||
|
assertRegisterIs(0, 5)
|
||||||
|
assertRegisterIs(1, 6)
|
||||||
|
assertRegisterIs(7, 7)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// region Helper methods
|
||||||
|
|
||||||
|
private fun applyToImplementation(block: MutableMethodImplementation.() -> Unit) {
|
||||||
|
testMethodImplementation.apply(block)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun applyToMethod(block: MutableMethod.() -> Unit) {
|
||||||
|
testMethod.apply(block)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun MutableMethodImplementation.assertRegisterIs(register: Int, atIndex: Int) = assertEquals(
|
||||||
|
register, getInstruction<OneRegisterInstruction>(atIndex).registerA
|
||||||
|
)
|
||||||
|
|
||||||
|
private fun MutableMethod.assertRegisterIs(register: Int, atIndex: Int) =
|
||||||
|
implementation!!.assertRegisterIs(register, atIndex)
|
||||||
|
|
||||||
|
private fun getTestInstructions(range: IntRange) = range.map { TestInstruction(it) }
|
||||||
|
|
||||||
|
private fun getTestSmaliInstruction(register: Int) = "const/16 v$register, 0"
|
||||||
|
|
||||||
|
private fun getTestSmaliInstructions(range: IntRange) = range.joinToString("\n") {
|
||||||
|
getTestSmaliInstruction(it)
|
||||||
|
}
|
||||||
|
|
||||||
|
// endregion
|
||||||
|
|
||||||
|
private class TestInstruction(register: Int) : BuilderInstruction21s(Opcode.CONST_16, register, 0)
|
||||||
|
}
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
package app.revanced.patcher.usage.bytecode
|
package app.revanced.patcher.usage.bytecode
|
||||||
|
|
||||||
import app.revanced.patcher.BytecodeContext
|
|
||||||
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.data.BytecodeContext
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
|
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
|
||||||
import app.revanced.patcher.extensions.or
|
import app.revanced.patcher.extensions.or
|
||||||
@@ -16,32 +15,31 @@ import app.revanced.patcher.usage.resource.annotation.ExampleResourceCompatibili
|
|||||||
import app.revanced.patcher.usage.resource.patch.ExampleResourcePatch
|
import app.revanced.patcher.usage.resource.patch.ExampleResourcePatch
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableField.Companion.toMutable
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableField.Companion.toMutable
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable
|
||||||
|
import com.android.tools.smali.dexlib2.AccessFlags
|
||||||
|
import com.android.tools.smali.dexlib2.Format
|
||||||
|
import com.android.tools.smali.dexlib2.Opcode
|
||||||
|
import com.android.tools.smali.dexlib2.builder.MutableMethodImplementation
|
||||||
|
import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction11x
|
||||||
|
import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction21c
|
||||||
|
import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction21c
|
||||||
|
import com.android.tools.smali.dexlib2.immutable.ImmutableField
|
||||||
|
import com.android.tools.smali.dexlib2.immutable.ImmutableMethod
|
||||||
|
import com.android.tools.smali.dexlib2.immutable.ImmutableMethodImplementation
|
||||||
|
import com.android.tools.smali.dexlib2.immutable.reference.ImmutableFieldReference
|
||||||
|
import com.android.tools.smali.dexlib2.immutable.reference.ImmutableStringReference
|
||||||
|
import com.android.tools.smali.dexlib2.immutable.value.ImmutableFieldEncodedValue
|
||||||
|
import com.android.tools.smali.dexlib2.util.Preconditions
|
||||||
import com.google.common.collect.ImmutableList
|
import com.google.common.collect.ImmutableList
|
||||||
import org.jf.dexlib2.AccessFlags
|
|
||||||
import org.jf.dexlib2.Format
|
|
||||||
import org.jf.dexlib2.Opcode
|
|
||||||
import org.jf.dexlib2.builder.MutableMethodImplementation
|
|
||||||
import org.jf.dexlib2.builder.instruction.BuilderInstruction11x
|
|
||||||
import org.jf.dexlib2.builder.instruction.BuilderInstruction21c
|
|
||||||
import org.jf.dexlib2.iface.instruction.formats.Instruction21c
|
|
||||||
import org.jf.dexlib2.immutable.ImmutableField
|
|
||||||
import org.jf.dexlib2.immutable.ImmutableMethod
|
|
||||||
import org.jf.dexlib2.immutable.ImmutableMethodImplementation
|
|
||||||
import org.jf.dexlib2.immutable.reference.ImmutableFieldReference
|
|
||||||
import org.jf.dexlib2.immutable.reference.ImmutableStringReference
|
|
||||||
import org.jf.dexlib2.immutable.value.ImmutableFieldEncodedValue
|
|
||||||
import org.jf.dexlib2.util.Preconditions
|
|
||||||
|
|
||||||
@Patch
|
@Patch
|
||||||
@Name("example-bytecode-patch")
|
@Name("example-bytecode-patch")
|
||||||
@Description("Example demonstration of a bytecode patch.")
|
@Description("Example demonstration of a bytecode patch.")
|
||||||
@ExampleResourceCompatibility
|
@ExampleResourceCompatibility
|
||||||
@Version("0.0.1")
|
|
||||||
@DependsOn([ExampleResourcePatch::class])
|
@DependsOn([ExampleResourcePatch::class])
|
||||||
class ExampleBytecodePatch : BytecodePatch(listOf(ExampleFingerprint)) {
|
class ExampleBytecodePatch : BytecodePatch(listOf(ExampleFingerprint)) {
|
||||||
// This function will be executed by the patcher.
|
// This function will be executed by the patcher.
|
||||||
// You can treat it as a constructor
|
// You can treat it as a constructor
|
||||||
override suspend fun execute(context: BytecodeContext) {
|
override fun execute(context: BytecodeContext) {
|
||||||
// Get the resolved method by its fingerprint from the resolver cache
|
// Get the resolved method by its fingerprint from the resolver cache
|
||||||
val result = ExampleFingerprint.result!!
|
val result = ExampleFingerprint.result!!
|
||||||
|
|
||||||
@@ -61,7 +59,7 @@ class ExampleBytecodePatch : BytecodePatch(listOf(ExampleFingerprint)) {
|
|||||||
implementation.replaceStringAt(startIndex, "Hello, ReVanced! Editing bytecode.")
|
implementation.replaceStringAt(startIndex, "Hello, ReVanced! Editing bytecode.")
|
||||||
|
|
||||||
// Get the class in which the method matching our fingerprint is defined in.
|
// Get the class in which the method matching our fingerprint is defined in.
|
||||||
val mainClass = context.classes.findClassProxied {
|
val mainClass = context.findClass {
|
||||||
it.type == result.classDef.type
|
it.type == result.classDef.type
|
||||||
}!!.mutableClass
|
}!!.mutableClass
|
||||||
|
|
||||||
@@ -2,8 +2,8 @@ package app.revanced.patcher.usage.bytecode
|
|||||||
import app.revanced.patcher.extensions.or
|
import app.revanced.patcher.extensions.or
|
||||||
import app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod
|
import app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||||
import org.jf.dexlib2.AccessFlags
|
import com.android.tools.smali.dexlib2.AccessFlags
|
||||||
import org.jf.dexlib2.Opcode
|
import com.android.tools.smali.dexlib2.Opcode
|
||||||
|
|
||||||
@FuzzyPatternScanMethod(2)
|
@FuzzyPatternScanMethod(2)
|
||||||
object ExampleFingerprint : MethodFingerprint(
|
object ExampleFingerprint : MethodFingerprint(
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user