You've already forked revanced-patcher
mirror of
https://github.com/revanced/revanced-patcher
synced 2025-09-06 16:38:50 +02:00
Compare commits
92 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f1775f83d0 | ||
![]() |
4055939c08 | ||
![]() |
85120374d6 | ||
![]() |
8b4819faa1 | ||
![]() |
d219276298 | ||
![]() |
79f91e0e5a | ||
![]() |
fadf62f594 | ||
![]() |
ad3d332e27 | ||
![]() |
8f66df7666 | ||
![]() |
80c2e80925 | ||
![]() |
c3db23d3c7 | ||
![]() |
c28584736e | ||
![]() |
6b909c1ee6 | ||
![]() |
0e8446516e | ||
![]() |
aa46b953db | ||
![]() |
a562e476c0 | ||
![]() |
75d2be8803 | ||
![]() |
d6308e126c | ||
![]() |
bb97af4d86 | ||
![]() |
392164862c | ||
![]() |
53e807dec1 | ||
![]() |
288d50a8b4 | ||
![]() |
131dedd4b0 | ||
![]() |
5a92d5c29d | ||
![]() |
4b81318710 | ||
![]() |
44f6a3ebc5 | ||
![]() |
7882a8d928 | ||
![]() |
cc3d32748b | ||
![]() |
f9da2ad531 | ||
![]() |
b19e1131e8 | ||
![]() |
123ad54c15 | ||
![]() |
09f6ab4155 | ||
![]() |
01cf3fb50f | ||
![]() |
6c5f9d4198 | ||
![]() |
7b2d058144 | ||
![]() |
db2804270e | ||
![]() |
2572cd04b5 | ||
![]() |
5eb8b428b9 | ||
![]() |
3a118d9b9d | ||
![]() |
14a73bfcaf | ||
![]() |
567bf52e16 | ||
![]() |
35c6489dba | ||
![]() |
371f0c4d0b | ||
![]() |
1b42f65d95 | ||
![]() |
2aee0cbd0f | ||
![]() |
19256b5437 | ||
![]() |
67a5237541 | ||
![]() |
4e2e772389 | ||
![]() |
799bc9e163 | ||
![]() |
2431785d0e | ||
![]() |
fb3c0e87d4 | ||
![]() |
5f7ef2dbff | ||
![]() |
ec1d8a8fba | ||
![]() |
814ce0b9ae | ||
![]() |
8d95b14f35 | ||
![]() |
711b8a25a7 | ||
![]() |
fbb09f38dc | ||
![]() |
9a4d30e152 | ||
![]() |
368c61c1bf | ||
![]() |
bbd40bf2f6 | ||
![]() |
3de999a2d3 | ||
![]() |
83cbb2f110 | ||
![]() |
fcc7fa75d0 | ||
![]() |
495ebface8 | ||
![]() |
8c12f8d488 | ||
![]() |
523f67b238 | ||
![]() |
4813a8b48e | ||
![]() |
d5c66022c9 | ||
![]() |
1d4034b36c | ||
![]() |
dd2d696d00 | ||
![]() |
6326321b65 | ||
![]() |
f291a4ae3e | ||
![]() |
817b8db019 | ||
![]() |
a321b8971b | ||
![]() |
783b2de9db | ||
![]() |
77604d4078 | ||
![]() |
21b5404180 | ||
![]() |
9ac6d5c7da | ||
![]() |
1b39278b24 | ||
![]() |
0ebab8bf59 | ||
![]() |
112bc998f4 | ||
![]() |
12c96bf818 | ||
![]() |
91298a8790 | ||
![]() |
f2a7cff41c | ||
![]() |
dd941233ca | ||
![]() |
fc06dd1c29 | ||
![]() |
482af78f2b | ||
![]() |
89a27dfbe6 | ||
![]() |
4ea030d0a0 | ||
![]() |
4cc2fa17f5 | ||
![]() |
48068cb3d7 | ||
![]() |
6bfe5716c3 |
60
.github/ISSUE_TEMPLATE/bug-issue.yml
vendored
Normal file
60
.github/ISSUE_TEMPLATE/bug-issue.yml
vendored
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
name: 🐞 Bug report
|
||||||
|
description: Report a very clearly broken issue.
|
||||||
|
title: 'bug: <title>'
|
||||||
|
labels: [bug]
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
# ReVanced bug report
|
||||||
|
|
||||||
|
Important to note that your issue may have already been reported before. Please check for existing issues [here](https://github.com/revanced/revanced-patcher/labels/bug).
|
||||||
|
|
||||||
|
- type: dropdown
|
||||||
|
attributes:
|
||||||
|
label: Type
|
||||||
|
options:
|
||||||
|
- Crash
|
||||||
|
- Cosmetic
|
||||||
|
- Other
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Bug description
|
||||||
|
description: How did you find the bug? Any additional details that might help?
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Steps to reproduce
|
||||||
|
description: Add the steps to reproduce this bug including your environment.
|
||||||
|
placeholder: Step 1. Download some files. Step 2. ...
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Relevant log output
|
||||||
|
description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
|
||||||
|
render: shell
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Screenshots or videos
|
||||||
|
description: Add screenshots or videos that show the bug here.
|
||||||
|
placeholder: Drag and drop the screenshots/videos into this box.
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Solution
|
||||||
|
description: If applicable, add a possible solution.
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Additional context
|
||||||
|
description: Add additional context here.
|
||||||
|
validations:
|
||||||
|
required: false
|
8
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
8
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
blank_issues_enabled: false
|
||||||
|
contact_links:
|
||||||
|
- name: 📃 Documentation
|
||||||
|
url: https://github.com/revanced/revanced-documentation/
|
||||||
|
about: Don't know how or where to start? Check out our documentation!
|
||||||
|
- name: 🗨 Discussions
|
||||||
|
url: https://github.com/revanced/revanced-suggestions/discussions
|
||||||
|
about: Got something you think should change or be added? Search for or start a new discussion!
|
46
.github/ISSUE_TEMPLATE/feature-issue.yml
vendored
Normal file
46
.github/ISSUE_TEMPLATE/feature-issue.yml
vendored
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
name: ⭐ Feature request
|
||||||
|
description: Create a detailed feature request.
|
||||||
|
title: 'feat: <title>'
|
||||||
|
labels: [feature-request]
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
# ReVanced feature request
|
||||||
|
|
||||||
|
Do not submit requests for patches here. Please submit them [here](https://github.com/orgs/revanced/discussions/categories/patches) instead.
|
||||||
|
Important to note that your feature request may have already been made before. Please check for existing feature requests [here](https://github.com/revanced/revanced-patcher/labels/feature-request).
|
||||||
|
|
||||||
|
- type: dropdown
|
||||||
|
attributes:
|
||||||
|
label: Type
|
||||||
|
options:
|
||||||
|
- Functionality
|
||||||
|
- Cosmetic
|
||||||
|
- Other
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Issue
|
||||||
|
description: What is the current problem. Why does it require a feature request?
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Feature
|
||||||
|
description: Describe your feature in detail. How does it solve the issue?
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Motivation
|
||||||
|
description: Why should your feature should be considered?
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Additional context
|
||||||
|
description: Add additional context here.
|
||||||
|
validations:
|
||||||
|
required: false
|
225
CHANGELOG.md
225
CHANGELOG.md
@@ -1,3 +1,228 @@
|
|||||||
|
## [4.1.3](https://github.com/revanced/revanced-patcher/compare/v4.1.2...v4.1.3) (2022-09-07)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* only run list option check if not null ([4055939](https://github.com/revanced/revanced-patcher/commit/4055939c089e3c396c308c980215d93a1dea5954))
|
||||||
|
|
||||||
|
## [4.1.2](https://github.com/revanced/revanced-patcher/compare/v4.1.1...v4.1.2) (2022-09-07)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* invalid types for example options ([79f91e0](https://github.com/revanced/revanced-patcher/commit/79f91e0e5a6d99828f30aae55339ce0d897394c7))
|
||||||
|
|
||||||
|
## [4.1.1](https://github.com/revanced/revanced-patcher/compare/v4.1.0...v4.1.1) (2022-09-07)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* handle private companion objects ([ad3d332](https://github.com/revanced/revanced-patcher/commit/ad3d332e27d07e9d074bbaaf51af7eb2f9bfc7d5))
|
||||||
|
|
||||||
|
# [4.1.0](https://github.com/revanced/revanced-patcher/compare/v4.0.0...v4.1.0) (2022-09-07)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* deprecation for patches ([80c2e80](https://github.com/revanced/revanced-patcher/commit/80c2e809251cdb04d2dd3b3bfdbb8844bdfa31fa))
|
||||||
|
|
||||||
|
# [4.0.0](https://github.com/revanced/revanced-patcher/compare/v3.5.1...v4.0.0) (2022-09-07)
|
||||||
|
|
||||||
|
|
||||||
|
### Code Refactoring
|
||||||
|
|
||||||
|
* Improve Patch Options ([6b909c1](https://github.com/revanced/revanced-patcher/commit/6b909c1ee6b8c2ea08bbca059df755e2e5f31656))
|
||||||
|
|
||||||
|
|
||||||
|
### BREAKING CHANGES
|
||||||
|
|
||||||
|
* Options has been moved from Patch to a new interface called OptionsContainer and are now handled entirely different. Make sure to check the examples to understand how it works.
|
||||||
|
|
||||||
|
## [3.5.1](https://github.com/revanced/revanced-patcher/compare/v3.5.0...v3.5.1) (2022-09-06)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* add tests for PathOption ([d6308e1](https://github.com/revanced/revanced-patcher/commit/d6308e126c6217b098192c51b6e98bc85a8656bd))
|
||||||
|
* PathOption should be open, not sealed ([a562e47](https://github.com/revanced/revanced-patcher/commit/a562e476c085841efbc7ee98b01d8e6bb18ed757))
|
||||||
|
* typo in ListOption ([3921648](https://github.com/revanced/revanced-patcher/commit/392164862c83d6e76b2a2113d6f6d59fef0020d1))
|
||||||
|
|
||||||
|
|
||||||
|
### Performance Improvements
|
||||||
|
|
||||||
|
* make exception an object ([75d2be8](https://github.com/revanced/revanced-patcher/commit/75d2be88037c9cf5436ab69d92abea575409a865))
|
||||||
|
|
||||||
|
# [3.5.0](https://github.com/revanced/revanced-patcher/compare/v3.4.1...v3.5.0) (2022-09-05)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* default value for `Package.versions` annotation parameter ([131dedd](https://github.com/revanced/revanced-patcher/commit/131dedd4b021fe1c3b0be49ccba4764b325770ea))
|
||||||
|
|
||||||
|
## [3.4.1](https://github.com/revanced/revanced-patcher/compare/v3.4.0...v3.4.1) (2022-09-03)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* remove default param from Package.versions ([4b81318](https://github.com/revanced/revanced-patcher/commit/4b813187107e85dc267dbc2d353884b2cc671cc4))
|
||||||
|
|
||||||
|
# [3.4.0](https://github.com/revanced/revanced-patcher/compare/v3.3.3...v3.4.0) (2022-08-31)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* nullable parameters ([7882a8d](https://github.com/revanced/revanced-patcher/commit/7882a8d928cad8de8cfea711947fc02659549d20))
|
||||||
|
|
||||||
|
## [3.3.3](https://github.com/revanced/revanced-patcher/compare/v3.3.2...v3.3.3) (2022-08-14)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* show error message if cause is null ([f9da2ad](https://github.com/revanced/revanced-patcher/commit/f9da2ad531644617ad5a2cc6a1819d530e18ba22))
|
||||||
|
|
||||||
|
## [3.3.2](https://github.com/revanced/revanced-patcher/compare/v3.3.1...v3.3.2) (2022-08-06)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* close open files ([#75](https://github.com/revanced/revanced-patcher/issues/75)) ([123ad54](https://github.com/revanced/revanced-patcher/commit/123ad54c150bd04f4b8ef5c65334ea468ceb99cc))
|
||||||
|
|
||||||
|
## [3.3.1](https://github.com/revanced/revanced-patcher/compare/v3.3.0...v3.3.1) (2022-08-03)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* revert soft dependencies ([7b2d058](https://github.com/revanced/revanced-patcher/commit/7b2d058144b0718992d329731e2af7cc704e4370))
|
||||||
|
|
||||||
|
# [3.3.0](https://github.com/revanced/revanced-patcher/compare/v3.2.1...v3.3.0) (2022-08-02)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add getValue & setValue for PatchOption ([2572cd0](https://github.com/revanced/revanced-patcher/commit/2572cd04b5da4eeae738c8dde31493177edf0bf8))
|
||||||
|
|
||||||
|
## [3.2.1](https://github.com/revanced/revanced-patcher/compare/v3.2.0...v3.2.1) (2022-08-02)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* check if patch option requirement is met ([14a73bf](https://github.com/revanced/revanced-patcher/commit/14a73bfcafac36bce2b8466788d460edde7a14fd))
|
||||||
|
|
||||||
|
# [3.2.0](https://github.com/revanced/revanced-patcher/compare/v3.1.0...v3.2.0) (2022-08-02)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* PatchOptions#nullify to nullify an option ([371f0c4](https://github.com/revanced/revanced-patcher/commit/371f0c4d0bf96e7f6db35085efccaed3000a096c))
|
||||||
|
|
||||||
|
# [3.1.0](https://github.com/revanced/revanced-patcher/compare/v3.0.0...v3.1.0) (2022-08-02)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* validator for patch options ([4e2e772](https://github.com/revanced/revanced-patcher/commit/4e2e77238957d7732326cfe5e05145bf7dab5bfb))
|
||||||
|
|
||||||
|
# [3.0.0](https://github.com/revanced/revanced-patcher/compare/v2.9.0...v3.0.0) (2022-08-02)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* registry for patch options ([2431785](https://github.com/revanced/revanced-patcher/commit/2431785d0e494d6271c6951eec9adfff9db95c17))
|
||||||
|
|
||||||
|
|
||||||
|
### BREAKING CHANGES
|
||||||
|
|
||||||
|
* Patch options now use the PatchOptions registry class instead of an Iterable. This change requires modifications to existing patches using this API.
|
||||||
|
|
||||||
|
# [2.9.0](https://github.com/revanced/revanced-patcher/compare/v2.8.0...v2.9.0) (2022-08-02)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* show error message instead of `null` ([8d95b14](https://github.com/revanced/revanced-patcher/commit/8d95b14f350b47ec029f35e776f6e627aaf5f607))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* exclusive mutable access to files ([814ce0b](https://github.com/revanced/revanced-patcher/commit/814ce0b9ae29725417c86b7d11b40d025724a426))
|
||||||
|
|
||||||
|
# [2.8.0](https://github.com/revanced/revanced-patcher/compare/v2.7.0...v2.8.0) (2022-08-01)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* remove requirement for solution [skip ci] ([#80](https://github.com/revanced/revanced-patcher/issues/80)) ([9a4d30e](https://github.com/revanced/revanced-patcher/commit/9a4d30e15234ef62844f035c58a1143674d4c12e))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* patch options ([#81](https://github.com/revanced/revanced-patcher/issues/81)) ([fbb09f3](https://github.com/revanced/revanced-patcher/commit/fbb09f38dce49adc7f63b71bdf2df2ef0b84db04))
|
||||||
|
|
||||||
|
# [2.7.0](https://github.com/revanced/revanced-patcher/compare/v2.6.0...v2.7.0) (2022-08-01)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* `Closeable` patches ([bbd40bf](https://github.com/revanced/revanced-patcher/commit/bbd40bf2f6ff200705f2bcb272dd1680bb244e3f))
|
||||||
|
|
||||||
|
# [2.6.0](https://github.com/revanced/revanced-patcher/compare/v2.5.2...v2.6.0) (2022-07-31)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add Patch#dependsOn extension ([523f67b](https://github.com/revanced/revanced-patcher/commit/523f67b238646caaa9b7676a0e238ce82adbdda4))
|
||||||
|
* Soft Dependencies for Patches ([8c12f8d](https://github.com/revanced/revanced-patcher/commit/8c12f8d488f939cc932e826aad0b20876ae165b7))
|
||||||
|
|
||||||
|
## [2.5.2](https://github.com/revanced/revanced-patcher/compare/v2.5.1...v2.5.2) (2022-07-24)
|
||||||
|
|
||||||
|
## [2.5.1](https://github.com/revanced/revanced-patcher/compare/v2.5.0...v2.5.1) (2022-07-17)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* close stream when closing `DomFileEditor` ([77604d4](https://github.com/revanced/revanced-patcher/commit/77604d40785847b775155c0e75b663a3c7336aa3))
|
||||||
|
|
||||||
|
# [2.5.0](https://github.com/revanced/revanced-patcher/compare/v2.4.0...v2.5.0) (2022-07-11)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* missing additional items [skip ci] ([0ebab8b](https://github.com/revanced/revanced-patcher/commit/0ebab8bf598d993df6e340651205cba48f1ef725))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* feature request issue template ([1b39278](https://github.com/revanced/revanced-patcher/commit/1b39278b24ba2f964d93bd8ad2e28472ee036d90))
|
||||||
|
* issue templates [skip ci] ([112bc99](https://github.com/revanced/revanced-patcher/commit/112bc998f4761a647cb9eab7454e35264fa96fd9))
|
||||||
|
|
||||||
|
# [2.4.0](https://github.com/revanced/revanced-patcher/compare/v2.3.1...v2.4.0) (2022-07-09)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* Improve Smali Compiler ([6bfe571](https://github.com/revanced/revanced-patcher/commit/6bfe5716c38181bbe9476b5c6ad29526edb4e022))
|
||||||
|
|
||||||
|
## [2.3.1](https://github.com/revanced/revanced-patcher/compare/v2.3.0...v2.3.1) (2022-07-07)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* handle null properly ([#64](https://github.com/revanced/revanced-patcher/issues/64)) ([482af78](https://github.com/revanced/revanced-patcher/commit/482af78f2ba23b8003fc9961df5fde54d7295d5c))
|
||||||
|
|
||||||
|
# [2.3.0](https://github.com/revanced/revanced-patcher/compare/v2.2.2...v2.3.0) (2022-07-05)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* nullability for `BytecodePatch` constructor ([#59](https://github.com/revanced/revanced-patcher/issues/59)) ([4ea030d](https://github.com/revanced/revanced-patcher/commit/4ea030d0a03f736bbecbd491317ba2167b18fe94))
|
||||||
|
|
||||||
|
## [2.2.2](https://github.com/revanced/revanced-patcher/compare/v2.2.1...v2.2.2) (2022-07-04)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* `MethodWalker` not accounting for all reference instructions ([48068cb](https://github.com/revanced/revanced-patcher/commit/48068cb3d79e283ff1cad9f3f78dc1d0fcd14f83))
|
||||||
|
|
||||||
## [2.2.1](https://github.com/revanced/revanced-patcher/compare/v2.2.0...v2.2.1) (2022-07-03)
|
## [2.2.1](https://github.com/revanced/revanced-patcher/compare/v2.2.0...v2.2.1) (2022-07-03)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1 +1,2 @@
|
|||||||
# Patcher
|
# Patcher
|
||||||
|
Patcher framework used in the ReVanced project.
|
@@ -24,8 +24,9 @@ dependencies {
|
|||||||
implementation("xpp3:xpp3:1.1.4c")
|
implementation("xpp3:xpp3:1.1.4c")
|
||||||
implementation("org.smali:smali:2.5.2")
|
implementation("org.smali:smali:2.5.2")
|
||||||
implementation("app.revanced:multidexlib2:2.5.2.r2")
|
implementation("app.revanced:multidexlib2:2.5.2.r2")
|
||||||
implementation("org.apktool:apktool-lib:2.6.9-SNAPSHOT")
|
implementation("org.apktool:apktool-lib:2.7.0-SNAPSHOT")
|
||||||
|
|
||||||
|
implementation(kotlin("reflect"))
|
||||||
testImplementation(kotlin("test"))
|
testImplementation(kotlin("test"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,2 +1,2 @@
|
|||||||
kotlin.code.style = official
|
kotlin.code.style = official
|
||||||
version = 2.2.1
|
version = 4.1.3
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -24,5 +24,5 @@ annotation class Compatibility(
|
|||||||
@MustBeDocumented
|
@MustBeDocumented
|
||||||
annotation class Package(
|
annotation class Package(
|
||||||
val name: String,
|
val name: String,
|
||||||
val versions: Array<String>
|
val versions: Array<String> = [],
|
||||||
)
|
)
|
||||||
|
@@ -0,0 +1,20 @@
|
|||||||
|
package app.revanced.patcher.annotation
|
||||||
|
|
||||||
|
import app.revanced.patcher.data.Data
|
||||||
|
import app.revanced.patcher.patch.Patch
|
||||||
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Declares a [Patch] deprecated for removal.
|
||||||
|
* @param reason The reason why the patch is deprecated.
|
||||||
|
* @param replacement The replacement for the deprecated patch, if any.
|
||||||
|
*/
|
||||||
|
@Target(AnnotationTarget.CLASS)
|
||||||
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
@MustBeDocumented
|
||||||
|
@Repeatable
|
||||||
|
annotation class PatchDeprecated(
|
||||||
|
val reason: String,
|
||||||
|
val replacement: KClass<out Patch<Data>> = Patch::class
|
||||||
|
// Values cannot be nullable in annotations, so this will have to do.
|
||||||
|
)
|
@@ -19,24 +19,66 @@ class ResourceData(private val resourceCacheDirectory: File) : Data, Iterable<Fi
|
|||||||
override fun iterator() = resourceCacheDirectory.walkTopDown().iterator()
|
override fun iterator() = resourceCacheDirectory.walkTopDown().iterator()
|
||||||
|
|
||||||
inner class XmlFileHolder {
|
inner class XmlFileHolder {
|
||||||
operator fun get(inputStream: InputStream, outputStream: OutputStream) =
|
operator fun get(inputStream: InputStream) =
|
||||||
DomFileEditor(inputStream, lazyOf(outputStream))
|
DomFileEditor(inputStream)
|
||||||
|
|
||||||
|
operator fun get(path: String): DomFileEditor {
|
||||||
|
return DomFileEditor(this@ResourceData[path])
|
||||||
|
}
|
||||||
|
|
||||||
operator fun get(path: String) = DomFileEditor(this@ResourceData[path])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DomFileEditor internal constructor(inputStream: InputStream, private val outputStream: Lazy<OutputStream>) : Closeable {
|
/**
|
||||||
|
* DomFileEditor is a wrapper for a file that can be edited as a dom document.
|
||||||
|
*
|
||||||
|
* @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 not be written.
|
||||||
|
*/
|
||||||
|
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
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The document of the xml file
|
||||||
|
*/
|
||||||
|
val file: Document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream)
|
||||||
|
.also(Document::normalize)
|
||||||
|
|
||||||
// lazily open an output stream
|
// 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
|
// 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
|
// 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() })
|
constructor(file: File) : this(file.inputStream(), lazy { file.outputStream() }) {
|
||||||
|
filePath = file.path
|
||||||
|
|
||||||
val file: Document =
|
// prevent sharing mutability of the same file between multiple instances of DomFileEditor
|
||||||
DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream).also(Document::normalize)
|
if (locks.contains(filePath))
|
||||||
|
throw IllegalStateException("Can not create a DomFileEditor for that file because it is already locked by another instance of DomFileEditor.")
|
||||||
|
locks.add(filePath!!)
|
||||||
|
}
|
||||||
|
|
||||||
override fun close() =
|
override fun close() {
|
||||||
TransformerFactory.newInstance().newTransformer().transform(DOMSource(file), StreamResult(outputStream.value))
|
inputStream.close()
|
||||||
|
|
||||||
|
// if the output stream is not null, do not close it
|
||||||
|
outputStream?.let {
|
||||||
|
val result = StreamResult(it.value)
|
||||||
|
TransformerFactory.newInstance().newTransformer().transform(DOMSource(file), result)
|
||||||
|
|
||||||
|
it.value.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove the lock, if it exists
|
||||||
|
filePath?.let {
|
||||||
|
locks.remove(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private companion object {
|
||||||
|
// list of locked file paths
|
||||||
|
val locks = mutableListOf<String>()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,13 +1,15 @@
|
|||||||
package app.revanced.patcher.extensions
|
package app.revanced.patcher.extensions
|
||||||
|
|
||||||
import app.revanced.patcher.annotation.Compatibility
|
import app.revanced.patcher.annotation.*
|
||||||
import app.revanced.patcher.annotation.Description
|
|
||||||
import app.revanced.patcher.annotation.Name
|
|
||||||
import app.revanced.patcher.annotation.Version
|
|
||||||
import app.revanced.patcher.data.Data
|
import app.revanced.patcher.data.Data
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||||
|
import app.revanced.patcher.patch.OptionsContainer
|
||||||
import app.revanced.patcher.patch.Patch
|
import app.revanced.patcher.patch.Patch
|
||||||
|
import app.revanced.patcher.patch.PatchOptions
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
import kotlin.reflect.KVisibility
|
||||||
|
import kotlin.reflect.full.companionObject
|
||||||
|
import kotlin.reflect.full.companionObjectInstance
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recursively find a given annotation on a class.
|
* Recursively find a given annotation on a class.
|
||||||
@@ -41,8 +43,27 @@ object PatchExtensions {
|
|||||||
val Class<out Patch<Data>>.version get() = recursiveAnnotation(Version::class)?.version
|
val Class<out Patch<Data>>.version get() = recursiveAnnotation(Version::class)?.version
|
||||||
val Class<out Patch<Data>>.include get() = recursiveAnnotation(app.revanced.patcher.patch.annotations.Patch::class)!!.include
|
val Class<out Patch<Data>>.include get() = recursiveAnnotation(app.revanced.patcher.patch.annotations.Patch::class)!!.include
|
||||||
val Class<out Patch<Data>>.description get() = recursiveAnnotation(Description::class)?.description
|
val Class<out Patch<Data>>.description get() = recursiveAnnotation(Description::class)?.description
|
||||||
val Class<out Patch<Data>>.dependencies get() = recursiveAnnotation(app.revanced.patcher.patch.annotations.Dependencies::class)?.dependencies
|
val Class<out Patch<Data>>.dependencies get() = recursiveAnnotation(app.revanced.patcher.patch.annotations.DependsOn::class)?.dependencies
|
||||||
val Class<out Patch<Data>>.compatiblePackages get() = recursiveAnnotation(Compatibility::class)?.compatiblePackages
|
val Class<out Patch<Data>>.compatiblePackages get() = recursiveAnnotation(Compatibility::class)?.compatiblePackages
|
||||||
|
val Class<out Patch<Data>>.options: PatchOptions?
|
||||||
|
get() = kotlin.companionObject?.let { cl ->
|
||||||
|
if (cl.visibility != KVisibility.PUBLIC) return null
|
||||||
|
kotlin.companionObjectInstance?.let {
|
||||||
|
(it as? OptionsContainer)?.options
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val Class<out Patch<Data>>.deprecated: Pair<String, KClass<out Patch<Data>>?>?
|
||||||
|
get() = recursiveAnnotation(PatchDeprecated::class)?.let {
|
||||||
|
it.reason to it.replacement.let { cl ->
|
||||||
|
if (cl == Patch::class) null else cl
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun Class<out Patch<Data>>.dependsOn(patch: Class<out Patch<Data>>): Boolean {
|
||||||
|
if (this.patchName == patch.patchName) throw IllegalArgumentException("thisval and patch may not be the same")
|
||||||
|
return this.dependencies?.any { it.java.patchName == this@dependsOn.patchName } == true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object MethodFingerprintExtensions {
|
object MethodFingerprintExtensions {
|
||||||
|
@@ -2,12 +2,17 @@ package app.revanced.patcher.extensions
|
|||||||
|
|
||||||
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 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.AccessFlags
|
import org.jf.dexlib2.AccessFlags
|
||||||
import org.jf.dexlib2.builder.BuilderInstruction
|
import org.jf.dexlib2.builder.BuilderInstruction
|
||||||
|
import org.jf.dexlib2.builder.BuilderOffsetInstruction
|
||||||
|
import org.jf.dexlib2.builder.Label
|
||||||
import org.jf.dexlib2.builder.MutableMethodImplementation
|
import org.jf.dexlib2.builder.MutableMethodImplementation
|
||||||
|
import org.jf.dexlib2.builder.instruction.*
|
||||||
import org.jf.dexlib2.iface.Method
|
import org.jf.dexlib2.iface.Method
|
||||||
|
import org.jf.dexlib2.iface.instruction.Instruction
|
||||||
import org.jf.dexlib2.iface.reference.MethodReference
|
import org.jf.dexlib2.iface.reference.MethodReference
|
||||||
import org.jf.dexlib2.immutable.ImmutableMethod
|
import org.jf.dexlib2.immutable.ImmutableMethod
|
||||||
import org.jf.dexlib2.immutable.ImmutableMethodImplementation
|
import org.jf.dexlib2.immutable.ImmutableMethodImplementation
|
||||||
@@ -23,6 +28,12 @@ fun MutableMethodImplementation.addInstructions(index: Int, instructions: List<B
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun MutableMethodImplementation.addInstructions(instructions: List<BuilderInstruction>) {
|
||||||
|
for (instruction in instructions) {
|
||||||
|
this.addInstruction(instruction)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun MutableMethodImplementation.replaceInstructions(index: Int, instructions: List<BuilderInstruction>) {
|
fun MutableMethodImplementation.replaceInstructions(index: Int, instructions: List<BuilderInstruction>) {
|
||||||
for (i in instructions.lastIndex downTo 0) {
|
for (i in instructions.lastIndex downTo 0) {
|
||||||
this.replaceInstruction(index + i, instructions[i])
|
this.replaceInstruction(index + i, instructions[i])
|
||||||
@@ -40,11 +51,11 @@ fun MutableMethodImplementation.removeInstructions(index: Int, count: Int) {
|
|||||||
* @param otherMethod The method to compare against.
|
* @param otherMethod The method to compare against.
|
||||||
* @return True if the methods match given the conditions.
|
* @return True if the methods match given the conditions.
|
||||||
*/
|
*/
|
||||||
fun Method.softCompareTo(
|
fun Method.softCompareTo(otherMethod: MethodReference): Boolean {
|
||||||
otherMethod: MethodReference
|
if (MethodUtil.isConstructor(this) && !parametersEqual(
|
||||||
): Boolean {
|
this.parameterTypes, otherMethod.parameterTypes
|
||||||
if (MethodUtil.isConstructor(this) && !parametersEqual(this.parameterTypes, otherMethod.parameterTypes))
|
)
|
||||||
return false
|
) return false
|
||||||
return this.name == otherMethod.name
|
return this.name == otherMethod.name
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,9 +65,7 @@ fun Method.softCompareTo(
|
|||||||
* This may be a positive or negative number.
|
* This may be a positive or negative number.
|
||||||
* @return The **immutable** cloned method. Call [toMutable] or [cloneMutable] to get a **mutable** copy.
|
* @return The **immutable** cloned method. Call [toMutable] or [cloneMutable] to get a **mutable** copy.
|
||||||
*/
|
*/
|
||||||
internal fun Method.clone(
|
internal fun Method.clone(registerCount: Int = 0): ImmutableMethod {
|
||||||
registerCount: Int = 0,
|
|
||||||
): ImmutableMethod {
|
|
||||||
val clonedImplementation = implementation?.let {
|
val clonedImplementation = implementation?.let {
|
||||||
ImmutableMethodImplementation(
|
ImmutableMethodImplementation(
|
||||||
it.registerCount + registerCount,
|
it.registerCount + registerCount,
|
||||||
@@ -66,14 +75,7 @@ internal fun Method.clone(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
return ImmutableMethod(
|
return ImmutableMethod(
|
||||||
returnType,
|
returnType, name, parameters, returnType, accessFlags, annotations, hiddenApiRestrictions, clonedImplementation
|
||||||
name,
|
|
||||||
parameters,
|
|
||||||
returnType,
|
|
||||||
accessFlags,
|
|
||||||
annotations,
|
|
||||||
hiddenApiRestrictions,
|
|
||||||
clonedImplementation
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,16 +106,89 @@ fun MutableMethod.replaceInstruction(index: Int, instruction: String) =
|
|||||||
* Remove a smali instruction within the method.
|
* Remove a smali instruction within the method.
|
||||||
* @param index The index to delete the instruction at.
|
* @param index The index to delete the instruction at.
|
||||||
*/
|
*/
|
||||||
fun MutableMethod.removeInstruction(index: Int) =
|
fun MutableMethod.removeInstruction(index: Int) = this.implementation!!.removeInstruction(index)
|
||||||
this.implementation!!.removeInstruction(index)
|
|
||||||
|
/**
|
||||||
|
* Create a label for the instruction at given index in the method's implementation.
|
||||||
|
* @param index The index to create the label for the instruction at.
|
||||||
|
* @return The label.
|
||||||
|
*/
|
||||||
|
fun MutableMethod.label(index: Int) = this.implementation!!.newLabelForIndex(index)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the instruction at given index in the method's implementation.
|
||||||
|
* @param index The index to get the instruction at.
|
||||||
|
* @return The instruction.
|
||||||
|
*/
|
||||||
|
fun MutableMethod.instruction(index: Int): BuilderInstruction = this.implementation!!.instructions[index]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add smali instructions to the method.
|
* Add smali instructions to the method.
|
||||||
* @param index The index to insert the instructions at.
|
* @param index The index to insert the instructions at.
|
||||||
|
* @param smali The smali instructions to add.
|
||||||
|
* @param externalLabels A list of [ExternalLabel] representing a list of labels for instructions which are not in the method to compile.
|
||||||
|
*/
|
||||||
|
|
||||||
|
fun MutableMethod.addInstructions(index: Int, smali: String, externalLabels: List<ExternalLabel> = emptyList()) {
|
||||||
|
// Create reference dummy instructions for the instructions.
|
||||||
|
val nopedSmali = StringBuilder(smali).also { builder ->
|
||||||
|
externalLabels.forEach { (name, _) ->
|
||||||
|
builder.append("\n:$name\nnop")
|
||||||
|
}
|
||||||
|
}.toString()
|
||||||
|
|
||||||
|
// Compile the instructions with the dummy labels
|
||||||
|
val compiledInstructions = nopedSmali.toInstructions(this)
|
||||||
|
|
||||||
|
// Add the compiled list of instructions to the method.
|
||||||
|
val methodImplementation = this.implementation!!
|
||||||
|
methodImplementation.addInstructions(index, compiledInstructions)
|
||||||
|
|
||||||
|
val methodInstructions = methodImplementation.instructions
|
||||||
|
methodInstructions.subList(index, index + compiledInstructions.size)
|
||||||
|
.forEachIndexed { compiledInstructionIndex, compiledInstruction ->
|
||||||
|
// If the compiled instruction is not an offset instruction, skip it.
|
||||||
|
if (compiledInstruction !is BuilderOffsetInstruction) return@forEachIndexed
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new label for the instruction and replaces it with the label of the [compiledInstruction] at [compiledInstructionIndex].
|
||||||
|
*/
|
||||||
|
fun Instruction.makeNewLabel() {
|
||||||
|
// Create the final label.
|
||||||
|
val label = methodImplementation.newLabelForIndex(methodInstructions.indexOf(this))
|
||||||
|
// Create the final instruction with the new label.
|
||||||
|
val newInstruction = replaceOffset(
|
||||||
|
compiledInstruction, label
|
||||||
|
)
|
||||||
|
// Replace the instruction pointing to the dummy label with the new instruction pointing to the real instruction.
|
||||||
|
methodImplementation.replaceInstruction(index + compiledInstructionIndex, newInstruction)
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the compiled instruction targets its own instruction,
|
||||||
|
// which means it points to some of its own, simply an offset has to be applied.
|
||||||
|
val labelIndex = compiledInstruction.target.location.index
|
||||||
|
if (labelIndex < compiledInstructions.size - externalLabels.size) {
|
||||||
|
// Get the targets index (insertion index + the index of the dummy instruction).
|
||||||
|
methodInstructions[index + labelIndex].makeNewLabel()
|
||||||
|
return@forEachIndexed
|
||||||
|
}
|
||||||
|
|
||||||
|
// Since the compiled instruction points to a dummy instruction,
|
||||||
|
// we can find the real instruction which it was created for by calculation.
|
||||||
|
|
||||||
|
// Get the index of the instruction in the externalLabels list which the dummy instruction was created for.
|
||||||
|
// this line works because we created the dummy instructions in the same order as the externalLabels list.
|
||||||
|
val (_, instruction) = externalLabels[(compiledInstructions.size - 1) - labelIndex]
|
||||||
|
instruction.makeNewLabel()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add smali instructions to the end of the method.
|
||||||
* @param instructions The smali instructions to add.
|
* @param instructions The smali instructions to add.
|
||||||
*/
|
*/
|
||||||
fun MutableMethod.addInstructions(index: Int, instructions: String) =
|
fun MutableMethod.addInstructions(instructions: String, labels: List<ExternalLabel> = emptyList()) =
|
||||||
this.implementation!!.addInstructions(index, instructions.toInstructions(this))
|
this.addInstructions(this.implementation!!.instructions.size, instructions, labels)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replace smali instructions within the method.
|
* Replace smali instructions within the method.
|
||||||
@@ -128,8 +203,21 @@ fun MutableMethod.replaceInstructions(index: Int, instructions: String) =
|
|||||||
* @param index The index to remove the instructions at.
|
* @param index The index to remove the instructions at.
|
||||||
* @param count The amount of instructions to remove.
|
* @param count The amount of instructions to remove.
|
||||||
*/
|
*/
|
||||||
fun MutableMethod.removeInstructions(index: Int, count: Int) =
|
fun MutableMethod.removeInstructions(index: Int, count: Int) = this.implementation!!.removeInstructions(index, count)
|
||||||
this.implementation!!.removeInstructions(index, count)
|
|
||||||
|
private fun replaceOffset(
|
||||||
|
i: BuilderOffsetInstruction, label: Label
|
||||||
|
): BuilderOffsetInstruction {
|
||||||
|
return when (i) {
|
||||||
|
is BuilderInstruction10t -> BuilderInstruction10t(i.opcode, label)
|
||||||
|
is BuilderInstruction20t -> BuilderInstruction20t(i.opcode, label)
|
||||||
|
is BuilderInstruction21t -> BuilderInstruction21t(i.opcode, i.registerA, label)
|
||||||
|
is BuilderInstruction22t -> BuilderInstruction22t(i.opcode, i.registerA, i.registerB, label)
|
||||||
|
is BuilderInstruction30t -> BuilderInstruction30t(i.opcode, label)
|
||||||
|
is BuilderInstruction31t -> BuilderInstruction31t(i.opcode, i.registerA, label)
|
||||||
|
else -> throw IllegalStateException("A non-offset instruction was given, this should never happen!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clones the method.
|
* Clones the method.
|
||||||
@@ -137,14 +225,11 @@ fun MutableMethod.removeInstructions(index: Int, count: Int) =
|
|||||||
* This may be a positive or negative number.
|
* This may be a positive or negative number.
|
||||||
* @return The **mutable** cloned method. Call [clone] to get an **immutable** copy.
|
* @return The **mutable** cloned method. Call [clone] to get an **immutable** copy.
|
||||||
*/
|
*/
|
||||||
internal fun Method.cloneMutable(
|
internal fun Method.cloneMutable(registerCount: Int = 0) = clone(registerCount).toMutable()
|
||||||
registerCount: Int = 0,
|
|
||||||
) = clone(registerCount).toMutable()
|
|
||||||
|
|
||||||
// FIXME: also check the order of parameters as different order equals different method overload
|
// FIXME: also check the order of parameters as different order equals different method overload
|
||||||
internal fun parametersEqual(
|
internal fun parametersEqual(
|
||||||
parameters1: Iterable<CharSequence>,
|
parameters1: Iterable<CharSequence>, parameters2: Iterable<CharSequence>
|
||||||
parameters2: Iterable<CharSequence>
|
|
||||||
): Boolean {
|
): Boolean {
|
||||||
return parameters1.count() == parameters2.count() && parameters1.all { parameter ->
|
return parameters1.count() == parameters2.count() && parameters1.all { parameter ->
|
||||||
parameters2.any {
|
parameters2.any {
|
||||||
@@ -155,10 +240,9 @@ internal fun parametersEqual(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal val nullOutputStream: OutputStream =
|
internal val nullOutputStream = object : OutputStream() {
|
||||||
object : OutputStream() {
|
override fun write(b: Int) {}
|
||||||
override fun write(b: Int) {}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Should be used to parse a list of parameters represented by their first letter,
|
* Should be used to parse a list of parameters represented by their first letter,
|
||||||
|
@@ -22,10 +22,10 @@ import org.jf.dexlib2.iface.Method
|
|||||||
* A `null` opcode is equals to an unknown opcode.
|
* A `null` opcode is equals to an unknown opcode.
|
||||||
*/
|
*/
|
||||||
abstract class MethodFingerprint(
|
abstract class MethodFingerprint(
|
||||||
internal val returnType: String?,
|
internal val returnType: String? = null,
|
||||||
internal val access: Int?,
|
internal val access: Int? = null,
|
||||||
internal val parameters: Iterable<String>?,
|
internal val parameters: Iterable<String>? = null,
|
||||||
internal val opcodes: Iterable<Opcode?>?,
|
internal val opcodes: Iterable<Opcode?>? = null,
|
||||||
internal val strings: Iterable<String>? = null,
|
internal val strings: Iterable<String>? = null,
|
||||||
internal val customFingerprint: ((methodDef: Method) -> Boolean)? = null
|
internal val customFingerprint: ((methodDef: Method) -> Boolean)? = null
|
||||||
) : Fingerprint {
|
) : Fingerprint {
|
||||||
|
@@ -3,16 +3,32 @@ package app.revanced.patcher.patch
|
|||||||
import app.revanced.patcher.data.Data
|
import app.revanced.patcher.data.Data
|
||||||
import app.revanced.patcher.patch.impl.BytecodePatch
|
import app.revanced.patcher.patch.impl.BytecodePatch
|
||||||
import app.revanced.patcher.patch.impl.ResourcePatch
|
import app.revanced.patcher.patch.impl.ResourcePatch
|
||||||
|
import java.io.Closeable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A ReVanced patch.
|
* A ReVanced patch.
|
||||||
|
*
|
||||||
* Can either be a [ResourcePatch] or a [BytecodePatch].
|
* Can either be a [ResourcePatch] or a [BytecodePatch].
|
||||||
|
* If it implements [Closeable], it will be closed after all patches have been executed.
|
||||||
|
* Closing will be done in reverse execution order.
|
||||||
*/
|
*/
|
||||||
abstract class Patch<out T : Data> {
|
abstract class Patch<out T : Data> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main function of the [Patch] which the patcher will call.
|
* The main function of the [Patch] which the patcher will call.
|
||||||
*/
|
*/
|
||||||
abstract fun execute(data: @UnsafeVariance T): PatchResult
|
abstract fun execute(data: @UnsafeVariance T): PatchResult
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class OptionsContainer {
|
||||||
|
/**
|
||||||
|
* A list of [PatchOption]s.
|
||||||
|
* @see PatchOptions
|
||||||
|
*/
|
||||||
|
@Suppress("MemberVisibilityCanBePrivate")
|
||||||
|
val options = PatchOptions()
|
||||||
|
|
||||||
|
protected fun option(opt: PatchOption<*>): PatchOption<*> {
|
||||||
|
options.register(opt)
|
||||||
|
return opt
|
||||||
|
}
|
||||||
}
|
}
|
230
src/main/kotlin/app/revanced/patcher/patch/PatchOption.kt
Normal file
230
src/main/kotlin/app/revanced/patcher/patch/PatchOption.kt
Normal file
@@ -0,0 +1,230 @@
|
|||||||
|
@file:Suppress("CanBeParameter", "MemberVisibilityCanBePrivate", "UNCHECKED_CAST")
|
||||||
|
|
||||||
|
package app.revanced.patcher.patch
|
||||||
|
|
||||||
|
import java.io.File
|
||||||
|
import java.nio.file.Path
|
||||||
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
|
class NoSuchOptionException(val option: String) : Exception("No such option: $option")
|
||||||
|
class IllegalValueException(val value: Any?) : Exception("Illegal value: $value")
|
||||||
|
class InvalidTypeException(val got: String, val expected: String) :
|
||||||
|
Exception("Invalid option value type: $got, expected $expected")
|
||||||
|
|
||||||
|
object RequirementNotMetException : Exception("null was passed into an option that requires a value")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A registry for an array of [PatchOption]s.
|
||||||
|
* @param options An array of [PatchOption]s.
|
||||||
|
*/
|
||||||
|
class PatchOptions(vararg val options: PatchOption<*>) : Iterable<PatchOption<*>> {
|
||||||
|
private val register = mutableMapOf<String, PatchOption<*>>()
|
||||||
|
|
||||||
|
init {
|
||||||
|
options.forEach { register(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun register(option: PatchOption<*>) {
|
||||||
|
if (register.containsKey(option.key)) {
|
||||||
|
throw IllegalStateException("Multiple options found with the same key")
|
||||||
|
}
|
||||||
|
register[option.key] = option
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a [PatchOption] by its key.
|
||||||
|
* @param key The key of the [PatchOption].
|
||||||
|
*/
|
||||||
|
operator fun get(key: String) = register[key] ?: throw NoSuchOptionException(key)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the value of a [PatchOption].
|
||||||
|
* @param key The key of the [PatchOption].
|
||||||
|
* @param value The value you want it to be.
|
||||||
|
* Please note that using the wrong value type results in a runtime error.
|
||||||
|
*/
|
||||||
|
inline operator fun <reified T> set(key: String, value: T) {
|
||||||
|
@Suppress("UNCHECKED_CAST") val opt = get(key) as PatchOption<T>
|
||||||
|
if (opt.value !is T) throw InvalidTypeException(
|
||||||
|
T::class.java.canonicalName,
|
||||||
|
opt.value?.let { it::class.java.canonicalName } ?: "null"
|
||||||
|
)
|
||||||
|
opt.value = value
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of a [PatchOption] to `null`.
|
||||||
|
* @param key The key of the [PatchOption].
|
||||||
|
*/
|
||||||
|
fun nullify(key: String) {
|
||||||
|
get(key).value = null
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun iterator() = options.iterator()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A [Patch] option.
|
||||||
|
* @param key Unique identifier of the option. Example: _`settings.microg.enabled`_
|
||||||
|
* @param default The default value of the option.
|
||||||
|
* @param title A human-readable title of the option. Example: _MicroG Settings_
|
||||||
|
* @param description A human-readable description of the option. Example: _Settings integration for MicroG._
|
||||||
|
* @param required Whether the option is required.
|
||||||
|
*/
|
||||||
|
@Suppress("MemberVisibilityCanBePrivate")
|
||||||
|
sealed class PatchOption<T>(
|
||||||
|
val key: String,
|
||||||
|
default: T?,
|
||||||
|
val title: String,
|
||||||
|
val description: String,
|
||||||
|
val required: Boolean,
|
||||||
|
val validator: (T?) -> Boolean
|
||||||
|
) {
|
||||||
|
var value: T? = default
|
||||||
|
set(value) {
|
||||||
|
if (value == null && required) {
|
||||||
|
throw RequirementNotMetException
|
||||||
|
}
|
||||||
|
if (!validator(value)) {
|
||||||
|
throw IllegalValueException(value)
|
||||||
|
}
|
||||||
|
field = value
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of the option.
|
||||||
|
* Please note that using the wrong value type results in a runtime error.
|
||||||
|
*/
|
||||||
|
operator fun <T> getValue(thisRef: Any?, property: KProperty<*>) = value as T
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of the option.
|
||||||
|
* Please note that using the wrong value type results in a runtime error.
|
||||||
|
*/
|
||||||
|
inline operator fun <reified V> setValue(thisRef: Any?, property: KProperty<*>, new: V) {
|
||||||
|
if (value !is V) throw InvalidTypeException(
|
||||||
|
V::class.java.canonicalName,
|
||||||
|
value?.let { it::class.java.canonicalName } ?: "null"
|
||||||
|
)
|
||||||
|
value = new as T
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A [PatchOption] representing a [String].
|
||||||
|
* @see PatchOption
|
||||||
|
*/
|
||||||
|
class StringOption(
|
||||||
|
key: String,
|
||||||
|
default: String?,
|
||||||
|
title: String,
|
||||||
|
description: String,
|
||||||
|
required: Boolean = false,
|
||||||
|
validator: (String?) -> Boolean = { true }
|
||||||
|
) : PatchOption<String>(
|
||||||
|
key, default, title, description, required, validator
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A [PatchOption] representing a [Boolean].
|
||||||
|
* @see PatchOption
|
||||||
|
*/
|
||||||
|
class BooleanOption(
|
||||||
|
key: String,
|
||||||
|
default: Boolean?,
|
||||||
|
title: String,
|
||||||
|
description: String,
|
||||||
|
required: Boolean = false,
|
||||||
|
validator: (Boolean?) -> Boolean = { true }
|
||||||
|
) : PatchOption<Boolean>(
|
||||||
|
key, default, title, description, required, validator
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A [PatchOption] with a list of allowed options.
|
||||||
|
* @param options A list of allowed options for the [ListOption].
|
||||||
|
* @see PatchOption
|
||||||
|
*/
|
||||||
|
sealed class ListOption<E>(
|
||||||
|
key: String,
|
||||||
|
default: E?,
|
||||||
|
val options: Iterable<E>,
|
||||||
|
title: String,
|
||||||
|
description: String,
|
||||||
|
required: Boolean = false,
|
||||||
|
validator: (E?) -> Boolean = { true }
|
||||||
|
) : PatchOption<E>(
|
||||||
|
key, default, title, description, required, {
|
||||||
|
(it?.let { it in options } ?: true) && validator(it)
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
init {
|
||||||
|
if (default != null && default !in options) {
|
||||||
|
throw IllegalStateException("Default option must be an allowed option")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A [ListOption] of type [String].
|
||||||
|
* @see ListOption
|
||||||
|
*/
|
||||||
|
class StringListOption(
|
||||||
|
key: String,
|
||||||
|
default: String?,
|
||||||
|
options: Iterable<String>,
|
||||||
|
title: String,
|
||||||
|
description: String,
|
||||||
|
required: Boolean = false,
|
||||||
|
validator: (String?) -> Boolean = { true }
|
||||||
|
) : ListOption<String>(
|
||||||
|
key, default, options, title, description, required, validator
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A [ListOption] of type [Int].
|
||||||
|
* @see ListOption
|
||||||
|
*/
|
||||||
|
class IntListOption(
|
||||||
|
key: String,
|
||||||
|
default: Int?,
|
||||||
|
options: Iterable<Int>,
|
||||||
|
title: String,
|
||||||
|
description: String,
|
||||||
|
required: Boolean = false,
|
||||||
|
validator: (Int?) -> Boolean = { true }
|
||||||
|
) : ListOption<Int>(
|
||||||
|
key, default, options, title, description, required, validator
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A [PatchOption] representing a [Path].
|
||||||
|
* @see PatchOption
|
||||||
|
*/
|
||||||
|
open class PathOption(
|
||||||
|
key: String,
|
||||||
|
default: Path?,
|
||||||
|
title: String,
|
||||||
|
description: String,
|
||||||
|
required: Boolean = false,
|
||||||
|
validator: (Path?) -> Boolean = { true }
|
||||||
|
) : PatchOption<Path>(
|
||||||
|
key, default, title, description, required, validator
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A [PathOption] of type [File].
|
||||||
|
* @see PathOption
|
||||||
|
*/
|
||||||
|
class FileOption(
|
||||||
|
key: String,
|
||||||
|
default: File?,
|
||||||
|
title: String,
|
||||||
|
description: String,
|
||||||
|
required: Boolean = false,
|
||||||
|
validator: (File?) -> Boolean = { true }
|
||||||
|
) : PathOption(
|
||||||
|
key, default?.toPath(), title, description, required, {
|
||||||
|
validator(it?.toFile())
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
@@ -19,6 +19,6 @@ annotation class Patch(val include: Boolean = true)
|
|||||||
@Target(AnnotationTarget.CLASS)
|
@Target(AnnotationTarget.CLASS)
|
||||||
@Retention(AnnotationRetention.RUNTIME)
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
@MustBeDocumented
|
@MustBeDocumented
|
||||||
annotation class Dependencies(
|
annotation class DependsOn(
|
||||||
val dependencies: Array<KClass<out Patch<Data>>> = []
|
val dependencies: Array<KClass<out Patch<Data>>> = []
|
||||||
)
|
)
|
@@ -9,5 +9,5 @@ import app.revanced.patcher.patch.Patch
|
|||||||
* @param fingerprints A list of [MethodFingerprint] this patch relies on.
|
* @param fingerprints A list of [MethodFingerprint] this patch relies on.
|
||||||
*/
|
*/
|
||||||
abstract class BytecodePatch(
|
abstract class BytecodePatch(
|
||||||
internal val fingerprints: Iterable<MethodFingerprint>
|
internal val fingerprints: Iterable<MethodFingerprint>? = null
|
||||||
) : Patch<BytecodeData>()
|
) : Patch<BytecodeData>()
|
||||||
|
@@ -5,6 +5,6 @@ import java.io.InputStream
|
|||||||
/**
|
/**
|
||||||
* Wrapper for dex files.
|
* Wrapper for dex files.
|
||||||
* @param name The original name of the dex file.
|
* @param name The original name of the dex file.
|
||||||
* @param dexFileInputStream The dex file as [InputStream].
|
* @param stream The dex file as [InputStream].
|
||||||
*/
|
*/
|
||||||
data class DexFile(val name: String, val dexFileInputStream: InputStream)
|
data class DexFile(val name: String, val stream: InputStream)
|
@@ -4,11 +4,9 @@ import app.revanced.patcher.data.impl.BytecodeData
|
|||||||
import app.revanced.patcher.data.impl.MethodNotFoundException
|
import app.revanced.patcher.data.impl.MethodNotFoundException
|
||||||
import app.revanced.patcher.extensions.softCompareTo
|
import app.revanced.patcher.extensions.softCompareTo
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
||||||
import org.jf.dexlib2.Format
|
|
||||||
import org.jf.dexlib2.iface.Method
|
import org.jf.dexlib2.iface.Method
|
||||||
import org.jf.dexlib2.iface.instruction.formats.Instruction35c
|
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
|
||||||
import org.jf.dexlib2.iface.reference.MethodReference
|
import org.jf.dexlib2.iface.reference.MethodReference
|
||||||
import org.jf.dexlib2.util.Preconditions
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find a method from another method via instruction offsets.
|
* Find a method from another method via instruction offsets.
|
||||||
@@ -37,9 +35,7 @@ class MethodWalker internal constructor(
|
|||||||
currentMethod.implementation?.instructions?.let { instructions ->
|
currentMethod.implementation?.instructions?.let { instructions ->
|
||||||
val instruction = instructions.elementAt(offset)
|
val instruction = instructions.elementAt(offset)
|
||||||
|
|
||||||
Preconditions.checkFormat(instruction.opcode, Format.Format35c)
|
val newMethod = (instruction as ReferenceInstruction).reference as MethodReference
|
||||||
|
|
||||||
val newMethod = (instruction as Instruction35c).reference as MethodReference
|
|
||||||
val proxy = bytecodeData.findClass(newMethod.definingClass)!!
|
val proxy = bytecodeData.findClass(newMethod.definingClass)!!
|
||||||
|
|
||||||
val methods = if (walkMutable) proxy.resolve().methods else proxy.immutableClass.methods
|
val methods = if (walkMutable) proxy.resolve().methods else proxy.immutableClass.methods
|
||||||
|
@@ -1,17 +1,17 @@
|
|||||||
package app.revanced.patcher.util.patch.base
|
package app.revanced.patcher.util.patch
|
||||||
|
|
||||||
import app.revanced.patcher.data.Data
|
import app.revanced.patcher.data.Data
|
||||||
import app.revanced.patcher.patch.Patch
|
import app.revanced.patcher.patch.Patch
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param patchBundlePath The path to the patch bundle.
|
* @param path The path to the patch bundle.
|
||||||
*/
|
*/
|
||||||
abstract class PatchBundle(patchBundlePath: String) : File(patchBundlePath) {
|
abstract class PatchBundle(path: String) : File(path) {
|
||||||
internal fun loadPatches(classLoader: ClassLoader, classNames: Iterator<String>) = buildList {
|
internal fun loadPatches(classLoader: ClassLoader, classNames: Iterator<String>) = buildList {
|
||||||
classNames.forEach { className ->
|
for (className in classNames) {
|
||||||
val clazz = classLoader.loadClass(className)
|
val clazz = classLoader.loadClass(className)
|
||||||
if (!clazz.isAnnotationPresent(app.revanced.patcher.patch.annotations.Patch::class.java)) return@forEach
|
if (!clazz.isAnnotationPresent(app.revanced.patcher.patch.annotations.Patch::class.java)) continue
|
||||||
@Suppress("UNCHECKED_CAST") this.add(clazz as Class<out Patch<Data>>)
|
@Suppress("UNCHECKED_CAST") this.add(clazz as Class<out Patch<Data>>)
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,4 +1,4 @@
|
|||||||
package app.revanced.patcher.util.patch.util
|
package app.revanced.patcher.util.patch
|
||||||
|
|
||||||
internal class StringIterator<T, I : Iterator<T>>(
|
internal class StringIterator<T, I : Iterator<T>>(
|
||||||
private val iterator: I,
|
private val iterator: I,
|
@@ -1,7 +1,7 @@
|
|||||||
package app.revanced.patcher.util.patch.implementation
|
package app.revanced.patcher.util.patch.impl
|
||||||
|
|
||||||
import app.revanced.patcher.util.patch.base.PatchBundle
|
import app.revanced.patcher.util.patch.PatchBundle
|
||||||
import app.revanced.patcher.util.patch.util.StringIterator
|
import app.revanced.patcher.util.patch.StringIterator
|
||||||
import org.jf.dexlib2.DexFileFactory
|
import org.jf.dexlib2.DexFileFactory
|
||||||
|
|
||||||
/**
|
/**
|
@@ -1,7 +1,7 @@
|
|||||||
package app.revanced.patcher.util.patch.implementation
|
package app.revanced.patcher.util.patch.impl
|
||||||
|
|
||||||
import app.revanced.patcher.util.patch.base.PatchBundle
|
import app.revanced.patcher.util.patch.PatchBundle
|
||||||
import app.revanced.patcher.util.patch.util.StringIterator
|
import app.revanced.patcher.util.patch.StringIterator
|
||||||
import java.net.URLClassLoader
|
import java.net.URLClassLoader
|
||||||
import java.util.jar.JarFile
|
import java.util.jar.JarFile
|
||||||
|
|
@@ -0,0 +1,10 @@
|
|||||||
|
package app.revanced.patcher.util.smali
|
||||||
|
|
||||||
|
import org.jf.dexlib2.iface.instruction.Instruction
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class that represents a label for an instruction.
|
||||||
|
* @param name The label name.
|
||||||
|
* @param instruction The instruction that this label is for.
|
||||||
|
*/
|
||||||
|
data class ExternalLabel(internal val name: String, internal val instruction: Instruction)
|
@@ -1,12 +1,12 @@
|
|||||||
package app.revanced.patcher.util.smali
|
package app.revanced.patcher.util.smali
|
||||||
|
|
||||||
|
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 org.jf.dexlib2.AccessFlags
|
||||||
import org.jf.dexlib2.Opcodes
|
import org.jf.dexlib2.Opcodes
|
||||||
import org.jf.dexlib2.builder.BuilderInstruction
|
import org.jf.dexlib2.builder.BuilderInstruction
|
||||||
import org.jf.dexlib2.iface.Method
|
|
||||||
import org.jf.dexlib2.writer.builder.DexBuilder
|
import org.jf.dexlib2.writer.builder.DexBuilder
|
||||||
import org.jf.smali.LexerErrorInterface
|
import org.jf.smali.LexerErrorInterface
|
||||||
import org.jf.smali.smaliFlexLexer
|
import org.jf.smali.smaliFlexLexer
|
||||||
@@ -27,18 +27,19 @@ class InlineSmaliCompiler {
|
|||||||
companion object {
|
companion object {
|
||||||
/**
|
/**
|
||||||
* Compiles a string of Smali code to a list of instructions.
|
* Compiles a string of Smali code to a list of instructions.
|
||||||
* p0, p1 etc. will only work correctly if the parameters and registers are passed.
|
* Special registers (such as p0, p1) will only work correctly
|
||||||
* Do not cross the boundaries of the control flow (if-nez insn, etc),
|
* if the parameters and registers of the method are passed.
|
||||||
* as that will result in exceptions since the labels cannot be calculated.
|
|
||||||
* Do not create dummy labels to fix the issue, since the code addresses will
|
|
||||||
* be messed up and results in broken Dalvik bytecode.
|
|
||||||
* FIXME: Fix the above issue. When this is fixed, add the proper conversions in [InstructionConverter].
|
|
||||||
*/
|
*/
|
||||||
fun compile(
|
fun compile(
|
||||||
instructions: String, parameters: String, registers: Int, forStaticMethod: Boolean
|
instructions: String, parameters: String, registers: Int, forStaticMethod: Boolean
|
||||||
): List<BuilderInstruction> {
|
): List<BuilderInstruction> {
|
||||||
val input =
|
val input = METHOD_TEMPLATE.format(
|
||||||
METHOD_TEMPLATE.format(if (forStaticMethod) "static" else "", parameters, registers, instructions)
|
if (forStaticMethod) {
|
||||||
|
"static"
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
}, parameters, registers, instructions
|
||||||
|
)
|
||||||
val reader = InputStreamReader(input.byteInputStream())
|
val reader = InputStreamReader(input.byteInputStream())
|
||||||
val lexer: LexerErrorInterface = smaliFlexLexer(reader, 15)
|
val lexer: LexerErrorInterface = smaliFlexLexer(reader, 15)
|
||||||
val tokens = CommonTokenStream(lexer as TokenSource)
|
val tokens = CommonTokenStream(lexer as TokenSource)
|
||||||
@@ -54,25 +55,30 @@ class InlineSmaliCompiler {
|
|||||||
val dexGen = smaliTreeWalker(treeStream)
|
val dexGen = smaliTreeWalker(treeStream)
|
||||||
dexGen.setDexBuilder(DexBuilder(Opcodes.getDefault()))
|
dexGen.setDexBuilder(DexBuilder(Opcodes.getDefault()))
|
||||||
val classDef = dexGen.smali_file()
|
val classDef = dexGen.smali_file()
|
||||||
return classDef.methods.first().implementation!!.instructions.map { it.toBuilderInstruction() }
|
return classDef.methods.first().implementation!!.instructions.map { it as BuilderInstruction }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compile lines of Smali code to a list of instructions.
|
* Compile lines of Smali code to a list of instructions.
|
||||||
* @param templateMethod The method to compile the instructions against.
|
*
|
||||||
|
* Note: Adding compiled instructions to an existing method with
|
||||||
|
* offset instructions WITHOUT specifying a parent method will not work.
|
||||||
|
* @param method The method to compile the instructions against.
|
||||||
* @returns A list of instructions.
|
* @returns A list of instructions.
|
||||||
*/
|
*/
|
||||||
fun String.toInstructions(templateMethod: Method? = null) = InlineSmaliCompiler.compile(this,
|
fun String.toInstructions(method: MutableMethod? = null): List<BuilderInstruction> {
|
||||||
templateMethod?.parameters?.joinToString("") { it } ?: "",
|
return InlineSmaliCompiler.compile(this,
|
||||||
templateMethod?.implementation?.registerCount ?: 1,
|
method?.parameters?.joinToString("") { it } ?: "",
|
||||||
templateMethod?.let { AccessFlags.STATIC.isSet(it.accessFlags) } ?: true
|
method?.implementation?.registerCount ?: 1,
|
||||||
)
|
method?.let { AccessFlags.STATIC.isSet(it.accessFlags) } ?: true
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compile a line of Smali code to an instruction.
|
* Compile a line of Smali code to an instruction.
|
||||||
* @param templateMethod The method to compile the instructions against.
|
* @param templateMethod The method to compile the instructions against.
|
||||||
* @return The instruction.
|
* @return The instruction.
|
||||||
*/
|
*/
|
||||||
fun String.toInstruction(templateMethod: Method? = null) = this.toInstructions(templateMethod).first()
|
fun String.toInstruction(templateMethod: MutableMethod? = null) = this.toInstructions(templateMethod).first()
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,93 @@
|
|||||||
|
package app.revanced.patcher.patch
|
||||||
|
|
||||||
|
import app.revanced.patcher.usage.bytecode.ExampleBytecodePatch
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.junit.jupiter.api.assertThrows
|
||||||
|
import java.io.File
|
||||||
|
import kotlin.test.assertNotEquals
|
||||||
|
|
||||||
|
internal class PatchOptionsTest {
|
||||||
|
private val options = ExampleBytecodePatch.options
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `should not throw an exception`() {
|
||||||
|
for (option in options) {
|
||||||
|
when (option) {
|
||||||
|
is PatchOption.StringOption -> {
|
||||||
|
option.value = "Hello World"
|
||||||
|
}
|
||||||
|
|
||||||
|
is PatchOption.BooleanOption -> {
|
||||||
|
option.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
is PatchOption.StringListOption -> {
|
||||||
|
option.value = option.options.first()
|
||||||
|
for (choice in option.options) {
|
||||||
|
println(choice)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
is PatchOption.IntListOption -> {
|
||||||
|
option.value = option.options.first()
|
||||||
|
for (choice in option.options) {
|
||||||
|
println(choice)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
is PatchOption.PathOption -> {
|
||||||
|
option.value = File("test.txt").toPath()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val option = options["key1"]
|
||||||
|
println(option.value)
|
||||||
|
options["key1"] = "Hello, world!"
|
||||||
|
println(option.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `should return a different value when changed`() {
|
||||||
|
var value: String by options["key1"]
|
||||||
|
val current = value + "" // force a copy
|
||||||
|
value = "Hello, world!"
|
||||||
|
assertNotEquals(current, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `should be able to set value to null`() {
|
||||||
|
// Sadly, doing:
|
||||||
|
// > options["key2"] = null
|
||||||
|
// is not possible because Kotlin
|
||||||
|
// cannot reify the type "Nothing?".
|
||||||
|
options.nullify("key2")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `should fail because the option does not exist`() {
|
||||||
|
assertThrows<NoSuchOptionException> {
|
||||||
|
options["this option does not exist"] = 123
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `should fail because of invalid value type`() {
|
||||||
|
assertThrows<InvalidTypeException> {
|
||||||
|
options["key1"] = 123
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `should fail because of an illegal value`() {
|
||||||
|
assertThrows<IllegalValueException> {
|
||||||
|
options["key3"] = "this value is not an allowed option"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `should fail because of the requirement is not met`() {
|
||||||
|
assertThrows<RequirementNotMetException> {
|
||||||
|
options.nullify("key1")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,46 +0,0 @@
|
|||||||
package app.revanced.patcher.usage
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test
|
|
||||||
|
|
||||||
internal class PatcherTest {
|
|
||||||
@Test
|
|
||||||
fun testPatcher() {
|
|
||||||
return // FIXME: create a proper resource to pass this test
|
|
||||||
/**
|
|
||||||
val patcher = Patcher(
|
|
||||||
File(PatcherTest::class.java.getResource("/example.apk")!!.toURI()),
|
|
||||||
"exampleCacheDirectory",
|
|
||||||
patchResources = true
|
|
||||||
)
|
|
||||||
|
|
||||||
patcher.addPatches(listOf(ExampleBytecodePatch(), ExampleResourcePatch()))
|
|
||||||
|
|
||||||
for (signature in patcher.resolveSignatures()) {
|
|
||||||
if (!signature.resolved) {
|
|
||||||
throw Exception("Signature ${signature.metadata.name} was not resolved!")
|
|
||||||
}
|
|
||||||
val patternScanMethod = signature.metadata.patternScanMethod
|
|
||||||
if (patternScanMethod is PatternScanMethod.Fuzzy) {
|
|
||||||
val warnings = patternScanMethod.warnings
|
|
||||||
if (warnings != null) {
|
|
||||||
println("Signature ${signature.metadata.name} had ${warnings.size} warnings!")
|
|
||||||
for (warning in warnings) {
|
|
||||||
println(warning.toString())
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
println("Signature ${signature.metadata.name} used the fuzzy resolver, but the warnings list is null!")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for ((metadata, result) in patcher.applyPatches()) {
|
|
||||||
if (result.isFailure) {
|
|
||||||
throw Exception("Patch ${metadata.shortName} failed", result.exceptionOrNull()!!)
|
|
||||||
} else {
|
|
||||||
println("Patch ${metadata.shortName} applied successfully!")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val out = patcher.save()
|
|
||||||
assertTrue(out.isNotEmpty(), "Expected the output of Patcher#save() to not be empty.")
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,4 +1,4 @@
|
|||||||
package app.revanced.patcher.usage.bytecode.annotation
|
package app.revanced.patcher.usage.bytecode
|
||||||
|
|
||||||
import app.revanced.patcher.annotation.Compatibility
|
import app.revanced.patcher.annotation.Compatibility
|
||||||
import app.revanced.patcher.annotation.Package
|
import app.revanced.patcher.annotation.Package
|
@@ -1,4 +1,4 @@
|
|||||||
package app.revanced.patcher.usage.bytecode.patch
|
package app.revanced.patcher.usage.bytecode
|
||||||
|
|
||||||
import app.revanced.patcher.annotation.Description
|
import app.revanced.patcher.annotation.Description
|
||||||
import app.revanced.patcher.annotation.Name
|
import app.revanced.patcher.annotation.Name
|
||||||
@@ -6,15 +6,17 @@ import app.revanced.patcher.annotation.Version
|
|||||||
import app.revanced.patcher.data.impl.BytecodeData
|
import app.revanced.patcher.data.impl.BytecodeData
|
||||||
import app.revanced.patcher.extensions.addInstructions
|
import app.revanced.patcher.extensions.addInstructions
|
||||||
import app.revanced.patcher.extensions.or
|
import app.revanced.patcher.extensions.or
|
||||||
|
import app.revanced.patcher.extensions.replaceInstruction
|
||||||
|
import app.revanced.patcher.patch.OptionsContainer
|
||||||
|
import app.revanced.patcher.patch.PatchOption
|
||||||
import app.revanced.patcher.patch.PatchResult
|
import app.revanced.patcher.patch.PatchResult
|
||||||
import app.revanced.patcher.patch.PatchResultSuccess
|
import app.revanced.patcher.patch.PatchResultSuccess
|
||||||
|
import app.revanced.patcher.patch.annotations.DependsOn
|
||||||
import app.revanced.patcher.patch.annotations.Patch
|
import app.revanced.patcher.patch.annotations.Patch
|
||||||
import app.revanced.patcher.patch.impl.BytecodePatch
|
import app.revanced.patcher.patch.impl.BytecodePatch
|
||||||
import app.revanced.patcher.usage.bytecode.fingerprints.ExampleFingerprint
|
|
||||||
import app.revanced.patcher.usage.resource.annotation.ExampleResourceCompatibility
|
import app.revanced.patcher.usage.resource.annotation.ExampleResourceCompatibility
|
||||||
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 app.revanced.patcher.util.smali.toInstruction
|
|
||||||
import com.google.common.collect.ImmutableList
|
import com.google.common.collect.ImmutableList
|
||||||
import org.jf.dexlib2.AccessFlags
|
import org.jf.dexlib2.AccessFlags
|
||||||
import org.jf.dexlib2.Format
|
import org.jf.dexlib2.Format
|
||||||
@@ -30,12 +32,15 @@ import org.jf.dexlib2.immutable.reference.ImmutableFieldReference
|
|||||||
import org.jf.dexlib2.immutable.reference.ImmutableStringReference
|
import org.jf.dexlib2.immutable.reference.ImmutableStringReference
|
||||||
import org.jf.dexlib2.immutable.value.ImmutableFieldEncodedValue
|
import org.jf.dexlib2.immutable.value.ImmutableFieldEncodedValue
|
||||||
import org.jf.dexlib2.util.Preconditions
|
import org.jf.dexlib2.util.Preconditions
|
||||||
|
import java.io.File
|
||||||
|
import java.nio.file.Path
|
||||||
|
|
||||||
@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")
|
@Version("0.0.1")
|
||||||
|
@DependsOn([ExampleBytecodePatch::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
|
||||||
@@ -43,6 +48,10 @@ class ExampleBytecodePatch : BytecodePatch(listOf(ExampleFingerprint)) {
|
|||||||
// 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!!
|
||||||
|
|
||||||
|
// Patch options
|
||||||
|
println(key1)
|
||||||
|
key2 = false
|
||||||
|
|
||||||
// Get the implementation for the resolved method
|
// Get the implementation for the resolved method
|
||||||
val method = result.mutableMethod
|
val method = result.mutableMethod
|
||||||
val implementation = method.implementation!!
|
val implementation = method.implementation!!
|
||||||
@@ -107,22 +116,21 @@ class ExampleBytecodePatch : BytecodePatch(listOf(ExampleFingerprint)) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// store the fields initial value into the first virtual register
|
// store the fields initial value into the first virtual register
|
||||||
implementation.replaceInstruction(
|
method.replaceInstruction(0, "sget-object v0, LTestClass;->dummyField:Ljava/io/PrintStream;")
|
||||||
0,
|
|
||||||
"sget-object v0, LTestClass;->dummyField:Ljava/io/PrintStream;".toInstruction()
|
|
||||||
)
|
|
||||||
|
|
||||||
// Now let's create a new call to our method and print the return value!
|
// Now let's create a new call to our method and print the return value!
|
||||||
// You can also use the smali compiler to create instructions.
|
// You can also use the smali compiler to create instructions.
|
||||||
// For this sake of example I reuse the TestClass field dummyField inside the virtual register 0.
|
// For this sake of example I reuse the TestClass field dummyField inside the virtual register 0.
|
||||||
//
|
//
|
||||||
// Control flow instructions are not supported as of now.
|
// Control flow instructions are not supported as of now.
|
||||||
val instructions = """
|
method.addInstructions(
|
||||||
invoke-static { }, LTestClass;->returnHello()Ljava/lang/String;
|
startIndex + 2,
|
||||||
move-result-object v1
|
"""
|
||||||
invoke-virtual { v0, v1 }, Ljava/io/PrintStream;->println(Ljava/lang/String;)V
|
invoke-static { }, LTestClass;->returnHello()Ljava/lang/String;
|
||||||
"""
|
move-result-object v1
|
||||||
method.addInstructions(startIndex + 2, instructions)
|
invoke-virtual { v0, v1 }, Ljava/io/PrintStream;->println(Ljava/lang/String;)V
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
// Finally, tell the patcher that this patch was a success.
|
// Finally, tell the patcher that this patch was a success.
|
||||||
// You can also return PatchResultError with a message.
|
// You can also return PatchResultError with a message.
|
||||||
@@ -161,4 +169,32 @@ class ExampleBytecodePatch : BytecodePatch(listOf(ExampleFingerprint)) {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object : OptionsContainer() {
|
||||||
|
private var key1: String by option(
|
||||||
|
PatchOption.StringOption(
|
||||||
|
"key1", "default", "title", "description", true
|
||||||
|
)
|
||||||
|
)
|
||||||
|
private var key2: Boolean by option(
|
||||||
|
PatchOption.BooleanOption(
|
||||||
|
"key2", true, "title", "description" // required defaults to false
|
||||||
|
)
|
||||||
|
)
|
||||||
|
private var key3: String by option(
|
||||||
|
PatchOption.StringListOption(
|
||||||
|
"key3", "TEST", listOf("TEST", "TEST1", "TEST2"), "title", "description"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
private var key4: Int by option(
|
||||||
|
PatchOption.IntListOption(
|
||||||
|
"key4", 1, listOf(1, 2, 3), "title", "description"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
private var key5: Path by option(
|
||||||
|
PatchOption.PathOption(
|
||||||
|
"key5", File("test.txt").toPath(), "title", "description"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
@@ -1,4 +1,4 @@
|
|||||||
package app.revanced.patcher.usage.bytecode.fingerprints
|
package app.revanced.patcher.usage.bytecode
|
||||||
|
|
||||||
import app.revanced.patcher.annotation.Name
|
import app.revanced.patcher.annotation.Name
|
||||||
import app.revanced.patcher.annotation.Version
|
import app.revanced.patcher.annotation.Version
|
||||||
@@ -6,7 +6,7 @@ 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.annotation.MatchingMethod
|
import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||||
import app.revanced.patcher.usage.bytecode.annotation.ExampleBytecodeCompatibility
|
import app.revanced.patcher.usage.bytecode.ExampleBytecodeCompatibility
|
||||||
import org.jf.dexlib2.AccessFlags
|
import org.jf.dexlib2.AccessFlags
|
||||||
import org.jf.dexlib2.Opcode
|
import org.jf.dexlib2.Opcode
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user