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 @@ -7,7 +7,7 @@ plugins {
}

group 'cn.enaium'
version '0.9.0'
version '0.10.0'

sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8

Expand Down
13 changes: 8 additions & 5 deletions src/main/java/cn/enaium/joe/JavaOctetEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package cn.enaium.joe;

import cn.enaium.joe.config.ConfigManager;
import cn.enaium.joe.config.extend.CFRConfig;
import cn.enaium.joe.gui.panel.BottomPanel;
import cn.enaium.joe.gui.panel.LeftPanel;
import cn.enaium.joe.gui.panel.file.tabbed.FileTabbedPanel;
Expand All @@ -27,6 +26,7 @@
import cn.enaium.joe.gui.panel.menu.HelpMenu;
import cn.enaium.joe.gui.panel.menu.SearchMenu;
import cn.enaium.joe.jar.Jar;
import cn.enaium.joe.task.TaskManager;
import cn.enaium.joe.util.LangUtil;
import cn.enaium.joe.util.MessageUtil;
import org.fife.ui.rsyntaxtextarea.AbstractTokenMakerFactory;
Expand Down Expand Up @@ -55,13 +55,16 @@ public class JavaOctetEditor {

public BottomPanel bottomPanel;

public ConfigManager configManager;
public ConfigManager config;

public TaskManager task;

public JavaOctetEditor() {
instance = this;
configManager = new ConfigManager();
configManager.load();
Runtime.getRuntime().addShutdownHook(new Thread(configManager::save));
config = new ConfigManager();
config.load();
task = new TaskManager();
Runtime.getRuntime().addShutdownHook(new Thread(config::save));
fileTabbedPanel = new FileTabbedPanel();
fileTreePanel = new FileTreePanel();
bottomPanel = new BottomPanel();
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/cn/enaium/joe/annotation/Indeterminate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* @author Enaium
* @since 0.9.0
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Indeterminate {
}
31 changes: 31 additions & 0 deletions src/main/java/cn/enaium/joe/annotation/Repeatable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* @author Enaium
* @since 0.9.0
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Repeatable {
}
3 changes: 1 addition & 2 deletions src/main/java/cn/enaium/joe/dialog/ConfigDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import cn.enaium.joe.config.value.*;
import cn.enaium.joe.util.LangUtil;
import cn.enaium.joe.util.MessageUtil;
import org.tinylog.Logger;

import javax.swing.*;
import javax.swing.event.DocumentEvent;
Expand Down Expand Up @@ -122,7 +121,7 @@ public void changedUpdate(DocumentEvent e) {
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
JavaOctetEditor.getInstance().configManager.save();
JavaOctetEditor.getInstance().config.save();
}
});
}
Expand Down
30 changes: 3 additions & 27 deletions src/main/java/cn/enaium/joe/dialog/SearchDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,52 +17,28 @@
package cn.enaium.joe.dialog;

import cn.enaium.joe.JavaOctetEditor;
import cn.enaium.joe.gui.panel.search.ResultNode;
import cn.enaium.joe.gui.panel.search.ResultPanel;
import cn.enaium.joe.gui.component.ResultList;
import cn.enaium.joe.jar.Jar;
import cn.enaium.joe.util.LangUtil;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.LdcInsnNode;
import org.objectweb.asm.tree.MethodNode;

import javax.swing.*;
import java.awt.*;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

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

public SearchDialog() {
super(LangUtil.i18n("menu.search"));
setLayout(new BorderLayout());
setSize(700, 400);
add(resultPanel, BorderLayout.CENTER);
}

public void searchInstruction(BiConsumer<ClassNode, AbstractInsnNode> consumer) {
Jar jar = JavaOctetEditor.getInstance().jar;
float loaded = 0;
float total = 0;
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) {
consumer.accept(stringClassNodeEntry.getValue(), instruction);
JavaOctetEditor.getInstance().bottomPanel.setProcess((int) ((loaded++ / total) * 100f));
}
}
}
JavaOctetEditor.getInstance().bottomPanel.setProcess(0);
add(new JScrollPane(resultList), BorderLayout.CENTER);
}
}
35 changes: 16 additions & 19 deletions src/main/java/cn/enaium/joe/dialog/search/SearchFieldDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,13 @@
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.task.SearchFieldTask;
import cn.enaium.joe.util.LangUtil;
import cn.enaium.joe.util.MessageUtil;
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
Expand All @@ -51,19 +46,21 @@ public SearchFieldDialog() {
add(description);
add(new JButton(LangUtil.i18n("button.search")) {{
addActionListener(e -> {
ASyncUtil.execute(() -> {
searchInstruction((classNode, instruction) -> {
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(classNode, fieldInsnNode.name + ":" + fieldInsnNode.desc));

if (StringUtil.isBlank(owner.getText()) && StringUtil.isBlank(name.getText()) && StringUtil.isBlank(description.getText())) {
MessageUtil.warning("Please input");
return;
}

((DefaultListModel<ResultNode>) resultList.getModel()).clear();

JavaOctetEditor.getInstance().task
.submit(new SearchFieldTask(JavaOctetEditor.getInstance().jar, owner.getText(), name.getText(), description.getText()))
.thenAccept(it -> {
for (ResultNode resultNode : it) {
((DefaultListModel<ResultNode>) resultList.getModel()).addElement(resultNode);
}
}
});
});
});
});
}});
}}, BorderLayout.SOUTH);
Expand Down
26 changes: 11 additions & 15 deletions src/main/java/cn/enaium/joe/dialog/search/SearchLdcDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@
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.task.SearchFieldTask;
import cn.enaium.joe.task.SearchLdcTask;
import cn.enaium.joe.util.ASyncUtil;
import cn.enaium.joe.util.LangUtil;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.LdcInsnNode;
import org.objectweb.asm.tree.MethodNode;

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

/**
* @author Enaium
Expand All @@ -42,17 +39,16 @@ public SearchLdcDialog() {
add(text);
add(new JButton(LangUtil.i18n("button.search")) {{
addActionListener(e -> {
if (!text.getText().replace(" ", "").isEmpty()) {
ASyncUtil.execute(() -> {
searchInstruction((classNode, instruction) -> {
if (instruction instanceof LdcInsnNode) {
String ldc = ((LdcInsnNode) instruction).cst.toString();
if (ldc.contains(text.getText())) {
((DefaultListModel<ResultNode>) resultPanel.getList().getModel()).addElement(new ResultNode(classNode, ldc));
if (!text.getText().isEmpty()) {
((DefaultListModel<ResultNode>) resultList.getModel()).clear();
JavaOctetEditor.getInstance().task
.submit(new SearchLdcTask(JavaOctetEditor.getInstance().jar, text.getText()))
.thenAccept(it -> {
resultList.removeAll();
for (ResultNode resultNode : it) {
((DefaultListModel<ResultNode>) resultList.getModel()).addElement(resultNode);
}
}
});
});
});
}
});
}});
Expand Down
35 changes: 19 additions & 16 deletions src/main/java/cn/enaium/joe/dialog/search/SearchMethodDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@
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.task.SearchFieldTask;
import cn.enaium.joe.task.SearchMethodTask;
import cn.enaium.joe.util.ASyncUtil;
import cn.enaium.joe.util.LangUtil;
import cn.enaium.joe.util.MessageUtil;
import cn.enaium.joe.util.StringUtil;
import org.objectweb.asm.tree.*;

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

/**
* @author Enaium
Expand All @@ -46,24 +47,26 @@ public SearchMethodDialog() {
add(new JLabel(LangUtil.i18n("search.description")));
JTextField description = new JTextField();
add(description);
JCheckBox anInterface = new JCheckBox("Interface");
JCheckBox anInterface = new JCheckBox(LangUtil.i18n("search.interface"));
add(anInterface);
add(new JButton(LangUtil.i18n("button.search")) {{
addActionListener(e -> {
ASyncUtil.execute(() -> {
searchInstruction((classNode, instruction) -> {
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(classNode, methodInsnNode.name + "#" + methodInsnNode.desc));


if (StringUtil.isBlank(owner.getText()) && StringUtil.isBlank(name.getText()) && StringUtil.isBlank(description.getText()) && !anInterface.isSelected()) {
MessageUtil.warning("Please input");
return;
}


JavaOctetEditor.getInstance().task
.submit(new SearchMethodTask(JavaOctetEditor.getInstance().jar, owner.getText(), name.getText(), description.getText(), anInterface.isSelected()))
.thenAccept(it -> {
((DefaultListModel<ResultNode>) resultList.getModel()).clear();
for (ResultNode resultNode : it) {
((DefaultListModel<ResultNode>) resultList.getModel()).addElement(resultNode);
}
}
});
});
});
});
}});
}}, BorderLayout.SOUTH);
Expand Down
Loading