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

Commit b4e15b3

Browse files
authored
Merge pull request #2 from Enaium/develop
Develop
2 parents 7b064df + dad4e97 commit b4e15b3

File tree

13 files changed

+329
-16
lines changed

13 files changed

+329
-16
lines changed

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.4.0'
9+
version '0.5.0'
1010

1111
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8
1212

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ public void run() {
5858

5959
window.setJMenuBar(new JMenuBar() {{
6060
add(new FileMenu());
61-
add(new HelpMenu());
6261
add(new SearchMenu());
62+
add(new HelpMenu());
6363
}});
6464

6565
window.setContentPane(new JPanel(new BorderLayout()) {

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

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

1717
package cn.enaium.joe.dialog;
1818

19-
import cn.enaium.joe.gui.panel.search.Result;
19+
import cn.enaium.joe.gui.panel.search.ResultPanel;
2020

2121
import java.awt.*;
2222

2323
/**
2424
* @author Enaium
2525
*/
2626
public class SearchDialog extends Dialog {
27-
public Result result = new Result();
27+
public ResultPanel resultPanel = new ResultPanel();
2828

2929
public SearchDialog() {
3030
super("Search");
3131
setLayout(new BorderLayout());
32-
setSize(400, 300);
33-
add(result, BorderLayout.CENTER);
32+
setSize(700, 400);
33+
add(resultPanel, BorderLayout.CENTER);
3434
}
3535
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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.jar.Jar;
23+
import cn.enaium.joe.util.ASyncUtil;
24+
import cn.enaium.joe.util.StringUtil;
25+
import org.objectweb.asm.tree.FieldInsnNode;
26+
import org.objectweb.asm.tree.AbstractInsnNode;
27+
import org.objectweb.asm.tree.ClassNode;
28+
import org.objectweb.asm.tree.MethodNode;
29+
30+
import javax.swing.*;
31+
import java.awt.*;
32+
import java.util.Map;
33+
34+
/**
35+
* @author Enaium
36+
* @since 0.5.0
37+
*/
38+
public class SearchFieldDialog extends SearchDialog {
39+
public SearchFieldDialog() {
40+
setTitle("Search Field");
41+
add(new JPanel(new FlowLayout()) {{
42+
add(new JLabel("Owner:"));
43+
JTextField owner = new JTextField();
44+
add(owner);
45+
add(new JLabel("Name:"));
46+
JTextField name = new JTextField();
47+
add(name);
48+
add(new JLabel("Description:"));
49+
JTextField description = new JTextField();
50+
add(description);
51+
add(new JButton("Search") {{
52+
addActionListener(e -> {
53+
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));
76+
}
77+
}
78+
}
79+
JavaOctetEditor.getInstance().bottomPanel.setProcess(0);
80+
});
81+
});
82+
}});
83+
}}, BorderLayout.SOUTH);
84+
}
85+
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,11 @@ public SearchLdcDialog() {
5454

5555
for (Map.Entry<String, ClassNode> stringClassNodeEntry : jar.classes.entrySet()) {
5656
for (MethodNode method : stringClassNodeEntry.getValue().methods) {
57-
5857
for (AbstractInsnNode instruction : method.instructions) {
5958
if (instruction instanceof LdcInsnNode) {
6059
String ldc = ((LdcInsnNode) instruction).cst.toString();
6160
if (ldc.contains(text.getText())) {
62-
((DefaultListModel<ResultNode>) result.getList().getModel()).addElement(new ResultNode(stringClassNodeEntry.getValue(), ldc));
61+
((DefaultListModel<ResultNode>) resultPanel.getList().getModel()).addElement(new ResultNode(stringClassNodeEntry.getValue(), ldc));
6362
}
6463
}
6564
JavaOctetEditor.getInstance().bottomPanel.setProcess((int) ((loaded++ / total) * 100f));
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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.jar.Jar;
23+
import cn.enaium.joe.util.ASyncUtil;
24+
import cn.enaium.joe.util.StringUtil;
25+
import org.objectweb.asm.tree.*;
26+
27+
import javax.swing.*;
28+
import java.awt.*;
29+
import java.util.Map;
30+
31+
/**
32+
* @author Enaium
33+
* @since 0.5.0
34+
*/
35+
public class SearchMethodDialog extends SearchDialog {
36+
public SearchMethodDialog() {
37+
setTitle("Search Method");
38+
add(new JPanel(new FlowLayout()) {{
39+
add(new JLabel("Owner:"));
40+
JTextField owner = new JTextField();
41+
add(owner);
42+
add(new JLabel("Name:"));
43+
JTextField name = new JTextField();
44+
add(name);
45+
add(new JLabel("Description:"));
46+
JTextField description = new JTextField();
47+
add(description);
48+
JCheckBox anInterface = new JCheckBox("Interface");
49+
add(anInterface);
50+
add(new JButton("Search") {{
51+
addActionListener(e -> {
52+
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));
76+
}
77+
}
78+
}
79+
JavaOctetEditor.getInstance().bottomPanel.setProcess(0);
80+
});
81+
});
82+
}});
83+
}}, BorderLayout.SOUTH);
84+
}
85+
}

src/main/java/cn/enaium/joe/gui/panel/menu/SearchMenu.java

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

1717
package cn.enaium.joe.gui.panel.menu;
1818

19+
import cn.enaium.joe.gui.panel.menu.search.FieldMenuItem;
1920
import cn.enaium.joe.gui.panel.menu.search.LdcMenuItem;
21+
import cn.enaium.joe.gui.panel.menu.search.MethodMenuItem;
2022

2123
import javax.swing.*;
2224

@@ -27,5 +29,7 @@ public class SearchMenu extends JMenu {
2729
public SearchMenu() {
2830
super("Search");
2931
add(new LdcMenuItem());
32+
add(new FieldMenuItem());
33+
add(new MethodMenuItem());
3034
}
3135
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
23+
import javax.swing.*;
24+
25+
/**
26+
* @author Enaium
27+
* @since 0.5.0
28+
*/
29+
public class FieldMenuItem extends JMenuItem {
30+
public FieldMenuItem() {
31+
super("Field");
32+
addActionListener(e -> {
33+
Jar jar = JavaOctetEditor.getInstance().jar;
34+
if (jar == null) {
35+
return;
36+
}
37+
new SearchFieldDialog().setVisible(true);
38+
});
39+
}
40+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
24+
import javax.swing.*;
25+
26+
/**
27+
* @author Enaium
28+
* @since 0.5.0
29+
*/
30+
public class MethodMenuItem extends JMenuItem {
31+
public MethodMenuItem() {
32+
super("Method");
33+
addActionListener(e -> {
34+
Jar jar = JavaOctetEditor.getInstance().jar;
35+
if (jar == null) {
36+
return;
37+
}
38+
new SearchMethodDialog().setVisible(true);
39+
});
40+
}
41+
}

src/main/java/cn/enaium/joe/gui/panel/search/ResultNode.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616

1717
package cn.enaium.joe.gui.panel.search;
1818

19+
import cn.enaium.joe.util.HtmlUtil;
1920
import org.objectweb.asm.tree.ClassNode;
2021

22+
import java.awt.*;
23+
2124
/**
2225
* @author Enaium
2326
*/
@@ -40,6 +43,6 @@ public String getResult() {
4043

4144
@Override
4245
public String toString() {
43-
return result;
46+
return HtmlUtil.toHtml(HtmlUtil.setColor(classNode.name, new Color(255, 255, 255)) + "#" + HtmlUtil.setColor(result, new Color(151, 194, 120)));
4447
}
4548
}

0 commit comments

Comments
 (0)