mirror of
https://github.com/SuspiciousActivity/ByteEdit.git
synced 2026-08-13 17:56:17 +00:00
New stuff
This commit is contained in:
1 parent
6b66ff27e2
commit
c91d8ccada
23 files changed
+10071
-9217
No files matched your search
@@ -1,174 +1,174 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,82 +1,52 @@
|
||||
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.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.KeyStroke;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.tools.FileObject;
|
||||
import javax.tools.JavaCompiler;
|
||||
import javax.tools.JavaCompiler.CompilationTask;
|
||||
import javax.tools.JavaFileManager;
|
||||
import javax.tools.JavaFileObject;
|
||||
import javax.tools.JavaFileObject.Kind;
|
||||
import javax.tools.SimpleJavaFileObject;
|
||||
import javax.tools.StandardJavaFileManager;
|
||||
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 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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,190 +1,195 @@
|
||||
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 = 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());
|
||||
String name = UnicodeUtils.unescape(txtName.getText());
|
||||
String desc = UnicodeUtils.unescape(txtDesc.getText());
|
||||
for (ClassNode cn : Main.classNodes.values()) {
|
||||
for (MethodNode mn : cn.methods) {
|
||||
for (AbstractInsnNode insn : mn.instructions.toArray()) {
|
||||
if (insn instanceof FieldInsnNode) {
|
||||
if (((FieldInsnNode) insn).owner.equals(owner) && ((FieldInsnNode) insn).name.equals(name)
|
||||
&& ((FieldInsnNode) insn).desc.equals(desc)) {
|
||||
set.add(new Info(cn.name, mn.name, mn.desc, mn));
|
||||
}
|
||||
} else if (insn instanceof MethodInsnNode) {
|
||||
if (((MethodInsnNode) insn).owner.equals(owner) && ((MethodInsnNode) insn).name.equals(name)
|
||||
&& ((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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,135 +1,134 @@
|
||||
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.ClassNode;
|
||||
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 = owner + ".class";
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,39 +1,39 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,238 +1,239 @@
|
||||
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(className + ".class");
|
||||
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(clazz.superName + ".class");
|
||||
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(checkCN.superName + ".class");
|
||||
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;
|
||||
}
|
||||
});
|
||||
btnRename.setBounds(345, 237, 89, 23);
|
||||
contentPane.add(btnRename);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,152 +1,152 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,116 +1,117 @@
|
||||
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;
|
||||
|
||||
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 = 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);
|
||||
}
|
||||
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,74 +1,74 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
+1610
-1577
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -1,60 +1,60 @@
|
||||
package me.ByteEdit.edit;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
OptionBox frame = new OptionBox();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
package me.ByteEdit.edit;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
OptionBox frame = new OptionBox();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
+151
-151
@@ -1,151 +1,151 @@
|
||||
package me.ByteEdit.edit;
|
||||
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
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), toReplace), 0, txt.length());
|
||||
}
|
||||
Main.txtByteEditView.setCaretPosition(prev);
|
||||
}
|
||||
}
|
||||
package me.ByteEdit.edit;
|
||||
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
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), toReplace), 0, txt.length());
|
||||
}
|
||||
Main.txtByteEditView.setCaretPosition(prev);
|
||||
}
|
||||
}
|
||||
@@ -1,119 +1,119 @@
|
||||
package me.ByteEdit.edit;
|
||||
|
||||
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;
|
||||
|
||||
public class TypeOpenBox extends JFrame {
|
||||
|
||||
public JPanel contentPane;
|
||||
public JTextField txtSearch;
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
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 = 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);
|
||||
}
|
||||
|
||||
}
|
||||
package me.ByteEdit.edit;
|
||||
|
||||
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;
|
||||
|
||||
public class TypeOpenBox extends JFrame {
|
||||
|
||||
public JPanel contentPane;
|
||||
public JTextField txtSearch;
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
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 = 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,19 +1,19 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
+1002
-897
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -1,20 +1,20 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
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,45 +1,47 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
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
@@ -1,15 +1,15 @@
|
||||
package me.ByteEdit.utils;
|
||||
|
||||
public class SwitchIntContainer {
|
||||
|
||||
private final int id;
|
||||
|
||||
public SwitchIntContainer(final int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
||||
package me.ByteEdit.utils;
|
||||
|
||||
public class SwitchIntContainer {
|
||||
|
||||
private final int id;
|
||||
|
||||
public SwitchIntContainer(final int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,159 +1,160 @@
|
||||
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 <= '~';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
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 <= '~';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user