Revert "New stuff"

This reverts commit 4263895148.
This commit is contained in:
Nico committed 2020-11-22 21:19:36 +01:00
1 parent 4263895148
commit 6b66ff27e2
20 files changed
-9741

No files matched your search

-174
View File
@@ -1,174 +0,0 @@
package me.ByteEdit.boxes;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URI;
import java.nio.file.Files;
import java.util.Arrays;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.KeyStroke;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import javax.tools.JavaCompiler;
import javax.tools.SimpleJavaFileObject;
import javax.tools.ToolProvider;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import org.fife.ui.rtextarea.RTextScrollPane;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.tree.ClassNode;
import me.ByteEdit.edit.Disassembler;
import me.ByteEdit.main.Main;
public class CompilationBox extends JFrame {
private JPanel contentPane;
private JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
RSyntaxTextArea textArea = new RSyntaxTextArea();
CompilationSuccess compSuccess;
public CompilationBox() {
compSuccess = new CompilationSuccess();
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
setTitle("Java Compiler");
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
setBounds((int) (Toolkit.getDefaultToolkit().getScreenSize().getWidth() / 2 - 400),
(int) (Toolkit.getDefaultToolkit().getScreenSize().getHeight() / 2 - 200), 800, 400);
contentPane = new JPanel();
contentPane.setBackground(Main.dark ? new Color(0x2F2F2F) : Color.GRAY);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(new BorderLayout(0, 0));
Main.theme.apply(textArea);
textArea.setEditable(true);
textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
textArea.setCodeFoldingEnabled(true);
textArea.setBackground(Main.dark ? new Color(0x2F2F2F) : Color.LIGHT_GRAY);
RTextScrollPane scrollPane = new RTextScrollPane();
scrollPane.setViewportView(textArea);
scrollPane.setLineNumbersEnabled(true);
scrollPane.setFoldIndicatorEnabled(true);
scrollPane.getGutter().setBackground(Main.dark ? new Color(0x2F2F2F) : Color.LIGHT_GRAY);
contentPane.add(scrollPane);
KeyStroke ctrlS = KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_DOWN_MASK);
textArea.registerKeyboardAction(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (compiler == null) {
Main.showError("No Java Compiler found!\nYou need JDK installed!");
return;
}
try (StringWriter out = new StringWriter(); PrintWriter outWriter = new PrintWriter(out)) {
File tmpFolder = Files.createTempDirectory("compiled").toFile();
String source = textArea.getText();
if (!source.contains("\npublic class Compiled {\n")) {
int importIndex = source.lastIndexOf("\nimport");
if (importIndex == -1) {
if (source.startsWith("import")) {
importIndex = 0;
}
} else {
importIndex++;
}
if (importIndex != -1) {
int newLineIndex = source.indexOf('\n', importIndex);
source = source.substring(0, newLineIndex) + "\npublic class Compiled {\n"
+ source.substring(newLineIndex) + "\n}";
} else {
source = "public class Compiled {\n" + source + "\n}";
}
}
compiler.getTask(outWriter, null, null,
Main.jarFile != null
? Arrays.asList("-d", tmpFolder.getAbsolutePath(), "-classpath",
Main.jarFile.getAbsolutePath())
: Arrays.asList("-d", tmpFolder.getAbsolutePath()),
null, Arrays.asList(new JavaSourceFromString("Compiled", source))).call();
String res = out.toString();
if (res.isEmpty()) {
File clazz = new File(tmpFolder, "Compiled.class");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream is = new FileInputStream(clazz);
byte[] tmp = new byte[1024];
int r;
while ((r = is.read(tmp)) > 0) {
baos.write(tmp, 0, r);
}
is.close();
ClassReader read = new ClassReader(baos.toByteArray());
ClassNode node = new ClassNode();
read.accept(node, 0);
String dis = Disassembler.disassemble(node);
File[] files = tmpFolder.listFiles();
if (files != null)
for (File f : files) {
if (f.getName().equals("Compiled.class"))
continue;
baos = new ByteArrayOutputStream();
is = new FileInputStream(f);
while ((r = is.read(tmp)) > 0) {
baos.write(tmp, 0, r);
}
is.close();
read = new ClassReader(baos.toByteArray());
node = new ClassNode();
read.accept(node, 0);
dis += "\n" + Disassembler.disassemble(node);
}
compSuccess.textArea.setText(dis);
compSuccess.setVisible(true);
} else {
JOptionPane.showMessageDialog(CompilationBox.this, res, "Error!", JOptionPane.ERROR_MESSAGE);
}
for (File f : tmpFolder.listFiles()) {
Files.delete(f.toPath());
}
Files.delete(tmpFolder.toPath());
} catch (IOException e1) {
e1.printStackTrace();
}
}
}, ctrlS, JComponent.WHEN_FOCUSED);
}
class JavaSourceFromString extends SimpleJavaFileObject {
final String code;
public JavaSourceFromString(String name, String code) {
super(URI.create("string:///" + name.replace('.', '/') + Kind.SOURCE.extension), Kind.SOURCE);
this.code = code;
}
@Override
public CharSequence getCharContent(boolean ignoreEncodingErrors) {
return code;
}
}
}
-52
View File
@@ -1,52 +0,0 @@
package me.ByteEdit.boxes;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import org.fife.ui.rtextarea.RTextScrollPane;
import me.ByteEdit.main.Main;
public class CompilationSuccess extends JFrame {
private JPanel contentPane;
RSyntaxTextArea textArea = new RSyntaxTextArea();
public CompilationSuccess() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
setTitle("Java Compiler - Result");
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
setBounds((int) (Toolkit.getDefaultToolkit().getScreenSize().getWidth() / 2 - 400),
(int) (Toolkit.getDefaultToolkit().getScreenSize().getHeight() / 2 - 200), 800, 400);
contentPane = new JPanel();
contentPane.setBackground(Main.dark ? new Color(0x2F2F2F) : Color.GRAY);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(new BorderLayout(0, 0));
Main.theme.apply(textArea);
textArea.setEditable(true);
textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA_DISASSEMBLE);
textArea.setCodeFoldingEnabled(true);
textArea.setBackground(Main.dark ? new Color(0x2F2F2F) : Color.LIGHT_GRAY);
RTextScrollPane scrollPane = new RTextScrollPane();
scrollPane.setViewportView(textArea);
scrollPane.setLineNumbersEnabled(true);
scrollPane.setFoldIndicatorEnabled(true);
scrollPane.getGutter().setBackground(Main.dark ? new Color(0x2F2F2F) : Color.LIGHT_GRAY);
contentPane.add(scrollPane);
}
}
-195
View File
@@ -1,195 +0,0 @@
package me.ByteEdit.boxes;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.HashSet;
import java.util.Set;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldInsnNode;
import org.objectweb.asm.tree.LdcInsnNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import me.ByteEdit.boxes.GlobalSearchOpenBox.Info;
import me.ByteEdit.main.Main;
import me.ByteEdit.utils.UnicodeUtils;
public class GlobalSearchBox extends JFrame {
public JPanel contentPane;
public JTextField txtString;
public JCheckBox chckbxCaseSensitive;
private JLabel lblOwner;
private JTextField txtOwner;
private JLabel lblName;
private JTextField txtName;
private JLabel lblDesc;
private JTextField txtDesc;
private GlobalSearchOpenBox openBox;
public GlobalSearchBox() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
openBox = new GlobalSearchOpenBox();
setResizable(false);
setTitle("Global Search");
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
setBounds((int) (Toolkit.getDefaultToolkit().getScreenSize().getWidth() / 2 - 128),
(int) (Toolkit.getDefaultToolkit().getScreenSize().getHeight() / 2 - 181), 256, 262);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblFind = new JLabel("String Search");
lblFind.setBounds(10, 25, 71, 14);
contentPane.add(lblFind);
txtString = new JTextField();
KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
txtString.registerKeyboardAction(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
find();
}
}, enter, JComponent.WHEN_IN_FOCUSED_WINDOW);
txtString.setBounds(91, 22, 149, 20);
contentPane.add(txtString);
txtString.setColumns(10);
chckbxCaseSensitive = new JCheckBox("Case sensitive");
chckbxCaseSensitive.setBounds(10, 199, 114, 23);
contentPane.add(chckbxCaseSensitive);
JButton btnFind = new JButton("Find");
btnFind.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
find();
}
});
btnFind.setBounds(130, 199, 110, 23);
contentPane.add(btnFind);
JLabel lblFieldmethodSearch = new JLabel("Field/Method Search");
lblFieldmethodSearch.setBounds(10, 53, 230, 14);
contentPane.add(lblFieldmethodSearch);
lblOwner = new JLabel("Owner");
lblOwner.setBounds(10, 81, 71, 14);
contentPane.add(lblOwner);
txtOwner = new JTextField();
txtOwner.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
find();
}
});
txtOwner.setColumns(10);
txtOwner.setBounds(91, 78, 149, 20);
contentPane.add(txtOwner);
lblName = new JLabel("Name");
lblName.setBounds(10, 109, 71, 14);
contentPane.add(lblName);
txtName = new JTextField();
txtName.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
find();
}
});
txtName.setColumns(10);
txtName.setBounds(91, 106, 149, 20);
contentPane.add(txtName);
lblDesc = new JLabel("Desc");
lblDesc.setBounds(10, 137, 71, 14);
contentPane.add(lblDesc);
txtDesc = new JTextField();
txtDesc.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
find();
}
});
txtDesc.setColumns(10);
txtDesc.setBounds(91, 134, 149, 20);
contentPane.add(txtDesc);
}
public void find() {
boolean ignoreCase = !chckbxCaseSensitive.isSelected();
openBox.model.clear();
Set<Info> set = new HashSet<>();
if (!txtString.getText().isEmpty()) {
String str = UnicodeUtils.unescape(txtString.getText());
if (ignoreCase) {
str = str.toLowerCase();
}
for (ClassNode cn : Main.classNodes.values()) {
for (MethodNode mn : cn.methods) {
for (AbstractInsnNode insn : mn.instructions.toArray()) {
if (insn instanceof LdcInsnNode && ((LdcInsnNode) insn).cst instanceof String) {
String s = (String) ((LdcInsnNode) insn).cst;
if (ignoreCase) {
s = s.toLowerCase();
}
if (s.contains(str)) {
set.add(new Info(cn.name, mn.name, mn.desc, mn));
}
}
}
}
}
} else {
String owner = UnicodeUtils.unescape(txtOwner.getText());
boolean wildCardOwner = owner.isEmpty();
String name = UnicodeUtils.unescape(txtName.getText());
boolean wildCardName = name.isEmpty();
String desc = UnicodeUtils.unescape(txtDesc.getText());
boolean wildCardDesc = desc.isEmpty();
for (ClassNode cn : Main.classNodes.values()) {
for (MethodNode mn : cn.methods) {
for (AbstractInsnNode insn : mn.instructions.toArray()) {
if (insn instanceof FieldInsnNode) {
if ((wildCardOwner || ((FieldInsnNode) insn).owner.equals(owner))
&& (wildCardName || ((FieldInsnNode) insn).name.equals(name))
&& (wildCardDesc || ((FieldInsnNode) insn).desc.equals(desc))) {
set.add(new Info(cn.name, mn.name, mn.desc, mn));
}
} else if (insn instanceof MethodInsnNode) {
if ((wildCardOwner || ((MethodInsnNode) insn).owner.equals(owner))
&& (wildCardName || ((MethodInsnNode) insn).name.equals(name))
&& (wildCardDesc || ((MethodInsnNode) insn).desc.equals(desc))) {
set.add(new Info(cn.name, mn.name, mn.desc, mn));
}
}
}
}
}
}
for (Info s : set) {
openBox.model.addElement(s);
}
openBox.setVisible(true);
}
}
-134
View File
@@ -1,134 +0,0 @@
package me.ByteEdit.boxes;
import java.awt.Toolkit;
import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.text.BadLocationException;
import org.objectweb.asm.tree.MethodNode;
import me.ByteEdit.main.Main;
public class GlobalSearchOpenBox extends JFrame {
public JPanel contentPane;
DefaultListModel<Info> model;
public GlobalSearchOpenBox() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
setResizable(false);
setTitle("Global Search - Result");
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
setBounds((int) (Toolkit.getDefaultToolkit().getScreenSize().getWidth() / 2 - 200),
(int) (Toolkit.getDefaultToolkit().getScreenSize().getHeight() / 2 - 140), 400, 280);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
model = new DefaultListModel<>();
JList<Info> list = new JList(model);
list.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
Info val = list.getSelectedValue();
if (val != null && !val.owner.equals(Main.currentNodeName)) {
int lineFound = Main.selectFileWithSearch(val.nodePath, val.mn);
if (lineFound != -1) {
try {
Main.txtByteEditView.setCaretPosition(Main.txtByteEditView.getLineStartOffset(lineFound));
} catch (BadLocationException e1) {
e1.printStackTrace();
}
}
}
}
});
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(10, 11, 374, 229);
contentPane.add(scrollPane);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
scrollPane.setViewportView(list);
}
static class Info {
String owner;
String name;
String desc;
MethodNode mn;
String nodePath;
public Info(String owner, String name, String desc, MethodNode mn) {
this.owner = owner;
this.name = name;
this.desc = desc;
this.mn = mn;
nodePath = Main.getFullName(owner);
}
@Override
public String toString() {
return owner + "/" + name + " " + desc;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((desc == null) ? 0 : desc.hashCode());
result = prime * result + ((mn == null) ? 0 : mn.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((owner == null) ? 0 : owner.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Info other = (Info) obj;
if (desc == null) {
if (other.desc != null)
return false;
} else if (!desc.equals(other.desc))
return false;
if (mn == null) {
if (other.mn != null)
return false;
} else if (!mn.equals(other.mn))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (owner == null) {
if (other.owner != null)
return false;
} else if (!owner.equals(other.owner))
return false;
return true;
}
}
}
-39
View File
@@ -1,39 +0,0 @@
package me.ByteEdit.boxes;
import java.awt.Toolkit;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
public class OptionBox extends JFrame {
private JPanel contentPane;
public JCheckBox chckbxComputeFrames;
public JCheckBox chckbxComputeMax;
public OptionBox() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
setResizable(false);
setTitle("Options");
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
setBounds((int) (Toolkit.getDefaultToolkit().getScreenSize().getWidth() / 2 - 150),
(int) (Toolkit.getDefaultToolkit().getScreenSize().getHeight() / 2 - 100), 300, 200);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
chckbxComputeFrames = new JCheckBox("Compute Frames");
chckbxComputeFrames.setBounds(6, 7, 138, 23);
contentPane.add(chckbxComputeFrames);
chckbxComputeMax = new JCheckBox("Compute Max");
chckbxComputeMax.setBounds(6, 33, 138, 23);
contentPane.add(chckbxComputeMax);
}
}
-239
View File
@@ -1,239 +0,0 @@
package me.ByteEdit.boxes;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedList;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldInsnNode;
import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import me.ByteEdit.edit.Disassembler;
import me.ByteEdit.main.Main;
import me.ByteEdit.utils.ClassUtil;
import me.ByteEdit.utils.UnicodeUtils;
public class RenameBox extends JFrame {
private JPanel contentPane;
public JTextField txtName;
public JTextField txtDesc;
public String className;
public String name;
public String desc;
public RenameBox() {
setResizable(false);
setTitle("Rename");
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
setBounds((int) (Toolkit.getDefaultToolkit().getScreenSize().getWidth() / 2 - 225),
(int) (Toolkit.getDefaultToolkit().getScreenSize().getHeight() / 2 - 150), 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblName = new JLabel("Name");
lblName.setBounds(10, 11, 33, 14);
contentPane.add(lblName);
JLabel lblDesc = new JLabel("Desc");
lblDesc.setBounds(10, 36, 33, 14);
contentPane.add(lblDesc);
txtName = new JTextField();
txtName.setBounds(53, 8, 381, 20);
contentPane.add(txtName);
txtName.setColumns(10);
txtDesc = new JTextField();
txtDesc.setColumns(10);
txtDesc.setBounds(53, 36, 381, 20);
contentPane.add(txtDesc);
JButton btnRename = new JButton("Rename");
btnRename.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (className == null) {
JOptionPane.showMessageDialog(null, "ClassName not set!", "Error!", JOptionPane.ERROR_MESSAGE);
return;
}
if (name == null) {
JOptionPane.showMessageDialog(null, "Name not set!", "Error!", JOptionPane.ERROR_MESSAGE);
return;
}
if (desc == null) {
JOptionPane.showMessageDialog(null, "Desc not set!", "Error!", JOptionPane.ERROR_MESSAGE);
return;
}
ClassNode clazz = Main.classNodes.get(Main.getFullName(className));
if (clazz == null) {
JOptionPane.showMessageDialog(null, "ClassNode not found!", "Error!", JOptionPane.ERROR_MESSAGE);
return;
}
String newName = UnicodeUtils.unescape(txtName.getText());
String newDesc = UnicodeUtils.unescape(txtDesc.getText());
if (ClassUtil.isObjectClassMethod(newName, newDesc, true)) {
JOptionPane.showMessageDialog(null, "Invalid name!", "Error!", JOptionPane.ERROR_MESSAGE);
return;
}
if (desc.startsWith("(")) {
if (newDesc.startsWith("(")) { // method
ClassNode lastHit = clazz;
while (clazz != null && clazz.superName != null) {
ClassNode tmp = Main.classNodes.get(Main.getFullName(clazz.superName));
if (tmp != null) {
boolean found = false;
for (MethodNode mn : clazz.methods) {
if (mn.name.equals(name) && mn.desc.equals(desc)) {
lastHit = clazz;
clazz = tmp;
found = true;
break;
}
}
if (!found) {
clazz = tmp;
lastHit = null;
}
} else {
break;
}
}
if (lastHit != null) {
clazz = lastHit;
}
LinkedList<MethodNode> methodsToRename = new LinkedList<>();
LinkedList<MethodInsnNode> minsToRename = new LinkedList<>();
for (ClassNode cn : Main.classNodes.values()) {
boolean extendsMyClass = cn == clazz;
if (!extendsMyClass) {
ClassNode checkCN = cn;
while (checkCN != null && checkCN.superName != null) {
if (clazz.name.equals(checkCN.superName)) {
extendsMyClass = true;
break;
}
ClassNode tmp = Main.classNodes.get(Main.getFullName(checkCN.superName));
if (tmp != null) {
checkCN = tmp;
} else {
break;
}
}
}
for (MethodNode mn : cn.methods) {
if (extendsMyClass) {
if (mn.name.equals(newName) && mn.desc.equals(newDesc)) {
JOptionPane.showMessageDialog(null, "Method already exists in " + cn.name + "!",
"Error!", JOptionPane.ERROR_MESSAGE);
return;
}
if (mn.name.equals(name) && mn.desc.equals(desc)) {
methodsToRename.add(mn);
}
}
for (AbstractInsnNode ain : mn.instructions.toArray()) {
if (ain instanceof MethodInsnNode) {
MethodInsnNode min = (MethodInsnNode) ain;
if (min.name.equals(name) && min.desc.equals(desc)
&& min.owner.equals(clazz.name)) {
minsToRename.add(min);
}
}
}
}
}
for (MethodNode mn : methodsToRename) {
mn.name = newName;
mn.desc = newDesc;
}
for (MethodInsnNode min : minsToRename) {
min.name = newName;
min.desc = newDesc;
}
} else {
JOptionPane.showMessageDialog(null, "New Desc is not a method desc!", "Error!",
JOptionPane.ERROR_MESSAGE);
return;
}
} else {
if (!newDesc.startsWith("(")) { // field
FieldNode currentFN = null;
for (FieldNode fn : clazz.fields) {
if (fn.name.equals(newName) && fn.desc.equals(newDesc)) {
JOptionPane.showMessageDialog(null, "Field already exists!", "Error!",
JOptionPane.ERROR_MESSAGE);
return;
}
if (fn.name.equals(name) && fn.desc.equals(desc)) {
currentFN = fn;
}
}
if (currentFN == null) {
JOptionPane.showMessageDialog(null, "Field not found?!", "Error!",
JOptionPane.ERROR_MESSAGE);
return;
}
currentFN.name = newName;
currentFN.desc = newDesc;
for (ClassNode cn : Main.classNodes.values()) {
for (MethodNode mn : cn.methods) {
for (AbstractInsnNode ain : mn.instructions.toArray()) {
if (ain instanceof FieldInsnNode) {
FieldInsnNode fin = (FieldInsnNode) ain;
if (fin.name.equals(name) && fin.desc.equals(desc)
&& fin.owner.equals(className)) {
fin.name = newName;
fin.desc = newDesc;
}
}
}
}
}
} else {
JOptionPane.showMessageDialog(null, "New Desc is not a field desc!", "Error!",
JOptionPane.ERROR_MESSAGE);
return;
}
}
try { // refresh
ClassNode classNode = Main.classNodes.get(Main.currentNodeName);
int prev = Main.txtByteEditView.getCaretPosition();
String dis = Disassembler.disassemble(classNode);
String substr = Main.currentNodeName.substring(0, Main.currentNodeName.length() - 6);
for (String key : Main.classNodes.keySet()) {
if (key.contains("$")) {
String[] split = key.split("\\$");
if (split[0].equals(substr)) {
dis += "\n" + Disassembler.disassemble(Main.classNodes.get(key));
}
}
}
Main.txtByteEditView.setText(dis);
Main.txtByteEditView.setCaretPosition(prev);
} catch (Exception e2) {
e2.printStackTrace();
}
name = newName;
desc = newDesc;
RenameBox.this.setVisible(false);
}
});
btnRename.setBounds(345, 237, 89, 23);
contentPane.add(btnRename);
}
}
-152
View File
@@ -1,152 +0,0 @@
package me.ByteEdit.boxes;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import me.ByteEdit.main.Main;
public class SearchBox extends JFrame {
public JPanel contentPane;
public JTextField txtFind;
public JTextField txtReplace;
public JCheckBox chckbxCaseSensitive;
public SearchBox() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
setResizable(false);
setTitle("Find/Replace");
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
setBounds((int) (Toolkit.getDefaultToolkit().getScreenSize().getWidth() / 2 - 128),
(int) (Toolkit.getDefaultToolkit().getScreenSize().getHeight() / 2 - 181), 256, 262);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblFind = new JLabel("Find:");
lblFind.setBounds(10, 25, 71, 14);
contentPane.add(lblFind);
txtFind = new JTextField();
KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
txtFind.registerKeyboardAction(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
find();
}
}, enter, JComponent.WHEN_IN_FOCUSED_WINDOW);
txtFind.setBounds(91, 22, 149, 20);
contentPane.add(txtFind);
txtFind.setColumns(10);
JLabel lblReplaceWith = new JLabel("Replace with:");
lblReplaceWith.setBounds(10, 53, 71, 14);
contentPane.add(lblReplaceWith);
txtReplace = new JTextField();
txtReplace.setColumns(10);
txtReplace.setBounds(91, 50, 149, 20);
contentPane.add(txtReplace);
chckbxCaseSensitive = new JCheckBox("Case sensitive");
chckbxCaseSensitive.setBounds(10, 103, 230, 23);
contentPane.add(chckbxCaseSensitive);
JButton btnFind = new JButton("Find");
btnFind.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
find();
}
});
btnFind.setBounds(10, 150, 110, 23);
contentPane.add(btnFind);
JButton btnReplacefind = new JButton("Replace/Find");
btnReplacefind.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
replaceFind();
}
});
btnReplacefind.setBounds(130, 150, 110, 23);
contentPane.add(btnReplacefind);
JButton btnReplace = new JButton("Replace");
btnReplace.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
replace();
}
});
btnReplace.setBounds(10, 184, 110, 23);
contentPane.add(btnReplace);
JButton btnReplaceAll = new JButton("Replace All");
btnReplaceAll.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
replaceAll();
}
});
btnReplaceAll.setBounds(130, 184, 110, 23);
contentPane.add(btnReplaceAll);
}
public void find() {
int startPos = Main.txtByteEditView.getCaretPosition();
String toFind = txtFind.getText();
String txt = chckbxCaseSensitive.isSelected() ? Main.txtByteEditView.getText().substring(startPos)
: Main.txtByteEditView.getText().substring(startPos).toLowerCase();
int index = txt.indexOf(chckbxCaseSensitive.isSelected() ? toFind : toFind.toLowerCase());
if (index == -1) {
txt = chckbxCaseSensitive.isSelected() ? Main.txtByteEditView.getText()
: Main.txtByteEditView.getText().toLowerCase();
index = txt.indexOf(chckbxCaseSensitive.isSelected() ? toFind : toFind.toLowerCase());
startPos = 0;
if (index == -1) {
return;
}
}
Main.txtByteEditView.select(startPos + index, startPos + index + toFind.length());
}
public void replaceFind() {
replace();
find();
}
public void replace() {
String txt = Main.txtByteEditView.getText();
int startPos = Main.txtByteEditView.getSelectionStart();
Main.txtByteEditView.replaceSelection(txtReplace.getText());
Main.txtByteEditView.select(startPos, startPos + txtReplace.getText().length());
}
public void replaceAll() {
String toFind = txtFind.getText();
String toReplace = txtReplace.getText();
String txt = Main.txtByteEditView.getText();
int prev = Main.txtByteEditView.getCaretPosition();
if (chckbxCaseSensitive.isSelected()) {
Main.txtByteEditView.replaceRange(txt.replace(toFind, toReplace), 0, txt.length());
} else {
Main.txtByteEditView.replaceRange(
txt.replaceAll("(?i)" + Pattern.quote(toFind), Matcher.quoteReplacement(toReplace)), 0,
txt.length());
}
Main.txtByteEditView.setCaretPosition(prev);
}
}
-117
View File
@@ -1,117 +0,0 @@
package me.ByteEdit.boxes;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import me.ByteEdit.main.Main;
import me.ByteEdit.utils.UnicodeUtils;
public class TypeOpenBox extends JFrame {
public JPanel contentPane;
public JTextField txtSearch;
public TypeOpenBox() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
setResizable(false);
setTitle("Open Type");
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
setBounds((int) (Toolkit.getDefaultToolkit().getScreenSize().getWidth() / 2 - 200),
(int) (Toolkit.getDefaultToolkit().getScreenSize().getHeight() / 2 - 140), 400, 280);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
DefaultListModel<String> model = new DefaultListModel<>();
JList<String> list = new JList(model);
list.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
String val = list.getSelectedValue();
if (val != null && !val.equals(Main.currentNodeName)) {
Main.selectFile(val);
}
}
});
txtSearch = new JTextField();
txtSearch.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (model.size() == 1) {
list.setSelectedIndex(0);
}
}
});
txtSearch.getDocument().addDocumentListener(new DocumentListener() {
public void changedUpdate(DocumentEvent e) {
updateList();
}
public void removeUpdate(DocumentEvent e) {
updateList();
}
public void insertUpdate(DocumentEvent e) {
updateList();
}
public void updateList() {
model.clear();
if (txtSearch.getText().isEmpty()) {
return;
}
String search = UnicodeUtils.unescape(txtSearch.getText()).toLowerCase();
if (search.contains("/")) {
for (String s : Main.classNodes.keySet()) {
String className = s.substring(0, s.length() - 6);
if (!className.contains("$") && className.toLowerCase().startsWith(search)) {
model.addElement(s);
}
}
} else {
for (String s : Main.classNodes.keySet()) {
String[] split = s.split("/");
String className = split[split.length - 1];
className = className.substring(0, className.length() - 6);
if (!className.contains("$") && className.toLowerCase().startsWith(search)) {
model.addElement(s);
}
}
}
}
});
txtSearch.setBounds(10, 11, 374, 20);
contentPane.add(txtSearch);
txtSearch.setColumns(10);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(10, 46, 374, 194);
contentPane.add(scrollPane);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
scrollPane.setViewportView(list);
}
}
-74
View File
@@ -1,74 +0,0 @@
package me.ByteEdit.boxes;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import me.ByteEdit.main.Main;
import me.ByteEdit.utils.UnicodeUtils;
public class UnicodeBox extends JFrame {
private JPanel contentPane;
public UnicodeBox() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
setResizable(false);
setTitle("Unicode Converter");
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
setBounds((int) (Toolkit.getDefaultToolkit().getScreenSize().getWidth() / 2 - 150),
(int) (Toolkit.getDefaultToolkit().getScreenSize().getHeight() / 2 - 100), 300, 200);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JTextArea textArea = new JTextArea();
JButton btnEscape = new JButton("Escape");
btnEscape.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
textArea.setText(UnicodeUtils.escape(textArea.getText()));
} catch (IllegalArgumentException ex) {
Main.showError(ex.getMessage());
}
}
});
btnEscape.setBounds(10, 137, 89, 23);
contentPane.add(btnEscape);
JButton btnUnescape = new JButton("Unescape");
btnUnescape.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
textArea.setText(UnicodeUtils.unescape(textArea.getText()));
} catch (IllegalArgumentException ex) {
Main.showError(ex.getMessage());
}
}
});
btnUnescape.setBounds(195, 137, 89, 23);
contentPane.add(btnUnescape);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(10, 11, 274, 115);
contentPane.add(scrollPane);
scrollPane.setViewportView(textArea);
}
}
File diff suppressed because it is too large. Load diff
-602
View File
@@ -1,602 +0,0 @@
package me.ByteEdit.edit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import org.objectweb.asm.Handle;
import org.objectweb.asm.Label;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldInsnNode;
import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.FrameNode;
import org.objectweb.asm.tree.IincInsnNode;
import org.objectweb.asm.tree.InnerClassNode;
import org.objectweb.asm.tree.InsnNode;
import org.objectweb.asm.tree.IntInsnNode;
import org.objectweb.asm.tree.InvokeDynamicInsnNode;
import org.objectweb.asm.tree.JumpInsnNode;
import org.objectweb.asm.tree.LabelNode;
import org.objectweb.asm.tree.LdcInsnNode;
import org.objectweb.asm.tree.LineNumberNode;
import org.objectweb.asm.tree.LocalVariableNode;
import org.objectweb.asm.tree.LookupSwitchInsnNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.MultiANewArrayInsnNode;
import org.objectweb.asm.tree.TableSwitchInsnNode;
import org.objectweb.asm.tree.TryCatchBlockNode;
import org.objectweb.asm.tree.TypeInsnNode;
import org.objectweb.asm.tree.VarInsnNode;
import me.ByteEdit.utils.ClassUtil;
import me.ByteEdit.utils.OpcodesReverse;
import me.ByteEdit.utils.UnicodeUtils;
public class Disassembler {
public static String disassemble(ClassNode classNode) {
return disassemble(classNode, null).getDisassembly();
}
public static class DisassembleTuple {
private final String dis;
private final int line;
public DisassembleTuple(String dis) {
this.dis = dis;
this.line = -1;
}
public DisassembleTuple(String dis, int line) {
this.dis = dis;
this.line = line;
}
public String getDisassembly() {
return dis;
}
public int getLine() {
return line;
}
}
public static DisassembleTuple disassemble(ClassNode classNode, Object nodeToFind) {
if (classNode == null) {
return new DisassembleTuple("ClassNode is null! This is not a valid java class file!");
}
try {
int lineFound = -1;
String s = "";
s += "// #Annotations:\n";
if (classNode.visibleAnnotations != null && !classNode.visibleAnnotations.isEmpty()) {
for (AnnotationNode annotationNode : classNode.visibleAnnotations) {
s += "@" + UnicodeUtils.escapeWithSpaces(annotationNode.desc);
if (annotationNode.values != null && !annotationNode.values.isEmpty()) {
s += " (";
boolean valBefore = true;
for (Object o : annotationNode.values) {
if (valBefore) {
s += o + " = [";
valBefore = false;
continue;
} else {
if (o instanceof String[]) {
String[] arr = (String[]) o;
boolean w8ing = false;
for (String rofl : arr) {
if (!w8ing) {
s += UnicodeUtils.escapeWithSpaces(rofl) + "/";
w8ing = true;
} else {
s += UnicodeUtils.escapeWithSpaces(rofl) + "]";
}
}
s += ", ";
} else if (o instanceof List) {
List list = (List) o;
s += "{ ";
for (Object obj : list) {
if (obj instanceof String[]) {
String[] arr = (String[]) obj;
boolean w8ing = false;
for (String rofl : arr) {
if (!w8ing) {
s += UnicodeUtils.escapeWithSpaces(rofl) + "/";
w8ing = true;
} else {
s += UnicodeUtils.escapeWithSpaces(rofl);
}
}
} else {
s += "\"" + UnicodeUtils.escape(String.valueOf(obj)) + "\"";
}
s += ", ";
}
s = s.substring(0, s.length() - 2);
s += " }]";
} else if (o instanceof String) {
s += "\"" + UnicodeUtils.escapeWithSpaces((String) o) + "\"], ";
} else {
s += "(" + o.getClass().getName().replace(".", "/") + ") " + o + "], ";
}
valBefore = true;
}
}
if (s.endsWith(", "))
s = s.substring(0, s.length() - 2);
s += ")";
}
s += "\n";
}
}
s += "// #Class v:" + classNode.version + "\n";
if (classNode.signature != null)
s += "// #Signature: " + UnicodeUtils.escapeWithSpaces(classNode.signature) + "\n";
if (classNode.outerMethod != null)
s += "// #OuterMethod: " + (classNode.outerMethod == null ? "null"
: (UnicodeUtils.escapeWithSpaces(classNode.outerMethod) + " "
+ UnicodeUtils.escapeWithSpaces(classNode.outerMethodDesc)))
+ "\n";
if (classNode.outerClass != null)
s += "// #OuterClass: " + UnicodeUtils.escapeWithSpaces(classNode.outerClass) + "\n";
s += "// #InnerClasses:\n";
if (classNode.innerClasses != null) {
for (InnerClassNode icn : classNode.innerClasses) {
s += "// " + UnicodeUtils.escapeWithSpaces(icn.name) + " "
+ UnicodeUtils.escapeWithSpaces(icn.outerName) + " "
+ UnicodeUtils.escapeWithSpaces(icn.innerName)
+ (icn.access == 0 ? "" : " " + ClassUtil.getAccessFlagsFull(icn.access).trim()) + "\n";
}
}
s += ClassUtil.getAccessFlagsClass(classNode.access) + UnicodeUtils.escapeWithSpaces(classNode.name) + " ";
s += "extends " + UnicodeUtils.escapeWithSpaces(classNode.superName) + " ";
if (classNode.interfaces != null && !classNode.interfaces.isEmpty()) {
String interfaceStr = "";
for (String interfc : classNode.interfaces) {
if (interfaceStr.isEmpty()) {
interfaceStr += UnicodeUtils.escapeWithSpaces(interfc);
} else {
interfaceStr += ", " + UnicodeUtils.escapeWithSpaces(interfc);
}
}
if (!interfaceStr.isEmpty())
s += "implements " + interfaceStr + " ";
}
s += "{\n// #SourceFile: "
+ (classNode.sourceFile == null ? "null" : UnicodeUtils.escape(classNode.sourceFile))
+ "\n\n// #Fields\n";
for (FieldNode fn : classNode.fields) {
if (fn.signature != null)
s += "\t// #Signature: " + UnicodeUtils.escapeWithSpaces(fn.signature) + "\n";
if (fn.visibleAnnotations != null && !fn.visibleAnnotations.isEmpty()) {
for (AnnotationNode annotationNode : fn.visibleAnnotations) {
s += "\t@" + UnicodeUtils.escapeWithSpaces(annotationNode.desc);
if (annotationNode.values != null && !annotationNode.values.isEmpty()) {
s += " (";
boolean valBefore = true;
for (Object o : annotationNode.values) {
if (valBefore) {
s += o + " = [";
valBefore = false;
continue;
} else {
if (o instanceof String[]) {
String[] arr = (String[]) o;
boolean w8ing = false;
for (String rofl : arr) {
if (!w8ing) {
s += UnicodeUtils.escapeWithSpaces(rofl) + "/";
w8ing = true;
} else {
s += UnicodeUtils.escapeWithSpaces(rofl) + "]";
}
}
s += ", ";
} else if (o instanceof List) {
List list = (List) o;
s += "{ ";
for (Object obj : list) {
if (obj instanceof String[]) {
String[] arr = (String[]) obj;
boolean w8ing = false;
for (String rofl : arr) {
if (!w8ing) {
s += UnicodeUtils.escapeWithSpaces(rofl) + "/";
w8ing = true;
} else {
s += UnicodeUtils.escapeWithSpaces(rofl);
}
}
} else {
s += "\"" + UnicodeUtils.escape(String.valueOf(obj)) + "\"";
}
s += ", ";
}
s = s.substring(0, s.length() - 2);
s += " }]";
} else {
s += "(" + o.getClass().getName().replace(".", "/") + ") " + o + "], ";
}
valBefore = true;
}
}
if (s.endsWith(", "))
s = s.substring(0, s.length() - 2);
s += ")";
}
s += "\n";
}
}
if (fn.equals(nodeToFind)) {
lineFound = s.split("\\n").length;
}
s += "\t" + ClassUtil.getAccessFlagsFull(fn.access).replace("varargs", "transient")
+ UnicodeUtils.escapeWithSpaces(fn.desc) + " " + UnicodeUtils.escapeWithSpaces(fn.name);
if (fn.value != null) {
s += " = " + ClassUtil.getDecompiledValue(fn.value, fn.desc, true);
}
s += "\n";
}
s += "\n// #Methods\n";
for (MethodNode mn : classNode.methods) {
try {
s += "\t// #Max: l:" + mn.maxLocals + " s:" + mn.maxStack + "\n";
if (mn.signature != null)
s += "\t// #Signature: " + UnicodeUtils.escapeWithSpaces(mn.signature) + "\n";
String[] dis = disassembleMethod(classNode.name, mn);
s += dis[2];
s += dis[1];
if (mn.visibleAnnotations != null && !mn.visibleAnnotations.isEmpty()) {
for (AnnotationNode annotationNode : mn.visibleAnnotations) {
s += "\t@" + annotationNode.desc;
if (annotationNode.values != null && !annotationNode.values.isEmpty()) {
s += " (";
boolean valBefore = true;
for (Object o : annotationNode.values) {
if (valBefore) {
s += o + " = [";
valBefore = false;
continue;
} else {
if (o instanceof String[]) {
String[] arr = (String[]) o;
boolean w8ing = false;
for (String rofl : arr) {
if (!w8ing) {
s += UnicodeUtils.escapeWithSpaces(rofl) + "/";
w8ing = true;
} else {
s += UnicodeUtils.escapeWithSpaces(rofl) + "]";
}
}
s += ", ";
} else if (o instanceof List) {
List list = (List) o;
s += "{ ";
for (Object obj : list) {
if (obj instanceof String[]) {
String[] arr = (String[]) obj;
boolean w8ing = false;
for (String rofl : arr) {
if (!w8ing) {
s += UnicodeUtils.escapeWithSpaces(rofl) + "/";
w8ing = true;
} else {
s += UnicodeUtils.escapeWithSpaces(rofl);
}
}
} else {
s += "\"" + UnicodeUtils.escape(String.valueOf(obj)) + "\"";
}
s += ", ";
}
s = s.substring(0, s.length() - 2);
s += " }]";
} else {
s += "(" + o.getClass().getName().replace(".", "/") + ") " + o + "], ";
}
valBefore = true;
}
}
if (s.endsWith(", "))
s = s.substring(0, s.length() - 2);
s += ")";
}
s += "\n";
}
}
if (mn.equals(nodeToFind)) {
lineFound = s.split("\\n").length;
}
s += "\t" + ClassUtil.getAccessFlagsFull(mn.access) + UnicodeUtils.escapeWithSpaces(mn.name) + " "
+ UnicodeUtils.escapeWithSpaces(mn.desc) + " ";
if (mn.exceptions != null && !mn.exceptions.isEmpty()) {
String exceptionStr = "";
for (String exc : mn.exceptions) {
if (exceptionStr.isEmpty()) {
exceptionStr += UnicodeUtils.escapeWithSpaces(exc);
} else {
exceptionStr += ", " + UnicodeUtils.escapeWithSpaces(exc);
}
}
if (!exceptionStr.isEmpty())
s += "throws " + exceptionStr + " ";
}
s += "{\n";
s += dis[0];
s += "\t}\n\n";
} catch (Exception e) {
s += "\t\t// Method couldn't be disassembled:\n\t\t// "
+ e.getClass().getName() + ": " + e.getMessage() + "\n" + Arrays.toString(e.getStackTrace())
.replace(", ", "\n\t\t// \tat ").replace("[", "\t\t// \tat ").replace("]", "")
+ "\n\t}\n\n";
}
}
s += "}\n";
return new DisassembleTuple(s, lineFound);
} catch (Throwable e) {
return new DisassembleTuple("Class couldn't be decompiled:\n" + e.getClass().getName() + ": "
+ e.getMessage() + "\n"
+ Arrays.toString(e.getStackTrace()).replace(", ", "\n\tat ").replace("[", "\tat ").replace("]", "")
+ "\n");
}
}
private static String[] disassembleMethod(String className, MethodNode mn) {
HashMap<Label, Integer> labels = new HashMap<Label, Integer>();
String s = "";
String localVarTable = "";
String tryCatchTable = "";
for (AbstractInsnNode n : mn.instructions.toArray()) {
if (n instanceof LabelNode) {
labels.put(((LabelNode) n).getLabel(), labels.size() + 1);
}
}
if (mn.localVariables != null && !mn.localVariables.isEmpty()) {
localVarTable = "\t// #LocalVars:\n";
for (LocalVariableNode lvn : mn.localVariables) {
localVarTable += "\t// " + UnicodeUtils.escapeWithSpaces(lvn.name) + ": "
+ UnicodeUtils.escapeWithSpaces(lvn.desc) + " i:" + lvn.index + " s:"
+ labels.get(lvn.start.getLabel()) + " e:" + labels.get(lvn.end.getLabel()) + " sig:"
+ UnicodeUtils.escapeWithSpaces(lvn.signature) + "\n";
}
}
if (mn.tryCatchBlocks != null && !mn.tryCatchBlocks.isEmpty()) {
tryCatchTable = "\t// #TryCatch:\n";
for (TryCatchBlockNode tcbn : mn.tryCatchBlocks) {
tryCatchTable += "\t// " + UnicodeUtils.escapeWithSpaces(tcbn.type) + " s:"
+ labels.get(tcbn.start.getLabel()) + " e:" + labels.get(tcbn.end.getLabel()) + " h:"
+ labels.get(tcbn.handler.getLabel()) + "\n";
}
}
for (AbstractInsnNode n : mn.instructions.toArray()) {
s += disassembleInstruction(n, labels);
}
return new String[] { s, localVarTable, tryCatchTable };
}
public static String disassembleInstruction(AbstractInsnNode n, HashMap<Label, Integer> labels) {
if (FieldInsnNode.class.isInstance(n)) {
FieldInsnNode node = (FieldInsnNode) n;
return "\t\t" + OpcodesReverse.reverseOpcode(node.getOpcode()) + " "
+ UnicodeUtils.escapeWithSpaces(node.desc) + " " + UnicodeUtils.escapeWithSpaces(node.owner) + "/"
+ UnicodeUtils.escapeWithSpaces(node.name).replace("/", "\\u002F") + "\n";
} else if (LabelNode.class.isInstance(n)) {
LabelNode node = (LabelNode) n;
return "\t\t// label " + labels.get(node.getLabel()) + "\n";
} else if (FrameNode.class.isInstance(n)) {
FrameNode node = (FrameNode) n;
String type = "";
switch (node.type) {
case Opcodes.F_NEW:
type = "NEW";
break;
case Opcodes.F_FULL:
type = "FULL";
break;
case Opcodes.F_APPEND:
type = "APPEND";
break;
case Opcodes.F_CHOP:
type = "CHOP";
break;
case Opcodes.F_SAME:
type = "SAME";
break;
case Opcodes.F_SAME1:
type = "SAME1";
break;
}
String s = "\t\t// frame " + type + " l:";
ArrayList<String> arr = new ArrayList<>();
if (node.local != null) {
for (Object o : node.local) {
if (o == null) {
arr.add(null);
} else {
if (o instanceof String) {
arr.add("\"" + UnicodeUtils.escapeWithSpaces((String) o) + "\"");
} else if (o instanceof LabelNode) {
arr.add("(label) " + labels.get(((LabelNode) o).getLabel()));
} else if (o instanceof Integer) {
String frameType = ClassUtil.getFrameTypeByID(((Integer) o).intValue());
if (frameType != null)
arr.add(frameType);
else
arr.add("(" + o.getClass().getName().replace(".", "/") + ") " + o);
} else {
arr.add("(" + o.getClass().getName().replace(".", "/") + ") " + o);
}
}
}
s += arr.toString();
} else {
s += "null";
}
arr.clear();
s += " s:";
if (node.stack != null) {
for (Object o : node.stack) {
if (o == null) {
arr.add(null);
} else {
if (o instanceof String) {
arr.add("\"" + UnicodeUtils.escapeWithSpaces((String) o) + "\"");
} else if (o instanceof LabelNode) {
arr.add("(label) " + labels.get(((LabelNode) o).getLabel()));
} else if (o instanceof Integer) {
String frameType = ClassUtil.getFrameTypeByID(((Integer) o).intValue());
if (frameType != null)
arr.add(frameType);
else
arr.add("(" + o.getClass().getName().replace(".", "/") + ") " + o);
} else {
arr.add("(" + o.getClass().getName().replace(".", "/") + ") " + o);
}
}
}
s += arr.toString();
} else {
s += "null";
}
s += "\n";
return s;
} else if (LineNumberNode.class.isInstance(n)) {
LineNumberNode node = (LineNumberNode) n;
return "\t\t// line " + node.line + " " + labels.get(node.start.getLabel()) + "\n";
} else if (InvokeDynamicInsnNode.class.isInstance(n)) {
InvokeDynamicInsnNode node = (InvokeDynamicInsnNode) n;
String s = "\t\t" + OpcodesReverse.reverseOpcode(node.getOpcode()) + " [\n\t\t\tname: "
+ UnicodeUtils.escapeWithSpaces(node.name).replace("/", "\\u002F") + "\n\t\t\tdesc: "
+ UnicodeUtils.escapeWithSpaces(node.desc) + "\n\t\t\tHandle: [\n\t\t\t\tname: "
+ UnicodeUtils.escapeWithSpaces(node.bsm.getName()) + "\n\t\t\t\towner: "
+ UnicodeUtils.escapeWithSpaces(node.bsm.getOwner()) + "\n\t\t\t\tdesc: "
+ UnicodeUtils.escapeWithSpaces(node.bsm.getDesc()) + "\n\t\t\t\tisInterface: "
+ node.bsm.isInterface() + "\n\t\t\t\ttag: " + OpcodesReverse.reverseHandleOpcode(node.bsm.getTag())
+ "\n\t\t\t]\n\t\t\targs: [\n";
for (Object l : node.bsmArgs) {
if (l.getClass().getName().equals("org.objectweb.asm.Type")) {
Type type = (Type) l;
int valueBegin = type.valueBegin;
int valueEnd = type.valueEnd;
String buf = type.valueBuffer;
// Reflection
s += "\t\t\t\tType: [\n\t\t\t\t\ttype: " + ClassUtil.getClassNameFromType(type)
+ "\n\t\t\t\t\tstart: " + valueBegin + "\n\t\t\t\t\tend: " + valueEnd + "\n\t\t\t\t\tbuf: "
+ ClassUtil.getDecompiledValue(buf, "");
s += "\n\t\t\t\t]\n";
} else if (l.getClass().getName().equals("org.objectweb.asm.Handle")) {
Handle h = (Handle) l;
s += "\t\t\t\tHandle: [\n\t\t\t\t\tname: "
+ UnicodeUtils.escapeWithSpaces(h.getName()).replace("/", "\\u002F") + "\n\t\t\t\t\towner: "
+ UnicodeUtils.escapeWithSpaces(h.getOwner()) + "\n\t\t\t\t\tdesc: "
+ UnicodeUtils.escapeWithSpaces(h.getDesc()) + "\n\t\t\t\t\tisInterface: " + h.isInterface()
+ "\n\t\t\t\t\ttag: " + OpcodesReverse.reverseHandleOpcode(h.getTag());
s += "\n\t\t\t\t]\n";
} else {
s += "\t\t\t\t" + ClassUtil.getDecompiledValue(l, "") + "\n";
}
}
s += "\t\t\t]\n\t\t]\n";
return s;
} else if (MethodInsnNode.class.isInstance(n)) {
MethodInsnNode node = (MethodInsnNode) n;
return "\t\t" + OpcodesReverse.reverseOpcode(node.getOpcode()) + " "
+ UnicodeUtils.escapeWithSpaces(node.desc) + " " + UnicodeUtils.escapeWithSpaces(node.owner) + "/"
+ UnicodeUtils.escapeWithSpaces(node.name).replace("/", "\\u002F") + "\n";
} else if (TypeInsnNode.class.isInstance(n)) {
TypeInsnNode node = (TypeInsnNode) n;
return "\t\t" + OpcodesReverse.reverseOpcode(node.getOpcode()) + " "
+ UnicodeUtils.escapeWithSpaces(node.desc) + "\n";
} else if (MultiANewArrayInsnNode.class.isInstance(n)) {
MultiANewArrayInsnNode node = (MultiANewArrayInsnNode) n;
return "\t\t" + OpcodesReverse.reverseOpcode(node.getOpcode()) + " "
+ UnicodeUtils.escapeWithSpaces(node.desc) + " " + node.dims + "\n";
} else if (LdcInsnNode.class.isInstance(n)) {
LdcInsnNode node = (LdcInsnNode) n;
switch (node.cst.getClass().getSimpleName()) {
case "String":
case "Double":
case "Integer":
case "Float":
case "Long": {
return "\t\t" + OpcodesReverse.reverseOpcode(node.getOpcode()) + " "
+ ClassUtil.getDecompiledValue(node.cst, "") + "\n";
}
case "Type": {
Type type = (Type) node.cst;
int valueBegin = type.valueBegin;
int valueEnd = type.valueEnd;
String buf = type.valueBuffer;
// Reflection
String s = "\t\t" + OpcodesReverse.reverseOpcode(n.getOpcode()) + " Type: [\n\t\t\ttype: "
+ ClassUtil.getClassNameFromType(type) + "\n\t\t\tstart: " + valueBegin + "\n\t\t\tend: "
+ valueEnd + "\n\t\t\tbuf: " + ClassUtil.getDecompiledValue(buf, "");
s += "\n\t\t]\n";
return s;
}
default: {
return "\t\tUNRESOLVED TYPE! " + OpcodesReverse.reverseOpcode(node.getOpcode()) + " "
+ node.cst.getClass().getName().replace(".", "/") + " " + node.cst + "\n";
}
}
} else if (VarInsnNode.class.isInstance(n)) {
VarInsnNode node = (VarInsnNode) n;
return "\t\t" + OpcodesReverse.reverseOpcode(n.getOpcode()) + " " + node.var + "\n";
} else if (InsnNode.class.isInstance(n)) {
InsnNode node = (InsnNode) n;
return "\t\t" + OpcodesReverse.reverseOpcode(n.getOpcode()) + "\n";
} else if (IntInsnNode.class.isInstance(n)) {
IntInsnNode node = (IntInsnNode) n;
if (n.getOpcode() == Opcodes.NEWARRAY) {
return "\t\t" + OpcodesReverse.reverseOpcode(n.getOpcode()) + " "
+ ClassUtil.getArrayTypeByID(node.operand) + "\n";
} else {
return "\t\t" + OpcodesReverse.reverseOpcode(n.getOpcode()) + " " + node.operand + "\n";
}
} else if (JumpInsnNode.class.isInstance(n)) {
JumpInsnNode node = (JumpInsnNode) n;
return "\t\t" + OpcodesReverse.reverseOpcode(n.getOpcode()) + " " + labels.get(node.label.getLabel())
+ "\n";
} else if (TableSwitchInsnNode.class.isInstance(n)) {
TableSwitchInsnNode node = (TableSwitchInsnNode) n;
String s = "\t\t" + OpcodesReverse.reverseOpcode(n.getOpcode()) + " [\n\t\t\tmin: " + node.min
+ "\n\t\t\tmax: " + node.max + "\n\t\t\tdefault: " + labels.get(node.dflt.getLabel())
+ "\n\t\t\tlabels: [\n";
for (LabelNode l : node.labels) {
s += "\t\t\t\t" + labels.get(l.getLabel()) + "\n";
}
s += "\t\t\t]\n\t\t]\n";
return s;
} else if (LookupSwitchInsnNode.class.isInstance(n)) {
LookupSwitchInsnNode node = (LookupSwitchInsnNode) n;
String s = "\t\t" + OpcodesReverse.reverseOpcode(n.getOpcode()) + " [\n\t\t\tdefault: "
+ labels.get(node.dflt.getLabel()) + "\n\t\t\tkeys: [\n";
for (Integer l : node.keys) {
s += "\t\t\t\t" + l + "\n";
}
s += "\t\t\t]" + "\n\t\t\tlabels: [\n";
for (LabelNode l : node.labels) {
s += "\t\t\t\t" + labels.get(l.getLabel()) + "\n";
}
s += "\t\t\t]\n\t\t]\n";
return s;
} else if (IincInsnNode.class.isInstance(n)) {
IincInsnNode node = (IincInsnNode) n;
return "\t\t" + OpcodesReverse.reverseOpcode(n.getOpcode()) + " " + node.var + " " + node.incr + "\n";
} else {
return "\t\tNOT HANDLED! " + OpcodesReverse.reverseOpcode(n.getOpcode()) + " "
+ n.getClass().getSimpleName() + "\n";
}
}
}
File diff suppressed because it is too large. Load diff
-19
View File
@@ -1,19 +0,0 @@
package me.ByteEdit.main;
import javax.swing.tree.DefaultMutableTreeNode;
public class ByteEditTreeNode extends DefaultMutableTreeNode {
public String path;
public ByteEditTreeNode(String name) {
super(name);
}
public ByteEditTreeNode(String name, String path) {
this(name);
if (name.endsWith(".class"))
this.path = path;
}
}
File diff suppressed because it is too large. Load diff
-644
View File
@@ -1,644 +0,0 @@
package me.ByteEdit.utils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import org.objectweb.asm.Type;
public class ClassUtil {
public static final int ACC_PUBLIC = 0x0001;
public static final int ACC_PRIVATE = 0x0002;
public static final int ACC_PROTECTED = 0x0004;
public static final int ACC_STATIC = 0x0008;
public static final int ACC_FINAL = 0x0010;
public static final int ACC_SYNCHRONIZED = 0x0020;
public static final int ACC_SUPER = 0x0020;
public static final int ACC_BRIDGE = 0x0040;
public static final int ACC_VARARGS = 0x0080;
public static final int ACC_NATIVE = 0x0100;
public static final int ACC_INTERFACE = 0x0200;
public static final int ACC_ABSTRACT = 0x0400;
public static final int ACC_STRICTFP = 0x0800;
public static final int ACC_SYNTHETIC = 0x1000;
public static final int ACC_ANNOTATION = 0x2000;
public static final int ACC_ENUM = 0x4000;
public static final int ACC_MANDATED = 0x8000;
public static boolean isObjectClassMethod(String name, String desc, boolean forbidInits) {
switch (name) {
case "<init>":
case "<clinit>":
if (forbidInits) {
return true;
}
case "notifyAll":
case "notify":
if (desc.equals("()V")) {
return true;
}
break;
case "wait":
if (desc.equals("()V") || desc.equals("(J)V") || desc.equals("(JI)V")) {
return true;
}
break;
case "equals":
if (desc.equals("(Ljava/lang/Object;)Z")) {
return true;
}
break;
case "hashCode":
if (desc.equals("()I")) {
return true;
}
break;
default:
break;
}
return false;
}
public static int getIDFromClassNameForType(String s) {
s = s.toUpperCase();
switch (s) {
case "V": {
return 0;
}
case "Z": {
return 1;
}
case "C": {
return 2;
}
case "B": {
return 3;
}
case "S": {
return 4;
}
case "I": {
return 5;
}
case "F": {
return 6;
}
case "J": {
return 7;
}
case "D": {
return 8;
}
case "NAME": {
return 10;
}
default: {
return Integer.parseInt(s);
}
}
}
public static String getClassNameFromType(Type type) {
switch (type.getSort()) {
case 0: {
return "V";
}
case 1: {
return "Z";
}
case 2: {
return "C";
}
case 3: {
return "B";
}
case 4: {
return "S";
}
case 5: {
return "I";
}
case 6: {
return "F";
}
case 7: {
return "J";
}
case 8: {
return "D";
}
case 9: {
return getClassNameFromType(type.getElementType());
}
case 10: {
return "Name";
}
}
return Integer.toString(type.getSort());
}
public static String getArrayTypeByID(int id) {
switch (id) {
case 4:
return "Z";
case 5:
return "C";
case 6:
return "F";
case 7:
return "D";
case 8:
return "B";
case 9:
return "S";
case 10:
return "I";
case 11:
return "J";
default:
return Integer.toString(id);
}
}
public static int getArrayIDByType(String type) {
switch (type) {
case "Z":
return 4;
case "C":
return 5;
case "F":
return 6;
case "D":
return 7;
case "B":
return 8;
case "S":
return 9;
case "I":
return 10;
case "J":
return 11;
default:
return Integer.parseInt(type);
}
}
public static String getFrameTypeByID(int type) {
switch (type) {
case 0:
return "top";
case 1:
return "I";
case 2:
return "F";
case 3:
return "D";
case 4:
return "J";
case 5:
return "null";
case 6:
return "uninitializedThis";
}
return null;
}
public static int getFrameTypeByName(String type) {
switch (type) {
case "top":
return 0;
case "I":
return 1;
case "F":
return 2;
case "D":
return 3;
case "J":
return 4;
case "null":
return 5;
case "uninitializedThis":
return 6;
}
return -1;
}
public static String getAccessFlagsClass(int access) {
String s = "";
if ((ACC_PUBLIC & access) != 0) {
s += "public ";
}
if ((ACC_FINAL & access) != 0) {
s += "final ";
}
if ((ACC_ABSTRACT & access) != 0 && (ACC_ANNOTATION & access) == 0 && (ACC_ENUM & access) == 0
&& (ACC_INTERFACE & access) == 0) {
s += "abstract ";
}
if ((ACC_SYNTHETIC & access) != 0) {
s += "synthetic ";
}
if ((ACC_ANNOTATION & access) != 0) {
s += "@interface ";
} else if ((ACC_INTERFACE & access) != 0) {
s += "interface ";
} else if ((ACC_ENUM & access) != 0) {
s += "enum ";
} else {
s += "class ";
}
return s;
}
public static String getAccessFlagsFull(int access) {
int acc = 0;
String s = "";
if ((ACC_PUBLIC & access) != 0) {
s += "public ";
acc ^= ACC_PUBLIC;
}
if ((ACC_PRIVATE & access) != 0) {
s += "private ";
acc ^= ACC_PRIVATE;
}
if ((ACC_PROTECTED & access) != 0) {
s += "protected ";
acc ^= ACC_PROTECTED;
}
if ((ACC_STATIC & access) != 0) {
s += "static ";
acc ^= ACC_STATIC;
}
if ((ACC_FINAL & access) != 0) {
s += "final ";
acc ^= ACC_FINAL;
}
if ((ACC_SYNCHRONIZED & access) != 0) {
s += "synchronized ";
acc ^= ACC_SYNCHRONIZED;
}
if ((ACC_VARARGS & access) != 0) {
s += "varargs ";
acc ^= ACC_VARARGS;
}
if ((ACC_NATIVE & access) != 0) {
s += "native ";
acc ^= ACC_NATIVE;
}
if ((ACC_ABSTRACT & access) != 0) {
s += "abstract ";
acc ^= ACC_ABSTRACT;
}
if ((ACC_STRICTFP & access) != 0) {
s += "strictfp ";
acc ^= ACC_STRICTFP;
}
if ((ACC_SYNTHETIC & access) != 0) {
s += "synthetic ";
acc ^= ACC_SYNTHETIC;
}
if ((ACC_BRIDGE & access) != 0) {
s += "bridge ";
acc ^= ACC_BRIDGE;
}
if ((ACC_MANDATED & access) != 0) {
s += "mandated ";
acc ^= ACC_MANDATED;
}
if ((ACC_INTERFACE & access) != 0) {
s += "interface ";
acc ^= ACC_INTERFACE;
}
if ((ACC_ANNOTATION & access) != 0) {
s += "annotation ";
acc ^= ACC_ANNOTATION;
}
if ((ACC_ENUM & access) != 0) {
s += "enum ";
acc ^= ACC_ENUM;
}
if (acc == access) {
return s;
} else {
return "0x" + Integer.toHexString(access) + " ";
}
}
/**
* @return { JavaType, Import }
*/
public static String[] reverseDescField(String desc) {
String type;
String importName = null;
int arrSize = 0;
while (desc.startsWith("[")) {
arrSize++;
desc = desc.substring(1);
}
switch (desc.substring(0, 1)) {
case "B":
type = "byte";
break;
case "Z":
type = "boolean";
break;
case "I":
type = "int";
break;
case "J":
type = "long";
break;
case "C":
type = "char";
break;
case "D":
type = "double";
break;
case "F":
type = "float";
break;
case "S":
type = "short";
break;
case "V":
type = "void";
break;
case "L": {
importName = desc.substring(1, desc.length() - 1).replace("/", ".");
if (!importName.contains(".")) {
type = importName;
importName = null;
} else {
type = importName.split("\\.")[importName.split("\\.").length - 1];
}
break;
}
default:
type = "ERROR";
break;
}
for (int i = 0; i < arrSize; i++) {
type += "[]";
}
return new String[] { type, importName };
}
/**
* @return { ReturnValue, ParameterValues, Imports } getrennt durch ";"
*/
public static String[] reverseDescMethod(String desc) {
HashSet<String> imports = new HashSet<>();
String[] returnType = reverseDescField(desc.split("\\)")[1]);
if (returnType[1] != null) {
imports.add(returnType[1]);
}
ArrayList<String> parameters = new ArrayList<>();
String parameterType = desc.split("\\)")[0].substring(1);
while (!parameterType.isEmpty()) {
String type = "";
int arrSize = 0;
while (parameterType.startsWith("[")) {
arrSize++;
parameterType = parameterType.substring(1);
}
switch (parameterType.substring(0, 1)) {
case "B":
type = "byte";
parameterType = parameterType.substring(1);
break;
case "Z":
type = "boolean";
parameterType = parameterType.substring(1);
break;
case "I":
type = "int";
parameterType = parameterType.substring(1);
break;
case "J":
type = "long";
parameterType = parameterType.substring(1);
break;
case "C":
type = "char";
parameterType = parameterType.substring(1);
break;
case "D":
type = "double";
parameterType = parameterType.substring(1);
break;
case "F":
type = "float";
parameterType = parameterType.substring(1);
break;
case "S":
type = "short";
parameterType = parameterType.substring(1);
break;
case "V":
type = "void";
parameterType = parameterType.substring(1);
break;
case "L": {
String rofl = "";
while (!parameterType.startsWith(";")) {
rofl += parameterType.substring(0, 1);
parameterType = parameterType.substring(1);
}
rofl += parameterType.substring(0, 1);
parameterType = parameterType.substring(1);
String importName = rofl.substring(1, rofl.length() - 1).replace("/", ".");
if (!importName.contains(".")) {
type = importName;
importName = null;
} else {
type = importName.split("\\.")[importName.split("\\.").length - 1];
}
if (importName != null) {
imports.add(importName);
}
break;
}
default:
type = "ERROR";
break;
}
for (int i = 0; i < arrSize; i++) {
type += "[]";
}
parameters.add(type);
}
String importStr = "";
for (String s : imports) {
if (importStr.isEmpty()) {
importStr += s;
} else {
importStr += ";" + s;
}
}
String parameterStr = "";
for (String s : parameters) {
if (parameterStr.isEmpty()) {
parameterStr += s;
} else {
parameterStr += ";" + s;
}
}
return new String[] { returnType[0], parameterStr, importStr };
}
public static int countMethodParams(String desc) {
int count = 0;
String parameterType = desc.split("\\)")[0].substring(1);
while (!parameterType.isEmpty()) {
while (parameterType.startsWith("[")) {
parameterType = parameterType.substring(1);
}
switch (parameterType.substring(0, 1)) {
case "B":
case "Z":
case "I":
case "J":
case "C":
case "D":
case "F":
case "S":
case "V":
parameterType = parameterType.substring(1);
count++;
break;
case "L": {
while (!parameterType.startsWith(";")) {
parameterType = parameterType.substring(1);
}
parameterType = parameterType.substring(1);
count++;
break;
}
default:
break;
}
}
return count;
}
public static String getDecompiledValue(Object o, String desc, boolean escapeSpaces) {
switch (o.getClass().getName()) {
case "java.lang.String": {
return "\"" + (escapeSpaces ? UnicodeUtils.escapeWithSpaces((String) o) : UnicodeUtils.escape((String) o))
+ "\"";
}
case "java.lang.Integer": {
if (desc.equals("Z")) {
return ((int) o) == 0 ? "false" : "true";
}
return o.toString();
}
case "java.lang.Long": {
return o.toString() + "l";
}
case "java.lang.Float": {
return o.toString() + "f";
}
default:
return o.toString();
}
}
public static String getDecompiledValue(Object o, String desc) {
return getDecompiledValue(o, desc, false);
}
public static Object getCastedValue(String o, String className) {
switch (className) {
case "java/lang/String": {
return o;
}
case "java/lang/Integer": {
return Integer.parseInt(o);
}
case "java/lang/Long": {
return Long.parseLong(o);
}
case "java/lang/Float": {
return Float.parseFloat(o);
}
case "java/lang/Double": {
return Double.parseDouble(o);
}
case "java/lang/Boolean": {
return Boolean.parseBoolean(o);
}
case "java/lang/Short": {
return Short.parseShort(o);
}
case "java/lang/Byte": {
return Byte.parseByte(o);
}
default:
return o.toString();
}
}
public static String getSimpleDesc(String type) {
String desc = "";
for (int i = 0; i < countArraySize(type); i++) {
desc += "[";
}
type = type.replace("[]", "");
if (VARS.containsKey(type)) {
desc += VARS.get(type);
} else {
desc += "L" + type + ";";
}
return desc;
}
private static int countArraySize(String type) {
int size = 0;
for (byte b : type.getBytes()) {
if (b == ']') {
size++;
}
}
return size;
}
public static final HashMap<String, String> VARS = new HashMap<>();
static {
VARS.put("byte", "B");
VARS.put("char", "C");
VARS.put("double", "D");
VARS.put("float", "F");
VARS.put("int", "I");
VARS.put("long", "J");
VARS.put("short", "S");
VARS.put("boolean", "Z");
VARS.put("void", "V");
}
public static int externalArrayTypeDimensionCount(String s) {
int i = 0;
int j = "[]".length();
int k = s.length() - j;
while (s.regionMatches(k, "[]", 0, j)) {
i++;
k -= j;
}
return i;
}
public static String internalMethodDescriptor(String returnType, String methodArgs) {
returnType = returnType.replace(".", "/");
methodArgs = methodArgs.replace(".", "/");
StringBuffer buf = new StringBuffer();
buf.append('(');
ExternalTypeEnumeration type = new ExternalTypeEnumeration(methodArgs);
while (type.hasMoreTypes()) {
buf.append(getSimpleDesc(type.nextType()));
}
buf.append(')');
buf.append(getSimpleDesc(returnType));
return buf.toString();
}
}
@@ -1,20 +0,0 @@
package me.ByteEdit.utils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
public class CustomBufferedReader extends BufferedReader {
public int currentLine = 0;
public CustomBufferedReader(Reader in) {
super(in);
}
@Override
public String readLine() throws IOException {
currentLine++;
return super.readLine();
}
}
@@ -1,47 +0,0 @@
package me.ByteEdit.utils;
public class ExternalTypeEnumeration {
private String descriptor;
private int index;
public ExternalTypeEnumeration(String paramString) {
setDescriptor(paramString);
}
ExternalTypeEnumeration() {
}
void setDescriptor(String paramString) {
this.descriptor = paramString;
reset();
}
public void reset() {
this.index = (this.descriptor.indexOf('(') + 1);
if (this.index < 1) {
throw new IllegalArgumentException("Missing opening parenthesis in descriptor [" + this.descriptor + "]");
}
}
public boolean hasMoreTypes() {
return this.index < this.descriptor.length() - 1;
}
public String nextType() {
int i = this.index;
this.index = this.descriptor.indexOf(',', i);
if (this.index < 0) {
this.index = this.descriptor.indexOf(')', i);
if (this.index < 0) {
throw new IllegalArgumentException(
"Missing closing parenthesis in descriptor [" + this.descriptor + "]");
}
}
return this.descriptor.substring(i, this.index++).trim();
}
public String methodName() {
return this.descriptor.substring(0, this.descriptor.indexOf('(')).trim();
}
}
File diff suppressed because it is too large. Load diff
-15
View File
@@ -1,15 +0,0 @@
package me.ByteEdit.utils;
public class SwitchIntContainer {
private final int id;
public SwitchIntContainer(final int id) {
this.id = id;
}
public int getId() {
return id;
}
}
-160
View File
@@ -1,160 +0,0 @@
package me.ByteEdit.utils;
public class UnicodeUtils {
public static String unescape(String s) {
if (s == null) {
return null;
}
StringBuilder sb = new StringBuilder();
char unicodeBuffer = 0;
int stage = 0;
for (char c : s.toCharArray()) {
if (c == '\\' && stage == 0) {
stage = 1;
continue;
}
if (stage == 1) {
switch (c) {
case 'b':
sb.append('\b');
stage = 0;
break;
case 't':
sb.append('\t');
stage = 0;
break;
case 'n':
sb.append('\n');
stage = 0;
break;
case 'r':
sb.append('\r');
stage = 0;
break;
case 'f':
sb.append('\f');
stage = 0;
break;
case '"':
sb.append('"');
stage = 0;
break;
case '\\':
sb.append('\\');
stage = 0;
break;
case 'u':
stage++;
break;
default:
throw new IllegalArgumentException("'\\" + c + "' is invalid.");
}
continue;
} else if (stage > 1 && stage < 6) { // \u1234 => up to 6
try {
int i = Integer.parseInt(Character.toString(c), 16);
unicodeBuffer += i << (4 * (5 - stage++)); // 4 bytes each, shift left byte * 4..3..2..1 and add to
// unicodeBuffer
if (stage == 6) {
sb.append(unicodeBuffer);
stage = 0;
unicodeBuffer = 0;
}
} catch (NumberFormatException e) {
throw new IllegalArgumentException("'" + c + "' is not a valid hex value.");
}
continue;
}
sb.append(c);
}
if (stage != 0) {
if (unicodeBuffer != 0) {
throw new IllegalArgumentException("The unicode at the end is incomplete.");
} else {
throw new IllegalArgumentException("'\\' at the end is invalid.");
}
}
return sb.toString();
}
public static String escapeWithSpaces(String s) {
if (s == null) {
return null;
}
s = escape(s).replace(" ", "\\u0020");
if (s.startsWith("/")) {
s = "\\u002F" + s.substring(1);
}
if (s.endsWith("/")) {
s = s.substring(0, s.length() - 1) + "\\u002F";
}
return s;
}
public static String escape(String s) {
if (s == null) {
return null;
}
StringBuilder sb = new StringBuilder();
for (char c : s.toCharArray()) {
if (isPrintable(c)) {
sb.append(c);
} else {
switch (c) {
case '\b':
sb.append("\\b");
break;
case '\t':
sb.append("\\t");
break;
case '\n':
sb.append("\\n");
break;
case '\r':
sb.append("\\r");
break;
case '\f':
sb.append("\\f");
break;
case '"':
sb.append("\\\"");
break;
case '\\':
sb.append("\\\\");
break;
default:
sb.append(String.format("\\u%04X", (int) c));
}
}
}
return sb.toString();
}
private static boolean isPrintable(char c) {
switch (c) {
case 'Ä':
case 'ä':
case 'Ö':
case 'ö':
case 'Ü':
case 'ü':
case 'ß':
case '€':
case '©':
case '®':
case '«':
case '»':
case '§':
case '£':
case '¥':
return true;
case '"':
case '\\':
return false;
default:
return c >= ' ' && c <= '~';
}
}
}