mirror of
https://github.com/SuspiciousActivity/ByteEdit.git
synced 2026-08-13 17:56:17 +00:00
When loading a file the default save path is now the parent folder
This commit is contained in:
1 parent
5862a57ed9
commit
8c94bb4497
1 file changed
+68
-38
@@ -101,6 +101,7 @@ public class Main extends JFrame {
|
|||||||
public static JTree tree;
|
public static JTree tree;
|
||||||
public static RTextScrollPane scrollPane_ByteEdit;
|
public static RTextScrollPane scrollPane_ByteEdit;
|
||||||
public static Theme theme;
|
public static Theme theme;
|
||||||
|
public static File saveFolder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Launch the application.
|
* Launch the application.
|
||||||
@@ -127,23 +128,39 @@ public class Main extends JFrame {
|
|||||||
for (int i = 0; i < 200; i++) {
|
for (int i = 0; i < 200; i++) {
|
||||||
String s = OpcodesReverse.reverseOpcode(i);
|
String s = OpcodesReverse.reverseOpcode(i);
|
||||||
if (!s.startsWith("Unknown "))
|
if (!s.startsWith("Unknown "))
|
||||||
provider.addCompletion(new BasicCompletion(provider, s, null, OpcodesReverse.generateCompletionDesc(s)));
|
provider.addCompletion(
|
||||||
|
new BasicCompletion(provider, s, null, OpcodesReverse.generateCompletionDesc(s)));
|
||||||
}
|
}
|
||||||
provider.addCompletion(new BasicCompletion(provider, "public", null, OpcodesReverse.generateCompletionDesc("public")));
|
provider.addCompletion(
|
||||||
provider.addCompletion(new BasicCompletion(provider, "private", null, OpcodesReverse.generateCompletionDesc("private")));
|
new BasicCompletion(provider, "public", null, OpcodesReverse.generateCompletionDesc("public")));
|
||||||
provider.addCompletion(new BasicCompletion(provider, "protected", null, OpcodesReverse.generateCompletionDesc("protected")));
|
provider.addCompletion(
|
||||||
provider.addCompletion(new BasicCompletion(provider, "final", null, OpcodesReverse.generateCompletionDesc("final")));
|
new BasicCompletion(provider, "private", null, OpcodesReverse.generateCompletionDesc("private")));
|
||||||
provider.addCompletion(new BasicCompletion(provider, "class", null, OpcodesReverse.generateCompletionDesc("class")));
|
provider.addCompletion(
|
||||||
provider.addCompletion(new BasicCompletion(provider, "enum", null, OpcodesReverse.generateCompletionDesc("enum")));
|
new BasicCompletion(provider, "protected", null, OpcodesReverse.generateCompletionDesc("protected")));
|
||||||
provider.addCompletion(new BasicCompletion(provider, "static", null, OpcodesReverse.generateCompletionDesc("static")));
|
provider.addCompletion(
|
||||||
provider.addCompletion(new BasicCompletion(provider, "strictfp", null, OpcodesReverse.generateCompletionDesc("strictfp")));
|
new BasicCompletion(provider, "final", null, OpcodesReverse.generateCompletionDesc("final")));
|
||||||
provider.addCompletion(new BasicCompletion(provider, "throws", null, OpcodesReverse.generateCompletionDesc("throws")));
|
provider.addCompletion(
|
||||||
provider.addCompletion(new BasicCompletion(provider, "synthetic", null, OpcodesReverse.generateCompletionDesc("synthetic")));
|
new BasicCompletion(provider, "class", null, OpcodesReverse.generateCompletionDesc("class")));
|
||||||
provider.addCompletion(new BasicCompletion(provider, "bridge", null, OpcodesReverse.generateCompletionDesc("bridge")));
|
provider.addCompletion(
|
||||||
provider.addCompletion(new BasicCompletion(provider, "label", null, OpcodesReverse.generateCompletionDesc("label")));
|
new BasicCompletion(provider, "enum", null, OpcodesReverse.generateCompletionDesc("enum")));
|
||||||
provider.addCompletion(new BasicCompletion(provider, "line", null, OpcodesReverse.generateCompletionDesc("line")));
|
provider.addCompletion(
|
||||||
provider.addCompletion(new BasicCompletion(provider, "extends", null, OpcodesReverse.generateCompletionDesc("extends")));
|
new BasicCompletion(provider, "static", null, OpcodesReverse.generateCompletionDesc("static")));
|
||||||
provider.addCompletion(new BasicCompletion(provider, "implements", null, OpcodesReverse.generateCompletionDesc("implements")));
|
provider.addCompletion(
|
||||||
|
new BasicCompletion(provider, "strictfp", null, OpcodesReverse.generateCompletionDesc("strictfp")));
|
||||||
|
provider.addCompletion(
|
||||||
|
new BasicCompletion(provider, "throws", null, OpcodesReverse.generateCompletionDesc("throws")));
|
||||||
|
provider.addCompletion(
|
||||||
|
new BasicCompletion(provider, "synthetic", null, OpcodesReverse.generateCompletionDesc("synthetic")));
|
||||||
|
provider.addCompletion(
|
||||||
|
new BasicCompletion(provider, "bridge", null, OpcodesReverse.generateCompletionDesc("bridge")));
|
||||||
|
provider.addCompletion(
|
||||||
|
new BasicCompletion(provider, "label", null, OpcodesReverse.generateCompletionDesc("label")));
|
||||||
|
provider.addCompletion(
|
||||||
|
new BasicCompletion(provider, "line", null, OpcodesReverse.generateCompletionDesc("line")));
|
||||||
|
provider.addCompletion(
|
||||||
|
new BasicCompletion(provider, "extends", null, OpcodesReverse.generateCompletionDesc("extends")));
|
||||||
|
provider.addCompletion(
|
||||||
|
new BasicCompletion(provider, "implements", null, OpcodesReverse.generateCompletionDesc("implements")));
|
||||||
provider.addCompletion(new ShorthandCompletion(provider, "invvi", "invokevirtual desc owner/name", null,
|
provider.addCompletion(new ShorthandCompletion(provider, "invvi", "invokevirtual desc owner/name", null,
|
||||||
"<html><b><u>invvi</u></b><br>Creates an example invokevirtual</html>"));
|
"<html><b><u>invvi</u></b><br>Creates an example invokevirtual</html>"));
|
||||||
provider.addCompletion(new ShorthandCompletion(provider, "invif", "invokeinterface desc owner/name", null,
|
provider.addCompletion(new ShorthandCompletion(provider, "invif", "invokeinterface desc owner/name", null,
|
||||||
@@ -159,8 +176,8 @@ public class Main extends JFrame {
|
|||||||
"// #Annotations\n// #Class v:52\n// #Signature: null\n// #OuterClass: null\n// #InnerClasses:\npublic class Main extends java/lang/Object {\n// #SourceFile: Main.java\n\n// #Fields\n\n// #Methods\n\n}\n",
|
"// #Annotations\n// #Class v:52\n// #Signature: null\n// #OuterClass: null\n// #InnerClasses:\npublic class Main extends java/lang/Object {\n// #SourceFile: Main.java\n\n// #Fields\n\n// #Methods\n\n}\n",
|
||||||
null, "<html><b><u>clazz</u></b><br>Creates an example class</html>"));
|
null, "<html><b><u>clazz</u></b><br>Creates an example class</html>"));
|
||||||
provider.addCompletion(new ShorthandCompletion(provider, "method",
|
provider.addCompletion(new ShorthandCompletion(provider, "method",
|
||||||
"// #Max: l:0 s:0\n\t// #TryCatch:\n\t// #LocalVars:\n\tpublic static method ()V {\n\t\treturn\n\t}", null,
|
"// #Max: l:0 s:0\n\t// #TryCatch:\n\t// #LocalVars:\n\tpublic static method ()V {\n\t\treturn\n\t}",
|
||||||
"<html><b><u>method</u></b><br>Creates an example method</html>"));
|
null, "<html><b><u>method</u></b><br>Creates an example method</html>"));
|
||||||
return provider;
|
return provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,7 +214,8 @@ public class Main extends JFrame {
|
|||||||
CompletionProvider provider = createCompletionProvider();
|
CompletionProvider provider = createCompletionProvider();
|
||||||
AutoCompletion ac = new AutoCompletion(provider);
|
AutoCompletion ac = new AutoCompletion(provider);
|
||||||
ac.setShowDescWindow(true);
|
ac.setShowDescWindow(true);
|
||||||
FoldParserManager.get().addFoldParserMapping(SyntaxConstants.SYNTAX_STYLE_JAVA_DISASSEMBLE, new CurlyFoldParser(false, true));
|
FoldParserManager.get().addFoldParserMapping(SyntaxConstants.SYNTAX_STYLE_JAVA_DISASSEMBLE,
|
||||||
|
new CurlyFoldParser(false, true));
|
||||||
try {
|
try {
|
||||||
Theme theme = Theme.load(getClass().getClassLoader().getResourceAsStream("org/fife/eclipse.xml"));
|
Theme theme = Theme.load(getClass().getClassLoader().getResourceAsStream("org/fife/eclipse.xml"));
|
||||||
} catch (IOException e2) {
|
} catch (IOException e2) {
|
||||||
@@ -246,7 +264,8 @@ public class Main extends JFrame {
|
|||||||
b = true;
|
b = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
s += (s.isEmpty() || s.replace("/", "").isEmpty() ? "" : "/") + (path.toString().isEmpty() ? "/" : path.toString());
|
s += (s.isEmpty() || s.replace("/", "").isEmpty() ? "" : "/")
|
||||||
|
+ (path.toString().isEmpty() ? "/" : path.toString());
|
||||||
}
|
}
|
||||||
selectFile(s);
|
selectFile(s);
|
||||||
}
|
}
|
||||||
@@ -266,6 +285,7 @@ public class Main extends JFrame {
|
|||||||
final File file = files.get(0);
|
final File file = files.get(0);
|
||||||
if (file.getName().endsWith(".jar")) {
|
if (file.getName().endsWith(".jar")) {
|
||||||
jarFile = file;
|
jarFile = file;
|
||||||
|
saveFolder = file.getParentFile();
|
||||||
isChangingFile = true;
|
isChangingFile = true;
|
||||||
try {
|
try {
|
||||||
tree.setModel(new ArchiveTreeModel(new JarFile(jarFile)));
|
tree.setModel(new ArchiveTreeModel(new JarFile(jarFile)));
|
||||||
@@ -293,16 +313,20 @@ public class Main extends JFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dragEnter(DropTargetDragEvent dtde) {}
|
public void dragEnter(DropTargetDragEvent dtde) {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dragOver(DropTargetDragEvent dtde) {}
|
public void dragOver(DropTargetDragEvent dtde) {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dropActionChanged(DropTargetDragEvent dtde) {}
|
public void dropActionChanged(DropTargetDragEvent dtde) {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dragExit(DropTargetEvent dte) {}
|
public void dragExit(DropTargetEvent dte) {
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
txtByteEditView = new RSyntaxTextArea();
|
txtByteEditView = new RSyntaxTextArea();
|
||||||
@@ -471,7 +495,8 @@ public class Main extends JFrame {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
selectFile(className + ".class");
|
selectFile(className + ".class");
|
||||||
} else if (line.startsWith("getstatic ") || line.startsWith("putstatic ") || line.startsWith("getfield ") || line.startsWith("putfield ")) {
|
} else if (line.startsWith("getstatic ") || line.startsWith("putstatic ") || line.startsWith("getfield ")
|
||||||
|
|| line.startsWith("putfield ")) {
|
||||||
String[] split = line.split(" ");
|
String[] split = line.split(" ");
|
||||||
String desc = UnicodeUtils.unescape(split[1]);
|
String desc = UnicodeUtils.unescape(split[1]);
|
||||||
String className = UnicodeUtils.unescape(split[2]);
|
String className = UnicodeUtils.unescape(split[2]);
|
||||||
@@ -497,7 +522,8 @@ public class Main extends JFrame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Pattern renameableFieldPattern = Pattern.compile("^\t(?:[a-z]+ |0x[0-9a-fA-F]+ )*?(\\[*(?:V|Z|C|B|S|I|F|J|D|L.+?;)) ([^ ]+) ?.*");
|
private final Pattern renameableFieldPattern = Pattern
|
||||||
|
.compile("^\t(?:[a-z]+ |0x[0-9a-fA-F]+ )*?(\\[*(?:V|Z|C|B|S|I|F|J|D|L.+?;)) ([^ ]+) ?.*");
|
||||||
private final Pattern renameableMethodPattern = Pattern
|
private final Pattern renameableMethodPattern = Pattern
|
||||||
.compile("^\t(?:[a-z]+ |0x[0-9a-fA-F]+ )*?([^ ]+) (\\((?:\\[*(?:V|Z|C|B|S|I|F|J|D|L.+?;))*\\)[^ ]+) .*\\{");
|
.compile("^\t(?:[a-z]+ |0x[0-9a-fA-F]+ )*?([^ ]+) (\\((?:\\[*(?:V|Z|C|B|S|I|F|J|D|L.+?;))*\\)[^ ]+) .*\\{");
|
||||||
|
|
||||||
@@ -512,7 +538,8 @@ public class Main extends JFrame {
|
|||||||
m = renameableMethodPattern.matcher(line);
|
m = renameableMethodPattern.matcher(line);
|
||||||
if (m.find()) {
|
if (m.find()) {
|
||||||
if (ClassUtil.isObjectClassMethod(m.group(1), m.group(2), false)) {
|
if (ClassUtil.isObjectClassMethod(m.group(1), m.group(2), false)) {
|
||||||
JOptionPane.showMessageDialog(null, "This method can not be renamed!", "Error!", JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(null, "This method can not be renamed!", "Error!",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setRenameInfo(m, lineEnd);
|
setRenameInfo(m, lineEnd);
|
||||||
@@ -602,8 +629,6 @@ public class Main extends JFrame {
|
|||||||
return selectFileWithSearch(s, null);
|
return selectFileWithSearch(s, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File saveFolder = null;
|
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
final JFileChooser fileChooser = new JFileChooser(saveFolder) {
|
final JFileChooser fileChooser = new JFileChooser(saveFolder) {
|
||||||
|
|
||||||
@@ -623,8 +648,8 @@ public class Main extends JFrame {
|
|||||||
final File file = fileChooser.getSelectedFile();
|
final File file = fileChooser.getSelectedFile();
|
||||||
saveFolder = file.getParentFile();
|
saveFolder = file.getParentFile();
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
int dialogResult = JOptionPane.showConfirmDialog(null, "This file already exists! Overwrite it?", "Warning",
|
int dialogResult = JOptionPane.showConfirmDialog(null, "This file already exists! Overwrite it?",
|
||||||
JOptionPane.YES_NO_OPTION);
|
"Warning", JOptionPane.YES_NO_OPTION);
|
||||||
if (dialogResult == JOptionPane.YES_OPTION) {
|
if (dialogResult == JOptionPane.YES_OPTION) {
|
||||||
save(file, classNodes.values());
|
save(file, classNodes.values());
|
||||||
}
|
}
|
||||||
@@ -651,9 +676,11 @@ public class Main extends JFrame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
name = JOptionPane.showInputDialog(INSTANCE,
|
name = JOptionPane.showInputDialog(INSTANCE,
|
||||||
"If you want a runnable jar file, please enter the class name.\nIf you only want a library, leave it empty.", name);
|
"If you want a runnable jar file, please enter the class name.\nIf you only want a library, leave it empty.",
|
||||||
|
name);
|
||||||
if (name != null && !name.isEmpty()) {
|
if (name != null && !name.isEmpty()) {
|
||||||
String val = "Manifest-Version: 1.0\n" + "Class-Path: .\n" + "Main-Class: " + name.replace('/', '.') + "\n\n";
|
String val = "Manifest-Version: 1.0\n" + "Class-Path: .\n" + "Main-Class: " + name.replace('/', '.')
|
||||||
|
+ "\n\n";
|
||||||
OTHER_FILES.put("META-INF/MANIFEST.MF", val.getBytes());
|
OTHER_FILES.put("META-INF/MANIFEST.MF", val.getBytes());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -713,7 +740,8 @@ public class Main extends JFrame {
|
|||||||
|
|
||||||
public ArchiveTreeModel(JarFile jar) {
|
public ArchiveTreeModel(JarFile jar) {
|
||||||
super(new DefaultMutableTreeNode(jar.getName().split(File.separator.equals("\\") ? "\\\\"
|
super(new DefaultMutableTreeNode(jar.getName().split(File.separator.equals("\\") ? "\\\\"
|
||||||
: File.separator)[jar.getName().split(File.separator.equals("\\") ? "\\\\" : File.separator).length - 1]));
|
: File.separator)[jar.getName().split(File.separator.equals("\\") ? "\\\\" : File.separator).length
|
||||||
|
- 1]));
|
||||||
try {
|
try {
|
||||||
ArrayList<String> paths = new ArrayList<>();
|
ArrayList<String> paths = new ArrayList<>();
|
||||||
classNodes.clear();
|
classNodes.clear();
|
||||||
@@ -723,12 +751,14 @@ public class Main extends JFrame {
|
|||||||
JarEntry next = enumeration.nextElement();
|
JarEntry next = enumeration.nextElement();
|
||||||
byte[] data = IOUtils.toByteArray(jar.getInputStream(next));
|
byte[] data = IOUtils.toByteArray(jar.getInputStream(next));
|
||||||
if (next.getName().endsWith(".class")) {
|
if (next.getName().endsWith(".class")) {
|
||||||
if (next.getName().contains("/") ? (!next.getName().split("/")[next.getName().split("/").length - 1].contains("$"))
|
if (next.getName().contains("/")
|
||||||
|
? (!next.getName().split("/")[next.getName().split("/").length - 1].contains("$"))
|
||||||
: (!next.getName().contains("$"))) {
|
: (!next.getName().contains("$"))) {
|
||||||
paths.add(next.getName());
|
paths.add(next.getName());
|
||||||
} else if (next.getName().startsWith("$") || next.getName().contains("$$") || next.getName().endsWith("$")) { // obfuscated
|
} else if (next.getName().startsWith("$") || next.getName().contains("$$")
|
||||||
// with
|
|| next.getName().endsWith("$")) { // obfuscated
|
||||||
// $
|
// with
|
||||||
|
// $
|
||||||
paths.add(next.getName());
|
paths.add(next.getName());
|
||||||
}
|
}
|
||||||
ClassReader reader;
|
ClassReader reader;
|
||||||
|
|||||||
Reference in new issue
Block a user