├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src ├── main ├── java │ └── cn │ │ └── enaium │ │ └── joe │ │ ├── Agent.java │ │ ├── JavaOctetEditor.java │ │ ├── Main.java │ │ ├── annotation │ │ ├── Indeterminate.java │ │ ├── NoUI.java │ │ └── Repeatable.java │ │ ├── config │ │ ├── Config.java │ │ ├── ConfigManager.java │ │ ├── extend │ │ │ ├── ApplicationConfig.java │ │ │ ├── CFRConfig.java │ │ │ ├── FernFlowerConfig.java │ │ │ └── ProcyonConfig.java │ │ └── value │ │ │ ├── EnableValue.java │ │ │ ├── IntegerValue.java │ │ │ ├── ModeValue.java │ │ │ ├── StringSetValue.java │ │ │ ├── StringValue.java │ │ │ └── Value.java │ │ ├── dialog │ │ ├── AboutDialog.java │ │ ├── AnnotationListDialog.java │ │ ├── AnnotationValueDialog.java │ │ ├── CallTreeDialog.java │ │ ├── ConfigDialog.java │ │ ├── ContactDialog.java │ │ ├── Dialog.java │ │ ├── FieldDialog.java │ │ ├── MethodDialog.java │ │ ├── ProcessListDialog.java │ │ ├── SearchDialog.java │ │ └── search │ │ │ ├── SearchFieldDialog.java │ │ │ ├── SearchLdcDialog.java │ │ │ └── SearchMethodDialog.java │ │ ├── event │ │ ├── Event.java │ │ ├── EventManager.java │ │ └── events │ │ │ └── FileTabbedSelectEvent.java │ │ ├── gui │ │ ├── component │ │ │ ├── FileTree.java │ │ │ ├── InstructionComboBox.java │ │ │ ├── LabelNodeComboBox.java │ │ │ ├── ResultList.java │ │ │ ├── RightTabBar.java │ │ │ └── TabPane.java │ │ ├── layout │ │ │ ├── AbstractLayout.java │ │ │ └── HalfLayout.java │ │ ├── panel │ │ │ ├── BorderPanel.java │ │ │ ├── BottomPanel.java │ │ │ ├── CodeAreaPanel.java │ │ │ ├── FieldInfoPanel.java │ │ │ ├── InheritPanel.java │ │ │ ├── LeftPanel.java │ │ │ ├── MemberListPanel.java │ │ │ ├── confirm │ │ │ │ ├── BootstrapMethodArgumentEditPanel.java │ │ │ │ ├── ConfirmPanel.java │ │ │ │ ├── FrameListEditPanel.java │ │ │ │ ├── HandleEditPanel.java │ │ │ │ ├── InstructionEditPanel.java │ │ │ │ ├── LabelListEditPanel.java │ │ │ │ ├── ListValueEditPanel.java │ │ │ │ ├── LookupSwitchEditPanel.java │ │ │ │ └── ValueEditPanel.java │ │ │ ├── file │ │ │ │ ├── FileDropTarget.java │ │ │ │ ├── tabbed │ │ │ │ │ ├── FileTabbedPanel.java │ │ │ │ │ └── tab │ │ │ │ │ │ ├── classes │ │ │ │ │ │ ├── ASMifierTablePanel.java │ │ │ │ │ │ ├── ClassInfoTabPanel.java │ │ │ │ │ │ ├── ClassNodeTabPanel.java │ │ │ │ │ │ ├── ClassTabPanel.java │ │ │ │ │ │ ├── DecompileTabPanel.java │ │ │ │ │ │ └── TraceBytecodeTabPanel.java │ │ │ │ │ │ └── resources │ │ │ │ │ │ ├── FileTablePane.java │ │ │ │ │ │ ├── HexTablePanel.java │ │ │ │ │ │ ├── ImageTablePanel.java │ │ │ │ │ │ └── TextTablePanel.java │ │ │ │ └── tree │ │ │ │ │ ├── CenterPanel.java │ │ │ │ │ ├── FileTreeCellRenderer.java │ │ │ │ │ └── node │ │ │ │ │ ├── ClassTreeNode.java │ │ │ │ │ ├── DefaultTreeNode.java │ │ │ │ │ ├── FileTreeNode.java │ │ │ │ │ ├── FolderTreeNode.java │ │ │ │ │ ├── MethodTreeNode.java │ │ │ │ │ └── PackageTreeNode.java │ │ │ ├── instruction │ │ │ │ ├── AbstractInstructionPanel.java │ │ │ │ ├── FieldInstructionPanel.java │ │ │ │ ├── FrameInstructionPanel.java │ │ │ │ ├── IncrInstructionPanel.java │ │ │ │ ├── InstructionPanel.java │ │ │ │ ├── IntInstructionPanel.java │ │ │ │ ├── InvokeDynamicInstructionPanel.java │ │ │ │ ├── JumpInstructionPanel.java │ │ │ │ ├── LdcInstructionPanel.java │ │ │ │ ├── LineInstructionPanel.java │ │ │ │ ├── LookupSwitchInstructionPanel.java │ │ │ │ ├── MethodInstructionPanel.java │ │ │ │ ├── MultiANewArrayInstructionPanel.java │ │ │ │ ├── TableSwitchInstructionPanel.java │ │ │ │ ├── TypeInstructionPanel.java │ │ │ │ └── VarInstructionPanel.java │ │ │ ├── menu │ │ │ │ ├── AttachMenu.java │ │ │ │ ├── ConfigMenu.java │ │ │ │ ├── FileMenu.java │ │ │ │ ├── HelpMenu.java │ │ │ │ ├── MappingMenu.java │ │ │ │ ├── SearchMenu.java │ │ │ │ ├── attach │ │ │ │ │ └── ProcessMenuItem.java │ │ │ │ ├── file │ │ │ │ │ ├── LoadMenuItem.java │ │ │ │ │ ├── LoadRecentMenu.java │ │ │ │ │ ├── SaveAllSourceMenuItem.java │ │ │ │ │ └── SaveMenuItem.java │ │ │ │ ├── help │ │ │ │ │ ├── AboutMenuItem.java │ │ │ │ │ └── ContactMenuItem.java │ │ │ │ └── search │ │ │ │ │ ├── FieldMenuItem.java │ │ │ │ │ ├── LdcMenuItem.java │ │ │ │ │ └── MethodMenuItem.java │ │ │ ├── method │ │ │ │ ├── MethodInfoTabPanel.java │ │ │ │ ├── MethodInstructionPanel.java │ │ │ │ └── MethodTabPanel.java │ │ │ ├── popup │ │ │ │ ├── AbstractPopup.java │ │ │ │ └── TaskListPopup.java │ │ │ └── search │ │ │ │ └── ResultNode.java │ │ └── ui │ │ │ └── VerticalLabelUI.java │ │ ├── jar │ │ └── Jar.java │ │ ├── mapping │ │ ├── Mapping.java │ │ └── MappingParser.java │ │ ├── service │ │ ├── DecompileService.java │ │ └── decompiler │ │ │ ├── CFRDecompiler.java │ │ │ ├── FernFlowerDecompiler.java │ │ │ ├── IDecompiler.java │ │ │ └── ProcyonDecompiler.java │ │ ├── task │ │ ├── AbstractTask.java │ │ ├── DecompileTask.java │ │ ├── InputJarTask.java │ │ ├── OutputJarTask.java │ │ ├── RemappingTask.java │ │ ├── SaveAllSourceTask.java │ │ ├── SearchFieldTask.java │ │ ├── SearchInstructionTask.java │ │ ├── SearchLdcTask.java │ │ ├── SearchMethodTask.java │ │ └── TaskManager.java │ │ ├── util │ │ ├── ASMUtil.java │ │ ├── ASyncUtil.java │ │ ├── BytecodeTokenMaker.java │ │ ├── ColorUtil.java │ │ ├── HtmlUtil.java │ │ ├── IOUtil.java │ │ ├── JFileChooserUtil.java │ │ ├── JMenuUtil.java │ │ ├── JTreeUtil.java │ │ ├── KeyStrokeUtil.java │ │ ├── LangUtil.java │ │ ├── ListUtil.java │ │ ├── MessageUtil.java │ │ ├── OpcodeUtil.java │ │ ├── Pair.java │ │ ├── ReflectUtil.java │ │ ├── StringUtil.java │ │ ├── TinyLogPrintStream.java │ │ └── Util.java │ │ └── wrapper │ │ ├── InstructionWrapper.java │ │ ├── LabelNodeWrapper.java │ │ ├── ObjectWrapper.java │ │ └── Wrapper.java └── resources │ ├── icons │ ├── abstractClass.svg │ ├── annotation.svg │ ├── biliBili.svg │ ├── class.svg │ ├── classesRoot.svg │ ├── cyan_dot.svg │ ├── enum.svg │ ├── field.svg │ ├── file.svg │ ├── finalClass.svg │ ├── folder.svg │ ├── github.svg │ ├── hierarchy.svg │ ├── inherit.svg │ ├── interface.svg │ ├── jar.svg │ ├── kook.svg │ ├── logo.svg │ ├── method.svg │ ├── minimize.svg │ ├── openjdk.svg │ ├── package.svg │ ├── private.svg │ ├── protected.svg │ ├── public.svg │ ├── resourceRoot.svg │ ├── static.svg │ └── structure.svg │ └── lang │ ├── en_US.json │ └── zh_CN.json └── test └── java └── cn └── enaium └── joe └── asm ├── GenerateDecompilerConfigTest.java ├── GenerateInstructionTypeSwitchTest.java ├── GenerateOpcodeTest.java └── VisitorTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | out 3 | build 4 | .gradle 5 | run -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JavaOctetEditor 2 | 3 | ![GitHub all releases](https://img.shields.io/github/downloads/Enaium/JavaOctetEditor/total?style=flat-square) 4 | ![GitHub release (latest by date)](https://img.shields.io/github/v/release/Enaium/JavaOctetEditor?style=flat-square) 5 | ![GitHub](https://img.shields.io/github/license/Enaium/JavaOctetEditor?style=flat-square) 6 | 7 | ![](https://user-images.githubusercontent.com/32991121/190947407-bbc6642e-2c9d-46f3-921c-6558c74272cf.png) 8 | ![](https://user-images.githubusercontent.com/32991121/190947409-9df48d03-e1b7-4c0a-ae1d-08e1ca2bc9aa.png) 9 | ![](https://user-images.githubusercontent.com/32991121/190947408-df6c6818-ea79-4a42-8b90-101b6daa3099.png) 10 | ![](https://user-images.githubusercontent.com/32991121/190947401-fc08fc4f-3714-49ca-a064-913e7312b191.png) 11 | ![](https://user-images.githubusercontent.com/32991121/190947410-4b8f224a-c589-4998-950a-e19618ce5734.png) 12 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Enaium/JavaOctetEditor/f1e4fc8a94f401d6ca6effe42d58a439e15cfdc5/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'JavaOctetEditor' 2 | 3 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/Agent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe; 18 | 19 | import cn.enaium.joe.jar.Jar; 20 | import cn.enaium.joe.util.ReflectUtil; 21 | import org.objectweb.asm.ClassReader; 22 | import org.objectweb.asm.tree.ClassNode; 23 | 24 | import java.io.IOException; 25 | import java.lang.instrument.Instrumentation; 26 | import java.lang.reflect.InvocationTargetException; 27 | import java.lang.reflect.Method; 28 | import java.net.URL; 29 | import java.net.URLClassLoader; 30 | 31 | /** 32 | * @author Enaium 33 | * @since 1.1.0 34 | */ 35 | public class Agent { 36 | public static void premain(String agentArgs, Instrumentation inst) throws Exception { 37 | agent(agentArgs, inst); 38 | } 39 | 40 | public static void agentmain(String agentArgs, Instrumentation inst) throws Exception { 41 | agent(agentArgs, inst); 42 | } 43 | 44 | private static void agent(String agentArgs, Instrumentation inst) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { 45 | URLClassLoader loader = new URLClassLoader(new URL[]{Agent.class.getProtectionDomain().getCodeSource().getLocation()}, ClassLoader.getSystemClassLoader().getParent()); 46 | Class main = loader.loadClass("cn.enaium.joe.Main"); 47 | Method agent = ReflectUtil.getMethod(main, "agent", Instrumentation.class); 48 | agent.invoke(null, inst); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/annotation/Indeterminate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.annotation; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * @author Enaium 26 | * @since 0.9.0 27 | */ 28 | @Retention(RetentionPolicy.RUNTIME) 29 | @Target(ElementType.TYPE) 30 | public @interface Indeterminate { 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/annotation/NoUI.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.annotation; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * @author Enaium 26 | * @since 0.9.0 27 | */ 28 | @Retention(RetentionPolicy.RUNTIME) 29 | @Target(ElementType.FIELD) 30 | public @interface NoUI { 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/annotation/Repeatable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.annotation; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * @author Enaium 26 | * @since 0.9.0 27 | */ 28 | @Retention(RetentionPolicy.RUNTIME) 29 | @Target(ElementType.TYPE) 30 | public @interface Repeatable { 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/config/Config.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.config; 18 | 19 | /** 20 | * @author Enaium 21 | * @since 0.7.0 22 | */ 23 | public class Config { 24 | private final String name; 25 | 26 | public Config(String name) { 27 | this.name = name; 28 | } 29 | 30 | public String getName() { 31 | return name; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/config/extend/ApplicationConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.config.extend; 18 | 19 | import cn.enaium.joe.annotation.NoUI; 20 | import cn.enaium.joe.config.Config; 21 | import cn.enaium.joe.config.value.EnableValue; 22 | import cn.enaium.joe.config.value.ModeValue; 23 | import cn.enaium.joe.config.value.StringSetValue; 24 | 25 | import java.util.ArrayList; 26 | import java.util.Arrays; 27 | import java.util.HashSet; 28 | 29 | /** 30 | * @author Enaium 31 | * @since 0.7.0 32 | */ 33 | public class ApplicationConfig extends Config { 34 | public ModeValue decompilerMode = new ModeValue("Decompiler", "CFR", "Java Decompiler", Arrays.asList("CFR", "Procyon", "FernFlower")); 35 | public ModeValue language = new ModeValue("Language", "System", "UI language", Arrays.asList("System", "zh_CN", "en_US")); 36 | public ModeValue packagePresentation = new ModeValue("Package Presentation", "Hierarchical", "Package Mode", Arrays.asList("Flat", "Hierarchical")); 37 | public EnableValue compactMiddlePackage = new EnableValue("Compact Middle Package", true, "Only Hierarchical Mode"); 38 | @NoUI 39 | public final StringSetValue loadRecent = new StringSetValue("Load Recent", new HashSet<>(), ""); 40 | 41 | public ApplicationConfig() { 42 | super("Application"); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/config/value/EnableValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.config.value; 18 | 19 | /** 20 | * @author Enaium 21 | * @since 0.7.0 22 | */ 23 | public class EnableValue extends Value { 24 | public EnableValue(String name, Boolean value, String description) { 25 | super(name, value, description); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/config/value/IntegerValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.config.value; 18 | 19 | /** 20 | * @author Enaium 21 | * @since 0.7.0 22 | */ 23 | public class IntegerValue extends Value { 24 | public IntegerValue(String name, Integer value, String description) { 25 | super(name, value, description); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/config/value/ModeValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.config.value; 18 | 19 | import com.google.gson.annotations.Expose; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * @author Enaium 25 | * @since 0.7.0 26 | */ 27 | public class ModeValue extends Value { 28 | 29 | @Expose(deserialize = false) 30 | private List mode; 31 | 32 | public ModeValue(String name, String value, String description, List mode) { 33 | super(name, value, description); 34 | this.mode = mode; 35 | } 36 | 37 | public List getMode() { 38 | return mode; 39 | } 40 | 41 | public void setMode(List mode) { 42 | this.mode = mode; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/config/value/StringSetValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.config.value; 18 | 19 | import java.util.List; 20 | import java.util.Set; 21 | 22 | /** 23 | * @author Enaium 24 | * @since 0.9.0 25 | */ 26 | public class StringSetValue extends Value>{ 27 | public StringSetValue(String name, Set value, String description) { 28 | super(name, value, description); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/config/value/StringValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.config.value; 18 | 19 | /** 20 | * @author Enaium 21 | * @since 0.7.0 22 | */ 23 | public class StringValue extends Value { 24 | public StringValue(String name, String value, String description) { 25 | super(name, value, description); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/config/value/Value.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.config.value; 18 | 19 | /** 20 | * @author Enaium 21 | * @since 0.7.0 22 | */ 23 | public class Value { 24 | private String name; 25 | private T value; 26 | private String description; 27 | 28 | public Value(String name, T value, String description) { 29 | this.name = name; 30 | this.value = value; 31 | this.description = description; 32 | } 33 | 34 | public String getName() { 35 | return name; 36 | } 37 | 38 | public String getDescription() { 39 | return description; 40 | } 41 | 42 | public T getValue() { 43 | return value; 44 | } 45 | 46 | public void setValue(T value) { 47 | this.value = value; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/dialog/AnnotationListDialog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.dialog; 18 | 19 | import cn.enaium.joe.util.JMenuUtil; 20 | import cn.enaium.joe.util.LangUtil; 21 | import cn.enaium.joe.wrapper.ObjectWrapper; 22 | import org.objectweb.asm.tree.AnnotationNode; 23 | 24 | import javax.swing.*; 25 | import javax.swing.table.DefaultTableModel; 26 | import java.awt.*; 27 | import java.util.List; 28 | 29 | /** 30 | * @author Enaium 31 | * @since 1.2.0 32 | */ 33 | public class AnnotationListDialog extends Dialog { 34 | public AnnotationListDialog(List annotationNodes) { 35 | super("Annotation"); 36 | setLayout(new BorderLayout()); 37 | DefaultTableModel dm = new DefaultTableModel(new Object[][]{}, new String[]{"Description", "Has Value"}); 38 | for (AnnotationNode annotationNode : annotationNodes) { 39 | dm.addRow(new Object[]{new ObjectWrapper(annotationNode), annotationNode.values != null}); 40 | } 41 | JTable jTable = new JTable(dm) { 42 | public boolean isCellEditable(int row, int column) { 43 | return false; 44 | } 45 | }; 46 | jTable.getTableHeader().setReorderingAllowed(false); 47 | jTable.getTableHeader().setResizingAllowed(false); 48 | add(new JScrollPane(jTable), BorderLayout.CENTER); 49 | JMenuUtil.addPopupMenu(jTable, () -> new JPopupMenu() {{ 50 | add(new JMenuItem(LangUtil.i18n("button.edit")) {{ 51 | addActionListener(e -> { 52 | new AnnotationValueDialog(((AnnotationNode) ((ObjectWrapper) dm.getValueAt(jTable.getSelectedRow(), 0)).getWrapper()).values).setVisible(true); 53 | }); 54 | }}); 55 | }}, () -> jTable.getSelectedRow() != -1 && Boolean.parseBoolean(dm.getValueAt(jTable.getSelectedRow(), 1).toString())); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/dialog/Dialog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.dialog; 18 | 19 | import com.formdev.flatlaf.extras.FlatSVGIcon; 20 | 21 | import javax.swing.*; 22 | 23 | public class Dialog extends JFrame { 24 | public Dialog(String title) { 25 | super(title); 26 | setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 27 | setSize(800, 500); 28 | setLocationRelativeTo(getOwner()); 29 | setIconImage(new FlatSVGIcon("icons/logo.svg").getImage()); 30 | } 31 | } -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/dialog/FieldDialog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.dialog; 18 | 19 | import cn.enaium.joe.gui.panel.FieldInfoPanel; 20 | import org.objectweb.asm.tree.ClassNode; 21 | import org.objectweb.asm.tree.FieldNode; 22 | 23 | import java.awt.*; 24 | 25 | /** 26 | * @author Enaium 27 | * @since 1.2.0 28 | */ 29 | public class FieldDialog extends Dialog { 30 | public FieldDialog(ClassNode classNode, FieldNode fieldNode) { 31 | super(classNode.name + "#" + fieldNode.name); 32 | setLayout(new BorderLayout()); 33 | add(new FieldInfoPanel(fieldNode), BorderLayout.CENTER); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/dialog/MethodDialog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.dialog; 18 | 19 | import cn.enaium.joe.gui.panel.method.MethodTabPanel; 20 | import org.objectweb.asm.tree.ClassNode; 21 | import org.objectweb.asm.tree.MethodNode; 22 | 23 | import java.awt.*; 24 | 25 | /** 26 | * @author Enaium 27 | * @since 1.2.0 28 | */ 29 | public class MethodDialog extends Dialog { 30 | public MethodDialog(ClassNode classNode, MethodNode methodNode) { 31 | super(classNode.name + "#" + methodNode.name); 32 | setLayout(new BorderLayout()); 33 | add(new MethodTabPanel(methodNode), BorderLayout.CENTER); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/dialog/SearchDialog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.dialog; 18 | 19 | import cn.enaium.joe.JavaOctetEditor; 20 | import cn.enaium.joe.gui.component.ResultList; 21 | import cn.enaium.joe.jar.Jar; 22 | import cn.enaium.joe.util.LangUtil; 23 | import org.objectweb.asm.tree.AbstractInsnNode; 24 | import org.objectweb.asm.tree.ClassNode; 25 | import org.objectweb.asm.tree.MethodNode; 26 | 27 | import javax.swing.*; 28 | import java.awt.*; 29 | import java.util.Map; 30 | import java.util.function.BiConsumer; 31 | 32 | /** 33 | * @author Enaium 34 | */ 35 | public class SearchDialog extends Dialog { 36 | public ResultList resultList = new ResultList(); 37 | 38 | public SearchDialog() { 39 | super(LangUtil.i18n("menu.search")); 40 | setLayout(new BorderLayout()); 41 | setSize(700, 400); 42 | add(new JScrollPane(resultList), BorderLayout.CENTER); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/dialog/search/SearchLdcDialog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.dialog.search; 18 | 19 | import cn.enaium.joe.JavaOctetEditor; 20 | import cn.enaium.joe.dialog.SearchDialog; 21 | import cn.enaium.joe.gui.panel.search.ResultNode; 22 | import cn.enaium.joe.task.SearchFieldTask; 23 | import cn.enaium.joe.task.SearchLdcTask; 24 | import cn.enaium.joe.util.ASyncUtil; 25 | import cn.enaium.joe.util.LangUtil; 26 | import org.objectweb.asm.tree.LdcInsnNode; 27 | 28 | import javax.swing.*; 29 | import java.awt.*; 30 | 31 | /** 32 | * @author Enaium 33 | */ 34 | public class SearchLdcDialog extends SearchDialog { 35 | public SearchLdcDialog() { 36 | setTitle(LangUtil.i18n("search.ldc.title")); 37 | add(new JPanel(new FlowLayout()) {{ 38 | JTextField text = new JTextField(15); 39 | add(text); 40 | add(new JButton(LangUtil.i18n("button.search")) {{ 41 | addActionListener(e -> { 42 | if (!text.getText().isEmpty()) { 43 | ((DefaultListModel) resultList.getModel()).clear(); 44 | JavaOctetEditor.getInstance().task 45 | .submit(new SearchLdcTask(JavaOctetEditor.getInstance().getJar(), text.getText())) 46 | .thenAccept(it -> { 47 | ((DefaultListModel) resultList.getModel()).clear(); 48 | for (ResultNode resultNode : it) { 49 | ((DefaultListModel) resultList.getModel()).addElement(resultNode); 50 | } 51 | }); 52 | } 53 | }); 54 | }}); 55 | }}, BorderLayout.SOUTH); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/event/Event.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.event; 18 | 19 | /** 20 | * @author Enaium 21 | * @since 1.2.0 22 | */ 23 | public interface Event { 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/event/EventManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.event; 18 | 19 | import cn.enaium.joe.util.Pair; 20 | 21 | import java.util.List; 22 | import java.util.concurrent.CopyOnWriteArrayList; 23 | import java.util.function.Consumer; 24 | 25 | /** 26 | * @author Enaium 27 | * @since 1.2.0 28 | */ 29 | public class EventManager { 30 | List, Consumer>> listeners = new CopyOnWriteArrayList<>(); 31 | 32 | @SuppressWarnings("unchecked") 33 | public void register(Class listener, Consumer consumer) { 34 | listeners.add(new Pair<>(listener, ((Consumer) consumer))); 35 | } 36 | 37 | public void call(Event event) { 38 | listeners.stream().filter(it -> it.getKey() == event.getClass()).forEach(it -> it.getValue().accept(event)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/event/events/FileTabbedSelectEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.event.events; 18 | 19 | import cn.enaium.joe.event.Event; 20 | 21 | import java.awt.*; 22 | 23 | /** 24 | * @author Enaium 25 | * @since 1.2.0 26 | */ 27 | public class FileTabbedSelectEvent implements Event { 28 | private final Component select; 29 | 30 | public FileTabbedSelectEvent(Component select) { 31 | this.select = select; 32 | } 33 | 34 | public Component getSelect() { 35 | return select; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/component/InstructionComboBox.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.component; 18 | 19 | import javax.swing.*; 20 | 21 | /** 22 | * @author Enaium 23 | * @since 0.9.0 24 | */ 25 | public class InstructionComboBox extends JComboBox { 26 | public InstructionComboBox() { 27 | super(new String[]{"Opcode", "Int", "Var", "Type", "Field", "Method", "InvokeDynamic", "Jump", "Label", "LDC", "Incr", "TableSwitch", "LookupSwitch", "MultiANewArray", "Frame", "Line"}); 28 | } 29 | } 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/component/LabelNodeComboBox.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.component; 18 | 19 | import cn.enaium.joe.util.OpcodeUtil; 20 | import cn.enaium.joe.wrapper.LabelNodeWrapper; 21 | import org.objectweb.asm.tree.AbstractInsnNode; 22 | import org.objectweb.asm.tree.LabelNode; 23 | 24 | import javax.swing.*; 25 | 26 | /** 27 | * @author Enaium 28 | * @since 0.8.0 29 | */ 30 | public class LabelNodeComboBox extends JComboBox { 31 | public LabelNodeComboBox(AbstractInsnNode instruction, LabelNode select) { 32 | super(new DefaultComboBoxModel<>()); 33 | LabelNodeWrapper selected = null; 34 | for (AbstractInsnNode abstractInsnNode : OpcodeUtil.getInstructionList(select)) { 35 | if (abstractInsnNode instanceof LabelNode) { 36 | LabelNodeWrapper anObject = new LabelNodeWrapper(((LabelNode) abstractInsnNode)); 37 | if (abstractInsnNode.equals(select)) { 38 | selected = anObject; 39 | } 40 | ((DefaultComboBoxModel) getModel()).addElement(anObject); 41 | } 42 | } 43 | getModel().setSelectedItem(selected); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/component/RightTabBar.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.component; 18 | 19 | import cn.enaium.joe.gui.panel.InheritPanel; 20 | import cn.enaium.joe.gui.panel.MemberListPanel; 21 | import cn.enaium.joe.util.LangUtil; 22 | import com.formdev.flatlaf.extras.FlatSVGIcon; 23 | 24 | import javax.swing.*; 25 | 26 | /** 27 | * @author Enaium 28 | * @since 1.3.0 29 | */ 30 | public class RightTabBar extends TabPane { 31 | public RightTabBar() { 32 | super(TabPane.RIGHT); 33 | addTab(LangUtil.i18n("sideTab.member"), new FlatSVGIcon("icons/structure.svg"), new MemberListPanel()); 34 | addTab(LangUtil.i18n("sideTab.inherit"), new FlatSVGIcon("icons/inherit.svg"), new InheritPanel()); 35 | cancelSelect(); 36 | setVerticalLabel(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/layout/AbstractLayout.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.layout; 18 | 19 | import java.awt.*; 20 | 21 | /** 22 | * @author Enaium 23 | * @since 1.2.0 24 | */ 25 | public abstract class AbstractLayout implements LayoutManager2 { 26 | 27 | @Override 28 | public Dimension maximumLayoutSize(Container target) { 29 | return null; 30 | } 31 | 32 | @Override 33 | public float getLayoutAlignmentX(Container target) { 34 | return 0; 35 | } 36 | 37 | @Override 38 | public float getLayoutAlignmentY(Container target) { 39 | return 0; 40 | } 41 | 42 | @Override 43 | public void invalidateLayout(Container target) { 44 | 45 | } 46 | 47 | @Override 48 | public void addLayoutComponent(String name, Component comp) { 49 | 50 | } 51 | 52 | @Override 53 | public void removeLayoutComponent(Component comp) { 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/BorderPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel; 18 | 19 | import javax.swing.*; 20 | import java.awt.*; 21 | 22 | /** 23 | * @author Enaium 24 | * @since 1.3.0 25 | */ 26 | public class BorderPanel extends JPanel { 27 | public BorderPanel() { 28 | super(new BorderLayout()); 29 | } 30 | 31 | public void setCenter(Component component) { 32 | add(component, BorderLayout.CENTER); 33 | } 34 | 35 | public void setTop(Component component) { 36 | add(component, BorderLayout.NORTH); 37 | } 38 | 39 | public void setBottom(Component component) { 40 | add(component, BorderLayout.SOUTH); 41 | } 42 | 43 | public void setLeft(Component component) { 44 | add(component, BorderLayout.WEST); 45 | } 46 | 47 | public void setRight(Component component) { 48 | add(component, BorderLayout.EAST); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/confirm/ConfirmPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.confirm; 18 | 19 | import javax.swing.*; 20 | import java.awt.*; 21 | 22 | /** 23 | * @author Enaium 24 | * @since 0.8.0 25 | */ 26 | public class ConfirmPanel extends JPanel { 27 | 28 | private Runnable confirm = () -> { 29 | }; 30 | private Runnable cancel = () -> { 31 | }; 32 | 33 | public Runnable getConfirm() { 34 | return confirm; 35 | } 36 | 37 | public void setConfirm(Runnable confirm) { 38 | this.confirm = confirm; 39 | } 40 | 41 | public Runnable getCancel() { 42 | return cancel; 43 | } 44 | 45 | public void setCancel(Runnable cancel) { 46 | this.cancel = cancel; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/confirm/ListValueEditPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.confirm; 18 | 19 | import cn.enaium.joe.util.ASMUtil; 20 | import cn.enaium.joe.util.ListUtil; 21 | 22 | import javax.swing.*; 23 | import java.awt.*; 24 | import java.util.List; 25 | 26 | /** 27 | * @author Enaium 28 | * @since 1.2.0 29 | */ 30 | public class ListValueEditPanel extends ConfirmPanel { 31 | public ListValueEditPanel(List objects) { 32 | setLayout(new BorderLayout()); 33 | 34 | Class type = ListUtil.getType(objects); 35 | 36 | JTextArea jTextArea = new JTextArea(); 37 | int index = 0; 38 | for (Object object : objects) { 39 | jTextArea.append(object.toString()); 40 | 41 | if (index != objects.size() - 1) { 42 | jTextArea.append("\n"); 43 | } 44 | } 45 | add(new JScrollPane(jTextArea), BorderLayout.CENTER); 46 | setConfirm(() -> { 47 | objects.clear(); 48 | for (String s : jTextArea.getText().replaceAll("^\\s+", "").split("\n")) { 49 | objects.add(ASMUtil.toType(type, s)); 50 | } 51 | }); 52 | } 53 | } 54 | 55 | 56 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/confirm/ValueEditPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.confirm; 18 | 19 | import cn.enaium.joe.util.ASMUtil; 20 | import cn.enaium.joe.wrapper.ObjectWrapper; 21 | 22 | import javax.swing.*; 23 | import java.awt.*; 24 | 25 | /** 26 | * @author Enaium 27 | * @since 1.2.0 28 | */ 29 | public class ValueEditPanel extends ConfirmPanel { 30 | public ValueEditPanel(ObjectWrapper objectWrapper) { 31 | setLayout(new BorderLayout()); 32 | JTextField jTextField = new JTextField(objectWrapper.getWrapper().toString()); 33 | add(jTextField, BorderLayout.CENTER); 34 | setConfirm(() -> { 35 | objectWrapper.setWrapper(ASMUtil.toType(objectWrapper.getWrapper().getClass(), jTextField.getText())); 36 | }); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/file/tabbed/tab/classes/ClassNodeTabPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.file.tabbed.tab.classes; 18 | 19 | import org.objectweb.asm.tree.ClassNode; 20 | 21 | import javax.swing.*; 22 | 23 | /** 24 | * @author Enaium 25 | */ 26 | public class ClassNodeTabPanel extends JPanel { 27 | private final ClassNode classNode; 28 | 29 | public ClassNodeTabPanel(ClassNode classNode) { 30 | this.classNode = classNode; 31 | } 32 | 33 | public ClassNode getClassNode() { 34 | return classNode; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/file/tabbed/tab/classes/ClassTabPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.file.tabbed.tab.classes; 18 | 19 | import cn.enaium.joe.util.LangUtil; 20 | import org.objectweb.asm.tree.ClassNode; 21 | 22 | import javax.swing.*; 23 | import java.awt.*; 24 | 25 | /** 26 | * @author Enaium 27 | */ 28 | public class ClassTabPanel extends JPanel { 29 | 30 | public final ClassNode classNode; 31 | 32 | public ClassTabPanel(ClassNode classNode) { 33 | super(new BorderLayout()); 34 | this.classNode = classNode; 35 | JTabbedPane jTabbedPane = new JTabbedPane(); 36 | jTabbedPane.setTabPlacement(JTabbedPane.BOTTOM); 37 | jTabbedPane.addTab(LangUtil.i18n("class.tab.bytecodeView"), new TraceBytecodeTabPanel(classNode)); 38 | jTabbedPane.addTab(LangUtil.i18n("class.tab.decompileView"), new DecompileTabPanel(classNode)); 39 | jTabbedPane.addTab(LangUtil.i18n("class.tab.visitorEdit"), new ASMifierTablePanel(classNode)); 40 | jTabbedPane.addTab(LangUtil.i18n("class.tab.infoEdit"), new ClassInfoTabPanel(classNode)); 41 | add(jTabbedPane); 42 | } 43 | } -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/file/tabbed/tab/classes/DecompileTabPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.file.tabbed.tab.classes; 18 | 19 | import cn.enaium.joe.JavaOctetEditor; 20 | import cn.enaium.joe.service.DecompileService; 21 | import cn.enaium.joe.gui.panel.CodeAreaPanel; 22 | import cn.enaium.joe.task.DecompileTask; 23 | import cn.enaium.joe.util.ASyncUtil; 24 | import org.objectweb.asm.tree.ClassNode; 25 | 26 | import java.awt.*; 27 | 28 | /** 29 | * @author Enaium 30 | */ 31 | public class DecompileTabPanel extends ClassNodeTabPanel { 32 | public DecompileTabPanel(ClassNode classNode) { 33 | super(classNode); 34 | setLayout(new BorderLayout()); 35 | CodeAreaPanel codeAreaPanel = new CodeAreaPanel(); 36 | codeAreaPanel.getTextArea().setSyntaxEditingStyle("text/java"); 37 | JavaOctetEditor.getInstance().task.submit(new DecompileTask(classNode)).thenAccept(it -> { 38 | codeAreaPanel.getTextArea().setText(it); 39 | }); 40 | codeAreaPanel.getTextArea().setCaretPosition(0); 41 | add(codeAreaPanel); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/file/tabbed/tab/classes/TraceBytecodeTabPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.file.tabbed.tab.classes; 18 | 19 | import cn.enaium.joe.gui.panel.CodeAreaPanel; 20 | import cn.enaium.joe.util.ASyncUtil; 21 | import org.objectweb.asm.tree.ClassNode; 22 | import org.objectweb.asm.util.TraceClassVisitor; 23 | 24 | import java.awt.*; 25 | import java.io.PrintWriter; 26 | import java.io.StringWriter; 27 | import java.nio.charset.StandardCharsets; 28 | 29 | /** 30 | * @author Enaium 31 | */ 32 | public class TraceBytecodeTabPanel extends ClassNodeTabPanel { 33 | public TraceBytecodeTabPanel(ClassNode classNode) { 34 | super(classNode); 35 | setLayout(new BorderLayout()); 36 | CodeAreaPanel codeAreaPanel = new CodeAreaPanel(); 37 | codeAreaPanel.getTextArea().setSyntaxEditingStyle("text/custom"); 38 | final StringWriter stringWriter = new StringWriter(); 39 | ASyncUtil.execute(() -> { 40 | classNode.accept(new TraceClassVisitor(new PrintWriter(stringWriter))); 41 | }, () -> { 42 | codeAreaPanel.getTextArea().setText(new String(stringWriter.toString().getBytes(StandardCharsets.UTF_8))); 43 | codeAreaPanel.getTextArea().setCaretPosition(0); 44 | }); 45 | add(codeAreaPanel); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/file/tabbed/tab/resources/FileTablePane.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.file.tabbed.tab.resources; 18 | 19 | import cn.enaium.joe.gui.panel.file.tree.node.FileTreeNode; 20 | import cn.enaium.joe.util.IOUtil; 21 | import cn.enaium.joe.util.StringUtil; 22 | import cn.enaium.joe.util.Util; 23 | 24 | import javax.swing.*; 25 | import java.awt.*; 26 | 27 | /** 28 | * @author Enaium 29 | * @since 1.2.0 30 | */ 31 | public class FileTablePane extends JPanel { 32 | public FileTablePane(FileTreeNode fileTreeNode) { 33 | super(new BorderLayout()); 34 | if (Util.isText(fileTreeNode.getData())) { 35 | add(new TextTablePanel(fileTreeNode)); 36 | } else if (IOUtil.isImage(fileTreeNode.getData())) { 37 | add(new ImageTablePanel(fileTreeNode)); 38 | } else { 39 | add(new HexTablePanel(fileTreeNode)); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/file/tabbed/tab/resources/HexTablePanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.file.tabbed.tab.resources; 18 | 19 | import cn.enaium.joe.gui.panel.file.tree.node.FileTreeNode; 20 | import cn.enaium.joe.util.ASyncUtil; 21 | 22 | import javax.swing.*; 23 | import javax.swing.table.DefaultTableModel; 24 | import java.awt.*; 25 | 26 | /** 27 | * @author Enaium 28 | * @since 0.7.0 29 | */ 30 | public class HexTablePanel extends JPanel { 31 | public HexTablePanel(FileTreeNode fileTreeNode) { 32 | super(new BorderLayout()); 33 | DefaultTableModel defaultTableModel = new DefaultTableModel(new Object[][]{}, new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}); 34 | JTable jTable = new JTable(defaultTableModel) { 35 | @Override 36 | public boolean isCellEditable(int row, int column) { 37 | return false; 38 | } 39 | }; 40 | jTable.getTableHeader().setReorderingAllowed(false); 41 | add(new JScrollPane(jTable), BorderLayout.CENTER); 42 | 43 | ASyncUtil.execute(() -> { 44 | int row = 0; 45 | Object[] array = new Object[16]; 46 | byte[] data = fileTreeNode.getData(); 47 | for (int i = 0; i < data.length; i++) { 48 | byte b = data[i]; 49 | array[row] = String.format("%02X", b); 50 | if (row == 15 || i == fileTreeNode.getData().length - 1) { 51 | defaultTableModel.addRow(array); 52 | row = 0; 53 | array = new Object[16]; 54 | continue; 55 | } 56 | row++; 57 | } 58 | }); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/file/tabbed/tab/resources/ImageTablePanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.file.tabbed.tab.resources; 18 | 19 | import cn.enaium.joe.gui.panel.file.tree.node.FileTreeNode; 20 | import cn.enaium.joe.util.IOUtil; 21 | import cn.enaium.joe.util.MessageUtil; 22 | 23 | import javax.swing.*; 24 | import java.awt.*; 25 | import java.io.IOException; 26 | 27 | /** 28 | * @author Enaium 29 | * @since 1.2.0 30 | */ 31 | public class ImageTablePanel extends JPanel { 32 | public ImageTablePanel(FileTreeNode fileTreeNode) { 33 | setLayout(new BorderLayout()); 34 | add(new JScrollPane(new JLabel() {{ 35 | try { 36 | setHorizontalAlignment(SwingUtilities.CENTER); 37 | setIcon(IOUtil.getIcon(fileTreeNode.getData())); 38 | } catch (IOException e) { 39 | MessageUtil.error(e); 40 | } 41 | }})); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/file/tabbed/tab/resources/TextTablePanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.file.tabbed.tab.resources; 18 | 19 | import cn.enaium.joe.gui.panel.BorderPanel; 20 | import cn.enaium.joe.gui.panel.CodeAreaPanel; 21 | import cn.enaium.joe.gui.panel.file.tree.node.FileTreeNode; 22 | import org.fife.ui.rsyntaxtextarea.FileTypeUtil; 23 | import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; 24 | import org.fife.ui.rsyntaxtextarea.SyntaxConstants; 25 | 26 | import javax.swing.*; 27 | import java.awt.*; 28 | import java.nio.charset.StandardCharsets; 29 | import java.util.List; 30 | import java.util.Map; 31 | 32 | /** 33 | * @author Enaium 34 | * @since 1.2.0 35 | */ 36 | public class TextTablePanel extends BorderPanel { 37 | public TextTablePanel(FileTreeNode fileTreeNode) { 38 | setCenter(new CodeAreaPanel() {{ 39 | String name = fileTreeNode.toString(); 40 | String syntax = SyntaxConstants.SYNTAX_STYLE_NONE; 41 | for (Map.Entry> stringListEntry : FileTypeUtil.get().getDefaultContentTypeToFilterMap().entrySet()) { 42 | for (String s : stringListEntry.getValue()) { 43 | if (name.matches("." + s)) { 44 | syntax = stringListEntry.getKey(); 45 | break; 46 | } 47 | } 48 | } 49 | getTextArea().setSyntaxEditingStyle(syntax); 50 | getTextArea().setText(new String(fileTreeNode.getData(), StandardCharsets.UTF_8)); 51 | }}); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/file/tree/CenterPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.file.tree; 18 | 19 | import cn.enaium.joe.JavaOctetEditor; 20 | import cn.enaium.joe.gui.component.RightTabBar; 21 | import cn.enaium.joe.gui.panel.BorderPanel; 22 | import cn.enaium.joe.gui.panel.LeftPanel; 23 | 24 | import javax.swing.*; 25 | import java.awt.*; 26 | 27 | /** 28 | * @author Enaium 29 | * @since 1.2.0 30 | */ 31 | public class CenterPanel extends BorderPanel { 32 | public CenterPanel() { 33 | setCenter(new JSplitPane() {{ 34 | setLeftComponent(new LeftPanel()); 35 | setRightComponent(JavaOctetEditor.getInstance().fileTabbedPanel); 36 | setDividerLocation(200); 37 | }}); 38 | setRight(new BorderPanel() {{ 39 | JViewport jViewport = new JViewport(); 40 | setCenter(jViewport); 41 | setRight(new RightTabBar() {{ 42 | addChangeListener(e -> { 43 | jViewport.setView(getSelectedComponent()); 44 | }); 45 | }}); 46 | 47 | }}); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/file/tree/node/ClassTreeNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.file.tree.node; 18 | 19 | import org.objectweb.asm.tree.ClassNode; 20 | 21 | /** 22 | * @author Enaium 23 | */ 24 | public class ClassTreeNode extends PackageTreeNode { 25 | public ClassNode classNode; 26 | 27 | public ClassTreeNode(ClassNode classNode) { 28 | super(classNode.name.substring(classNode.name.lastIndexOf("/") + 1)); 29 | this.classNode = classNode; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/file/tree/node/DefaultTreeNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.file.tree.node; 18 | 19 | import javax.swing.tree.DefaultMutableTreeNode; 20 | import javax.swing.tree.MutableTreeNode; 21 | import javax.swing.tree.TreeNode; 22 | import java.util.Vector; 23 | import java.util.concurrent.CopyOnWriteArrayList; 24 | 25 | /** 26 | * @author Enaium 27 | */ 28 | public class DefaultTreeNode extends DefaultMutableTreeNode { 29 | public DefaultTreeNode(Object userObject) { 30 | super(userObject); 31 | } 32 | 33 | 34 | @SuppressWarnings("unchecked") 35 | public Vector getChildren() { 36 | if (children == null) { 37 | return new Vector<>(); 38 | } 39 | return children; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/file/tree/node/FileTreeNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.file.tree.node; 18 | 19 | /** 20 | * @author Enaium 21 | */ 22 | public class FileTreeNode extends FolderTreeNode { 23 | 24 | private final byte[] data; 25 | 26 | public FileTreeNode(Object userObject, byte[] data) { 27 | super(userObject); 28 | this.data = data; 29 | } 30 | 31 | public byte[] getData() { 32 | return data; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/file/tree/node/FolderTreeNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.file.tree.node; 18 | 19 | /** 20 | * @author Enaium 21 | */ 22 | public class FolderTreeNode extends DefaultTreeNode { 23 | public FolderTreeNode(Object userObject) { 24 | super(userObject); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/file/tree/node/MethodTreeNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.file.tree.node; 18 | 19 | import org.objectweb.asm.tree.ClassNode; 20 | import org.objectweb.asm.tree.MethodNode; 21 | 22 | /** 23 | * @author Enaium 24 | */ 25 | public class MethodTreeNode extends PackageTreeNode { 26 | public ClassNode classNode; 27 | public MethodNode methodNode; 28 | 29 | public MethodTreeNode(ClassNode classNode, MethodNode methodNode) { 30 | super(classNode.name + "." + methodNode.name + methodNode.desc); 31 | this.classNode = classNode; 32 | this.methodNode = methodNode; 33 | } 34 | } -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/file/tree/node/PackageTreeNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.file.tree.node; 18 | 19 | /** 20 | * @author Enaium 21 | */ 22 | public class PackageTreeNode extends DefaultTreeNode { 23 | public PackageTreeNode(Object userObject) { 24 | super(userObject); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/instruction/FieldInstructionPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.instruction; 18 | 19 | import cn.enaium.joe.util.LangUtil; 20 | import org.objectweb.asm.tree.FieldInsnNode; 21 | import org.objectweb.asm.tree.InsnList; 22 | import org.objectweb.asm.tree.TypeInsnNode; 23 | 24 | import javax.swing.*; 25 | import java.util.ArrayList; 26 | import java.util.List; 27 | 28 | /** 29 | * @author Enaium 30 | * @since 0.8.0 31 | */ 32 | public class FieldInstructionPanel extends AbstractInstructionPanel { 33 | public FieldInstructionPanel(FieldInsnNode instruction) { 34 | super(instruction); 35 | JTextField owner = new JTextField(instruction.owner); 36 | JTextField name = new JTextField(instruction.name); 37 | JTextField description = new JTextField(instruction.desc); 38 | addComponent(new JLabel(LangUtil.i18n("instruction.owner")), owner); 39 | addComponent(new JLabel(LangUtil.i18n("instruction.name")), name); 40 | addComponent(new JLabel(LangUtil.i18n("instruction.description")), description); 41 | setConfirm(() -> { 42 | instruction.setOpcode(getOpcode()); 43 | instruction.owner = owner.getText(); 44 | instruction.name = owner.getText(); 45 | instruction.desc = description.getText(); 46 | return true; 47 | }); 48 | } 49 | 50 | @Override 51 | public List getOpcodes() { 52 | return new ArrayList() {{ 53 | add("GETSTATIC"); 54 | add("PUTSTATIC"); 55 | add("GETFIELD"); 56 | add("PUTFIELD"); 57 | }}; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/instruction/IncrInstructionPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.instruction; 18 | 19 | import cn.enaium.joe.util.LangUtil; 20 | import org.objectweb.asm.tree.IincInsnNode; 21 | import org.objectweb.asm.tree.InsnList; 22 | 23 | import javax.swing.*; 24 | import java.util.ArrayList; 25 | import java.util.Collections; 26 | import java.util.List; 27 | 28 | /** 29 | * @author Enaium 30 | * @since 0.8.0 31 | */ 32 | public class IncrInstructionPanel extends AbstractInstructionPanel { 33 | public IncrInstructionPanel(IincInsnNode instruction) { 34 | super(instruction); 35 | JSpinner varIndex = new JSpinner(); 36 | varIndex.setValue(instruction.var); 37 | addComponent(new JLabel(LangUtil.i18n("instruction.varIndex")), varIndex); 38 | JSpinner incr = new JSpinner(); 39 | incr.setValue(instruction.incr); 40 | addComponent(new JLabel(LangUtil.i18n("instruction.incr")), incr); 41 | setConfirm(() -> { 42 | instruction.var = Integer.parseInt(varIndex.getValue().toString()); 43 | instruction.incr = Integer.parseInt(incr.getValue().toString()); 44 | return true; 45 | }); 46 | } 47 | 48 | @Override 49 | public List getOpcodes() { 50 | return Collections.singletonList("IINC"); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/instruction/IntInstructionPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.instruction; 18 | 19 | import cn.enaium.joe.util.LangUtil; 20 | import org.objectweb.asm.tree.AbstractInsnNode; 21 | import org.objectweb.asm.tree.InsnList; 22 | import org.objectweb.asm.tree.InsnNode; 23 | import org.objectweb.asm.tree.IntInsnNode; 24 | 25 | import javax.swing.*; 26 | import java.util.ArrayList; 27 | import java.util.List; 28 | 29 | /** 30 | * @author Enaium 31 | * @since 0.8.0 32 | */ 33 | public class IntInstructionPanel extends AbstractInstructionPanel { 34 | public IntInstructionPanel(IntInsnNode instruction) { 35 | super(instruction); 36 | JSpinner operand = new JSpinner(); 37 | operand.setValue(instruction.operand); 38 | addComponent(new JLabel(LangUtil.i18n("instruction.operand")), operand); 39 | setConfirm(() -> { 40 | instruction.setOpcode(getOpcode()); 41 | instruction.operand = Integer.parseInt(operand.getValue().toString()); 42 | return true; 43 | }); 44 | } 45 | 46 | @Override 47 | public List getOpcodes() { 48 | return new ArrayList() {{ 49 | add("BIPUSH"); 50 | add("SIPUSH"); 51 | add("NEWARRAY"); 52 | }}; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/instruction/JumpInstructionPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.instruction; 18 | 19 | import cn.enaium.joe.gui.component.LabelNodeComboBox; 20 | import cn.enaium.joe.util.LangUtil; 21 | import cn.enaium.joe.util.OpcodeUtil; 22 | import cn.enaium.joe.wrapper.LabelNodeWrapper; 23 | import org.objectweb.asm.tree.*; 24 | 25 | import javax.swing.*; 26 | import java.util.ArrayList; 27 | import java.util.List; 28 | 29 | /** 30 | * @author Enaium 31 | * @since 0.8.0 32 | */ 33 | public class JumpInstructionPanel extends AbstractInstructionPanel { 34 | public JumpInstructionPanel(JumpInsnNode instruction) { 35 | super(instruction); 36 | LabelNodeComboBox component = new LabelNodeComboBox(instruction, instruction.label); 37 | addComponent(new JLabel(LangUtil.i18n("instruction.label")), component); 38 | setConfirm(() -> { 39 | Object selectedItem = component.getSelectedItem(); 40 | if (selectedItem != null) { 41 | instruction.setOpcode(getOpcode()); 42 | instruction.label = ((LabelNodeWrapper) selectedItem).getWrapper(); 43 | return true; 44 | } 45 | return false; 46 | }); 47 | } 48 | 49 | @Override 50 | public List getOpcodes() { 51 | return new ArrayList() {{ 52 | add("IFEQ"); 53 | add("IFNE"); 54 | add("IFLT"); 55 | add("IFGE"); 56 | add("IFGT"); 57 | add("IFLE"); 58 | add("IF_ICMPEQ"); 59 | add("IF_ICMPNE"); 60 | add("IF_ICMPLT"); 61 | add("IF_ICMPGE"); 62 | add("IF_ICMPGT"); 63 | add("IF_ICMPLE"); 64 | add("IF_ACMPEQ"); 65 | add("IF_ACMPNE"); 66 | add("GOTO"); 67 | add("JSR"); 68 | add("IFNULL"); 69 | add("IFNONNULL"); 70 | }}; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/instruction/LineInstructionPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.instruction; 18 | 19 | import cn.enaium.joe.gui.component.LabelNodeComboBox; 20 | import cn.enaium.joe.util.LangUtil; 21 | import cn.enaium.joe.util.OpcodeUtil; 22 | import cn.enaium.joe.wrapper.LabelNodeWrapper; 23 | import org.objectweb.asm.tree.*; 24 | 25 | import javax.swing.*; 26 | import java.util.ArrayList; 27 | import java.util.HashMap; 28 | import java.util.List; 29 | import java.util.Map; 30 | 31 | /** 32 | * @author Enaium 33 | * @since 0.8.0 34 | */ 35 | public class LineInstructionPanel extends AbstractInstructionPanel { 36 | public LineInstructionPanel(LineNumberNode instruction) { 37 | super(instruction); 38 | JSpinner spinner = new JSpinner(); 39 | spinner.setValue(instruction.line); 40 | addComponent(new JLabel(LangUtil.i18n("instruction.line")), spinner); 41 | LabelNodeComboBox component = new LabelNodeComboBox(instruction, instruction.start); 42 | addComponent(new JLabel(LangUtil.i18n("instruction.start")), component); 43 | 44 | setConfirm(() -> { 45 | Object selectedItem = component.getSelectedItem(); 46 | if (selectedItem != null) { 47 | instruction.line = Integer.parseInt(spinner.getValue().toString()); 48 | instruction.start = ((LabelNodeWrapper) selectedItem).getWrapper(); 49 | return true; 50 | } 51 | return false; 52 | }); 53 | } 54 | 55 | @Override 56 | public List getOpcodes() { 57 | return null; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/instruction/MethodInstructionPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.instruction; 18 | 19 | import cn.enaium.joe.util.LangUtil; 20 | import org.objectweb.asm.tree.FieldInsnNode; 21 | import org.objectweb.asm.tree.InsnList; 22 | import org.objectweb.asm.tree.MethodInsnNode; 23 | 24 | import javax.swing.*; 25 | import java.util.ArrayList; 26 | import java.util.List; 27 | 28 | /** 29 | * @author Enaium 30 | * @since 0.8.0 31 | */ 32 | public class MethodInstructionPanel extends AbstractInstructionPanel { 33 | public MethodInstructionPanel(MethodInsnNode instruction) { 34 | super(instruction); 35 | JTextField owner = new JTextField(instruction.owner); 36 | JTextField name = new JTextField(instruction.name); 37 | JTextField description = new JTextField(instruction.desc); 38 | JCheckBox isInterface = new JCheckBox() {{ 39 | setHorizontalAlignment(JCheckBox.RIGHT); 40 | }}; 41 | addComponent(new JLabel(LangUtil.i18n("instruction.owner")), owner); 42 | addComponent(new JLabel(LangUtil.i18n("instruction.name")), name); 43 | addComponent(new JLabel(LangUtil.i18n("instruction.description")), description); 44 | addComponent(new JLabel(LangUtil.i18n("instruction.interface")), isInterface); 45 | setConfirm(() -> { 46 | instruction.setOpcode(getOpcode()); 47 | instruction.owner = owner.getText(); 48 | instruction.name = name.getText(); 49 | instruction.desc = description.getText(); 50 | instruction.itf = isInterface.isSelected(); 51 | return true; 52 | }); 53 | } 54 | 55 | @Override 56 | public List getOpcodes() { 57 | return new ArrayList() {{ 58 | add("INVOKEVIRTUAL"); 59 | add("INVOKESPECIAL"); 60 | add("INVOKESTATIC"); 61 | add("INVOKEINTERFACE"); 62 | }}; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/instruction/MultiANewArrayInstructionPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.instruction; 18 | 19 | import cn.enaium.joe.util.LangUtil; 20 | import org.objectweb.asm.tree.AbstractInsnNode; 21 | import org.objectweb.asm.tree.InsnList; 22 | import org.objectweb.asm.tree.MultiANewArrayInsnNode; 23 | 24 | import javax.swing.*; 25 | import java.util.Collections; 26 | import java.util.List; 27 | 28 | /** 29 | * @author Enaium 30 | * @since 0.8.0 31 | */ 32 | public class MultiANewArrayInstructionPanel extends AbstractInstructionPanel { 33 | public MultiANewArrayInstructionPanel(MultiANewArrayInsnNode instruction) { 34 | super(instruction); 35 | JTextField description = new JTextField(); 36 | description.setText(instruction.desc); 37 | addComponent(new JLabel(LangUtil.i18n("instruction.description")), description); 38 | JSpinner dimension = new JSpinner(); 39 | dimension.setValue(instruction.dims); 40 | addComponent(new JLabel(LangUtil.i18n("instruction.dimension")), dimension); 41 | setConfirm(() -> { 42 | instruction.desc = description.getText(); 43 | instruction.dims = Integer.parseInt(dimension.getValue().toString()); 44 | return true; 45 | }); 46 | } 47 | 48 | @Override 49 | public List getOpcodes() { 50 | return Collections.singletonList("MULTIANEWARRAY"); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/instruction/TypeInstructionPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.instruction; 18 | 19 | import cn.enaium.joe.util.LangUtil; 20 | import org.objectweb.asm.tree.AbstractInsnNode; 21 | import org.objectweb.asm.tree.InsnList; 22 | import org.objectweb.asm.tree.TypeInsnNode; 23 | 24 | import javax.swing.*; 25 | import java.util.ArrayList; 26 | import java.util.List; 27 | 28 | /** 29 | * @author Enaium 30 | * @since 0.8.0 31 | */ 32 | public class TypeInstructionPanel extends AbstractInstructionPanel { 33 | public TypeInstructionPanel(TypeInsnNode instruction) { 34 | super(instruction); 35 | JTextField description = new JTextField(instruction.desc); 36 | addComponent(new JLabel(LangUtil.i18n("instruction.description")), description); 37 | setConfirm(() -> { 38 | instruction.setOpcode(getOpcode()); 39 | instruction.desc = description.getText(); 40 | return true; 41 | }); 42 | } 43 | 44 | @Override 45 | public List getOpcodes() { 46 | return new ArrayList() {{ 47 | add("NEW"); 48 | add("ANEWARRAY"); 49 | add("CHECKCAST"); 50 | add("INSTANCEOF"); 51 | }}; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/instruction/VarInstructionPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.instruction; 18 | 19 | import cn.enaium.joe.util.LangUtil; 20 | import org.objectweb.asm.tree.AbstractInsnNode; 21 | import org.objectweb.asm.tree.InsnList; 22 | import org.objectweb.asm.tree.IntInsnNode; 23 | import org.objectweb.asm.tree.VarInsnNode; 24 | 25 | import javax.swing.*; 26 | import java.util.ArrayList; 27 | import java.util.List; 28 | 29 | /** 30 | * @author Enaium 31 | * @since 0.8.0 32 | */ 33 | public class VarInstructionPanel extends AbstractInstructionPanel { 34 | public VarInstructionPanel(VarInsnNode instruction) { 35 | super(instruction); 36 | JSpinner spinner = new JSpinner(); 37 | spinner.setValue(instruction.var); 38 | addComponent(new JLabel(LangUtil.i18n("instruction.var")), spinner); 39 | setConfirm(() -> { 40 | instruction.setOpcode(getOpcode()); 41 | instruction.var = Integer.parseInt(spinner.getValue().toString()); 42 | return true; 43 | }); 44 | } 45 | 46 | @Override 47 | public List getOpcodes() { 48 | return new ArrayList() {{ 49 | add("ILOAD"); 50 | add("LLOAD"); 51 | add("FLOAD"); 52 | add("DLOAD"); 53 | add("ALOAD"); 54 | add("ISTORE"); 55 | add("LSTORE"); 56 | add("FSTORE"); 57 | add("DSTORE"); 58 | add("ASTORE"); 59 | add("RET"); 60 | }}; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/menu/AttachMenu.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.menu; 18 | 19 | import cn.enaium.joe.gui.panel.menu.attach.ProcessMenuItem; 20 | import cn.enaium.joe.util.LangUtil; 21 | 22 | import javax.swing.*; 23 | 24 | /** 25 | * @author Enaium 26 | * @since 1.1.0 27 | */ 28 | public class AttachMenu extends JMenu { 29 | public AttachMenu() { 30 | super(LangUtil.i18n("menu.attach")); 31 | add(new ProcessMenuItem()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/menu/ConfigMenu.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.menu; 18 | 19 | import cn.enaium.joe.JavaOctetEditor; 20 | import cn.enaium.joe.config.Config; 21 | import cn.enaium.joe.dialog.ConfigDialog; 22 | import cn.enaium.joe.util.LangUtil; 23 | 24 | import javax.swing.*; 25 | 26 | /** 27 | * @author Enaium 28 | * @since 0.7.0 29 | */ 30 | public class ConfigMenu extends JMenu { 31 | public ConfigMenu() { 32 | super(LangUtil.i18n("menu.config")); 33 | for (Config value : JavaOctetEditor.getInstance().config.getConfig().values()) { 34 | add(new JMenuItem(value.getName()) {{ 35 | addActionListener(e -> { 36 | new ConfigDialog(value).setVisible(true); 37 | }); 38 | }}); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/menu/FileMenu.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.menu; 18 | 19 | import cn.enaium.joe.gui.panel.menu.file.LoadMenuItem; 20 | import cn.enaium.joe.gui.panel.menu.file.LoadRecentMenu; 21 | import cn.enaium.joe.gui.panel.menu.file.SaveAllSourceMenuItem; 22 | import cn.enaium.joe.gui.panel.menu.file.SaveMenuItem; 23 | import cn.enaium.joe.util.LangUtil; 24 | 25 | import javax.swing.*; 26 | 27 | /** 28 | * @author Enaium 29 | */ 30 | public class FileMenu extends JMenu { 31 | public FileMenu() { 32 | super(LangUtil.i18n("menu.file")); 33 | add(new LoadMenuItem()); 34 | add(new LoadRecentMenu()); 35 | add(new SaveMenuItem()); 36 | add(new JSeparator()); 37 | add(new SaveAllSourceMenuItem()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/menu/HelpMenu.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.menu; 18 | 19 | import cn.enaium.joe.gui.panel.menu.help.AboutMenuItem; 20 | import cn.enaium.joe.gui.panel.menu.help.ContactMenuItem; 21 | import cn.enaium.joe.util.LangUtil; 22 | 23 | import javax.swing.*; 24 | 25 | /** 26 | * @author Enaium 27 | */ 28 | public class HelpMenu extends JMenu { 29 | public HelpMenu() { 30 | super(LangUtil.i18n("menu.help")); 31 | add(new AboutMenuItem()); 32 | add(new ContactMenuItem()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/menu/MappingMenu.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.menu; 18 | 19 | import cn.enaium.joe.JavaOctetEditor; 20 | import cn.enaium.joe.task.RemappingTask; 21 | import cn.enaium.joe.util.JFileChooserUtil; 22 | import cn.enaium.joe.util.LangUtil; 23 | import net.fabricmc.mappingio.format.MappingFormat; 24 | 25 | import javax.swing.*; 26 | import javax.swing.filechooser.FileFilter; 27 | import java.io.File; 28 | 29 | /** 30 | * @author Enaium 31 | * @since 1.0.0 32 | */ 33 | public class MappingMenu extends JMenu { 34 | public MappingMenu() { 35 | super(LangUtil.i18n("menu.mapping")); 36 | for (MappingFormat value : MappingFormat.values()) { 37 | add(new JMenuItem(value.name) {{ 38 | addActionListener(e -> { 39 | File show = JFileChooserUtil.show(JFileChooserUtil.Type.OPEN, new FileFilter() { 40 | @Override 41 | public boolean accept(File f) { 42 | return f.getName().matches(".+(txt|map|mapping|pro|srg|tsrg|tiny|tiyv2)") || f.isDirectory(); 43 | } 44 | 45 | @Override 46 | public String getDescription() { 47 | return "Mapping file(*.txt,*.map,*.mapping,*.pro,*.srg)"; 48 | } 49 | }); 50 | if (JavaOctetEditor.getInstance().getJar() != null && show != null) { 51 | JavaOctetEditor.getInstance().task.submit(new RemappingTask(show, value)); 52 | } 53 | }); 54 | }}); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/menu/SearchMenu.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.menu; 18 | 19 | import cn.enaium.joe.gui.panel.menu.search.FieldMenuItem; 20 | import cn.enaium.joe.gui.panel.menu.search.LdcMenuItem; 21 | import cn.enaium.joe.gui.panel.menu.search.MethodMenuItem; 22 | import cn.enaium.joe.util.LangUtil; 23 | 24 | import javax.swing.*; 25 | 26 | /** 27 | * @author Enaium 28 | */ 29 | public class SearchMenu extends JMenu { 30 | public SearchMenu() { 31 | super(LangUtil.i18n("menu.search")); 32 | add(new LdcMenuItem()); 33 | add(new FieldMenuItem()); 34 | add(new MethodMenuItem()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/menu/attach/ProcessMenuItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.menu.attach; 18 | 19 | import cn.enaium.joe.dialog.ProcessListDialog; 20 | import cn.enaium.joe.util.LangUtil; 21 | 22 | import javax.swing.*; 23 | 24 | /** 25 | * @author Enaium 26 | * @since 1.1.0 27 | */ 28 | public class ProcessMenuItem extends JMenuItem { 29 | public ProcessMenuItem() { 30 | super(LangUtil.i18n("menu.attach.process")); 31 | addActionListener(e -> { 32 | new ProcessListDialog().setVisible(true); 33 | }); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/menu/file/LoadMenuItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.menu.file; 18 | 19 | import cn.enaium.joe.JavaOctetEditor; 20 | import cn.enaium.joe.task.InputJarTask; 21 | import cn.enaium.joe.util.JFileChooserUtil; 22 | import cn.enaium.joe.util.LangUtil; 23 | 24 | import javax.swing.*; 25 | import java.io.File; 26 | 27 | /** 28 | * @author Enaium 29 | */ 30 | public class LoadMenuItem extends JMenuItem { 31 | public LoadMenuItem() { 32 | super(LangUtil.i18n("menu.file.load")); 33 | addActionListener(e -> { 34 | File show = JFileChooserUtil.show(JFileChooserUtil.Type.OPEN); 35 | if (show != null) { 36 | JavaOctetEditor.getInstance().task.submit(new InputJarTask(show)); 37 | } 38 | }); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/menu/file/SaveAllSourceMenuItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.menu.file; 18 | 19 | import cn.enaium.joe.JavaOctetEditor; 20 | import cn.enaium.joe.service.decompiler.ProcyonDecompiler; 21 | import cn.enaium.joe.jar.Jar; 22 | import cn.enaium.joe.task.OutputJarTask; 23 | import cn.enaium.joe.task.SaveAllSourceTask; 24 | import cn.enaium.joe.util.ASyncUtil; 25 | import cn.enaium.joe.util.JFileChooserUtil; 26 | import cn.enaium.joe.util.LangUtil; 27 | import org.objectweb.asm.tree.ClassNode; 28 | 29 | import javax.swing.*; 30 | import java.io.File; 31 | import java.io.IOException; 32 | import java.nio.charset.StandardCharsets; 33 | import java.nio.file.Files; 34 | import java.util.Map; 35 | import java.util.jar.JarEntry; 36 | import java.util.zip.ZipEntry; 37 | import java.util.zip.ZipOutputStream; 38 | 39 | /** 40 | * @author Enaium 41 | */ 42 | public class SaveAllSourceMenuItem extends JMenuItem { 43 | public SaveAllSourceMenuItem() { 44 | super(LangUtil.i18n("menu.file.saveAllSource")); 45 | addActionListener(e -> { 46 | Jar jar = JavaOctetEditor.getInstance().getJar(); 47 | if (jar == null) { 48 | return; 49 | } 50 | 51 | File show = JFileChooserUtil.show(JFileChooserUtil.Type.SAVE); 52 | if (show != null) { 53 | JavaOctetEditor.getInstance().task.submit(new SaveAllSourceTask(jar, show)); 54 | } 55 | }); 56 | } 57 | } -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/menu/file/SaveMenuItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.menu.file; 18 | 19 | import cn.enaium.joe.JavaOctetEditor; 20 | import cn.enaium.joe.jar.Jar; 21 | import cn.enaium.joe.task.OutputJarTask; 22 | import cn.enaium.joe.util.ASyncUtil; 23 | import cn.enaium.joe.util.JFileChooserUtil; 24 | import cn.enaium.joe.util.LangUtil; 25 | import org.objectweb.asm.ClassWriter; 26 | import org.objectweb.asm.tree.ClassNode; 27 | 28 | import javax.swing.*; 29 | import java.io.File; 30 | import java.io.IOException; 31 | import java.nio.file.Files; 32 | import java.util.Map; 33 | import java.util.jar.JarEntry; 34 | import java.util.zip.ZipOutputStream; 35 | 36 | /** 37 | * @author Enaium 38 | */ 39 | public class SaveMenuItem extends JMenuItem { 40 | public SaveMenuItem() { 41 | super(LangUtil.i18n("menu.file.save")); 42 | addActionListener(e -> { 43 | Jar jar = JavaOctetEditor.getInstance().getJar(); 44 | if (jar == null) { 45 | return; 46 | } 47 | File show = JFileChooserUtil.show(JFileChooserUtil.Type.SAVE); 48 | if (show != null) { 49 | JavaOctetEditor.getInstance().task.submit(new OutputJarTask(jar, show)); 50 | } 51 | }); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/menu/help/AboutMenuItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.menu.help; 18 | 19 | import cn.enaium.joe.dialog.AboutDialog; 20 | import cn.enaium.joe.util.LangUtil; 21 | 22 | import javax.swing.*; 23 | 24 | /** 25 | * @author Enaium 26 | */ 27 | public class AboutMenuItem extends JMenuItem { 28 | public AboutMenuItem() { 29 | super(LangUtil.i18n("menu.help.about")); 30 | addActionListener(e -> new AboutDialog().setVisible(true)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/menu/help/ContactMenuItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.menu.help; 18 | 19 | import cn.enaium.joe.dialog.ContactDialog; 20 | import cn.enaium.joe.util.LangUtil; 21 | 22 | import javax.swing.*; 23 | 24 | /** 25 | * @author Enaium 26 | */ 27 | public class ContactMenuItem extends JMenuItem { 28 | public ContactMenuItem() { 29 | super(LangUtil.i18n("menu.help.contact")); 30 | addActionListener(e -> { 31 | new ContactDialog().setVisible(true); 32 | }); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/menu/search/FieldMenuItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.menu.search; 18 | 19 | import cn.enaium.joe.JavaOctetEditor; 20 | import cn.enaium.joe.dialog.search.SearchFieldDialog; 21 | import cn.enaium.joe.jar.Jar; 22 | import cn.enaium.joe.util.LangUtil; 23 | 24 | import javax.swing.*; 25 | 26 | /** 27 | * @author Enaium 28 | * @since 0.5.0 29 | */ 30 | public class FieldMenuItem extends JMenuItem { 31 | public FieldMenuItem() { 32 | super(LangUtil.i18n("menu.search.field")); 33 | addActionListener(e -> { 34 | Jar jar = JavaOctetEditor.getInstance().getJar(); 35 | if (jar == null) { 36 | return; 37 | } 38 | new SearchFieldDialog().setVisible(true); 39 | }); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/menu/search/LdcMenuItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.menu.search; 18 | 19 | import cn.enaium.joe.JavaOctetEditor; 20 | import cn.enaium.joe.dialog.search.SearchLdcDialog; 21 | import cn.enaium.joe.jar.Jar; 22 | import cn.enaium.joe.util.LangUtil; 23 | 24 | import javax.swing.*; 25 | 26 | /** 27 | * @author Enaium 28 | */ 29 | public class LdcMenuItem extends JMenuItem { 30 | public LdcMenuItem() { 31 | super(LangUtil.i18n("menu.search.ldc")); 32 | addActionListener(e -> { 33 | Jar jar = JavaOctetEditor.getInstance().getJar(); 34 | if (jar == null) { 35 | return; 36 | } 37 | 38 | new SearchLdcDialog().setVisible(true); 39 | }); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/menu/search/MethodMenuItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.menu.search; 18 | 19 | import cn.enaium.joe.JavaOctetEditor; 20 | import cn.enaium.joe.dialog.search.SearchFieldDialog; 21 | import cn.enaium.joe.dialog.search.SearchMethodDialog; 22 | import cn.enaium.joe.jar.Jar; 23 | import cn.enaium.joe.util.LangUtil; 24 | 25 | import javax.swing.*; 26 | 27 | /** 28 | * @author Enaium 29 | * @since 0.5.0 30 | */ 31 | public class MethodMenuItem extends JMenuItem { 32 | public MethodMenuItem() { 33 | super(LangUtil.i18n("menu.search.method")); 34 | addActionListener(e -> { 35 | Jar jar = JavaOctetEditor.getInstance().getJar(); 36 | if (jar == null) { 37 | return; 38 | } 39 | new SearchMethodDialog().setVisible(true); 40 | }); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/method/MethodTabPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.method; 18 | 19 | import org.objectweb.asm.tree.MethodNode; 20 | 21 | import javax.swing.*; 22 | import java.awt.*; 23 | 24 | /** 25 | * @author Enaium 26 | * @since 0.8.0 27 | */ 28 | public class MethodTabPanel extends JPanel { 29 | public MethodTabPanel(MethodNode methodNode) { 30 | super(new BorderLayout()); 31 | JTabbedPane jTabbedPane = new JTabbedPane(); 32 | jTabbedPane.setTabPlacement(JTabbedPane.BOTTOM); 33 | jTabbedPane.addTab("InstructionEdit", new MethodInstructionPanel(methodNode)); 34 | jTabbedPane.addTab("InfoEdit", new MethodInfoTabPanel(methodNode)); 35 | add(jTabbedPane); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/popup/AbstractPopup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.popup; 18 | 19 | import cn.enaium.joe.JavaOctetEditor; 20 | import com.formdev.flatlaf.extras.FlatSVGIcon; 21 | 22 | import javax.swing.*; 23 | import javax.swing.border.EmptyBorder; 24 | import java.awt.*; 25 | import java.awt.event.FocusEvent; 26 | import java.awt.event.FocusListener; 27 | import java.awt.event.MouseAdapter; 28 | import java.awt.event.MouseEvent; 29 | 30 | /** 31 | * @author Enaium 32 | * @since 1.2.0 33 | */ 34 | public abstract class AbstractPopup extends JPanel { 35 | private Popup popup; 36 | 37 | protected AbstractPopup(String name) { 38 | super(new BorderLayout()); 39 | add(new JPanel(new BorderLayout()) {{ 40 | setBorder(new EmptyBorder(5, 5, 5, 5)); 41 | setBackground(new JButton().getBackground()); 42 | add(new JLabel(name), BorderLayout.CENTER); 43 | add(new JLabel(new FlatSVGIcon("icons/minimize.svg") {{ 44 | addMouseListener(new MouseAdapter() { 45 | @Override 46 | public void mouseClicked(MouseEvent e) { 47 | destroy(); 48 | } 49 | }); 50 | }}), BorderLayout.EAST); 51 | 52 | }}, BorderLayout.NORTH); 53 | } 54 | 55 | public void place(int x, int y) { 56 | if (popup == null) { 57 | popup = PopupFactory.getSharedInstance().getPopup(JavaOctetEditor.getInstance().window, this, x, y); 58 | popup.show(); 59 | } 60 | } 61 | 62 | public void destroy() { 63 | if (popup != null) { 64 | popup.hide(); 65 | popup = null; 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/popup/TaskListPopup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.popup; 18 | 19 | import cn.enaium.joe.JavaOctetEditor; 20 | import cn.enaium.joe.task.AbstractTask; 21 | import cn.enaium.joe.util.Pair; 22 | 23 | import javax.swing.*; 24 | import java.awt.*; 25 | import java.util.concurrent.CompletableFuture; 26 | import java.util.concurrent.Executors; 27 | import java.util.concurrent.ScheduledExecutorService; 28 | import java.util.concurrent.TimeUnit; 29 | 30 | /** 31 | * @author Enaium 32 | * @since 1.2.0 33 | */ 34 | public class TaskListPopup extends AbstractPopup { 35 | public TaskListPopup() { 36 | super("TaskList"); 37 | JList> comp = new JList<>(); 38 | comp.setCellRenderer((list, value, index, isSelected, cellHasFocus) -> new JProgressBar() {{ 39 | setValue(value.getProgress()); 40 | setStringPainted(true); 41 | setString(String.format("%s:%s", value.getName(), value.getProgress()) + "%"); 42 | }}); 43 | add(new JScrollPane(comp), BorderLayout.CENTER); 44 | ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1); 45 | scheduledExecutorService.scheduleAtFixedRate(() -> { 46 | SwingUtilities.invokeLater(() -> { 47 | DefaultListModel> abstractTaskDefaultListModel = new DefaultListModel<>(); 48 | for (Pair, CompletableFuture> abstractTaskCompletableFuturePair : JavaOctetEditor.getInstance().task.getTask()) { 49 | abstractTaskDefaultListModel.addElement(abstractTaskCompletableFuturePair.getKey()); 50 | } 51 | comp.setModel(abstractTaskDefaultListModel); 52 | }); 53 | }, 1, 1, TimeUnit.MILLISECONDS); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/gui/panel/search/ResultNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.gui.panel.search; 18 | 19 | import cn.enaium.joe.util.ColorUtil; 20 | import cn.enaium.joe.util.HtmlUtil; 21 | import org.objectweb.asm.tree.ClassNode; 22 | 23 | import java.awt.*; 24 | 25 | /** 26 | * @author Enaium 27 | */ 28 | public class ResultNode { 29 | private ClassNode classNode; 30 | 31 | private final String text; 32 | 33 | public ResultNode() { 34 | text = " "; 35 | } 36 | 37 | public ResultNode(ClassNode classNode, String result) { 38 | this.classNode = classNode; 39 | text = HtmlUtil.toHtml(HtmlUtil.setColor(classNode.name, Color.WHITE) + "#" + result); 40 | } 41 | 42 | public ClassNode getClassNode() { 43 | return classNode; 44 | } 45 | 46 | @Override 47 | public String toString() { 48 | return text; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/jar/Jar.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.jar; 18 | 19 | import cn.enaium.joe.JavaOctetEditor; 20 | import cn.enaium.joe.config.extend.ApplicationConfig; 21 | import cn.enaium.joe.util.Util; 22 | import org.objectweb.asm.ClassReader; 23 | import org.objectweb.asm.tree.ClassNode; 24 | 25 | import java.io.ByteArrayOutputStream; 26 | import java.io.File; 27 | import java.io.IOException; 28 | import java.io.InputStream; 29 | import java.util.Enumeration; 30 | import java.util.LinkedHashMap; 31 | import java.util.Map; 32 | import java.util.jar.JarEntry; 33 | import java.util.jar.JarFile; 34 | 35 | /** 36 | * @author Enaium 37 | */ 38 | public class Jar { 39 | public Map classes = new LinkedHashMap<>(); 40 | public Map resources = new LinkedHashMap<>(); 41 | 42 | public Jar copy() { 43 | Jar jar = new Jar(); 44 | jar.classes.putAll(classes); 45 | jar.resources.putAll(resources); 46 | return jar; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/mapping/Mapping.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.mapping; 18 | 19 | import net.fabricmc.mappingio.MappedElementKind; 20 | import net.fabricmc.mappingio.MappingVisitor; 21 | 22 | import java.io.IOException; 23 | import java.util.HashMap; 24 | import java.util.List; 25 | import java.util.Map; 26 | 27 | /** 28 | * @author Enaium 29 | * @since 1.0.0 30 | */ 31 | public class Mapping { 32 | public final Map MAP = new HashMap<>(); 33 | public final Map CLEAN = new HashMap<>(); 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/service/DecompileService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.service; 18 | 19 | import cn.enaium.joe.JavaOctetEditor; 20 | import cn.enaium.joe.config.extend.ApplicationConfig; 21 | import cn.enaium.joe.config.value.ModeValue; 22 | import cn.enaium.joe.service.decompiler.*; 23 | 24 | /** 25 | * @author Enaium 26 | * @since 0.7.0 27 | */ 28 | public class DecompileService { 29 | public static IDecompiler getService() { 30 | ModeValue decompilerMode = JavaOctetEditor.getInstance().config.getByClass(ApplicationConfig.class).decompilerMode; 31 | switch (decompilerMode.getValue()) { 32 | case "CFR": return new CFRDecompiler(); 33 | case "Procyon": return new ProcyonDecompiler(); 34 | case "FernFlower": return new FernFlowerDecompiler(); 35 | } 36 | throw new NullPointerException("Not found decompiler"); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/service/decompiler/CFRDecompiler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.service.decompiler; 18 | 19 | import cn.enaium.joe.JavaOctetEditor; 20 | import cn.enaium.joe.config.extend.CFRConfig; 21 | import org.benf.cfr.reader.PluginRunner; 22 | import org.benf.cfr.reader.api.ClassFileSource; 23 | import org.benf.cfr.reader.bytecode.analysis.parse.utils.Pair; 24 | import org.objectweb.asm.ClassWriter; 25 | import org.objectweb.asm.tree.ClassNode; 26 | 27 | import java.io.IOException; 28 | import java.util.Collection; 29 | 30 | /** 31 | * @author Enaium 32 | * @since 0.7.0 33 | */ 34 | public class CFRDecompiler implements IDecompiler { 35 | @Override 36 | public String decompile(ClassNode classNode) { 37 | ClassFileSource cfs = new ClassFileSource() { 38 | @Override 39 | public void informAnalysisRelativePathDetail(String a, String b) { 40 | } 41 | 42 | @Override 43 | public String getPossiblyRenamedPath(String path) { 44 | return path; 45 | } 46 | 47 | @Override 48 | public Pair getClassFileContent(String path) throws IOException { 49 | String name = path.substring(0, path.length() - 6); 50 | if (name.equals(classNode.name)) { 51 | ClassWriter classWriter = new ClassWriter(0); 52 | classNode.accept(classWriter); 53 | return Pair.make(classWriter.toByteArray(), name); 54 | } 55 | return null; 56 | } 57 | 58 | @Override 59 | public Collection addJar(String arg0) { 60 | throw new RuntimeException(); 61 | } 62 | }; 63 | return new PluginRunner(JavaOctetEditor.getInstance().config.getConfigMap(CFRConfig.class), cfs).getDecompilationFor(classNode.name); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/service/decompiler/IDecompiler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.service.decompiler; 18 | 19 | import org.objectweb.asm.tree.ClassNode; 20 | 21 | /** 22 | * @author Enaium 23 | * @since 0.7.0 24 | */ 25 | public interface IDecompiler { 26 | String decompile(ClassNode classNode); 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/task/AbstractTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.task; 18 | 19 | import java.util.concurrent.Callable; 20 | import java.util.function.Supplier; 21 | 22 | /** 23 | * @author Enaium 24 | * @since 0.10.0 25 | */ 26 | public abstract class AbstractTask implements Supplier { 27 | private final String name; 28 | 29 | private int progress; 30 | 31 | public AbstractTask(String name) { 32 | this.name = name; 33 | } 34 | 35 | public String getName() { 36 | return name; 37 | } 38 | 39 | public int getProgress() { 40 | return progress; 41 | } 42 | 43 | public void setProgress(int progress) { 44 | this.progress = progress; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/task/DecompileTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.task; 18 | 19 | import cn.enaium.joe.annotation.Repeatable; 20 | import cn.enaium.joe.service.DecompileService; 21 | import org.objectweb.asm.tree.ClassNode; 22 | import org.pmw.tinylog.Logger; 23 | 24 | /** 25 | * @author Enaium 26 | * @since 0.10.0 27 | */ 28 | @Repeatable 29 | public class DecompileTask extends AbstractTask { 30 | 31 | private final ClassNode classNode; 32 | 33 | public DecompileTask(ClassNode classNode) { 34 | super("Decompile"); 35 | this.classNode = classNode; 36 | } 37 | 38 | @Override 39 | public String get() { 40 | Logger.info("DECOMPILE:{}", classNode.name); 41 | return DecompileService.getService().decompile(classNode); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/task/SearchFieldTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.task; 18 | 19 | import cn.enaium.joe.gui.panel.search.ResultNode; 20 | import cn.enaium.joe.jar.Jar; 21 | import cn.enaium.joe.util.ColorUtil; 22 | import cn.enaium.joe.util.HtmlUtil; 23 | import cn.enaium.joe.util.StringUtil; 24 | import org.objectweb.asm.tree.FieldInsnNode; 25 | 26 | import java.awt.*; 27 | import java.util.ArrayList; 28 | import java.util.List; 29 | 30 | /** 31 | * @author Enaium 32 | * @since 0.10.0 33 | */ 34 | public class SearchFieldTask extends SearchInstructionTask> { 35 | 36 | private final String owner; 37 | private final String name; 38 | private final String description; 39 | 40 | 41 | public SearchFieldTask(Jar jar, String owner, String name, String description) { 42 | super("SearchField", jar); 43 | this.owner = owner; 44 | this.name = name; 45 | this.description = description; 46 | } 47 | 48 | @Override 49 | public List get() { 50 | List resultNodes = new ArrayList<>(); 51 | searchInstruction((classNode, instruction) -> { 52 | if (instruction instanceof FieldInsnNode) { 53 | FieldInsnNode fieldInsnNode = (FieldInsnNode) instruction; 54 | if ((fieldInsnNode.owner.contains(owner) || StringUtil.isBlank(owner)) && 55 | (fieldInsnNode.name.contains(name) || StringUtil.isBlank(name)) && 56 | (fieldInsnNode.desc.contains(description) || StringUtil.isBlank(description)) 57 | ) { 58 | resultNodes.add(new ResultNode(classNode, HtmlUtil.setColor(fieldInsnNode.name, ColorUtil.name) + HtmlUtil.setColor(":", ColorUtil.opcode) + HtmlUtil.setColor(fieldInsnNode.desc, ColorUtil.desc))); 59 | } 60 | } 61 | }); 62 | return resultNodes; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/task/SearchInstructionTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.task; 18 | 19 | import cn.enaium.joe.jar.Jar; 20 | import org.objectweb.asm.tree.AbstractInsnNode; 21 | import org.objectweb.asm.tree.ClassNode; 22 | import org.objectweb.asm.tree.MethodNode; 23 | 24 | import java.util.Map; 25 | import java.util.function.BiConsumer; 26 | 27 | /** 28 | * @author Enaium 29 | * @since 0.10.0 30 | */ 31 | public abstract class SearchInstructionTask extends AbstractTask { 32 | 33 | private final Jar jar; 34 | 35 | public SearchInstructionTask(String name, Jar jar) { 36 | super(name); 37 | this.jar = jar; 38 | } 39 | 40 | public void searchInstruction(BiConsumer consumer) { 41 | float loaded = 0; 42 | float total = 0; 43 | for (Map.Entry stringClassNodeEntry : jar.classes.entrySet()) { 44 | for (MethodNode method : stringClassNodeEntry.getValue().methods) { 45 | total += method.instructions.size(); 46 | } 47 | } 48 | 49 | for (Map.Entry stringClassNodeEntry : jar.classes.entrySet()) { 50 | for (MethodNode method : stringClassNodeEntry.getValue().methods) { 51 | for (AbstractInsnNode instruction : method.instructions) { 52 | consumer.accept(stringClassNodeEntry.getValue(), instruction); 53 | setProgress((int) ((loaded++ / total) * 100f)); 54 | } 55 | } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/task/SearchLdcTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.task; 18 | 19 | import cn.enaium.joe.gui.panel.search.ResultNode; 20 | import cn.enaium.joe.jar.Jar; 21 | import cn.enaium.joe.util.ColorUtil; 22 | import cn.enaium.joe.util.HtmlUtil; 23 | import org.objectweb.asm.tree.LdcInsnNode; 24 | 25 | import javax.swing.*; 26 | import java.util.ArrayList; 27 | import java.util.List; 28 | 29 | /** 30 | * @author Enaium 31 | * @since 0.10.0 32 | */ 33 | public class SearchLdcTask extends SearchInstructionTask> { 34 | 35 | private final Object ldc; 36 | 37 | public SearchLdcTask(Jar jar, Object ldc) { 38 | super("SearchLdc", jar); 39 | this.ldc = ldc; 40 | } 41 | 42 | @Override 43 | public List get() { 44 | List resultNodes = new ArrayList<>(); 45 | searchInstruction((classNode, instruction) -> { 46 | if (instruction instanceof LdcInsnNode) { 47 | String ldc = ((LdcInsnNode) instruction).cst.toString(); 48 | if (ldc.contains(this.ldc.toString())) { 49 | resultNodes.add(new ResultNode(classNode, HtmlUtil.setColor(ldc, ColorUtil.string))); 50 | } 51 | } 52 | }); 53 | return resultNodes; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/task/TaskManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.task; 18 | 19 | import cn.enaium.joe.annotation.Repeatable; 20 | import cn.enaium.joe.util.MessageUtil; 21 | import cn.enaium.joe.util.Pair; 22 | 23 | import java.util.ArrayList; 24 | import java.util.HashMap; 25 | import java.util.List; 26 | import java.util.Map; 27 | import java.util.concurrent.CompletableFuture; 28 | import java.util.concurrent.ExecutorService; 29 | import java.util.concurrent.Executors; 30 | import java.util.logging.Logger; 31 | 32 | /** 33 | * @author Enaium 34 | * @since 0.10.0 35 | */ 36 | public class TaskManager { 37 | private final ExecutorService executorService = Executors.newCachedThreadPool(); 38 | private final List, CompletableFuture>> task = new ArrayList<>(); 39 | 40 | public CompletableFuture submit(AbstractTask abstractTask) { 41 | for (Pair, CompletableFuture> classCompletableFuturePair : task) { 42 | if (classCompletableFuturePair.getKey().getClass().equals(abstractTask.getClass()) && !classCompletableFuturePair.getKey().getClass().isAnnotationPresent(Repeatable.class)) { 43 | MessageUtil.warning("task already exists"); 44 | throw new RuntimeException("task already exists"); 45 | } 46 | } 47 | CompletableFuture completableFuture = CompletableFuture.supplyAsync(abstractTask, executorService); 48 | completableFuture.whenComplete((t, throwable) -> { 49 | task.removeIf(it -> it.getValue().isDone()); 50 | if (throwable != null) { 51 | MessageUtil.error(throwable); 52 | } 53 | }); 54 | 55 | task.add(new Pair<>(abstractTask, completableFuture)); 56 | return completableFuture; 57 | } 58 | 59 | public List, CompletableFuture>> getTask() { 60 | return task; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/util/ASMUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.util; 18 | 19 | import org.objectweb.asm.ClassReader; 20 | import org.objectweb.asm.Type; 21 | import org.objectweb.asm.tree.ClassNode; 22 | 23 | import java.lang.reflect.InvocationTargetException; 24 | import java.lang.reflect.Method; 25 | import java.util.HashSet; 26 | import java.util.Set; 27 | 28 | /** 29 | * @author Enaium 30 | * @since 1.2.0 31 | */ 32 | public class ASMUtil { 33 | public static Object toType(Class type, String text) { 34 | try { 35 | Method valueOf = type.getMethod("valueOf", String.class); 36 | return valueOf.invoke(null, text); 37 | } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { 38 | if (type == Type.class) { 39 | return Type.getType(text); 40 | } else { 41 | return text; 42 | } 43 | } 44 | } 45 | 46 | public static ClassNode acceptClassNode(ClassReader classReader) { 47 | ClassNode classNode = new ClassNode(); 48 | try { 49 | classReader.accept(classNode, ClassReader.EXPAND_FRAMES); 50 | } catch (Throwable throwable) { 51 | try { 52 | classReader.accept(classNode, ClassReader.SKIP_FRAMES | ClassReader.SKIP_DEBUG); 53 | } catch (Throwable ignored) { 54 | 55 | } 56 | } 57 | return classNode; 58 | } 59 | 60 | public static Set getParentClass(ClassNode classNode) { 61 | Set parent = new HashSet<>(); 62 | if (classNode.superName != null && !classNode.superName.equals(Object.class.getName().replace(".", "/"))) { 63 | parent.add(classNode.superName); 64 | } 65 | parent.addAll(classNode.interfaces); 66 | return parent; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/util/ASyncUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.util; 18 | 19 | import javax.swing.*; 20 | import java.util.concurrent.ExecutorService; 21 | import java.util.concurrent.Executors; 22 | 23 | /** 24 | * @author Enaium 25 | */ 26 | public class ASyncUtil { 27 | 28 | public static void execute(Runnable run) { 29 | execute(run, null); 30 | } 31 | 32 | public static void execute(Runnable run, Runnable ui) { 33 | ExecutorService executorService = Executors.newSingleThreadExecutor(); 34 | executorService.execute(() -> { 35 | run.run(); 36 | if (ui != null) { 37 | SwingUtilities.invokeLater(ui); 38 | } 39 | }); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/util/ColorUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.util; 18 | 19 | import java.awt.*; 20 | 21 | /** 22 | * @author Enaium 23 | * @since 0.10.0 24 | */ 25 | public interface ColorUtil { 26 | Color opcode = new Color(196, 118, 215); 27 | Color name = new Color(222, 107, 116); 28 | Color desc = new Color(227, 191, 122); 29 | Color base = new Color(208, 153, 102); 30 | Color string = new Color(150, 193, 115); 31 | Color bool = new Color(196, 118, 215); 32 | Color other = new Color(62, 137, 236); 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/util/HtmlUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.util; 18 | 19 | import java.awt.*; 20 | import java.util.regex.Matcher; 21 | import java.util.regex.Pattern; 22 | 23 | /** 24 | * @author Enaium 25 | * @since 0.5.0 26 | */ 27 | public class HtmlUtil { 28 | public static String toHtml(String text) { 29 | return String.format("%s", text); 30 | } 31 | 32 | public static String setColor(String text, Color color) { 33 | return String.format("%s", color.getRed(), color.getGreen(), color.getBlue(), text); 34 | } 35 | 36 | public static String remove(String text) { 37 | return text.replaceAll("<[^>]+>",""); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/util/IOUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.util; 18 | 19 | import javax.imageio.ImageIO; 20 | import javax.swing.*; 21 | import java.awt.image.BufferedImage; 22 | import java.io.ByteArrayInputStream; 23 | import java.io.ByteArrayOutputStream; 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | import java.nio.charset.StandardCharsets; 27 | 28 | /** 29 | * @author Enaium 30 | * @since 0.9.0 31 | */ 32 | public class IOUtil { 33 | public static String getString(InputStream inputStream) throws IOException { 34 | return new String(getBytes(inputStream), StandardCharsets.UTF_8); 35 | } 36 | 37 | public static byte[] getBytes(InputStream inputStream) throws IOException { 38 | ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream(); 39 | byte[] buffer = new byte[1024 * 4]; 40 | int n; 41 | while (-1 != (n = inputStream.read(buffer))) { 42 | byteOutputStream.write(buffer, 0, n); 43 | } 44 | inputStream.close(); 45 | return byteOutputStream.toByteArray(); 46 | } 47 | 48 | public static Icon getIcon(byte[] data) throws IOException { 49 | return new ImageIcon(ImageIO.read(new ByteArrayInputStream(data))); 50 | } 51 | 52 | public static boolean isImage(byte[] data) { 53 | ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(data); 54 | try { 55 | BufferedImage read = ImageIO.read(byteArrayInputStream); 56 | return read != null; 57 | } catch (Throwable ignore) { 58 | return false; 59 | } finally { 60 | try { 61 | byteArrayInputStream.close(); 62 | } catch (IOException e) { 63 | MessageUtil.error(e); 64 | } 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/util/JMenuUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.util; 18 | 19 | import javax.swing.*; 20 | import java.awt.*; 21 | import java.awt.event.MouseAdapter; 22 | import java.awt.event.MouseEvent; 23 | import java.util.function.Supplier; 24 | 25 | /** 26 | * @author Enaium 27 | * @since 1.2.0 28 | */ 29 | public class JMenuUtil { 30 | public static void addPopupMenu(Component component, Supplier popupMenu, Supplier show) { 31 | component.addMouseListener(new MouseAdapter() { 32 | @Override 33 | public void mouseClicked(MouseEvent e) { 34 | if (SwingUtilities.isRightMouseButton(e) && show.get()) { 35 | popupMenu.get().show(component, e.getX(), e.getY()); 36 | } 37 | } 38 | }); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/util/JTreeUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.util; 18 | 19 | import cn.enaium.joe.gui.panel.file.tree.node.ClassTreeNode; 20 | import cn.enaium.joe.gui.panel.file.tree.node.PackageTreeNode; 21 | 22 | import javax.swing.*; 23 | import javax.swing.tree.DefaultMutableTreeNode; 24 | import javax.swing.tree.TreeNode; 25 | import javax.swing.tree.TreePath; 26 | import java.util.Enumeration; 27 | 28 | public class JTreeUtil { 29 | public static void setTreeExpandedState(JTree tree, boolean expanded) { 30 | DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getModel().getRoot(); 31 | setNodeExpandedState(tree, node, expanded); 32 | } 33 | 34 | public static void setNodeExpandedState(JTree tree, DefaultMutableTreeNode node, boolean expanded) { 35 | Enumeration children = node.children(); 36 | while (children.hasMoreElements()) { 37 | setNodeExpandedState(tree, (DefaultMutableTreeNode) children.nextElement(), expanded); 38 | } 39 | 40 | if (!expanded && node.isRoot()) { 41 | return; 42 | } 43 | TreePath path = new TreePath(node.getPath()); 44 | if (expanded) { 45 | tree.expandPath(path); 46 | } else { 47 | tree.collapsePath(path); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/util/KeyStrokeUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.util; 18 | 19 | import javax.swing.*; 20 | import java.awt.event.ActionEvent; 21 | import java.awt.event.InputEvent; 22 | import java.awt.event.KeyEvent; 23 | import java.util.concurrent.atomic.AtomicInteger; 24 | 25 | /** 26 | * @author Enaium 27 | * @since 1.0.0 28 | */ 29 | public class KeyStrokeUtil { 30 | 31 | private static final AtomicInteger ATOMIC_INTEGER = new AtomicInteger(0); 32 | 33 | public static void register(JComponent component, KeyStroke keyStroke, Runnable action) { 34 | String key = String.valueOf(ATOMIC_INTEGER.incrementAndGet()); 35 | InputMap inputMap = component.getInputMap(JComponent.WHEN_FOCUSED); 36 | inputMap.put(keyStroke, key); 37 | ActionMap actionMap = component.getActionMap(); 38 | actionMap.put(key, new AbstractAction() { 39 | @Override 40 | public void actionPerformed(ActionEvent e) { 41 | action.run(); 42 | } 43 | }); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/util/ListUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.util; 18 | 19 | import java.util.List; 20 | 21 | /** 22 | * @author Enaium 23 | * @since 1.2.0 24 | */ 25 | public class ListUtil { 26 | public static Class getType(List list) { 27 | return list.get(0).getClass(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/util/Pair.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.util; 18 | 19 | import java.util.Objects; 20 | 21 | /** 22 | * @author Enaium 23 | * @since 1.0.0 24 | */ 25 | public class Pair { 26 | private K key; 27 | private V value; 28 | 29 | public Pair(K key, V value) { 30 | this.key = key; 31 | this.value = value; 32 | } 33 | 34 | public K getKey() { 35 | return key; 36 | } 37 | 38 | public void setKey(K key) { 39 | this.key = key; 40 | } 41 | 42 | public V getValue() { 43 | return value; 44 | } 45 | 46 | public void setValue(V value) { 47 | this.value = value; 48 | } 49 | 50 | @Override 51 | public boolean equals(Object o) { 52 | if (this == o) return true; 53 | if (o == null || getClass() != o.getClass()) return false; 54 | Pair pair = (Pair) o; 55 | return Objects.equals(key, pair.key) && Objects.equals(value, pair.value); 56 | } 57 | 58 | @Override 59 | public int hashCode() { 60 | return Objects.hash(key, value); 61 | } 62 | 63 | @Override 64 | public String toString() { 65 | return "Pair{" + 66 | "key=" + key + 67 | ", value=" + value + 68 | '}'; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/util/ReflectUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.util; 18 | 19 | import java.lang.reflect.Field; 20 | import java.lang.reflect.Method; 21 | 22 | /** 23 | * @author Enaium 24 | * @since 1.0.0 25 | */ 26 | public class ReflectUtil { 27 | public static void setAll(T old, T t) throws NoSuchFieldException, IllegalAccessException { 28 | for (Field oldField : old.getClass().getDeclaredFields()) { 29 | oldField.setAccessible(true); 30 | Field declaredField = t.getClass().getDeclaredField(oldField.getName()); 31 | oldField.set(old, declaredField.get(t)); 32 | } 33 | } 34 | 35 | public static Field getField(Class klass, String name) throws NoSuchFieldException { 36 | Field declaredField = klass.getDeclaredField(name); 37 | declaredField.setAccessible(true); 38 | return declaredField; 39 | } 40 | 41 | public static Method getMethod(Class klass, String name, Class... parameterTypes) throws NoSuchMethodException { 42 | Method declaredMethod = klass.getDeclaredMethod(name, parameterTypes); 43 | declaredMethod.setAccessible(true); 44 | return declaredMethod; 45 | } 46 | 47 | @SuppressWarnings("unchecked") 48 | public static T getFieldValue(Object o, String name) throws IllegalAccessException, NoSuchFieldException { 49 | return (T) getField(o.getClass(), name).get(o); 50 | } 51 | 52 | public static boolean classHas(String name) { 53 | try { 54 | Class.forName(name); 55 | } catch (ClassNotFoundException e) { 56 | return false; 57 | } 58 | return true; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/util/StringUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.util; 18 | 19 | /** 20 | * @author Enaium 21 | * @since 0.5.0 22 | */ 23 | public class StringUtil { 24 | public static boolean isBlank(String string) { 25 | if (string == null) { 26 | return true; 27 | } 28 | return string.replace(" ", "").isEmpty(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/util/TinyLogPrintStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.util; 18 | 19 | import org.pmw.tinylog.Logger; 20 | 21 | import java.io.OutputStream; 22 | import java.io.PrintStream; 23 | 24 | /** 25 | * @author Enaium 26 | * @since 1.3.0 27 | */ 28 | public class TinyLogPrintStream extends PrintStream { 29 | 30 | private final Type type; 31 | 32 | public TinyLogPrintStream(OutputStream out, Type type) { 33 | super(out); 34 | this.type = type; 35 | } 36 | 37 | @Override 38 | public void println(String x) { 39 | log(x); 40 | } 41 | 42 | @Override 43 | public void println(Object x) { 44 | log(String.valueOf(x)); 45 | } 46 | 47 | private void log(String log) { 48 | if (type == Type.STDOUT) { 49 | Logger.info(log); 50 | } else if (type == Type.STDERR) { 51 | Logger.error(log); 52 | } 53 | } 54 | 55 | public enum Type { 56 | STDOUT, STDERR 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/util/Util.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.util; 18 | 19 | import java.util.Enumeration; 20 | import java.util.jar.JarEntry; 21 | import java.util.jar.JarFile; 22 | 23 | /** 24 | * @author Enaium 25 | */ 26 | public class Util { 27 | public static int countFiles(JarFile zipFile) { 28 | final Enumeration entries = zipFile.entries(); 29 | int c = 0; 30 | while (entries.hasMoreElements()) { 31 | entries.nextElement(); 32 | ++c; 33 | } 34 | return c; 35 | } 36 | 37 | public static boolean isText(byte[] bytes) { 38 | int total = bytes.length; 39 | if (total >= 8000) { 40 | total = 8000; 41 | } 42 | for (int i = 0; i < total; i++) { 43 | if (((char) bytes[i]) == '\0') { 44 | return false; 45 | } 46 | } 47 | return true; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/wrapper/LabelNodeWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.wrapper; 18 | 19 | import cn.enaium.joe.util.OpcodeUtil; 20 | import org.objectweb.asm.tree.LabelNode; 21 | 22 | /** 23 | * @author Enaium 24 | * @since 0.8.0 25 | */ 26 | public class LabelNodeWrapper extends Wrapper { 27 | public LabelNodeWrapper(LabelNode wrapper) { 28 | super(wrapper); 29 | } 30 | 31 | @Override 32 | public String toString() { 33 | return "L " + OpcodeUtil.getLabelIndex(getWrapper()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/wrapper/ObjectWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.wrapper; 18 | 19 | import org.objectweb.asm.Type; 20 | import org.objectweb.asm.tree.AnnotationNode; 21 | 22 | import java.util.ArrayList; 23 | import java.util.Arrays; 24 | import java.util.stream.Collectors; 25 | 26 | /** 27 | * @author Enaium 28 | * @since 1.2.0 29 | */ 30 | public class ObjectWrapper extends Wrapper { 31 | public ObjectWrapper(Object wrapper) { 32 | super(wrapper); 33 | } 34 | 35 | @Override 36 | public String toString() { 37 | if (getWrapper() instanceof AnnotationNode) { 38 | return ((AnnotationNode) getWrapper()).desc; 39 | } else if (getWrapper() instanceof ArrayList) { 40 | return ((ArrayList) getWrapper()).stream().map(it -> new ObjectWrapper(it).toString()).collect(Collectors.toList()).toString(); 41 | } else if (getWrapper() instanceof Object[]) { 42 | return Arrays.toString(((Object[]) getWrapper())); 43 | } else if (getWrapper() instanceof Type) { 44 | return ((Type) getWrapper()).toString(); 45 | } 46 | return getWrapper().toString(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/cn/enaium/joe/wrapper/Wrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.wrapper; 18 | 19 | /** 20 | * @author Enaium 21 | * @since 0.8.0 22 | */ 23 | public class Wrapper { 24 | 25 | private T wrapper; 26 | 27 | public Wrapper(T wrapper) { 28 | this.wrapper = wrapper; 29 | } 30 | 31 | public T getWrapper() { 32 | return wrapper; 33 | } 34 | 35 | public void setWrapper(T wrapper) { 36 | this.wrapper = wrapper; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/resources/icons/abstractClass.svg: -------------------------------------------------------------------------------- 1 | 26 | 27 | 29 | 31 | 32 | -------------------------------------------------------------------------------- /src/main/resources/icons/annotation.svg: -------------------------------------------------------------------------------- 1 | 26 | 27 | 28 | 30 | 32 | 33 | -------------------------------------------------------------------------------- /src/main/resources/icons/biliBili.svg: -------------------------------------------------------------------------------- 1 | Bilibili -------------------------------------------------------------------------------- /src/main/resources/icons/class.svg: -------------------------------------------------------------------------------- 1 | 26 | 27 | 28 | 30 | 32 | 33 | -------------------------------------------------------------------------------- /src/main/resources/icons/classesRoot.svg: -------------------------------------------------------------------------------- 1 | 26 | 27 | 29 | 31 | 34 | 35 | -------------------------------------------------------------------------------- /src/main/resources/icons/cyan_dot.svg: -------------------------------------------------------------------------------- 1 | 26 | 27 | 28 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/main/resources/icons/enum.svg: -------------------------------------------------------------------------------- 1 | 26 | 27 | 28 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/main/resources/icons/field.svg: -------------------------------------------------------------------------------- 1 | 26 | 27 | 28 | 30 | 32 | 33 | -------------------------------------------------------------------------------- /src/main/resources/icons/file.svg: -------------------------------------------------------------------------------- 1 | 26 | 27 | 28 | 29 | 31 | 32 | -------------------------------------------------------------------------------- /src/main/resources/icons/folder.svg: -------------------------------------------------------------------------------- 1 | 26 | 27 | 28 | 30 | 32 | 33 | -------------------------------------------------------------------------------- /src/main/resources/icons/github.svg: -------------------------------------------------------------------------------- 1 | GitHub -------------------------------------------------------------------------------- /src/main/resources/icons/hierarchy.svg: -------------------------------------------------------------------------------- 1 | 26 | 27 | 28 | 29 | 31 | 32 | -------------------------------------------------------------------------------- /src/main/resources/icons/inherit.svg: -------------------------------------------------------------------------------- 1 | 26 | 27 | 28 | 30 | 31 | -------------------------------------------------------------------------------- /src/main/resources/icons/interface.svg: -------------------------------------------------------------------------------- 1 | 26 | 27 | 28 | 30 | 32 | 33 | -------------------------------------------------------------------------------- /src/main/resources/icons/jar.svg: -------------------------------------------------------------------------------- 1 | 26 | 27 | 28 | 30 | 32 | 33 | -------------------------------------------------------------------------------- /src/main/resources/icons/kook.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 10 | 12 | 14 | 16 | 18 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/main/resources/icons/logo.svg: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/main/resources/icons/method.svg: -------------------------------------------------------------------------------- 1 | 26 | 27 | 28 | 30 | 32 | 35 | 36 | -------------------------------------------------------------------------------- /src/main/resources/icons/minimize.svg: -------------------------------------------------------------------------------- 1 | 26 | 27 | 28 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/main/resources/icons/openjdk.svg: -------------------------------------------------------------------------------- 1 | OpenJDK -------------------------------------------------------------------------------- /src/main/resources/icons/package.svg: -------------------------------------------------------------------------------- 1 | 26 | 27 | 28 | 29 | 30 | 33 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/main/resources/icons/private.svg: -------------------------------------------------------------------------------- 1 | 26 | 27 | 28 | 30 | 32 | 33 | -------------------------------------------------------------------------------- /src/main/resources/icons/protected.svg: -------------------------------------------------------------------------------- 1 | 26 | 27 | 28 | 30 | 32 | 33 | -------------------------------------------------------------------------------- /src/main/resources/icons/public.svg: -------------------------------------------------------------------------------- 1 | 26 | 27 | 28 | 30 | 32 | 33 | -------------------------------------------------------------------------------- /src/main/resources/icons/resourceRoot.svg: -------------------------------------------------------------------------------- 1 | 26 | 27 | 29 | 31 | 34 | 35 | -------------------------------------------------------------------------------- /src/main/resources/icons/static.svg: -------------------------------------------------------------------------------- 1 | 26 | 27 | 28 | 30 | 32 | 33 | -------------------------------------------------------------------------------- /src/main/resources/icons/structure.svg: -------------------------------------------------------------------------------- 1 | 26 | 27 | 28 | 29 | 31 | 32 | -------------------------------------------------------------------------------- /src/test/java/cn/enaium/joe/asm/GenerateInstructionTypeSwitchTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.asm; 18 | 19 | import org.junit.jupiter.api.Test; 20 | import org.objectweb.asm.tree.AbstractInsnNode; 21 | 22 | import java.lang.reflect.Field; 23 | 24 | /** 25 | * @author Enaium 26 | */ 27 | class GenerateInstructionTypeSwitchTest { 28 | @Test 29 | public void test() { 30 | StringBuilder stringBuilder = new StringBuilder(); 31 | stringBuilder.append("switch (i) {").append("\n"); 32 | for (Field field : AbstractInsnNode.class.getFields()) { 33 | stringBuilder.append(String.format("case AbstractInsnNode.%s: break;", field.getName())); 34 | } 35 | stringBuilder.append("}"); 36 | System.out.println(stringBuilder); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/cn/enaium/joe/asm/GenerateOpcodeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Enaium 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.enaium.joe.asm; 18 | 19 | import org.junit.jupiter.api.Test; 20 | import org.objectweb.asm.Opcodes; 21 | 22 | import java.lang.reflect.Field; 23 | 24 | /** 25 | * @author Enaium 26 | */ 27 | public class GenerateOpcodeTest { 28 | @Test 29 | public void map() { 30 | for (Field field : Opcodes.class.getFields()) { 31 | System.out.println("put(Opcodes." + field.getName() + "," + "\"" + field.getName() + "\");"); 32 | } 33 | } 34 | 35 | @Test 36 | public void list() { 37 | for (Field field : Opcodes.class.getFields()) { 38 | System.out.println("add(\"" + field.getName() + "\");"); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/cn/enaium/joe/asm/VisitorTest.java: -------------------------------------------------------------------------------- 1 | package cn.enaium.joe.asm; 2 | 3 | import javassist.*; 4 | import org.junit.jupiter.api.Test; 5 | import org.objectweb.asm.ClassReader; 6 | import org.objectweb.asm.util.ASMifier; 7 | import org.objectweb.asm.util.TraceClassVisitor; 8 | 9 | import java.io.*; 10 | import java.lang.reflect.InvocationTargetException; 11 | 12 | /** 13 | * @author Enaium 14 | */ 15 | class VisitorTest { 16 | @Test 17 | public void test() throws IOException, CannotCompileException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, NotFoundException { 18 | StringWriter stringWriter = new StringWriter(); 19 | ClassReader classReader = new ClassReader(this.getClass().getName()); 20 | classReader.accept(new TraceClassVisitor(null, new ASMifier(), new PrintWriter(stringWriter)), 0); 21 | ClassPool classPool = ClassPool.getDefault(); 22 | classPool.importPackage("org.objectweb.asm.AnnotationVisitor"); 23 | classPool.importPackage("org.objectweb.asm.Attribute"); 24 | classPool.importPackage("org.objectweb.asm.ClassReader"); 25 | classPool.importPackage("org.objectweb.asm.ClassWriter"); 26 | classPool.importPackage("org.objectweb.asm.ConstantDynamic"); 27 | classPool.importPackage("org.objectweb.asm.FieldVisitor"); 28 | classPool.importPackage("org.objectweb.asm.Handle"); 29 | classPool.importPackage("org.objectweb.asm.Label"); 30 | classPool.importPackage("org.objectweb.asm.MethodVisitor"); 31 | classPool.importPackage("org.objectweb.asm.Opcodes"); 32 | classPool.importPackage("org.objectweb.asm.RecordComponentVisitor"); 33 | classPool.importPackage("org.objectweb.asm.Type"); 34 | classPool.importPackage("org.objectweb.asm.TypePath"); 35 | CtClass ctClass = classPool.makeClass(ASMifier.class.getSimpleName()); 36 | ctClass.addInterface(classPool.get("org.objectweb.asm.Opcodes")); 37 | String substring = stringWriter.toString().substring(stringWriter.toString().indexOf("{") + 1, stringWriter.toString().lastIndexOf("}")); 38 | ctClass.addMethod(CtMethod.make(substring, ctClass)); 39 | System.out.println(ctClass.toClass().getMethod("dump").invoke(null)); 40 | } 41 | } --------------------------------------------------------------------------------