diff --git a/.github/workflows/checkBuild.yml b/.github/workflows/checkBuild.yml index aec2a6c..a3753b0 100644 --- a/.github/workflows/checkBuild.yml +++ b/.github/workflows/checkBuild.yml @@ -16,16 +16,16 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Setup - Java - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: - java-version: 11.0.x - distribution: 'adopt' + java-version: 21 + distribution: 'temurin' - name: Setup - Restore Cache - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} @@ -39,7 +39,7 @@ jobs: run: mvn -B clean verify - name: Upload snupkg - Upload asset - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: javgent-standalone path: ./target/javgent-standalone.jar diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index 3394c4a..11269fd 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -3,7 +3,7 @@ name: GH-Pages CI on: workflow_dispatch: push: - branches: master + branches: [ master ] jobs: publish-pages: @@ -11,16 +11,16 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Setup - Java - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: - java-version: 11.0.x - distribution: 'adopt' + java-version: 21 + distribution: 'temurin' - name: Restore - Maven Cache - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} @@ -31,7 +31,7 @@ jobs: run: mvn -B project-info-reports:dependencies - name: Upload licenses - Upload Artifact - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: dependencies-licenses path: target/site @@ -55,7 +55,7 @@ jobs: echo "theme: jekyll-theme-midnight" > _config.yml - name: Deploy to Github pages - uses: peaceiris/actions-gh-pages@v3 + uses: peaceiris/actions-gh-pages@v4 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./docs diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c48a6a3..36f7242 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,16 +11,16 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Setup - Java - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: - java-version: 11.0.x - distribution: 'adopt' + java-version: 21 + distribution: 'temurin' - name: Setup - Restore Cache - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} @@ -35,7 +35,7 @@ jobs: - name: Release - Create Draft for Release id: create_draft - uses: release-drafter/release-drafter@v5 + uses: release-drafter/release-drafter@v6 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml deleted file mode 100644 index 718887a..0000000 --- a/.github/workflows/sonar.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: Sonar CI - -on: - workflow_dispatch: - push: - branches: [ master, develop ] - paths-ignore: - - '**.md' - pull_request: - types: [opened, synchronize, reopened] - -jobs: - sonar: - name: SonarCloud Scan - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Setup - Java - uses: actions/setup-java@v2 - with: - java-version: 11.0.x - distribution: 'adopt' - - - name: Setup - Fetch complete history for all tags and branches - run: git fetch --prune --unshallow - - - name: Restore - Maven Cache - uses: actions/cache@v2 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven-: - - - name: Analyze - SonarCloud Scan - run: mvn -B clean verify -Psonar -Dsonar.login=${{ secrets.SONAR_TOKEN }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/LICENSE b/LICENSE index 81f990d..63f4724 100644 --- a/LICENSE +++ b/LICENSE @@ -1,21 +1,201 @@ -MIT License - -Copyright (c) 2020 - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2024 litetex + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md index 75c1b05..3e271a1 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,18 @@ -# javgent [![Build](https://img.shields.io/github/workflow/status/BaseMC/javgent/Release)](https://github.com/BaseMC/javgent/actions?query=workflow%3A%22Release%22) [![Latest Version](https://img.shields.io/github/v/release/BaseMC/javgent)](https://github.com/BaseMC/javgent/releases) -Deobfuscates jars (.class-files) with mappings +[![Latest Version](https://img.shields.io/github/v/release/BaseMC/javgent)](https://github.com/BaseMC/javgent/releases) +# javgent +Best effort deobfuscating jars (.class-files) with mappings Mainly written as utility for [Aves](https://github.com/BaseMC/Aves) → Java-Aves-Agent -Uses [ASM](https://asm.ow2.io/) to make obfuscated java files readable (at least it tries it's best :innocent:). +Uses [ASM](https://asm.ow2.io/) to make obfuscated java files readable ### [Download](https://github.com/BaseMC/javgent/releases) #### Requirements -* Java 11+
Download it via [AdoptOpenJDK](https://adoptopenjdk.net/?variant=openjdk11&jvmVariant=hotspot) (just follow the instructions) +* Java 21+
Download it via [Adoptium](https://adoptium.net/) (just follow the instructions) ### [Usage](docs/Usage.md) -### [Developing](docs/Developing.md) [![Build Develop](https://img.shields.io/github/workflow/status/BaseMC/javgent/Check%20Build/develop?label=build%20develop)](https://github.com/BaseMC/javgent/actions?query=workflow%3A%22Check+Build%22+branch%3Adevelop) +### [Developing](docs/Developing.md) ### [Building](docs/Building.md) diff --git a/docs/Building.md b/docs/Building.md index d022d78..e4c2d2c 100644 --- a/docs/Building.md +++ b/docs/Building.md @@ -3,7 +3,7 @@ If you don't want to use the [official releases](https://github.com/BaseMC/javge ### Requirements Recommend: use an IDE (e.g. IDEA or Eclipse) that already contains the following requirements -* Java 11 JDK (see [Requirements](https://github.com/BaseMC/javgent#requirements)) +* Java 21 JDK (see [Requirements](https://github.com/BaseMC/javgent#requirements)) * latest Maven (3+) * [download](https://maven.apache.org/download.cgi) * [install it](https://maven.apache.org/install.html) diff --git a/pom.xml b/pom.xml index 47a3d0a..517d9ab 100644 --- a/pom.xml +++ b/pom.xml @@ -1,220 +1,184 @@ - 4.0.0 - - javgent - javgent - 1.0-SNAPSHOT - - javgent - https://github.com/BaseMC/javgent - - - - MIT License - https://github.com/BaseMC/javgent/blob/develop/LICENSE - repo - - - - - - BaseMC - https://github.com/BaseMC - - - - UTF-8 - - 1.7.31 - 2.14.1 - - 9.2 - - 5.7.2 - - javgent.App - - - - - - - org.slf4j - slf4j-api - ${slf4j.version} - - - org.apache.logging.log4j - log4j-core - ${log4j.version} - - - org.apache.logging.log4j - log4j-api - ${log4j.version} - - - org.apache.logging.log4j - log4j-slf4j-impl - ${log4j.version} - - - - - - org.ow2.asm - asm - ${asm.version} - - - org.ow2.asm - asm-util - ${asm.version} - - - - - org.apache.commons - commons-lang3 - 3.12.0 - - - commons-io - commons-io - 2.10.0 - - - commons-cli - commons-cli - 1.4 - - - - - com.fasterxml.jackson.core - jackson-databind - 2.12.4 - - - - - org.junit.jupiter - junit-jupiter-api - ${junit.version} - test - - - org.junit.jupiter - junit-jupiter-engine - ${junit.version} - test - - - - - javgent - - - - - maven-clean-plugin - 3.1.0 - - - - maven-resources-plugin - 3.2.0 - - - maven-compiler-plugin - 3.8.1 - - - maven-surefire-plugin - 2.22.2 - - - maven-jar-plugin - 3.2.0 - - - maven-install-plugin - 2.5.2 - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - 11 - 11 - - - - org.apache.maven.plugins - maven-assembly-plugin - 3.3.0 - - - package - - single - - - - - javgent-standalone - false - - - ${main.class} - - - true - - - - jar-with-dependencies - - - - - - - - sonar - - BaseMC_javgent - basemc - https://sonarcloud.io - - - false - - - - - org.sonarsource.scanner.maven - sonar-maven-plugin - - 3.9.0.2155 - - - verify - - sonar - - - - - - - - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + + javgent + javgent + 1.0-SNAPSHOT + + javgent + https://github.com/BaseMC/javgent + + + + Apache License, Version 2.0 + https://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + BaseMC + https://github.com/BaseMC + + + + UTF-8 + + 2.0.16 + 2.23.1 + + 9.7 + + 5.11.0 + + javgent.App + + + + + + + org.slf4j + slf4j-api + ${slf4j.version} + + + org.apache.logging.log4j + log4j-core + ${log4j.version} + + + org.apache.logging.log4j + log4j-slf4j2-impl + ${log4j.version} + + + + + + org.ow2.asm + asm + ${asm.version} + + + org.ow2.asm + asm-util + ${asm.version} + + + + + org.apache.commons + commons-lang3 + 3.17.0 + + + commons-io + commons-io + 2.16.1 + + + commons-cli + commons-cli + 1.9.0 + + + + + com.fasterxml.jackson.core + jackson-databind + 2.17.2 + + + + + org.junit.jupiter + junit-jupiter-api + ${junit.version} + test + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + test + + + + + javgent + + + org.apache.maven.plugins + maven-compiler-plugin + 3.13.0 + + -proc:none + 21 + 21 + + + + org.apache.maven.plugins + maven-assembly-plugin + 3.7.1 + + + package + + single + + + + + javgent-standalone + false + + + ${main.class} + + + true + + + + jar-with-dependencies + + + + + + + + sonar + + BaseMC_javgent + basemc + https://sonarcloud.io + + + false + + + + + org.sonarsource.scanner.maven + sonar-maven-plugin + 4.0.0.4121 + + + verify + + sonar + + + + + + + + diff --git a/src/main/java/javgent/App.java b/src/main/java/javgent/App.java index 8156577..d8c143a 100644 --- a/src/main/java/javgent/App.java +++ b/src/main/java/javgent/App.java @@ -21,8 +21,6 @@ public static void main(String[] args) { System.exit(-1); }); - LOG.info("project and license information: https://github.com/BaseMC/javgent"); - try { Optional optionalExecutorConfig = Parser.parse(args); if (optionalExecutorConfig.isEmpty()) diff --git a/src/main/java/javgent/executor/bytecode/abstractdefault/AbstractClassBasedSignatureWriter.java b/src/main/java/javgent/executor/bytecode/abstractdefault/AbstractClassBasedSignatureWriter.java index 189e8a1..dd3e706 100644 --- a/src/main/java/javgent/executor/bytecode/abstractdefault/AbstractClassBasedSignatureWriter.java +++ b/src/main/java/javgent/executor/bytecode/abstractdefault/AbstractClassBasedSignatureWriter.java @@ -3,11 +3,11 @@ import javgent.executor.bytecode.clazz.CurrentClassController; import org.objectweb.asm.signature.SignatureWriter; -public class AbstractClassBasedSignatureWriter extends SignatureWriter { +public abstract class AbstractClassBasedSignatureWriter extends SignatureWriter { protected CurrentClassController controller; - public AbstractClassBasedSignatureWriter(CurrentClassController controller) { + protected AbstractClassBasedSignatureWriter(CurrentClassController controller) { this.controller = controller; } diff --git a/src/main/java/javgent/executor/bytecode/abstractdefault/AbstractDefaultSignatureWriter.java b/src/main/java/javgent/executor/bytecode/abstractdefault/AbstractDefaultSignatureWriter.java new file mode 100644 index 0000000..0285a58 --- /dev/null +++ b/src/main/java/javgent/executor/bytecode/abstractdefault/AbstractDefaultSignatureWriter.java @@ -0,0 +1,25 @@ +package javgent.executor.bytecode.abstractdefault; + +import javgent.executor.bytecode.clazz.CurrentClassController; +import javgent.executor.bytecode.clazz.util.InnerClassTypeResolver; + +public abstract class AbstractDefaultSignatureWriter extends AbstractClassBasedSignatureWriter { + + protected AbstractDefaultSignatureWriter(CurrentClassController controller) { + super(controller); + } + + @Override + public void visitInnerClassType(String name) { + var newName = InnerClassTypeResolver.resolve(controller, name); + + super.visitInnerClassType(newName); + } + + @Override + public void visitTypeVariable(String name) { + var newName = controller.findNameByObfNameOrReturn(name); + + super.visitTypeVariable(newName); + } +} diff --git a/src/main/java/javgent/executor/bytecode/abstractdefault/AbstractDescriptorWriter.java b/src/main/java/javgent/executor/bytecode/abstractdefault/AbstractDescriptorWriter.java new file mode 100644 index 0000000..0ecc7e1 --- /dev/null +++ b/src/main/java/javgent/executor/bytecode/abstractdefault/AbstractDescriptorWriter.java @@ -0,0 +1,41 @@ +package javgent.executor.bytecode.abstractdefault; + +import javgent.executor.bytecode.clazz.CurrentClassController; +import org.objectweb.asm.signature.SignatureWriter; +import org.slf4j.Logger; + +public abstract class AbstractDescriptorWriter extends SignatureWriter { + + protected CurrentClassController controller; + protected Logger log; + + protected AbstractDescriptorWriter(CurrentClassController controller, Logger log) { + this.controller = controller; + this.log = log; + } + + @Override + public void visitClassType(String name) { + var newName = controller.findNameByObfNameOrReturn(name); + + super.visitClassType(newName); + } + + @Override + public void visitFormalTypeParameter(String name) { + log.warn("Visiting not implemented method 'visitFormalTypeParameter'! name='{}'", name); + super.visitFormalTypeParameter(name); + } + + @Override + public void visitInnerClassType(String name) { + log.warn("Visiting not implemented method 'visitInnerClassType'! name='{}'", name); + super.visitInnerClassType(name); + } + + @Override + public void visitTypeVariable(String name) { + log.warn("Visiting not implemented method 'visitTypeVariable'! name='{}'", name); + super.visitTypeVariable(name); + } +} diff --git a/src/main/java/javgent/executor/bytecode/clazz/BCClassVisitor.java b/src/main/java/javgent/executor/bytecode/clazz/BCClassVisitor.java index f9e770c..8740951 100644 --- a/src/main/java/javgent/executor/bytecode/clazz/BCClassVisitor.java +++ b/src/main/java/javgent/executor/bytecode/clazz/BCClassVisitor.java @@ -8,6 +8,8 @@ import javgent.executor.bytecode.clazz.sub.method.ModifierForMethod; import javgent.executor.bytecode.clazz.sub.method.visitor.MethodSignatureWriter; import javgent.executor.bytecode.clazz.util.RemoteMethodResolver; +import javgent.executor.bytecode.clazz.visitor.RecordDescriptorWriter; +import javgent.executor.bytecode.clazz.visitor.RecordSignatureWriter; import javgent.executor.bytecode.clazz.writers.ClassDescriptorWriter; import org.objectweb.asm.AnnotationVisitor; import org.objectweb.asm.Attribute; @@ -129,7 +131,7 @@ public void visitOuterClass(String owner, String name, String descriptor) { //name of a method (likely) var optNewController = controller.getRegistry().getByObfName(owner); - if (!optNewController.isPresent()) { + if (optNewController.isEmpty()) { Log.debug("Unable to get controller for owner='{}'", owner); super.visitOuterClass(owner, name, descriptor); return; @@ -142,7 +144,7 @@ public void visitOuterClass(String owner, String name, String descriptor) { name, descriptor); - if (!optResult.isPresent()) { + if (optResult.isEmpty()) { Log.debug("Unable to get result for owner='{}', name='{}'", owner, name); super.visitOuterClass(owner, name, descriptor); return; @@ -223,7 +225,15 @@ public void visitAttribute(Attribute attribute) { @Override public RecordComponentVisitor visitRecordComponent(String name, String descriptor, String signature) { - Log.warn("Visiting not implemented 'visitRecordComponent'! name='{},descriptor='{}'", name, descriptor); + if (!controllerPresent()) { + return super.visitRecordComponent(name, descriptor, signature); + } + + name = controller.getFieldsController().findNameByObfNameOrReturn(name); + descriptor = RecordDescriptorWriter.convert(controller, descriptor); + if (signature != null) + signature = RecordSignatureWriter.convert(controller, signature); + return super.visitRecordComponent(name, descriptor, signature); } } diff --git a/src/main/java/javgent/executor/bytecode/clazz/CurrentClassController.java b/src/main/java/javgent/executor/bytecode/clazz/CurrentClassController.java index a6365a1..b98e0fd 100644 --- a/src/main/java/javgent/executor/bytecode/clazz/CurrentClassController.java +++ b/src/main/java/javgent/executor/bytecode/clazz/CurrentClassController.java @@ -26,7 +26,7 @@ public PatchClass getCurrentPatchClass() { public String findNameByObfNameOrReturn(String obfName) { var opt = findPatchClassByObfName(obfName); - if (!opt.isPresent()) + if (opt.isEmpty()) return obfName; return opt.get().Name; } diff --git a/src/main/java/javgent/executor/bytecode/clazz/sub/method/BCMethodVisitor.java b/src/main/java/javgent/executor/bytecode/clazz/sub/method/BCMethodVisitor.java index f0a58c7..833c537 100644 --- a/src/main/java/javgent/executor/bytecode/clazz/sub/method/BCMethodVisitor.java +++ b/src/main/java/javgent/executor/bytecode/clazz/sub/method/BCMethodVisitor.java @@ -59,7 +59,8 @@ public void visitFieldInsn(int opcode, String owner, String name, String descrip if (optName.isPresent()) name = optName.get(); else - Log.info("Failed to find name: {}, {}, {} ", owner, name, descriptor); + Log.debug("Failed to find name: {} aka {}, {}, {} - Assuming that name needs no translation", + owner, methodFieldResolverResult.Owner, name, descriptor); owner = methodFieldResolverResult.Owner; } else @@ -208,6 +209,12 @@ public void visitAttribute(Attribute attribute) { @Override public void visitParameter(String name, int access) { + if(name == null) + { + super.visitParameter(null, access); + return; + } + Log.warn("Visiting not implemented 'visitParameter'! name='{}'", name); super.visitParameter(name, access); } diff --git a/src/main/java/javgent/executor/bytecode/clazz/sub/method/visitor/MethodDescriptorWriter.java b/src/main/java/javgent/executor/bytecode/clazz/sub/method/visitor/MethodDescriptorWriter.java index fcbe167..a91a998 100644 --- a/src/main/java/javgent/executor/bytecode/clazz/sub/method/visitor/MethodDescriptorWriter.java +++ b/src/main/java/javgent/executor/bytecode/clazz/sub/method/visitor/MethodDescriptorWriter.java @@ -1,44 +1,18 @@ package javgent.executor.bytecode.clazz.sub.method.visitor; +import javgent.executor.bytecode.abstractdefault.AbstractDescriptorWriter; import javgent.executor.bytecode.clazz.CurrentClassController; import org.objectweb.asm.signature.SignatureReader; import org.objectweb.asm.signature.SignatureWriter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class MethodDescriptorWriter extends SignatureWriter { +public class MethodDescriptorWriter extends AbstractDescriptorWriter { private static final Logger Log = LoggerFactory.getLogger(MethodDescriptorWriter.class); - private CurrentClassController controller; - public MethodDescriptorWriter(CurrentClassController controller) { - this.controller = controller; - } - - @Override - public void visitClassType(String name) { - var newName = controller.findNameByObfNameOrReturn(name); - - super.visitClassType(newName); - } - - @Override - public void visitFormalTypeParameter(String name) { - Log.warn("Visiting not implemented method 'visitFormalTypeParameter'! name='{}'", name); - super.visitFormalTypeParameter(name); - } - - @Override - public void visitInnerClassType(String name) { - Log.warn("Visiting not implemented method 'visitInnerClassType'! name='{}'", name); - super.visitInnerClassType(name); - } - - @Override - public void visitTypeVariable(String name) { - Log.warn("Visiting not implemented method 'visitTypeVariable'! name='{}'", name); - super.visitTypeVariable(name); + super(controller, Log); } public static String convert(CurrentClassController controller, String descriptor) { diff --git a/src/main/java/javgent/executor/bytecode/clazz/sub/method/visitor/MethodSignatureWriter.java b/src/main/java/javgent/executor/bytecode/clazz/sub/method/visitor/MethodSignatureWriter.java index d94f0c3..dad05a7 100644 --- a/src/main/java/javgent/executor/bytecode/clazz/sub/method/visitor/MethodSignatureWriter.java +++ b/src/main/java/javgent/executor/bytecode/clazz/sub/method/visitor/MethodSignatureWriter.java @@ -1,46 +1,13 @@ package javgent.executor.bytecode.clazz.sub.method.visitor; +import javgent.executor.bytecode.abstractdefault.AbstractDefaultSignatureWriter; import javgent.executor.bytecode.clazz.CurrentClassController; -import javgent.executor.bytecode.clazz.util.InnerClassTypeResolver; import org.objectweb.asm.signature.SignatureReader; -import org.objectweb.asm.signature.SignatureWriter; -public class MethodSignatureWriter extends SignatureWriter { - - private CurrentClassController controller; +public class MethodSignatureWriter extends AbstractDefaultSignatureWriter { public MethodSignatureWriter(CurrentClassController controller) { - this.controller = controller; - } - - @Override - public void visitClassType(String name) { - - String newName = controller.findNameByObfNameOrReturn(name); - - super.visitClassType(newName); - } - - @Override - public void visitFormalTypeParameter(String name) { - - String newName = controller.findNameByObfNameOrReturn(name); - - super.visitFormalTypeParameter(newName); - } - - @Override - public void visitInnerClassType(String name) { - var newName = InnerClassTypeResolver.resolve(controller, name); - - super.visitInnerClassType(newName); - } - - @Override - public void visitTypeVariable(String name) { - String newName = controller.findNameByObfNameOrReturn(name); - - super.visitTypeVariable(newName); + super(controller); } public static String convert(CurrentClassController currentClassController, String signature) { diff --git a/src/main/java/javgent/executor/bytecode/clazz/util/RemoteMethodResolver.java b/src/main/java/javgent/executor/bytecode/clazz/util/RemoteMethodResolver.java index 6b54d57..07c29ce 100644 --- a/src/main/java/javgent/executor/bytecode/clazz/util/RemoteMethodResolver.java +++ b/src/main/java/javgent/executor/bytecode/clazz/util/RemoteMethodResolver.java @@ -26,7 +26,7 @@ public static Optional resolve(CurrentClassControlle result.Owner = currentClassController.findNameByObfNameOrReturn(owner); if(obfName == null && desc == null) - return Optional.ofNullable(result); + return Optional.of(result); var selector = MethodSelectorVistiorDetector.findSelector(remoteController, desc, null); @@ -37,7 +37,7 @@ public static Optional resolve(CurrentClassControlle result.Name = Optional.ofNullable(remotePatchMethod.Name); } - return Optional.ofNullable(result); + return Optional.of(result); } @SuppressWarnings({"squid:ClassVariableVisibilityCheck", "squid:S00116"}) diff --git a/src/main/java/javgent/executor/bytecode/clazz/visitor/RecordDescriptorWriter.java b/src/main/java/javgent/executor/bytecode/clazz/visitor/RecordDescriptorWriter.java new file mode 100644 index 0000000..f65a5f6 --- /dev/null +++ b/src/main/java/javgent/executor/bytecode/clazz/visitor/RecordDescriptorWriter.java @@ -0,0 +1,25 @@ +package javgent.executor.bytecode.clazz.visitor; + +import javgent.executor.bytecode.abstractdefault.AbstractDescriptorWriter; +import javgent.executor.bytecode.clazz.CurrentClassController; +import org.objectweb.asm.signature.SignatureReader; +import org.objectweb.asm.signature.SignatureWriter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class RecordDescriptorWriter extends AbstractDescriptorWriter { + + private static final Logger Log = LoggerFactory.getLogger(RecordDescriptorWriter.class); + + public RecordDescriptorWriter(CurrentClassController controller) { + super(controller, Log); + } + + public static String convert(CurrentClassController controller, String descriptor) { + var writer = new RecordDescriptorWriter(controller); + + new SignatureReader(descriptor).accept(writer); + + return writer.toString(); + } +} diff --git a/src/main/java/javgent/executor/bytecode/clazz/visitor/RecordSignatureWriter.java b/src/main/java/javgent/executor/bytecode/clazz/visitor/RecordSignatureWriter.java new file mode 100644 index 0000000..ebbacc3 --- /dev/null +++ b/src/main/java/javgent/executor/bytecode/clazz/visitor/RecordSignatureWriter.java @@ -0,0 +1,23 @@ +package javgent.executor.bytecode.clazz.visitor; + +import javgent.executor.bytecode.abstractdefault.AbstractDefaultSignatureWriter; +import javgent.executor.bytecode.clazz.CurrentClassController; +import org.objectweb.asm.signature.SignatureReader; + +public class RecordSignatureWriter extends AbstractDefaultSignatureWriter { + + public RecordSignatureWriter(CurrentClassController controller) { + super(controller); + } + + public static String convert(CurrentClassController currentClassController, String signature) { + if(signature == null) + return null; + + var writer = new RecordSignatureWriter(currentClassController); + + new SignatureReader(signature).accept(writer); + + return writer.toString(); + } +}