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

Commit 246deb3

Browse files
authored
Merge pull request #11 from Enaium/develop
Develop
2 parents 63a2ad5 + 253900d commit 246deb3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+963
-328
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
}
88

99
group 'cn.enaium'
10-
version '0.9.0'
10+
version '0.10.0'
1111

1212
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8
1313

src/main/java/cn/enaium/joe/JavaOctetEditor.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package cn.enaium.joe;
1818

1919
import cn.enaium.joe.config.ConfigManager;
20-
import cn.enaium.joe.config.extend.CFRConfig;
2120
import cn.enaium.joe.gui.panel.BottomPanel;
2221
import cn.enaium.joe.gui.panel.LeftPanel;
2322
import cn.enaium.joe.gui.panel.file.tabbed.FileTabbedPanel;
@@ -27,6 +26,7 @@
2726
import cn.enaium.joe.gui.panel.menu.HelpMenu;
2827
import cn.enaium.joe.gui.panel.menu.SearchMenu;
2928
import cn.enaium.joe.jar.Jar;
29+
import cn.enaium.joe.task.TaskManager;
3030
import cn.enaium.joe.util.LangUtil;
3131
import cn.enaium.joe.util.MessageUtil;
3232
import org.fife.ui.rsyntaxtextarea.AbstractTokenMakerFactory;
@@ -55,13 +55,16 @@ public class JavaOctetEditor {
5555

5656
public BottomPanel bottomPanel;
5757

58-
public ConfigManager configManager;
58+
public ConfigManager config;
59+
60+
public TaskManager task;
5961

6062
public JavaOctetEditor() {
6163
instance = this;
62-
configManager = new ConfigManager();
63-
configManager.load();
64-
Runtime.getRuntime().addShutdownHook(new Thread(configManager::save));
64+
config = new ConfigManager();
65+
config.load();
66+
task = new TaskManager();
67+
Runtime.getRuntime().addShutdownHook(new Thread(config::save));
6568
fileTabbedPanel = new FileTabbedPanel();
6669
fileTreePanel = new FileTreePanel();
6770
bottomPanel = new BottomPanel();
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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.annotation;
18+
19+
import java.lang.annotation.ElementType;
20+
import java.lang.annotation.Retention;
21+
import java.lang.annotation.RetentionPolicy;
22+
import java.lang.annotation.Target;
23+
24+
/**
25+
* @author Enaium
26+
* @since 0.9.0
27+
*/
28+
@Retention(RetentionPolicy.RUNTIME)
29+
@Target(ElementType.TYPE)
30+
public @interface Indeterminate {
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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.annotation;
18+
19+
import java.lang.annotation.ElementType;
20+
import java.lang.annotation.Retention;
21+
import java.lang.annotation.RetentionPolicy;
22+
import java.lang.annotation.Target;
23+
24+
/**
25+
* @author Enaium
26+
* @since 0.9.0
27+
*/
28+
@Retention(RetentionPolicy.RUNTIME)
29+
@Target(ElementType.TYPE)
30+
public @interface Repeatable {
31+
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import cn.enaium.joe.config.value.*;
2323
import cn.enaium.joe.util.LangUtil;
2424
import cn.enaium.joe.util.MessageUtil;
25-
import org.tinylog.Logger;
2625

2726
import javax.swing.*;
2827
import javax.swing.event.DocumentEvent;
@@ -122,7 +121,7 @@ public void changedUpdate(DocumentEvent e) {
122121
addWindowListener(new WindowAdapter() {
123122
@Override
124123
public void windowClosing(WindowEvent e) {
125-
JavaOctetEditor.getInstance().configManager.save();
124+
JavaOctetEditor.getInstance().config.save();
126125
}
127126
});
128127
}

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

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,52 +17,28 @@
1717
package cn.enaium.joe.dialog;
1818

1919
import cn.enaium.joe.JavaOctetEditor;
20-
import cn.enaium.joe.gui.panel.search.ResultNode;
21-
import cn.enaium.joe.gui.panel.search.ResultPanel;
20+
import cn.enaium.joe.gui.component.ResultList;
2221
import cn.enaium.joe.jar.Jar;
2322
import cn.enaium.joe.util.LangUtil;
2423
import org.objectweb.asm.tree.AbstractInsnNode;
2524
import org.objectweb.asm.tree.ClassNode;
26-
import org.objectweb.asm.tree.LdcInsnNode;
2725
import org.objectweb.asm.tree.MethodNode;
2826

2927
import javax.swing.*;
3028
import java.awt.*;
3129
import java.util.Map;
3230
import java.util.function.BiConsumer;
33-
import java.util.function.Consumer;
3431

3532
/**
3633
* @author Enaium
3734
*/
3835
public class SearchDialog extends Dialog {
39-
public ResultPanel resultPanel = new ResultPanel();
36+
public ResultList resultList = new ResultList();
4037

4138
public SearchDialog() {
4239
super(LangUtil.i18n("menu.search"));
4340
setLayout(new BorderLayout());
4441
setSize(700, 400);
45-
add(resultPanel, BorderLayout.CENTER);
46-
}
47-
48-
public void searchInstruction(BiConsumer<ClassNode, AbstractInsnNode> consumer) {
49-
Jar jar = JavaOctetEditor.getInstance().jar;
50-
float loaded = 0;
51-
float total = 0;
52-
for (Map.Entry<String, ClassNode> stringClassNodeEntry : jar.classes.entrySet()) {
53-
for (MethodNode method : stringClassNodeEntry.getValue().methods) {
54-
total += method.instructions.size();
55-
}
56-
}
57-
58-
for (Map.Entry<String, ClassNode> stringClassNodeEntry : jar.classes.entrySet()) {
59-
for (MethodNode method : stringClassNodeEntry.getValue().methods) {
60-
for (AbstractInsnNode instruction : method.instructions) {
61-
consumer.accept(stringClassNodeEntry.getValue(), instruction);
62-
JavaOctetEditor.getInstance().bottomPanel.setProcess((int) ((loaded++ / total) * 100f));
63-
}
64-
}
65-
}
66-
JavaOctetEditor.getInstance().bottomPanel.setProcess(0);
42+
add(new JScrollPane(resultList), BorderLayout.CENTER);
6743
}
6844
}

src/main/java/cn/enaium/joe/dialog/search/SearchFieldDialog.java

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,13 @@
1919
import cn.enaium.joe.JavaOctetEditor;
2020
import cn.enaium.joe.dialog.SearchDialog;
2121
import cn.enaium.joe.gui.panel.search.ResultNode;
22-
import cn.enaium.joe.jar.Jar;
23-
import cn.enaium.joe.util.ASyncUtil;
22+
import cn.enaium.joe.task.SearchFieldTask;
2423
import cn.enaium.joe.util.LangUtil;
24+
import cn.enaium.joe.util.MessageUtil;
2525
import cn.enaium.joe.util.StringUtil;
26-
import org.objectweb.asm.tree.FieldInsnNode;
27-
import org.objectweb.asm.tree.AbstractInsnNode;
28-
import org.objectweb.asm.tree.ClassNode;
29-
import org.objectweb.asm.tree.MethodNode;
3026

3127
import javax.swing.*;
3228
import java.awt.*;
33-
import java.util.Map;
3429

3530
/**
3631
* @author Enaium
@@ -51,19 +46,21 @@ public SearchFieldDialog() {
5146
add(description);
5247
add(new JButton(LangUtil.i18n("button.search")) {{
5348
addActionListener(e -> {
54-
ASyncUtil.execute(() -> {
55-
searchInstruction((classNode, instruction) -> {
56-
if (instruction instanceof FieldInsnNode) {
57-
FieldInsnNode fieldInsnNode = (FieldInsnNode) instruction;
58-
if ((fieldInsnNode.owner.contains(owner.getText()) || StringUtil.isBlank(owner.getText())) &&
59-
(fieldInsnNode.name.contains(name.getText()) || StringUtil.isBlank(name.getText())) &&
60-
(fieldInsnNode.desc.contains(description.getText()) || StringUtil.isBlank(description.getText()))
61-
) {
62-
((DefaultListModel<ResultNode>) resultPanel.getList().getModel()).addElement(new ResultNode(classNode, fieldInsnNode.name + ":" + fieldInsnNode.desc));
49+
50+
if (StringUtil.isBlank(owner.getText()) && StringUtil.isBlank(name.getText()) && StringUtil.isBlank(description.getText())) {
51+
MessageUtil.warning("Please input");
52+
return;
53+
}
54+
55+
((DefaultListModel<ResultNode>) resultList.getModel()).clear();
56+
57+
JavaOctetEditor.getInstance().task
58+
.submit(new SearchFieldTask(JavaOctetEditor.getInstance().jar, owner.getText(), name.getText(), description.getText()))
59+
.thenAccept(it -> {
60+
for (ResultNode resultNode : it) {
61+
((DefaultListModel<ResultNode>) resultList.getModel()).addElement(resultNode);
6362
}
64-
}
65-
});
66-
});
63+
});
6764
});
6865
}});
6966
}}, BorderLayout.SOUTH);

src/main/java/cn/enaium/joe/dialog/search/SearchLdcDialog.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,14 @@
1919
import cn.enaium.joe.JavaOctetEditor;
2020
import cn.enaium.joe.dialog.SearchDialog;
2121
import cn.enaium.joe.gui.panel.search.ResultNode;
22-
import cn.enaium.joe.jar.Jar;
22+
import cn.enaium.joe.task.SearchFieldTask;
23+
import cn.enaium.joe.task.SearchLdcTask;
2324
import cn.enaium.joe.util.ASyncUtil;
2425
import cn.enaium.joe.util.LangUtil;
25-
import org.objectweb.asm.tree.AbstractInsnNode;
26-
import org.objectweb.asm.tree.ClassNode;
2726
import org.objectweb.asm.tree.LdcInsnNode;
28-
import org.objectweb.asm.tree.MethodNode;
2927

3028
import javax.swing.*;
3129
import java.awt.*;
32-
import java.util.Map;
3330

3431
/**
3532
* @author Enaium
@@ -42,17 +39,16 @@ public SearchLdcDialog() {
4239
add(text);
4340
add(new JButton(LangUtil.i18n("button.search")) {{
4441
addActionListener(e -> {
45-
if (!text.getText().replace(" ", "").isEmpty()) {
46-
ASyncUtil.execute(() -> {
47-
searchInstruction((classNode, instruction) -> {
48-
if (instruction instanceof LdcInsnNode) {
49-
String ldc = ((LdcInsnNode) instruction).cst.toString();
50-
if (ldc.contains(text.getText())) {
51-
((DefaultListModel<ResultNode>) resultPanel.getList().getModel()).addElement(new ResultNode(classNode, ldc));
42+
if (!text.getText().isEmpty()) {
43+
((DefaultListModel<ResultNode>) resultList.getModel()).clear();
44+
JavaOctetEditor.getInstance().task
45+
.submit(new SearchLdcTask(JavaOctetEditor.getInstance().jar, text.getText()))
46+
.thenAccept(it -> {
47+
resultList.removeAll();
48+
for (ResultNode resultNode : it) {
49+
((DefaultListModel<ResultNode>) resultList.getModel()).addElement(resultNode);
5250
}
53-
}
54-
});
55-
});
51+
});
5652
}
5753
});
5854
}});

src/main/java/cn/enaium/joe/dialog/search/SearchMethodDialog.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@
1919
import cn.enaium.joe.JavaOctetEditor;
2020
import cn.enaium.joe.dialog.SearchDialog;
2121
import cn.enaium.joe.gui.panel.search.ResultNode;
22-
import cn.enaium.joe.jar.Jar;
22+
import cn.enaium.joe.task.SearchFieldTask;
23+
import cn.enaium.joe.task.SearchMethodTask;
2324
import cn.enaium.joe.util.ASyncUtil;
2425
import cn.enaium.joe.util.LangUtil;
26+
import cn.enaium.joe.util.MessageUtil;
2527
import cn.enaium.joe.util.StringUtil;
2628
import org.objectweb.asm.tree.*;
2729

2830
import javax.swing.*;
2931
import java.awt.*;
30-
import java.util.Map;
3132

3233
/**
3334
* @author Enaium
@@ -46,24 +47,26 @@ public SearchMethodDialog() {
4647
add(new JLabel(LangUtil.i18n("search.description")));
4748
JTextField description = new JTextField();
4849
add(description);
49-
JCheckBox anInterface = new JCheckBox("Interface");
50+
JCheckBox anInterface = new JCheckBox(LangUtil.i18n("search.interface"));
5051
add(anInterface);
5152
add(new JButton(LangUtil.i18n("button.search")) {{
5253
addActionListener(e -> {
53-
ASyncUtil.execute(() -> {
54-
searchInstruction((classNode, instruction) -> {
55-
if (instruction instanceof MethodInsnNode) {
56-
MethodInsnNode methodInsnNode = (MethodInsnNode) instruction;
57-
if ((methodInsnNode.owner.contains(owner.getText()) || StringUtil.isBlank(owner.getText())) &&
58-
(methodInsnNode.name.contains(name.getText()) || StringUtil.isBlank(name.getText())) &&
59-
(methodInsnNode.desc.contains(description.getText()) || StringUtil.isBlank(description.getText())) &&
60-
(methodInsnNode.itf && anInterface.isSelected() || !anInterface.isSelected())
61-
) {
62-
((DefaultListModel<ResultNode>) resultPanel.getList().getModel()).addElement(new ResultNode(classNode, methodInsnNode.name + "#" + methodInsnNode.desc));
54+
55+
56+
if (StringUtil.isBlank(owner.getText()) && StringUtil.isBlank(name.getText()) && StringUtil.isBlank(description.getText()) && !anInterface.isSelected()) {
57+
MessageUtil.warning("Please input");
58+
return;
59+
}
60+
61+
62+
JavaOctetEditor.getInstance().task
63+
.submit(new SearchMethodTask(JavaOctetEditor.getInstance().jar, owner.getText(), name.getText(), description.getText(), anInterface.isSelected()))
64+
.thenAccept(it -> {
65+
((DefaultListModel<ResultNode>) resultList.getModel()).clear();
66+
for (ResultNode resultNode : it) {
67+
((DefaultListModel<ResultNode>) resultList.getModel()).addElement(resultNode);
6368
}
64-
}
65-
});
66-
});
69+
});
6770
});
6871
}});
6972
}}, BorderLayout.SOUTH);

0 commit comments

Comments
 (0)