diff --git a/src/me/ByteEdit/boxes/CompilationBox.java b/src/me/ByteEdit/boxes/CompilationBox.java index fcd1409..cc1bf88 100644 --- a/src/me/ByteEdit/boxes/CompilationBox.java +++ b/src/me/ByteEdit/boxes/CompilationBox.java @@ -56,7 +56,7 @@ public class CompilationBox extends JFrame { setBounds((int) (Toolkit.getDefaultToolkit().getScreenSize().getWidth() / 2 - 400), (int) (Toolkit.getDefaultToolkit().getScreenSize().getHeight() / 2 - 200), 800, 400); contentPane = new JPanel(); - contentPane.setBackground(Main.dark ? Color.DARK_GRAY : Color.GRAY); + 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)); @@ -65,13 +65,13 @@ public class CompilationBox extends JFrame { textArea.setEditable(true); textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA); textArea.setCodeFoldingEnabled(true); - textArea.setBackground(Main.dark ? Color.DARK_GRAY : Color.LIGHT_GRAY); + 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 ? Color.DARK_GRAY : Color.LIGHT_GRAY); + 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); diff --git a/src/me/ByteEdit/boxes/CompilationSuccess.java b/src/me/ByteEdit/boxes/CompilationSuccess.java index 464288e..845334b 100644 --- a/src/me/ByteEdit/boxes/CompilationSuccess.java +++ b/src/me/ByteEdit/boxes/CompilationSuccess.java @@ -61,7 +61,7 @@ public class CompilationSuccess extends JFrame { setBounds((int) (Toolkit.getDefaultToolkit().getScreenSize().getWidth() / 2 - 400), (int) (Toolkit.getDefaultToolkit().getScreenSize().getHeight() / 2 - 200), 800, 400); contentPane = new JPanel(); - contentPane.setBackground(Main.dark ? Color.DARK_GRAY : Color.GRAY); + 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)); @@ -70,13 +70,13 @@ public class CompilationSuccess extends JFrame { textArea.setEditable(true); textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA_DISASSEMBLE); textArea.setCodeFoldingEnabled(true); - textArea.setBackground(Main.dark ? Color.DARK_GRAY : Color.LIGHT_GRAY); + 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 ? Color.DARK_GRAY : Color.LIGHT_GRAY); + scrollPane.getGutter().setBackground(Main.dark ? new Color(0x2F2F2F) : Color.LIGHT_GRAY); contentPane.add(scrollPane); } } diff --git a/src/me/ByteEdit/edit/Assembler.java b/src/me/ByteEdit/edit/Assembler.java index 44c2d4d..51073c1 100644 --- a/src/me/ByteEdit/edit/Assembler.java +++ b/src/me/ByteEdit/edit/Assembler.java @@ -80,10 +80,66 @@ public class Assembler { clazz.innerClasses = new ArrayList<>(); } else { String split[] = s.split(" "); + int access = 0; + String cons = s + .substring( + split[0].length() + split[1].length() + split[2].length() + split[3].length() + 3) + .trim(); + if (cons.startsWith("0x")) { + access = Integer.parseInt(cons.substring(2), 16); + } else { + if (cons.contains("public")) { + access ^= ClassUtil.ACC_PUBLIC; + } + if (cons.contains("private")) { + access ^= ClassUtil.ACC_PRIVATE; + } + if (cons.contains("protected")) { + access ^= ClassUtil.ACC_PROTECTED; + } + if (cons.contains("static")) { + access ^= ClassUtil.ACC_STATIC; + } + if (cons.contains("final")) { + access ^= ClassUtil.ACC_FINAL; + } + if (cons.contains("synchronized")) { + access ^= ClassUtil.ACC_SYNCHRONIZED; + } + if (cons.contains("bridge")) { + access ^= ClassUtil.ACC_BRIDGE; + } + if (cons.contains("transient")) { + access ^= ClassUtil.ACC_VARARGS; + } + if (cons.contains("native")) { + access ^= ClassUtil.ACC_NATIVE; + } + if (cons.contains("interface")) { + access ^= ClassUtil.ACC_INTERFACE; + } + if (cons.contains("abstract")) { + access ^= ClassUtil.ACC_ABSTRACT; + } + if (cons.contains("strictfp")) { + access ^= ClassUtil.ACC_STRICTFP; + } + if (cons.contains("synthetic")) { + access ^= ClassUtil.ACC_SYNTHETIC; + } + if (cons.contains("annotation")) { + access ^= ClassUtil.ACC_ANNOTATION; + } + if (cons.contains("enum")) { + access ^= ClassUtil.ACC_ENUM; + } + if (cons.contains("mandated")) { + access ^= ClassUtil.ACC_MANDATED; + } + } clazz.innerClasses.add(new InnerClassNode(UnicodeUtils.unescape(split[1]), split[2].equals("null") ? null : UnicodeUtils.unescape(split[2]), - split[3].equals("null") ? null : UnicodeUtils.unescape(split[3]), - Integer.parseInt(split[4].substring(2), 16))); + split[3].equals("null") ? null : UnicodeUtils.unescape(split[3]), access)); } } { diff --git a/src/me/ByteEdit/edit/Disassembler.java b/src/me/ByteEdit/edit/Disassembler.java index d25aa93..5f2fbd4 100644 --- a/src/me/ByteEdit/edit/Disassembler.java +++ b/src/me/ByteEdit/edit/Disassembler.java @@ -77,7 +77,7 @@ public class Disassembler { try { int lineFound = -1; String s = ""; - s += "// #Annotations\n"; + s += "// #Annotations:\n"; if (classNode.visibleAnnotations != null && !classNode.visibleAnnotations.isEmpty()) { for (AnnotationNode annotationNode : classNode.visibleAnnotations) { s += "@" + UnicodeUtils.escapeWithSpaces(annotationNode.desc); @@ -138,19 +138,22 @@ public class Disassembler { } } s += "// #Class v:" + classNode.version + "\n"; - s += "// #Signature: " + UnicodeUtils.escapeWithSpaces(classNode.signature) + "\n"; - s += "// #OuterMethod: " + (classNode.outerMethod == null ? "null" - : (UnicodeUtils.escapeWithSpaces(classNode.outerMethod) + " " - + UnicodeUtils.escapeWithSpaces(classNode.outerMethodDesc))) - + "\n"; - s += "// #OuterClass: " + UnicodeUtils.escapeWithSpaces(classNode.outerClass) + "\n"; + if (classNode.signature != null) + s += "// #Signature: " + UnicodeUtils.escapeWithSpaces(classNode.signature) + "\n"; + if (classNode.outerMethod != null) + s += "// #OuterMethod: " + (classNode.outerMethod == null ? "null" + : (UnicodeUtils.escapeWithSpaces(classNode.outerMethod) + " " + + UnicodeUtils.escapeWithSpaces(classNode.outerMethodDesc))) + + "\n"; + if (classNode.outerClass != null) + s += "// #OuterClass: " + UnicodeUtils.escapeWithSpaces(classNode.outerClass) + "\n"; s += "// #InnerClasses:\n"; if (classNode.innerClasses != null) { for (InnerClassNode icn : classNode.innerClasses) { s += "// " + UnicodeUtils.escapeWithSpaces(icn.name) + " " + UnicodeUtils.escapeWithSpaces(icn.outerName) + " " - + UnicodeUtils.escapeWithSpaces(icn.innerName) + " 0x" + Integer.toHexString(icn.access) - + "\n"; + + UnicodeUtils.escapeWithSpaces(icn.innerName) + + (icn.access == 0 ? "" : " " + ClassUtil.getAccessFlagsFull(icn.access).trim()) + "\n"; } } s += ClassUtil.getAccessFlagsClass(classNode.access) + UnicodeUtils.escapeWithSpaces(classNode.name) + " "; @@ -350,14 +353,15 @@ public class Disassembler { private static String[] disassembleMethod(String className, MethodNode mn) { HashMap labels = new HashMap(); String s = ""; - String localVarTable = "\t// #LocalVars:\n"; - String tryCatchTable = "\t// #TryCatch:\n"; + String localVarTable = ""; + String tryCatchTable = ""; for (AbstractInsnNode n : mn.instructions.toArray()) { if (n instanceof LabelNode) { labels.put(((LabelNode) n).getLabel(), labels.size() + 1); } } - if (mn.localVariables != null) { + if (mn.localVariables != null && !mn.localVariables.isEmpty()) { + localVarTable = "\t// #LocalVars:\n"; for (LocalVariableNode lvn : mn.localVariables) { localVarTable += "\t// " + UnicodeUtils.escapeWithSpaces(lvn.name) + ": " + UnicodeUtils.escapeWithSpaces(lvn.desc) + " i:" + lvn.index + " s:" @@ -365,7 +369,8 @@ public class Disassembler { + UnicodeUtils.escapeWithSpaces(lvn.signature) + "\n"; } } - if (mn.tryCatchBlocks != null) { + if (mn.tryCatchBlocks != null && !mn.tryCatchBlocks.isEmpty()) { + tryCatchTable = "\t// #TryCatch:\n"; for (TryCatchBlockNode tcbn : mn.tryCatchBlocks) { tryCatchTable += "\t// " + UnicodeUtils.escapeWithSpaces(tcbn.type) + " s:" + labels.get(tcbn.start.getLabel()) + " e:" + labels.get(tcbn.end.getLabel()) + " h:" diff --git a/src/me/ByteEdit/main/Main.java b/src/me/ByteEdit/main/Main.java index a732de3..10610d1 100644 --- a/src/me/ByteEdit/main/Main.java +++ b/src/me/ByteEdit/main/Main.java @@ -177,7 +177,7 @@ public class Main extends JFrame { "getstatic Ljava/io/PrintStream; java/lang/System/out\n\t\tldc \"text\"\n\t\tinvokevirtual (Ljava/lang/String;)V java/io/PrintStream/println", null, "sysout
Writes a System.out.println(\"text\"); as bytecode")); provider.addCompletion(new ShorthandCompletion(provider, "clazz", - "// #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, "clazz
Creates an example class")); 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}", @@ -221,12 +221,12 @@ public class Main extends JFrame { e.printStackTrace(); } contentPane = new JPanel(); - contentPane.setBackground(dark ? Color.DARK_GRAY : Color.GRAY); + contentPane.setBackground(dark ? new Color(0x2F2F2F) : Color.GRAY); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(new GridLayout(0, 1, 0, 0)); JSplitPane splitPane = new JSplitPane(); - splitPane.setBackground(dark ? Color.DARK_GRAY : Color.GRAY); + splitPane.setBackground(dark ? new Color(0x2F2F2F) : Color.GRAY); splitPane.setResizeWeight(0.2); contentPane.add(splitPane); JScrollPane scrollPane = new JScrollPane(); @@ -295,10 +295,10 @@ public class Main extends JFrame { } }); tree.setFont(new Font("Verdana", Font.PLAIN, 11)); - tree.setBackground(dark ? Color.DARK_GRAY : Color.LIGHT_GRAY); + tree.setBackground(dark ? new Color(0x2F2F2F) : Color.LIGHT_GRAY); if (tree.getCellRenderer() instanceof DefaultTreeCellRenderer) { final DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) (tree.getCellRenderer()); - renderer.setBackgroundNonSelectionColor(dark ? Color.DARK_GRAY : Color.LIGHT_GRAY); + renderer.setBackgroundNonSelectionColor(dark ? new Color(0x2F2F2F) : Color.LIGHT_GRAY); renderer.setBackgroundSelectionColor(Color.GRAY); renderer.setTextNonSelectionColor(dark ? new Color(0xeeeeee) : Color.BLACK); renderer.setTextSelectionColor(dark ? new Color(0xeeeeee) : Color.BLACK); @@ -531,11 +531,11 @@ public class Main extends JFrame { theme.apply(txtByteEditView); splitPane.setRightComponent(scrollPane_ByteEdit); - txtByteEditView.setBackground(dark ? Color.DARK_GRAY : Color.LIGHT_GRAY); + txtByteEditView.setBackground(dark ? new Color(0x2F2F2F) : Color.LIGHT_GRAY); scrollPane_ByteEdit.setViewportView(txtByteEditView); scrollPane_ByteEdit.setLineNumbersEnabled(true); scrollPane_ByteEdit.setFoldIndicatorEnabled(true); - scrollPane_ByteEdit.getGutter().setBackground(dark ? Color.DARK_GRAY : Color.LIGHT_GRAY); + scrollPane_ByteEdit.getGutter().setBackground(dark ? new Color(0x2F2F2F) : Color.LIGHT_GRAY); } private final Pattern jumpableInstructionPattern = Pattern.compile("^\t\t(?!//|\t+).+ .+"); @@ -665,7 +665,7 @@ public class Main extends JFrame { private void saveCurrentClassNode() { String txt = txtByteEditView.getText(); - for (String s : txt.split("\\/\\/ #Annotations\n")) { + for (String s : txt.split("\\/\\/ #Annotations:\n")) { if (s.isEmpty()) continue; ClassNode node = Assembler.assemble(s); diff --git a/src/me/ByteEdit/utils/ClassUtil.java b/src/me/ByteEdit/utils/ClassUtil.java index 7f10130..649a3c5 100644 --- a/src/me/ByteEdit/utils/ClassUtil.java +++ b/src/me/ByteEdit/utils/ClassUtil.java @@ -286,10 +286,6 @@ public class ClassUtil { s += "native "; acc ^= ACC_NATIVE; } - if ((ACC_INTERFACE & access) != 0) { - s += "interface "; - acc ^= ACC_INTERFACE; - } if ((ACC_ABSTRACT & access) != 0) { s += "abstract "; acc ^= ACC_ABSTRACT; @@ -306,6 +302,14 @@ public class ClassUtil { s += "bridge "; acc ^= ACC_BRIDGE; } + if ((ACC_MANDATED & access) != 0) { + s += "mandated "; + acc ^= ACC_MANDATED; + } + if ((ACC_INTERFACE & access) != 0) { + s += "interface "; + acc ^= ACC_INTERFACE; + } if ((ACC_ANNOTATION & access) != 0) { s += "annotation "; acc ^= ACC_ANNOTATION; @@ -314,10 +318,6 @@ public class ClassUtil { s += "enum "; acc ^= ACC_ENUM; } - if ((ACC_MANDATED & access) != 0) { - s += "mandated "; - acc ^= ACC_MANDATED; - } if (acc == access) { return s; } else { diff --git a/src/me/ByteEdit/utils/UnicodeUtils.java b/src/me/ByteEdit/utils/UnicodeUtils.java index 52a93e9..d0c052c 100644 --- a/src/me/ByteEdit/utils/UnicodeUtils.java +++ b/src/me/ByteEdit/utils/UnicodeUtils.java @@ -81,7 +81,14 @@ public class UnicodeUtils { if (s == null) { return null; } - return escape(s).replace(" ", "\\u0020"); + 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) { diff --git a/src/org/fife/eclipse_dark.xml b/src/org/fife/eclipse_dark.xml index edd62e7..2cd3f00 100644 --- a/src/org/fife/eclipse_dark.xml +++ b/src/org/fife/eclipse_dark.xml @@ -70,10 +70,10 @@