Skip to content
This repository was archived by the owner on Jan 2, 2023. It is now read-only.

Commit f1e4fc8

Browse files
authored
Merge pull request #17 from Enaium/develop
Develop
2 parents cbe8fd2 + 19f31a1 commit f1e4fc8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1380
-658
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
# JavaOctetEditor
22

3-
![](https://user-images.githubusercontent.com/32991121/188775455-da15ea74-dac0-4982-bc4e-a5794b339ad3.png)
4-
![](https://user-images.githubusercontent.com/32991121/188775462-2bedb357-7c3a-4212-a652-5a4e53f583e6.png)
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)

build.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88
}
99

1010
group 'cn.enaium'
11-
version '1.2.0'
11+
version '1.3.0'
1212

1313
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8
1414

@@ -41,6 +41,8 @@ dependencies {
4141

4242
implementation 'com.formdev:flatlaf:2.4'
4343
implementation 'com.formdev:flatlaf-extras:2.4'
44+
//noinspection GradlePackageUpdate
45+
implementation 'com.miglayout:miglayout-swing:5.3'
4446
implementation 'com.github.bobbylight:RSyntaxTextArea:3.2.0'
4547
implementation 'org.ow2.asm:asm-tree:9.3'
4648
implementation 'org.ow2.asm:asm-util:9.3'
@@ -53,7 +55,7 @@ dependencies {
5355
implementation 'org.tinylog:tinylog:1.3.6'
5456
implementation 'com.github.FabricMC:mapping-io:597f0722d6'
5557

56-
compileOnly files(Jvm.current().getToolsJar())
58+
compileOnly files(Jvm.current().getToolsJar())//Must use jdk8
5759
}
5860

5961
test {
@@ -63,6 +65,7 @@ test {
6365
shadowJar {
6466
dependencies {
6567
include(dependency('com.formdev:.*'))
68+
include(dependency('com.miglayout:.*'))
6669
include(dependency('com.github.bobbylight:RSyntaxTextArea'))
6770
include(dependency('org.ow2.asm:.*'))
6871
include(dependency('org.benf:cfr'))

src/main/java/cn/enaium/joe/JavaOctetEditor.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@
1919
import cn.enaium.joe.config.ConfigManager;
2020
import cn.enaium.joe.event.EventManager;
2121
import cn.enaium.joe.gui.panel.BottomPanel;
22-
import cn.enaium.joe.gui.panel.file.tree.FileTreePanel;
23-
import cn.enaium.joe.gui.panel.LeftPanel;
22+
import cn.enaium.joe.gui.panel.file.tree.CenterPanel;
2423
import cn.enaium.joe.gui.panel.file.tabbed.FileTabbedPanel;
2524
import cn.enaium.joe.gui.component.FileTree;
2625
import cn.enaium.joe.gui.panel.menu.*;
2726
import cn.enaium.joe.jar.Jar;
2827
import cn.enaium.joe.task.TaskManager;
29-
import cn.enaium.joe.util.KeyStrokeUtil;
28+
import cn.enaium.joe.util.BytecodeTokenMaker;
3029
import cn.enaium.joe.util.LangUtil;
3130
import cn.enaium.joe.util.MessageUtil;
3231
import cn.enaium.joe.util.ReflectUtil;
32+
import com.formdev.flatlaf.extras.FlatSVGIcon;
3333
import org.fife.ui.rsyntaxtextarea.AbstractTokenMakerFactory;
3434
import org.fife.ui.rsyntaxtextarea.TokenMakerFactory;
3535

@@ -81,6 +81,8 @@ public void run() {
8181
AbstractTokenMakerFactory abstractTokenMakerFactory = (AbstractTokenMakerFactory) TokenMakerFactory.getDefaultInstance();
8282
abstractTokenMakerFactory.putMapping("text/custom", BytecodeTokenMaker.class.getName());
8383

84+
window.setIconImage(new FlatSVGIcon("icons/logo.svg").getImage());
85+
8486
window.setJMenuBar(new JMenuBar() {{
8587
add(new FileMenu());
8688
add(new SearchMenu());
@@ -97,11 +99,7 @@ public void run() {
9799
}});
98100

99101
window.setContentPane(new JPanel(new BorderLayout()) {{
100-
add(new LeftPanel(), BorderLayout.WEST);
101-
add(new JSplitPane() {{
102-
setLeftComponent(new FileTreePanel());
103-
setRightComponent(fileTabbedPanel);
104-
}}, BorderLayout.CENTER);
102+
add(new CenterPanel(), BorderLayout.CENTER);
105103
add(bottomPanel, BorderLayout.SOUTH);
106104
}});
107105

src/main/java/cn/enaium/joe/Main.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import cn.enaium.joe.util.IOUtil;
2121
import cn.enaium.joe.util.MessageUtil;
2222
import cn.enaium.joe.util.ReflectUtil;
23+
import cn.enaium.joe.util.TinyLogPrintStream;
2324
import com.formdev.flatlaf.FlatDarkLaf;
2425
import org.objectweb.asm.ClassReader;
2526
import org.objectweb.asm.tree.ClassNode;
@@ -28,7 +29,7 @@
2829
import org.pmw.tinylog.writers.ConsoleWriter;
2930
import org.pmw.tinylog.writers.FileWriter;
3031

31-
import java.io.File;
32+
import javax.swing.*;
3233
import java.io.IOException;
3334
import java.lang.instrument.Instrumentation;
3435
import java.lang.reflect.InvocationTargetException;
@@ -41,6 +42,9 @@
4142
import java.nio.file.Paths;
4243
import java.util.Objects;
4344

45+
import static cn.enaium.joe.util.TinyLogPrintStream.Type.STDERR;
46+
import static cn.enaium.joe.util.TinyLogPrintStream.Type.STDOUT;
47+
4448
/**
4549
* @author Enaium
4650
*/
@@ -72,9 +76,12 @@ private static void agent(Instrumentation inst) throws IOException {
7276

7377
private static void launch() {
7478
Configurator.currentConfig().writer(new ConsoleWriter(), "[{date: HH:mm:ss.SSS}] {level} > {message}").addWriter(new FileWriter("latest.log"), "[{date: HH:mm:ss.SSS}] {level} > {message}").activate();
79+
System.setOut(new TinyLogPrintStream(System.out, STDOUT));
80+
System.setErr(new TinyLogPrintStream(System.err, STDERR));
7581

7682
Logger.info("DIR:{}", System.getProperty("user.dir"));
7783
FlatDarkLaf.setup();
84+
UIManager.put("Tree.paintLines", true);
7885
new JavaOctetEditor().run();
7986
}
8087

src/main/java/cn/enaium/joe/dialog/AboutDialog.java

Lines changed: 31 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,61 +18,49 @@
1818

1919
import cn.enaium.joe.util.LangUtil;
2020
import cn.enaium.joe.util.ReflectUtil;
21+
import net.miginfocom.swing.MigLayout;
2122

2223
import javax.swing.*;
2324
import javax.swing.border.EmptyBorder;
2425
import javax.tools.ToolProvider;
25-
import java.awt.*;
2626

2727
/**
2828
* @author Enaium
2929
*/
3030
public class AboutDialog extends Dialog {
3131
public AboutDialog() {
3232
super(LangUtil.i18n("menu.help.about"));
33-
setContentPane(new JPanel(new GridLayout(2, 0)) {{
33+
setContentPane(new JPanel(new MigLayout("fillx", "[fill][fill]")) {{
3434
setBorder(new EmptyBorder(10, 10, 10, 10));
35-
add(new JPanel(new GridLayout(5, 0)) {{
36-
add(new JLabel(LangUtil.i18n("about.system")));
37-
add(new JLabel(LangUtil.i18n("about.system.description")));
38-
add(new JPanel(new BorderLayout()) {{
39-
add(new JLabel(LangUtil.i18n("about.system.name")), BorderLayout.WEST);
40-
add(new JLabel(System.getProperty("os.name")), BorderLayout.EAST);
41-
}});
42-
add(new JPanel(new BorderLayout()) {{
43-
add(new JLabel(LangUtil.i18n("about.system.architecture")), BorderLayout.WEST);
44-
add(new JLabel(System.getProperty("os.arch")), BorderLayout.EAST);
45-
}});
46-
add(new JSeparator());
47-
}});
48-
add(new JPanel(new GridLayout(8, 0)) {{
49-
add(new JLabel(LangUtil.i18n("about.java")));
50-
add(new JLabel(LangUtil.i18n("about.java.description")));
51-
add(new JPanel(new BorderLayout()) {{
52-
add(new JLabel(LangUtil.i18n("about.java.version")), BorderLayout.WEST);
53-
add(new JLabel(System.getProperty("java.version")), BorderLayout.EAST);
54-
}});
55-
add(new JPanel(new BorderLayout()) {{
56-
add(new JLabel(LangUtil.i18n("about.java.vm.name")), BorderLayout.WEST);
57-
add(new JLabel(System.getProperty("java.vm.name")), BorderLayout.EAST);
58-
}});
59-
add(new JPanel(new BorderLayout()) {{
60-
add(new JLabel(LangUtil.i18n("about.java.vm.vendor")), BorderLayout.WEST);
61-
add(new JLabel(System.getProperty("java.vm.vendor")), BorderLayout.EAST);
62-
}});
63-
add(new JPanel(new BorderLayout()) {{
64-
add(new JLabel(LangUtil.i18n("about.java.home")), BorderLayout.WEST);
65-
add(new JLabel(System.getProperty("java.home")), BorderLayout.EAST);
66-
}});
67-
add(new JPanel(new BorderLayout()) {{
68-
add(new JLabel(LangUtil.i18n("about.java.supportCompiler")), BorderLayout.WEST);
69-
add(new JLabel(String.valueOf(ToolProvider.getSystemJavaCompiler() != null)), BorderLayout.EAST);
70-
}});
71-
add(new JPanel(new BorderLayout()) {{
72-
add(new JLabel(LangUtil.i18n("about.java.supportAttach")), BorderLayout.WEST);
73-
add(new JLabel(String.valueOf(ReflectUtil.classHas("com.sun.tools.attach.VirtualMachine"))), BorderLayout.EAST);
74-
}});
75-
}});
35+
add(new JLabel(LangUtil.i18n("about.system")), "wrap");
36+
add(new JLabel(LangUtil.i18n("about.system.description")), "wrap");
37+
38+
add(new JLabel(LangUtil.i18n("about.system.name")));
39+
add(new JLabel(System.getProperty("os.name")), "wrap");
40+
add(new JLabel(LangUtil.i18n("about.system.architecture")));
41+
add(new JLabel(System.getProperty("os.arch")), "wrap");
42+
43+
add(new JSeparator(), "span 2");
44+
add(new JLabel(), "wrap");
45+
46+
add(new JLabel(LangUtil.i18n("about.java")), "wrap");
47+
add(new JLabel(LangUtil.i18n("about.java.description")), "wrap");
48+
49+
50+
add(new JLabel(LangUtil.i18n("about.java.version")));
51+
add(new JLabel(System.getProperty("java.version")), "wrap");
52+
add(new JLabel(LangUtil.i18n("about.java.vm.name")));
53+
add(new JLabel(System.getProperty("java.vm.name")), "wrap");
54+
add(new JLabel(LangUtil.i18n("about.java.vm.vendor")));
55+
add(new JLabel(System.getProperty("java.vm.vendor")), "wrap");
56+
add(new JLabel(LangUtil.i18n("about.java.home")));
57+
add(new JLabel(System.getProperty("java.home")), "wrap");
58+
add(new JLabel(LangUtil.i18n("about.java.supportCompiler")));
59+
add(new JLabel(String.valueOf(ToolProvider.getSystemJavaCompiler() != null)), "wrap");
60+
add(new JLabel(LangUtil.i18n("about.java.supportAttach")));
61+
add(new JLabel(String.valueOf(ReflectUtil.classHas("com.sun.tools.attach.VirtualMachine"))), "wrap");
7662
}});
63+
setResizable(false);
64+
pack();
7765
}
7866
}

src/main/java/cn/enaium/joe/dialog/AnnotationListDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public boolean isCellEditable(int row, int column) {
4646
jTable.getTableHeader().setReorderingAllowed(false);
4747
jTable.getTableHeader().setResizingAllowed(false);
4848
add(new JScrollPane(jTable), BorderLayout.CENTER);
49-
JMenuUtil.addPopupMenu(jTable, new JPopupMenu() {{
49+
JMenuUtil.addPopupMenu(jTable, () -> new JPopupMenu() {{
5050
add(new JMenuItem(LangUtil.i18n("button.edit")) {{
5151
addActionListener(e -> {
5252
new AnnotationValueDialog(((AnnotationNode) ((ObjectWrapper) dm.getValueAt(jTable.getSelectedRow(), 0)).getWrapper()).values).setVisible(true);

src/main/java/cn/enaium/joe/dialog/AnnotationValueDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public boolean isCellEditable(int row, int column) {
5656
jTable.getTableHeader().setReorderingAllowed(false);
5757
jTable.getTableHeader().setResizingAllowed(false);
5858
add(new JScrollPane(jTable), BorderLayout.CENTER);
59-
JMenuUtil.addPopupMenu(jTable, new JPopupMenu() {{
59+
JMenuUtil.addPopupMenu(jTable, () -> new JPopupMenu() {{
6060
add(new JMenuItem(LangUtil.i18n("button.edit")) {{
6161
addActionListener(e -> {
6262
ObjectWrapper valueAt = (ObjectWrapper) dm.getValueAt(jTable.getSelectedRow(), 1);
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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.panel.BorderPanel;
21+
import cn.enaium.joe.gui.panel.MemberListPanel;
22+
import cn.enaium.joe.gui.panel.file.tree.node.MethodTreeNode;
23+
import cn.enaium.joe.util.JMenuUtil;
24+
import cn.enaium.joe.util.LangUtil;
25+
import cn.enaium.joe.util.Pair;
26+
import com.formdev.flatlaf.extras.FlatSVGIcon;
27+
import org.objectweb.asm.tree.AbstractInsnNode;
28+
import org.objectweb.asm.tree.ClassNode;
29+
import org.objectweb.asm.tree.MethodInsnNode;
30+
import org.objectweb.asm.tree.MethodNode;
31+
32+
import javax.swing.*;
33+
import javax.swing.tree.DefaultTreeCellRenderer;
34+
import javax.swing.tree.DefaultTreeModel;
35+
import java.awt.*;
36+
import java.util.*;
37+
38+
/**
39+
* @author Enaium
40+
* @since 1.3.0
41+
*/
42+
public class CallTreeDialog extends Dialog {
43+
public CallTreeDialog(ClassNode classNode, MethodNode methodNode) {
44+
super(LangUtil.i18n("popup.member.callTree"));
45+
setContentPane(new BorderPanel() {{
46+
JTree call = new JTree() {{
47+
setModel(new DefaultTreeModel(new MethodTreeNode(classNode, methodNode) {{
48+
recursion(this);
49+
}}));
50+
51+
setCellRenderer(new DefaultTreeCellRenderer() {
52+
@Override
53+
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
54+
setIcon(new FlatSVGIcon("icons/method.svg"));
55+
setText(value.toString());
56+
return this;
57+
}
58+
});
59+
}};
60+
JMenuUtil.addPopupMenu(call, () -> {
61+
MethodTreeNode lastPathComponent = (MethodTreeNode) Objects.requireNonNull(call.getSelectionPath()).getLastPathComponent();
62+
return MemberListPanel.getPopupMenu(new Pair<>(lastPathComponent.classNode, lastPathComponent.methodNode));
63+
}, () -> call.getSelectionPath() != null);
64+
setCenter(new JScrollPane(call));
65+
}});
66+
}
67+
68+
private final Set<MethodNode> set = new HashSet<>();
69+
70+
private void recursion(MethodTreeNode methodTreeNode) {
71+
MethodNode methodNode = methodTreeNode.methodNode;
72+
Map<String, Pair<ClassNode, MethodNode>> map = new HashMap<>();
73+
74+
for (AbstractInsnNode instruction : methodNode.instructions) {
75+
if (instruction instanceof MethodInsnNode) {
76+
MethodInsnNode methodInsnNode = (MethodInsnNode) instruction;
77+
if (!(methodTreeNode.classNode.name + "." + methodNode.name + methodNode.desc).equals(methodInsnNode.owner + "." + methodInsnNode.name + methodInsnNode.desc)) {
78+
Map<String, ClassNode> classes = JavaOctetEditor.getInstance().getJar().classes;
79+
String key = methodInsnNode.owner + ".class";
80+
if (classes.containsKey(key)) {
81+
ClassNode classNode = classes.get(key);
82+
//Find target method
83+
for (MethodNode method : classNode.methods) {
84+
if ((classNode.name + "." + method.name + method.desc).equals(methodInsnNode.owner + "." + methodInsnNode.name + methodInsnNode.desc)) {
85+
//Deduplication
86+
map.put(classNode.name + "." + method.name + method.desc, new Pair<>(classNode, method));
87+
break;
88+
}
89+
}
90+
}
91+
}
92+
}
93+
}
94+
95+
for (Pair<ClassNode, MethodNode> value : map.values()) {
96+
MethodTreeNode newChild = new MethodTreeNode(value.getKey(), value.getValue());
97+
methodTreeNode.add(newChild);
98+
if (!set.contains(value.getValue())) {
99+
set.add(value.getValue());
100+
recursion(newChild);
101+
}
102+
}
103+
}
104+
}

0 commit comments

Comments
 (0)