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

Commit ed0ad34

Browse files
committed
search
1 parent a3533a3 commit ed0ad34

File tree

6 files changed

+132
-3
lines changed

6 files changed

+132
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class SearchDialog extends Dialog {
2929
public SearchDialog() {
3030
super("Search");
3131
setLayout(new BorderLayout());
32-
setSize(400, 300);
32+
setSize(700, 400);
3333
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: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ 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();

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
@@ -16,6 +16,7 @@
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;
2021

2122
import javax.swing.*;
@@ -27,5 +28,6 @@ public class SearchMenu extends JMenu {
2728
public SearchMenu() {
2829
super("Search");
2930
add(new LdcMenuItem());
31+
add(new FieldMenuItem());
3032
}
3133
}
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+
}

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)