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

Commit b5f4dee

Browse files
authored
Merge pull request #3 from Enaium/develop
Develop
2 parents b4e15b3 + 01d045a commit b5f4dee

File tree

14 files changed

+408
-82
lines changed

14 files changed

+408
-82
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# JavaOctetEditor
22

3-
![](https://user-images.githubusercontent.com/32991121/179437944-92726f48-5fe9-44c1-a65d-38b4091e8a84.png)
3+
![](https://s1.ax1x.com/2022/07/30/vi7Lp8.png)

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

88
group 'cn.enaium'
9-
version '0.5.0'
9+
version '0.6.0'
1010

1111
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8
1212

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,20 @@
1616

1717
package cn.enaium.joe.dialog;
1818

19+
import cn.enaium.joe.JavaOctetEditor;
20+
import cn.enaium.joe.gui.panel.search.ResultNode;
1921
import cn.enaium.joe.gui.panel.search.ResultPanel;
22+
import cn.enaium.joe.jar.Jar;
23+
import org.objectweb.asm.tree.AbstractInsnNode;
24+
import org.objectweb.asm.tree.ClassNode;
25+
import org.objectweb.asm.tree.LdcInsnNode;
26+
import org.objectweb.asm.tree.MethodNode;
2027

28+
import javax.swing.*;
2129
import java.awt.*;
30+
import java.util.Map;
31+
import java.util.function.BiConsumer;
32+
import java.util.function.Consumer;
2233

2334
/**
2435
* @author Enaium
@@ -32,4 +43,25 @@ public SearchDialog() {
3243
setSize(700, 400);
3344
add(resultPanel, BorderLayout.CENTER);
3445
}
46+
47+
public void searchInstruction(BiConsumer<ClassNode, AbstractInsnNode> consumer) {
48+
Jar jar = JavaOctetEditor.getInstance().jar;
49+
float loaded = 0;
50+
float total = 0;
51+
for (Map.Entry<String, ClassNode> stringClassNodeEntry : jar.classes.entrySet()) {
52+
for (MethodNode method : stringClassNodeEntry.getValue().methods) {
53+
total += method.instructions.size();
54+
}
55+
}
56+
57+
for (Map.Entry<String, ClassNode> stringClassNodeEntry : jar.classes.entrySet()) {
58+
for (MethodNode method : stringClassNodeEntry.getValue().methods) {
59+
for (AbstractInsnNode instruction : method.instructions) {
60+
consumer.accept(stringClassNodeEntry.getValue(), instruction);
61+
JavaOctetEditor.getInstance().bottomPanel.setProcess((int) ((loaded++ / total) * 100f));
62+
}
63+
}
64+
}
65+
JavaOctetEditor.getInstance().bottomPanel.setProcess(0);
66+
}
3567
}

src/main/java/cn/enaium/joe/dialog/search/SearchFieldDialog.java

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,32 +51,17 @@ public SearchFieldDialog() {
5151
add(new JButton("Search") {{
5252
addActionListener(e -> {
5353
ASyncUtil.execute(() -> {
54-
float loaded = 0;
55-
float total = 0;
56-
Jar jar = JavaOctetEditor.getInstance().jar;
57-
for (Map.Entry<String, ClassNode> stringClassNodeEntry : jar.classes.entrySet()) {
58-
for (MethodNode method : stringClassNodeEntry.getValue().methods) {
59-
total += method.instructions.size();
60-
}
61-
}
62-
63-
for (Map.Entry<String, ClassNode> stringClassNodeEntry : jar.classes.entrySet()) {
64-
for (MethodNode method : stringClassNodeEntry.getValue().methods) {
65-
for (AbstractInsnNode instruction : method.instructions) {
66-
if (instruction instanceof FieldInsnNode) {
67-
FieldInsnNode fieldInsnNode = (FieldInsnNode) instruction;
68-
if ((fieldInsnNode.owner.contains(owner.getText()) || StringUtil.isBlank(owner.getText())) &&
69-
(fieldInsnNode.name.contains(name.getText()) || StringUtil.isBlank(name.getText())) &&
70-
(fieldInsnNode.desc.contains(description.getText()) || StringUtil.isBlank(description.getText()))
71-
) {
72-
((DefaultListModel<ResultNode>) resultPanel.getList().getModel()).addElement(new ResultNode(stringClassNodeEntry.getValue(), fieldInsnNode.name + ":" + fieldInsnNode.desc));
73-
}
74-
}
75-
JavaOctetEditor.getInstance().bottomPanel.setProcess((int) ((loaded++ / total) * 100f));
54+
searchInstruction((classNode, instruction) -> {
55+
if (instruction instanceof FieldInsnNode) {
56+
FieldInsnNode fieldInsnNode = (FieldInsnNode) instruction;
57+
if ((fieldInsnNode.owner.contains(owner.getText()) || StringUtil.isBlank(owner.getText())) &&
58+
(fieldInsnNode.name.contains(name.getText()) || StringUtil.isBlank(name.getText())) &&
59+
(fieldInsnNode.desc.contains(description.getText()) || StringUtil.isBlank(description.getText()))
60+
) {
61+
((DefaultListModel<ResultNode>) resultPanel.getList().getModel()).addElement(new ResultNode(classNode, fieldInsnNode.name + ":" + fieldInsnNode.desc));
7662
}
7763
}
78-
}
79-
JavaOctetEditor.getInstance().bottomPanel.setProcess(0);
64+
});
8065
});
8166
});
8267
}});

src/main/java/cn/enaium/joe/dialog/search/SearchLdcDialog.java

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,30 +42,15 @@ public SearchLdcDialog() {
4242
add(new JButton("Search") {{
4343
addActionListener(e -> {
4444
if (!text.getText().replace(" ", "").isEmpty()) {
45-
Jar jar = JavaOctetEditor.getInstance().jar;
4645
ASyncUtil.execute(() -> {
47-
float loaded = 0;
48-
float total = 0;
49-
for (Map.Entry<String, ClassNode> stringClassNodeEntry : jar.classes.entrySet()) {
50-
for (MethodNode method : stringClassNodeEntry.getValue().methods) {
51-
total += method.instructions.size();
52-
}
53-
}
54-
55-
for (Map.Entry<String, ClassNode> stringClassNodeEntry : jar.classes.entrySet()) {
56-
for (MethodNode method : stringClassNodeEntry.getValue().methods) {
57-
for (AbstractInsnNode instruction : method.instructions) {
58-
if (instruction instanceof LdcInsnNode) {
59-
String ldc = ((LdcInsnNode) instruction).cst.toString();
60-
if (ldc.contains(text.getText())) {
61-
((DefaultListModel<ResultNode>) resultPanel.getList().getModel()).addElement(new ResultNode(stringClassNodeEntry.getValue(), ldc));
62-
}
63-
}
64-
JavaOctetEditor.getInstance().bottomPanel.setProcess((int) ((loaded++ / total) * 100f));
46+
searchInstruction((classNode, instruction) -> {
47+
if (instruction instanceof LdcInsnNode) {
48+
String ldc = ((LdcInsnNode) instruction).cst.toString();
49+
if (ldc.contains(text.getText())) {
50+
((DefaultListModel<ResultNode>) resultPanel.getList().getModel()).addElement(new ResultNode(classNode, ldc));
6551
}
6652
}
67-
}
68-
JavaOctetEditor.getInstance().bottomPanel.setProcess(0);
53+
});
6954
});
7055
}
7156
});

src/main/java/cn/enaium/joe/dialog/search/SearchMethodDialog.java

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -50,33 +50,18 @@ public SearchMethodDialog() {
5050
add(new JButton("Search") {{
5151
addActionListener(e -> {
5252
ASyncUtil.execute(() -> {
53-
float loaded = 0;
54-
float total = 0;
55-
Jar jar = JavaOctetEditor.getInstance().jar;
56-
for (Map.Entry<String, ClassNode> stringClassNodeEntry : jar.classes.entrySet()) {
57-
for (MethodNode method : stringClassNodeEntry.getValue().methods) {
58-
total += method.instructions.size();
59-
}
60-
}
61-
62-
for (Map.Entry<String, ClassNode> stringClassNodeEntry : jar.classes.entrySet()) {
63-
for (MethodNode method : stringClassNodeEntry.getValue().methods) {
64-
for (AbstractInsnNode instruction : method.instructions) {
65-
if (instruction instanceof MethodInsnNode) {
66-
MethodInsnNode methodInsnNode = (MethodInsnNode) instruction;
67-
if ((methodInsnNode.owner.contains(owner.getText()) || StringUtil.isBlank(owner.getText())) &&
68-
(methodInsnNode.name.contains(name.getText()) || StringUtil.isBlank(name.getText())) &&
69-
(methodInsnNode.desc.contains(description.getText()) || StringUtil.isBlank(description.getText())) &&
70-
(methodInsnNode.itf && anInterface.isSelected() || !anInterface.isSelected())
71-
) {
72-
((DefaultListModel<ResultNode>) resultPanel.getList().getModel()).addElement(new ResultNode(stringClassNodeEntry.getValue(), methodInsnNode.name + "#" + methodInsnNode.desc));
73-
}
74-
}
75-
JavaOctetEditor.getInstance().bottomPanel.setProcess((int) ((loaded++ / total) * 100f));
53+
searchInstruction((classNode, instruction) -> {
54+
if (instruction instanceof MethodInsnNode) {
55+
MethodInsnNode methodInsnNode = (MethodInsnNode) instruction;
56+
if ((methodInsnNode.owner.contains(owner.getText()) || StringUtil.isBlank(owner.getText())) &&
57+
(methodInsnNode.name.contains(name.getText()) || StringUtil.isBlank(name.getText())) &&
58+
(methodInsnNode.desc.contains(description.getText()) || StringUtil.isBlank(description.getText())) &&
59+
(methodInsnNode.itf && anInterface.isSelected() || !anInterface.isSelected())
60+
) {
61+
((DefaultListModel<ResultNode>) resultPanel.getList().getModel()).addElement(new ResultNode(classNode, methodInsnNode.name + "#" + methodInsnNode.desc));
7662
}
7763
}
78-
}
79-
JavaOctetEditor.getInstance().bottomPanel.setProcess(0);
64+
});
8065
});
8166
});
8267
}});
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
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;
18+
19+
20+
import cn.enaium.joe.util.StringUtil;
21+
import org.benf.cfr.reader.util.StringUtils;
22+
import org.objectweb.asm.tree.ClassNode;
23+
24+
import javax.swing.*;
25+
import java.awt.*;
26+
import java.util.ArrayList;
27+
import java.util.Arrays;
28+
29+
/**
30+
* @author Enaium
31+
* @since 0.6.0
32+
*/
33+
public class ClassInfoTabPanel extends ClassNodeTabPanel {
34+
public ClassInfoTabPanel(ClassNode classNode) {
35+
super(classNode);
36+
setLayout(new BorderLayout());
37+
JPanel labels = new JPanel(new GridLayout(0, 1));
38+
JPanel rights = new JPanel(new GridLayout(0, 1));
39+
add(labels, BorderLayout.WEST);
40+
add(rights, BorderLayout.CENTER);
41+
labels.add(new JLabel("Name:"));
42+
JTextField name = new JTextField(classNode.name);
43+
rights.add(name);
44+
labels.add(new JLabel("SourceFile:"));
45+
JTextField sourceFile = new JTextField(classNode.sourceFile);
46+
rights.add(sourceFile);
47+
labels.add(new JLabel("DebugFile:"));
48+
JTextField sourceDebug = new JTextField(classNode.sourceDebug);
49+
rights.add(sourceDebug);
50+
labels.add(new JLabel("Access:"));
51+
JTextField access = new JTextField(String.valueOf(classNode.access));
52+
rights.add(access);
53+
labels.add(new JLabel("Version:"));
54+
JTextField version = new JTextField(String.valueOf(classNode.version));
55+
rights.add(version);
56+
labels.add(new JLabel("Signature:"));
57+
JTextField signature = new JTextField(classNode.signature);
58+
rights.add(signature);
59+
labels.add(new JLabel("Super Name:"));
60+
JTextField superName = new JTextField(classNode.superName);
61+
rights.add(superName);
62+
labels.add(new JLabel("Interfaces:"));
63+
JTextField interfaces = new JTextField(StringUtils.join(classNode.interfaces, ";"));
64+
rights.add(interfaces);
65+
labels.add(new JLabel("Outer Class:"));
66+
JTextField outerClass = new JTextField(classNode.outerClass);
67+
rights.add(outerClass);
68+
labels.add(new JLabel("Outer Method:"));
69+
JTextField outerMethod = new JTextField(classNode.outerMethod);
70+
rights.add(outerMethod);
71+
labels.add(new JLabel("Outer Method Description:"));
72+
JTextField outerMethodDesc = new JTextField(classNode.outerMethodDesc);
73+
rights.add(outerMethodDesc);
74+
add(new JButton("Save") {{
75+
addActionListener(e -> {
76+
77+
if (!StringUtil.isBlank(name.getText())) {
78+
classNode.name = name.getText();
79+
}
80+
81+
if (!StringUtil.isBlank(sourceFile.getText())) {
82+
classNode.sourceFile = sourceFile.getText();
83+
} else {
84+
classNode.sourceFile = null;
85+
}
86+
87+
if (!StringUtil.isBlank(sourceDebug.getText())) {
88+
classNode.sourceDebug = sourceDebug.getText();
89+
} else {
90+
classNode.sourceDebug = null;
91+
}
92+
93+
if (!StringUtil.isBlank(access.getText())) {
94+
classNode.access = Integer.parseInt(access.getText());
95+
}
96+
97+
if (!StringUtil.isBlank(version.getText())) {
98+
classNode.version = Integer.parseInt(version.getText());
99+
}
100+
101+
if (!StringUtil.isBlank(signature.getText())) {
102+
classNode.signature = signature.getName();
103+
} else {
104+
classNode.signature = null;
105+
}
106+
107+
if (!StringUtil.isBlank(interfaces.getText())) {
108+
classNode.interfaces = Arrays.asList(superName.getText().split(";"));
109+
} else {
110+
classNode.interfaces = new ArrayList<>();
111+
}
112+
113+
if (!StringUtil.isBlank(outerClass.getText())) {
114+
classNode.outerClass = outerClass.getText();
115+
} else {
116+
classNode.outerClass = null;
117+
}
118+
119+
if (!StringUtil.isBlank(outerMethod.getText())) {
120+
classNode.outerMethod = outerMethod.getText();
121+
} else {
122+
classNode.outerClass = null;
123+
}
124+
125+
if (!StringUtil.isBlank(outerMethodDesc.getText())) {
126+
classNode.outerMethodDesc = outerMethodDesc.getText();
127+
} else {
128+
classNode.outerClass = null;
129+
}
130+
131+
JOptionPane.showMessageDialog(ClassInfoTabPanel.this, "Save success");
132+
});
133+
}}, BorderLayout.SOUTH);
134+
}
135+
}

src/main/java/cn/enaium/joe/gui/panel/file/tabbed/tab/FileTabPanel.java renamed to src/main/java/cn/enaium/joe/gui/panel/file/tabbed/tab/ClassTabPanel.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
/**
99
* @author Enaium
1010
*/
11-
public class FileTabPanel extends JPanel {
12-
public FileTabPanel(ClassNode classNode) {
11+
public class ClassTabPanel extends JPanel {
12+
public ClassTabPanel(ClassNode classNode) {
1313
super(new BorderLayout());
1414
JTabbedPane jTabbedPane = new JTabbedPane();
1515
jTabbedPane.setTabPlacement(JTabbedPane.BOTTOM);
1616
jTabbedPane.addTab("BytecodeView", new TraceBytecodeTabPanel(classNode));
1717
jTabbedPane.addTab("DecompileView", new DecompileTabPanel(classNode));
1818
jTabbedPane.addTab("VisitorEdit", new ASMifierTablePanel(classNode));
19+
jTabbedPane.addTab("InfoEdit", new ClassInfoTabPanel(classNode));
1920
add(jTabbedPane);
2021
}
2122
}

0 commit comments

Comments
 (0)