|
| 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 | +} |
0 commit comments