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

Commit 459ba64

Browse files
authored
Merge pull request #8 from Enaium/develop
Develop
2 parents 67411f9 + de6b8db commit 459ba64

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

+2544
-14
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# JavaOctetEditor
22

3-
![](https://s1.ax1x.com/2022/07/30/vi7Lp8.png)
3+
![](https://s1.ax1x.com/2022/08/11/v8T7M8.png)
4+
![](https://s1.ax1x.com/2022/08/11/v8Toxf.png)

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
}
88

99
group 'cn.enaium'
10-
version '0.7.0'
10+
version '0.8.0'
1111

1212
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8
1313

@@ -30,8 +30,8 @@ repositories {
3030
}
3131

3232
dependencies {
33-
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
34-
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
33+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0'
34+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0'
3535

3636
implementation 'com.formdev:flatlaf:2.4'
3737
implementation 'com.formdev:flatlaf-extras:2.4'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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.component;
18+
19+
import cn.enaium.joe.util.OpcodeUtil;
20+
import cn.enaium.joe.wrapper.LabelNodeWrapper;
21+
import org.objectweb.asm.tree.AbstractInsnNode;
22+
import org.objectweb.asm.tree.LabelNode;
23+
24+
import javax.swing.*;
25+
26+
/**
27+
* @author Enaium
28+
* @since 0.8.0
29+
*/
30+
public class LabelNodeComboBox extends JComboBox<LabelNodeWrapper> {
31+
public LabelNodeComboBox(AbstractInsnNode instruction, LabelNode select) {
32+
super(new DefaultComboBoxModel<>());
33+
LabelNodeWrapper selected = null;
34+
for (AbstractInsnNode abstractInsnNode : OpcodeUtil.getInstructionList(instruction)) {
35+
if (abstractInsnNode instanceof LabelNode) {
36+
LabelNodeWrapper anObject = new LabelNodeWrapper(((LabelNode) abstractInsnNode));
37+
if (abstractInsnNode.equals(select)) {
38+
selected = anObject;
39+
}
40+
((DefaultComboBoxModel<LabelNodeWrapper>) getModel()).addElement(anObject);
41+
}
42+
}
43+
getModel().setSelectedItem(selected);
44+
}
45+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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.confirm;
18+
19+
import cn.enaium.joe.util.MessageUtil;
20+
import cn.enaium.joe.wrapper.Wrapper;
21+
import org.objectweb.asm.Handle;
22+
import org.objectweb.asm.Type;
23+
24+
import javax.swing.*;
25+
import java.awt.*;
26+
import java.util.ArrayList;
27+
import java.util.List;
28+
29+
/**
30+
* @author Enaium
31+
* @since 0.8.0
32+
*/
33+
public class BootstrapMethodArgumentEditPanel extends ConfirmPanel {
34+
public BootstrapMethodArgumentEditPanel(Wrapper<Object[]> wrapper) {
35+
setLayout(new BorderLayout());
36+
DefaultListModel<Object> objectDefaultListModel = new DefaultListModel<>();
37+
JList<Object> objectJList = new JList<>(objectDefaultListModel);
38+
for (Object bsmArg : wrapper.getWrapper()) {
39+
objectDefaultListModel.addElement(bsmArg);
40+
}
41+
add(new JScrollPane(objectJList), BorderLayout.CENTER);
42+
add(new JPanel() {{
43+
add(new JButton("Add") {{
44+
addActionListener(e -> {
45+
MessageUtil.confirm(new ConfirmPanel() {{
46+
setLayout(new BorderLayout());
47+
JPanel left = new JPanel(new GridLayout(0, 1));
48+
JPanel right = new JPanel(new GridLayout(0, 1));
49+
add(left, BorderLayout.WEST);
50+
add(right, BorderLayout.CENTER);
51+
JComboBox<String> jComboBox = new JComboBox<>(new String[]{"String", "float", "double", "int", "long", "Class"});
52+
left.add(new JLabel("Type:"));
53+
right.add(jComboBox);
54+
left.add(new JLabel("Var:"));
55+
JTextField ldc = new JTextField();
56+
right.add(ldc);
57+
setConfirm(() -> {
58+
Object value;
59+
if (jComboBox.getSelectedItem() != null) {
60+
switch (jComboBox.getSelectedItem().toString()) {
61+
case "float":
62+
value = Float.parseFloat(ldc.getText());
63+
break;
64+
case "double":
65+
value = Double.parseDouble(ldc.getText());
66+
break;
67+
case "int":
68+
value = Integer.parseInt(ldc.getText());
69+
break;
70+
case "long":
71+
value = Long.parseLong(ldc.getText());
72+
break;
73+
case "Class":
74+
value = Type.getType(ldc.getText());
75+
break;
76+
default:
77+
value = ldc.getText();
78+
}
79+
objectDefaultListModel.addElement(value);
80+
}
81+
});
82+
}}, "Add");
83+
});
84+
}});
85+
add(new JButton("Add Handle") {{
86+
addActionListener(e -> {
87+
Wrapper<Handle> handleWrapper = new Wrapper<>(new Handle(1, "", "", "", false));
88+
HandleEditPanel confirmPanel = new HandleEditPanel(handleWrapper);
89+
MessageUtil.confirm(confirmPanel, "Add Handle", () -> {
90+
confirmPanel.getConfirm().run();
91+
objectDefaultListModel.addElement(handleWrapper.getWrapper());
92+
}, () -> {
93+
});
94+
});
95+
}});
96+
add(new JButton("Remove") {{
97+
addActionListener(e -> {
98+
if (objectJList.getSelectedIndex() != -1) {
99+
objectDefaultListModel.remove(objectJList.getSelectedIndex());
100+
}
101+
});
102+
}});
103+
}}, BorderLayout.SOUTH);
104+
setConfirm(() -> {
105+
List<Object> objects = new ArrayList<>();
106+
for (int i = 0; i < objectDefaultListModel.size(); i++) {
107+
objects.add(objectDefaultListModel.get(i));
108+
}
109+
wrapper.setWrapper(objects.toArray(new Object[0]));
110+
});
111+
}
112+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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.confirm;
18+
19+
import javax.swing.*;
20+
import java.awt.*;
21+
22+
/**
23+
* @author Enaium
24+
* @since 0.8.0
25+
*/
26+
public class ConfirmPanel extends JPanel {
27+
28+
private Runnable confirm = () -> {
29+
};
30+
private Runnable cancel = () -> {
31+
};
32+
33+
public Runnable getConfirm() {
34+
return confirm;
35+
}
36+
37+
public void setConfirm(Runnable confirm) {
38+
this.confirm = confirm;
39+
}
40+
41+
public Runnable getCancel() {
42+
return cancel;
43+
}
44+
45+
public void setCancel(Runnable cancel) {
46+
this.cancel = cancel;
47+
}
48+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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.confirm;
18+
19+
import cn.enaium.joe.util.MessageUtil;
20+
import cn.enaium.joe.util.OpcodeUtil;
21+
import cn.enaium.joe.util.StringUtil;
22+
import org.objectweb.asm.tree.FrameNode;
23+
24+
import javax.swing.*;
25+
import javax.swing.border.EmptyBorder;
26+
import java.awt.*;
27+
import java.util.Arrays;
28+
import java.util.List;
29+
import java.util.Map;
30+
import java.util.stream.Collectors;
31+
32+
/**
33+
* @author Enaium
34+
* @since 0.8.0
35+
*/
36+
public class FrameListEditPanel extends ConfirmPanel {
37+
38+
public FrameListEditPanel(FrameNode frameNode) {
39+
setLayout(new BorderLayout(10, 10));
40+
JPanel left = new JPanel(new BorderLayout());
41+
JPanel right = new JPanel(new BorderLayout());
42+
left.add(new JLabel("Local", JLabel.CENTER), BorderLayout.NORTH);
43+
ObjectList localObjectList = new ObjectList(frameNode.local);
44+
left.add(localObjectList, BorderLayout.CENTER);
45+
right.add(new JLabel("Stack", JLabel.CENTER), BorderLayout.NORTH);
46+
ObjectList stackObjectList = new ObjectList(frameNode.stack);
47+
right.add(stackObjectList, BorderLayout.CENTER);
48+
add(left, BorderLayout.WEST);
49+
add(new JSeparator(JSeparator.VERTICAL), BorderLayout.CENTER);
50+
add(right, BorderLayout.EAST);
51+
setConfirm(() -> {
52+
frameNode.local = localObjectList.getList().stream().map(it -> {
53+
Map<String, Integer> reverse = OpcodeUtil.reverse(OpcodeUtil.FRAME_ELEMENT);
54+
if (reverse.containsKey(it.toString())) {
55+
return reverse.get(it.toString());
56+
} else {
57+
return it;
58+
}
59+
}).collect(Collectors.toList());
60+
61+
frameNode.stack = stackObjectList.getList().stream().map(it -> {
62+
Map<String, Integer> reverse = OpcodeUtil.reverse(OpcodeUtil.FRAME_ELEMENT);
63+
if (reverse.containsKey(it.toString())) {
64+
return reverse.get(it.toString());
65+
} else {
66+
return it;
67+
}
68+
}).collect(Collectors.toList());
69+
});
70+
}
71+
72+
private static class ObjectList extends JPanel {
73+
DefaultListModel<String> stringDefaultListModel = new DefaultListModel<>();
74+
75+
public ObjectList(List<Object> list) {
76+
setLayout(new BorderLayout());
77+
setBorder(new EmptyBorder(5, 5, 5, 5));
78+
JList<String> jList = new JList<>(stringDefaultListModel);
79+
for (Object o : list) {
80+
if (o instanceof String) {
81+
stringDefaultListModel.addElement(o.toString());
82+
} else if (o instanceof Integer) {
83+
stringDefaultListModel.addElement(OpcodeUtil.FRAME_ELEMENT.get(Integer.parseInt(o.toString())));
84+
}
85+
}
86+
add(new JScrollPane(jList), BorderLayout.CENTER);
87+
add(new JPanel(new GridLayout(1, 3)) {{
88+
add(new JButton("Add String") {{
89+
addActionListener(e -> {
90+
String s = JOptionPane.showInputDialog(ObjectList.this, "Input:");
91+
if (s != null && !StringUtil.isBlank(s)) {
92+
stringDefaultListModel.addElement(s);
93+
}
94+
});
95+
}});
96+
add(new JButton("Add Type") {{
97+
addActionListener(e -> {
98+
JComboBox<String> message = new JComboBox<>(OpcodeUtil.FRAME_ELEMENT.values().toArray(new String[0]));
99+
MessageUtil.confirm(message, "Type", () -> {
100+
Object selectedItem = message.getSelectedItem();
101+
if (selectedItem != null) {
102+
stringDefaultListModel.addElement(selectedItem.toString());
103+
}
104+
}, () -> {
105+
106+
});
107+
});
108+
}});
109+
add(new JButton("Remove") {{
110+
addActionListener(e -> {
111+
if (jList.getSelectedIndex() != -1) {
112+
stringDefaultListModel.remove(jList.getSelectedIndex());
113+
}
114+
});
115+
}});
116+
}}, BorderLayout.SOUTH);
117+
}
118+
119+
public List<Object> getList() {
120+
return Arrays.asList(stringDefaultListModel.toArray());
121+
}
122+
}
123+
}

0 commit comments

Comments
 (0)