Skip to content
This repository was archived by the owner on Jan 2, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group 'cn.enaium'
version '0.4.0'
version '0.5.0'

sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/enaium/joe/JavaOctetEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public void run() {

window.setJMenuBar(new JMenuBar() {{
add(new FileMenu());
add(new HelpMenu());
add(new SearchMenu());
add(new HelpMenu());
}});

window.setContentPane(new JPanel(new BorderLayout()) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/cn/enaium/joe/dialog/SearchDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@

package cn.enaium.joe.dialog;

import cn.enaium.joe.gui.panel.search.Result;
import cn.enaium.joe.gui.panel.search.ResultPanel;

import java.awt.*;

/**
* @author Enaium
*/
public class SearchDialog extends Dialog {
public Result result = new Result();
public ResultPanel resultPanel = new ResultPanel();

public SearchDialog() {
super("Search");
setLayout(new BorderLayout());
setSize(400, 300);
add(result, BorderLayout.CENTER);
setSize(700, 400);
add(resultPanel, BorderLayout.CENTER);
}
}
85 changes: 85 additions & 0 deletions src/main/java/cn/enaium/joe/dialog/search/SearchFieldDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright 2022 Enaium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package cn.enaium.joe.dialog.search;

import cn.enaium.joe.JavaOctetEditor;
import cn.enaium.joe.dialog.SearchDialog;
import cn.enaium.joe.gui.panel.search.ResultNode;
import cn.enaium.joe.jar.Jar;
import cn.enaium.joe.util.ASyncUtil;
import cn.enaium.joe.util.StringUtil;
import org.objectweb.asm.tree.FieldInsnNode;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;

import javax.swing.*;
import java.awt.*;
import java.util.Map;

/**
* @author Enaium
* @since 0.5.0
*/
public class SearchFieldDialog extends SearchDialog {
public SearchFieldDialog() {
setTitle("Search Field");
add(new JPanel(new FlowLayout()) {{
add(new JLabel("Owner:"));
JTextField owner = new JTextField();
add(owner);
add(new JLabel("Name:"));
JTextField name = new JTextField();
add(name);
add(new JLabel("Description:"));
JTextField description = new JTextField();
add(description);
add(new JButton("Search") {{
addActionListener(e -> {
ASyncUtil.execute(() -> {
float loaded = 0;
float total = 0;
Jar jar = JavaOctetEditor.getInstance().jar;
for (Map.Entry<String, ClassNode> stringClassNodeEntry : jar.classes.entrySet()) {
for (MethodNode method : stringClassNodeEntry.getValue().methods) {
total += method.instructions.size();
}
}

for (Map.Entry<String, ClassNode> stringClassNodeEntry : jar.classes.entrySet()) {
for (MethodNode method : stringClassNodeEntry.getValue().methods) {
for (AbstractInsnNode instruction : method.instructions) {
if (instruction instanceof FieldInsnNode) {
FieldInsnNode fieldInsnNode = (FieldInsnNode) instruction;
if ((fieldInsnNode.owner.contains(owner.getText()) || StringUtil.isBlank(owner.getText())) &&
(fieldInsnNode.name.contains(name.getText()) || StringUtil.isBlank(name.getText())) &&
(fieldInsnNode.desc.contains(description.getText()) || StringUtil.isBlank(description.getText()))
) {
((DefaultListModel<ResultNode>) resultPanel.getList().getModel()).addElement(new ResultNode(stringClassNodeEntry.getValue(), fieldInsnNode.name + ":" + fieldInsnNode.desc));
}
}
JavaOctetEditor.getInstance().bottomPanel.setProcess((int) ((loaded++ / total) * 100f));
}
}
}
JavaOctetEditor.getInstance().bottomPanel.setProcess(0);
});
});
}});
}}, BorderLayout.SOUTH);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@ public SearchLdcDialog() {

for (Map.Entry<String, ClassNode> stringClassNodeEntry : jar.classes.entrySet()) {
for (MethodNode method : stringClassNodeEntry.getValue().methods) {

for (AbstractInsnNode instruction : method.instructions) {
if (instruction instanceof LdcInsnNode) {
String ldc = ((LdcInsnNode) instruction).cst.toString();
if (ldc.contains(text.getText())) {
((DefaultListModel<ResultNode>) result.getList().getModel()).addElement(new ResultNode(stringClassNodeEntry.getValue(), ldc));
((DefaultListModel<ResultNode>) resultPanel.getList().getModel()).addElement(new ResultNode(stringClassNodeEntry.getValue(), ldc));
}
}
JavaOctetEditor.getInstance().bottomPanel.setProcess((int) ((loaded++ / total) * 100f));
Expand Down
85 changes: 85 additions & 0 deletions src/main/java/cn/enaium/joe/dialog/search/SearchMethodDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright 2022 Enaium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package cn.enaium.joe.dialog.search;

import cn.enaium.joe.JavaOctetEditor;
import cn.enaium.joe.dialog.SearchDialog;
import cn.enaium.joe.gui.panel.search.ResultNode;
import cn.enaium.joe.jar.Jar;
import cn.enaium.joe.util.ASyncUtil;
import cn.enaium.joe.util.StringUtil;
import org.objectweb.asm.tree.*;

import javax.swing.*;
import java.awt.*;
import java.util.Map;

/**
* @author Enaium
* @since 0.5.0
*/
public class SearchMethodDialog extends SearchDialog {
public SearchMethodDialog() {
setTitle("Search Method");
add(new JPanel(new FlowLayout()) {{
add(new JLabel("Owner:"));
JTextField owner = new JTextField();
add(owner);
add(new JLabel("Name:"));
JTextField name = new JTextField();
add(name);
add(new JLabel("Description:"));
JTextField description = new JTextField();
add(description);
JCheckBox anInterface = new JCheckBox("Interface");
add(anInterface);
add(new JButton("Search") {{
addActionListener(e -> {
ASyncUtil.execute(() -> {
float loaded = 0;
float total = 0;
Jar jar = JavaOctetEditor.getInstance().jar;
for (Map.Entry<String, ClassNode> stringClassNodeEntry : jar.classes.entrySet()) {
for (MethodNode method : stringClassNodeEntry.getValue().methods) {
total += method.instructions.size();
}
}

for (Map.Entry<String, ClassNode> stringClassNodeEntry : jar.classes.entrySet()) {
for (MethodNode method : stringClassNodeEntry.getValue().methods) {
for (AbstractInsnNode instruction : method.instructions) {
if (instruction instanceof MethodInsnNode) {
MethodInsnNode methodInsnNode = (MethodInsnNode) instruction;
if ((methodInsnNode.owner.contains(owner.getText()) || StringUtil.isBlank(owner.getText())) &&
(methodInsnNode.name.contains(name.getText()) || StringUtil.isBlank(name.getText())) &&
(methodInsnNode.desc.contains(description.getText()) || StringUtil.isBlank(description.getText())) &&
(methodInsnNode.itf && anInterface.isSelected() || !anInterface.isSelected())
) {
((DefaultListModel<ResultNode>) resultPanel.getList().getModel()).addElement(new ResultNode(stringClassNodeEntry.getValue(), methodInsnNode.name + "#" + methodInsnNode.desc));
}
}
JavaOctetEditor.getInstance().bottomPanel.setProcess((int) ((loaded++ / total) * 100f));
}
}
}
JavaOctetEditor.getInstance().bottomPanel.setProcess(0);
});
});
}});
}}, BorderLayout.SOUTH);
}
}
4 changes: 4 additions & 0 deletions src/main/java/cn/enaium/joe/gui/panel/menu/SearchMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

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

import cn.enaium.joe.gui.panel.menu.search.FieldMenuItem;
import cn.enaium.joe.gui.panel.menu.search.LdcMenuItem;
import cn.enaium.joe.gui.panel.menu.search.MethodMenuItem;

import javax.swing.*;

Expand All @@ -27,5 +29,7 @@ public class SearchMenu extends JMenu {
public SearchMenu() {
super("Search");
add(new LdcMenuItem());
add(new FieldMenuItem());
add(new MethodMenuItem());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2022 Enaium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package cn.enaium.joe.gui.panel.menu.search;

import cn.enaium.joe.JavaOctetEditor;
import cn.enaium.joe.dialog.search.SearchFieldDialog;
import cn.enaium.joe.jar.Jar;

import javax.swing.*;

/**
* @author Enaium
* @since 0.5.0
*/
public class FieldMenuItem extends JMenuItem {
public FieldMenuItem() {
super("Field");
addActionListener(e -> {
Jar jar = JavaOctetEditor.getInstance().jar;
if (jar == null) {
return;
}
new SearchFieldDialog().setVisible(true);
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2022 Enaium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package cn.enaium.joe.gui.panel.menu.search;

import cn.enaium.joe.JavaOctetEditor;
import cn.enaium.joe.dialog.search.SearchFieldDialog;
import cn.enaium.joe.dialog.search.SearchMethodDialog;
import cn.enaium.joe.jar.Jar;

import javax.swing.*;

/**
* @author Enaium
* @since 0.5.0
*/
public class MethodMenuItem extends JMenuItem {
public MethodMenuItem() {
super("Method");
addActionListener(e -> {
Jar jar = JavaOctetEditor.getInstance().jar;
if (jar == null) {
return;
}
new SearchMethodDialog().setVisible(true);
});
}
}
5 changes: 4 additions & 1 deletion src/main/java/cn/enaium/joe/gui/panel/search/ResultNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@

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

import cn.enaium.joe.util.HtmlUtil;
import org.objectweb.asm.tree.ClassNode;

import java.awt.*;

/**
* @author Enaium
*/
Expand All @@ -40,6 +43,6 @@ public String getResult() {

@Override
public String toString() {
return result;
return HtmlUtil.toHtml(HtmlUtil.setColor(classNode.name, new Color(255, 255, 255)) + "#" + HtmlUtil.setColor(result, new Color(151, 194, 120)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,22 @@
import cn.enaium.joe.gui.panel.file.tree.node.*;
import cn.enaium.joe.util.ASyncUtil;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.nio.charset.StandardCharsets;

/**
* @author Enaium
*/
public class Result extends JPanel {
public class ResultPanel extends JPanel {

private final JList<ResultNode> list;

public Result() {
public ResultPanel() {
super(new BorderLayout());
list = new JList<>(new DefaultListModel<>());
add(new JScrollPane(list), BorderLayout.CENTER);
Expand All @@ -53,7 +49,7 @@ public Result() {
SwingUtilities.invokeLater(() -> {
FileTreePanel fileTreePanel = JavaOctetEditor.getInstance().fileTreePanel;
DefaultTreeModel model = (DefaultTreeModel) fileTreePanel.getModel();
if (selectEntry(fileTreePanel, list.getSelectedValue().getClassNode(), model, (DefaultTreeNode) model.getRoot())) {
if (selectEntry(fileTreePanel, list.getSelectedValue().getClassNode(), model, FileTreePanel.classesRoot)) {
fileTreePanel.repaint();
}
});
Expand Down
Loading