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

Commit dad4e97

Browse files
committed
search
1 parent ed0ad34 commit dad4e97

File tree

4 files changed

+129
-1
lines changed

4 files changed

+129
-1
lines changed

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()) {
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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import cn.enaium.joe.gui.panel.menu.search.FieldMenuItem;
2020
import cn.enaium.joe.gui.panel.menu.search.LdcMenuItem;
21+
import cn.enaium.joe.gui.panel.menu.search.MethodMenuItem;
2122

2223
import javax.swing.*;
2324

@@ -29,5 +30,6 @@ public SearchMenu() {
2930
super("Search");
3031
add(new LdcMenuItem());
3132
add(new FieldMenuItem());
33+
add(new MethodMenuItem());
3234
}
3335
}
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+
}

0 commit comments

Comments
 (0)