33import java .awt .Desktop ;
44import java .awt .event .ActionEvent ;
55import java .awt .event .ActionListener ;
6+ import java .awt .event .KeyEvent ;
67import java .io .ByteArrayOutputStream ;
78import java .io .File ;
89import java .io .FileInputStream ;
1415import java .net .URL ;
1516import java .util .ArrayList ;
1617import java .util .HashMap ;
17- import java .util .List ;
1818import java .util .Map .Entry ;
1919
2020import javax .swing .JDialog ;
7676 * bytecode editor that works by editing per method instead of entire class, methods are in a pane like the file navigator
7777 * Make the tabs menu and middle mouse button click work on the tab itself not just the close button.
7878 *
79- * 2.9.2 :
79+ * before 3.0.0 :
8080 * make it use that global last used inside of export as jar
8181 * Spiffy up the plugin console with hilighted lines
8282 * Take https://github.com/ptnkjke/Java-Bytecode-Editor visualize
8383 * fix the randomly sometimes fucked up names on file navigation bug
8484 * make zipfile not include the decode shit
85+ * When you drag a folder, it must add the folder name not just the child into the root jtree path
8586 *
86- * -----2.9.2-----:
87- * 02/24/2015 - Actually fixed the compiler, LOL.
87+ * -----2.9.3-----:
88+ * 02/28/2015 - Added drag and drop for any file.
89+ * 02/28/2015 - Added ctrl + w to close the current opened tab.
90+ * 02/28/2015 - Updated to CFR 0_97.jar
91+ * 02/28/2015 - Fixed a concurrency issue with the decompilers.
92+ * 02/28/2015 - Added image resize via scroll on mouse.
93+ * 02/28/2015 - Added resource refreshing.
94+ * 02/28/2015 - Im Frizzy started working on Obfuscation.
8895 *
8996 * @author Konloch
9097 *
93100public class BytecodeViewer {
94101
95102 /*per version*/
96- public static String version = "2.9.2 " ;
103+ public static String version = "2.9.3 " ;
97104 public static String krakatauVersion = "2" ;
98105 /*the rest*/
99106 public static MainViewerGUI viewer = null ;
@@ -118,10 +125,7 @@ public class BytecodeViewer {
118125 private static long start = System .currentTimeMillis ();
119126 public static String lastDirectory = "" ;
120127 public static ArrayList <Process > krakatau = new ArrayList <Process >();
121-
122- /* ASM Re-mapping Constants */
123128 public static Refactorer refactorer = new Refactorer ();
124- /* ASM Re-mapping Constants */
125129
126130 /**
127131 * The version checker thread
@@ -354,7 +358,7 @@ public static void exit(int i) {
354358 * @return the currently opened ClassNode
355359 */
356360 public static ClassNode getCurrentlyOpenedClassNode () {
357- return viewer .workPane .getCurrentClass ().cn ;
361+ return viewer .workPane .getCurrentViewer ().cn ;
358362 }
359363
360364 /**
@@ -388,18 +392,6 @@ public static void updateNode(ClassNode oldNode, ClassNode newNode) {
388392 BytecodeViewer .loadedClasses .remove (oldNode .name );
389393 BytecodeViewer .loadedClasses .put (oldNode .name , newNode );
390394 }
391-
392- /**
393- * Replaces an old node with a new instance
394- * @param oldNode the old instance
395- * @param newNode the new instance
396- */
397- public static void relocate (String name , ClassNode node ) {
398- if (BytecodeViewer .loadedClasses .containsKey (name ))
399- BytecodeViewer .loadedClasses .remove (name );
400-
401- BytecodeViewer .loadedClasses .put (node .name , node );
402- }
403395
404396 /**
405397 * Gets all of the loaded classes as an array list
@@ -422,9 +414,6 @@ public static ArrayList<ClassNode> getLoadedClasses() {
422414 * @return true if no errors, false if it failed to compile.
423415 */
424416 public static boolean compile (boolean message ) {
425- if (getLoadedClasses ().isEmpty ())
426- return false ;
427-
428417 boolean actuallyTried = false ;
429418
430419 for (java .awt .Component c : BytecodeViewer .viewer .workPane .getLoadedViewers ()) {
@@ -620,6 +609,9 @@ public void run() {
620609 new the .bytecode .club .bytecodeviewer .api .ExceptionUI (e );
621610 }
622611 return ;
612+ } else {
613+ byte [] bytes = JarUtils .getBytes (new FileInputStream (f ));
614+ BytecodeViewer .loadedResources .put (f .getName (), bytes );
623615 }
624616 }
625617 }
@@ -672,12 +664,10 @@ public static void resetWorkSpace(boolean ask) {
672664 if (!ask ) {
673665 loadedResources .clear ();
674666 loadedClasses .clear ();
675- MainViewerGUI .getComponent (FileNavigationPane .class )
676- .resetWorkspace ();
667+ MainViewerGUI .getComponent (FileNavigationPane .class ).resetWorkspace ();
677668 MainViewerGUI .getComponent (WorkPane .class ).resetWorkspace ();
678669 MainViewerGUI .getComponent (SearchingPane .class ).resetWorkspace ();
679- the .bytecode .club .bytecodeviewer .api .BytecodeViewer
680- .getClassNodeLoader ().clear ();
670+ the .bytecode .club .bytecodeviewer .api .BytecodeViewer .getClassNodeLoader ().clear ();
681671 } else {
682672 JOptionPane pane = new JOptionPane (
683673 "Are you sure you want to reset the workspace?\n \r It will also reset your file navigator and search." );
@@ -695,12 +685,10 @@ public static void resetWorkSpace(boolean ask) {
695685 if (result == 0 ) {
696686 loadedResources .clear ();
697687 loadedClasses .clear ();
698- MainViewerGUI .getComponent (FileNavigationPane .class )
699- .resetWorkspace ();
688+ MainViewerGUI .getComponent (FileNavigationPane .class ).resetWorkspace ();
700689 MainViewerGUI .getComponent (WorkPane .class ).resetWorkspace ();
701690 MainViewerGUI .getComponent (SearchingPane .class ).resetWorkspace ();
702- the .bytecode .club .bytecodeviewer .api .BytecodeViewer
703- .getClassNodeLoader ().clear ();
691+ the .bytecode .club .bytecodeviewer .api .BytecodeViewer .getClassNodeLoader ().clear ();
704692 }
705693 }
706694 }
@@ -828,6 +816,19 @@ public static String getRandomizedName() {
828816 return name ;
829817 }
830818
819+
820+ /**
821+ * Replaces an old node with a new instance
822+ * @param oldNode the old instance
823+ * @param newNode the new instance
824+ */
825+ public static void relocate (String name , ClassNode node ) {
826+ if (BytecodeViewer .loadedClasses .containsKey (name ))
827+ BytecodeViewer .loadedClasses .remove (name );
828+
829+ BytecodeViewer .loadedClasses .put (node .name , node );
830+ }
831+
831832 /**
832833 * Returns the BCV directory
833834 * @return the static BCV directory
@@ -876,4 +877,46 @@ private static String quickConvert(ArrayList<String> a) {
876877 s += r + nl ;
877878 return s ;
878879 }
880+
881+ private static long last = System .currentTimeMillis ();
882+ /**
883+ * Checks the hotkeys
884+ * @param e
885+ */
886+ public static void checkHotKey (KeyEvent e ) {
887+ if (System .currentTimeMillis () - last <= (4000 ))
888+ return ;
889+
890+ if ((e .getKeyCode () == KeyEvent .VK_O ) && ((e .getModifiers () & KeyEvent .CTRL_MASK ) != 0 )) {
891+ last = System .currentTimeMillis ();
892+ JFileChooser fc = new JFileChooser ();
893+ try {
894+ fc .setSelectedFile (new File (BytecodeViewer .lastDirectory ));
895+ } catch (Exception e2 ) {
896+
897+ }
898+ fc .setFileFilter (viewer .new APKDEXJarZipClassFileFilter ());
899+ fc .setFileHidingEnabled (false );
900+ fc .setAcceptAllFileFilterUsed (false );
901+ int returnVal = fc .showOpenDialog (BytecodeViewer .viewer );
902+
903+ if (returnVal == JFileChooser .APPROVE_OPTION ) {
904+ BytecodeViewer .lastDirectory = fc .getSelectedFile ().getAbsolutePath ();
905+ try {
906+ BytecodeViewer .viewer .setIcon (true );
907+ BytecodeViewer .openFiles (new File [] { fc .getSelectedFile () }, true );
908+ BytecodeViewer .viewer .setIcon (false );
909+ } catch (Exception e1 ) {
910+ new the .bytecode .club .bytecodeviewer .api .ExceptionUI (e1 );
911+ }
912+ }
913+ } else if ((e .getKeyCode () == KeyEvent .VK_N ) && ((e .getModifiers () & KeyEvent .CTRL_MASK ) != 0 )) {
914+ last = System .currentTimeMillis ();
915+ BytecodeViewer .resetWorkSpace (true );
916+ } else if ((e .getKeyCode () == KeyEvent .VK_W ) && ((e .getModifiers () & KeyEvent .CTRL_MASK ) != 0 )) {
917+ last = System .currentTimeMillis ();
918+ if (viewer .workPane .getCurrentViewer () != null )
919+ viewer .workPane .tabs .remove (viewer .workPane .getCurrentViewer ());
920+ }
921+ }
879922}
0 commit comments