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 README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# JavaOctetEditor

![](https://user-images.githubusercontent.com/32991121/179437944-92726f48-5fe9-44c1-a65d-38b4091e8a84.png)
![](https://s1.ax1x.com/2022/07/30/vi7Lp8.png)
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.5.0'
version '0.6.0'

sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8

Expand Down
32 changes: 32 additions & 0 deletions src/main/java/cn/enaium/joe/dialog/SearchDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,20 @@

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.jar.Jar;
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
Expand All @@ -32,4 +43,25 @@ public SearchDialog() {
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);
}
}
33 changes: 9 additions & 24 deletions src/main/java/cn/enaium/joe/dialog/search/SearchFieldDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,32 +51,17 @@ public SearchFieldDialog() {
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));
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));
}
}
}
JavaOctetEditor.getInstance().bottomPanel.setProcess(0);
});
});
});
}});
Expand Down
27 changes: 6 additions & 21 deletions src/main/java/cn/enaium/joe/dialog/search/SearchLdcDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,15 @@ public SearchLdcDialog() {
add(new JButton("Search") {{
addActionListener(e -> {
if (!text.getText().replace(" ", "").isEmpty()) {
Jar jar = JavaOctetEditor.getInstance().jar;
ASyncUtil.execute(() -> {
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) {
if (instruction instanceof LdcInsnNode) {
String ldc = ((LdcInsnNode) instruction).cst.toString();
if (ldc.contains(text.getText())) {
((DefaultListModel<ResultNode>) resultPanel.getList().getModel()).addElement(new ResultNode(stringClassNodeEntry.getValue(), ldc));
}
}
JavaOctetEditor.getInstance().bottomPanel.setProcess((int) ((loaded++ / total) * 100f));
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));
}
}
}
JavaOctetEditor.getInstance().bottomPanel.setProcess(0);
});
});
}
});
Expand Down
35 changes: 10 additions & 25 deletions src/main/java/cn/enaium/joe/dialog/search/SearchMethodDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,33 +50,18 @@ public SearchMethodDialog() {
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));
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));
}
}
}
JavaOctetEditor.getInstance().bottomPanel.setProcess(0);
});
});
});
}});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* 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.file.tabbed.tab;


import cn.enaium.joe.util.StringUtil;
import org.benf.cfr.reader.util.StringUtils;
import org.objectweb.asm.tree.ClassNode;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.Arrays;

/**
* @author Enaium
* @since 0.6.0
*/
public class ClassInfoTabPanel extends ClassNodeTabPanel {
public ClassInfoTabPanel(ClassNode classNode) {
super(classNode);
setLayout(new BorderLayout());
JPanel labels = new JPanel(new GridLayout(0, 1));
JPanel rights = new JPanel(new GridLayout(0, 1));
add(labels, BorderLayout.WEST);
add(rights, BorderLayout.CENTER);
labels.add(new JLabel("Name:"));
JTextField name = new JTextField(classNode.name);
rights.add(name);
labels.add(new JLabel("SourceFile:"));
JTextField sourceFile = new JTextField(classNode.sourceFile);
rights.add(sourceFile);
labels.add(new JLabel("DebugFile:"));
JTextField sourceDebug = new JTextField(classNode.sourceDebug);
rights.add(sourceDebug);
labels.add(new JLabel("Access:"));
JTextField access = new JTextField(String.valueOf(classNode.access));
rights.add(access);
labels.add(new JLabel("Version:"));
JTextField version = new JTextField(String.valueOf(classNode.version));
rights.add(version);
labels.add(new JLabel("Signature:"));
JTextField signature = new JTextField(classNode.signature);
rights.add(signature);
labels.add(new JLabel("Super Name:"));
JTextField superName = new JTextField(classNode.superName);
rights.add(superName);
labels.add(new JLabel("Interfaces:"));
JTextField interfaces = new JTextField(StringUtils.join(classNode.interfaces, ";"));
rights.add(interfaces);
labels.add(new JLabel("Outer Class:"));
JTextField outerClass = new JTextField(classNode.outerClass);
rights.add(outerClass);
labels.add(new JLabel("Outer Method:"));
JTextField outerMethod = new JTextField(classNode.outerMethod);
rights.add(outerMethod);
labels.add(new JLabel("Outer Method Description:"));
JTextField outerMethodDesc = new JTextField(classNode.outerMethodDesc);
rights.add(outerMethodDesc);
add(new JButton("Save") {{
addActionListener(e -> {

if (!StringUtil.isBlank(name.getText())) {
classNode.name = name.getText();
}

if (!StringUtil.isBlank(sourceFile.getText())) {
classNode.sourceFile = sourceFile.getText();
} else {
classNode.sourceFile = null;
}

if (!StringUtil.isBlank(sourceDebug.getText())) {
classNode.sourceDebug = sourceDebug.getText();
} else {
classNode.sourceDebug = null;
}

if (!StringUtil.isBlank(access.getText())) {
classNode.access = Integer.parseInt(access.getText());
}

if (!StringUtil.isBlank(version.getText())) {
classNode.version = Integer.parseInt(version.getText());
}

if (!StringUtil.isBlank(signature.getText())) {
classNode.signature = signature.getName();
} else {
classNode.signature = null;
}

if (!StringUtil.isBlank(interfaces.getText())) {
classNode.interfaces = Arrays.asList(superName.getText().split(";"));
} else {
classNode.interfaces = new ArrayList<>();
}

if (!StringUtil.isBlank(outerClass.getText())) {
classNode.outerClass = outerClass.getText();
} else {
classNode.outerClass = null;
}

if (!StringUtil.isBlank(outerMethod.getText())) {
classNode.outerMethod = outerMethod.getText();
} else {
classNode.outerClass = null;
}

if (!StringUtil.isBlank(outerMethodDesc.getText())) {
classNode.outerMethodDesc = outerMethodDesc.getText();
} else {
classNode.outerClass = null;
}

JOptionPane.showMessageDialog(ClassInfoTabPanel.this, "Save success");
});
}}, BorderLayout.SOUTH);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
/**
* @author Enaium
*/
public class FileTabPanel extends JPanel {
public FileTabPanel(ClassNode classNode) {
public class ClassTabPanel extends JPanel {
public ClassTabPanel(ClassNode classNode) {
super(new BorderLayout());
JTabbedPane jTabbedPane = new JTabbedPane();
jTabbedPane.setTabPlacement(JTabbedPane.BOTTOM);
jTabbedPane.addTab("BytecodeView", new TraceBytecodeTabPanel(classNode));
jTabbedPane.addTab("DecompileView", new DecompileTabPanel(classNode));
jTabbedPane.addTab("VisitorEdit", new ASMifierTablePanel(classNode));
jTabbedPane.addTab("InfoEdit", new ClassInfoTabPanel(classNode));
add(jTabbedPane);
}
}
Loading