Skip to content

Commit a1dc3ae

Browse files
committed
A bunch of changes for 2.9.3
* -----2.9.3-----: * 02/28/2015 - Added drag and drop for any file. * 02/28/2015 - Added ctrl + w to close the current opened tab. * 02/28/2015 - Updated to CFR 0_97.jar * 02/28/2015 - Fixed a concurrency issue with the decompilers. * 02/28/2015 - Added image resize via scroll on mouse. * 02/28/2015 - Added resource refreshing. * 02/28/2015 - Im Frizzy started working on Obfuscation.
1 parent 90241eb commit a1dc3ae

26 files changed

+378
-170
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/bin/
2+
.classpath
3+
.project
1.33 MB
Binary file not shown.

plugins/Skeleton.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ public class Skeleton extends Plugin {
88
public void execute(ArrayList<ClassNode> classNodesList) {
99
PluginConsole gui = new PluginConsole("Skeleton");
1010
gui.setVisible(true);
11-
gui.appendText("exceuted skeleton");
11+
gui.appendText("executed skeleton");
1212
}
1313
}

src/the/bytecode/club/bytecodeviewer/BytecodeViewer.java

Lines changed: 75 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.awt.Desktop;
44
import java.awt.event.ActionEvent;
55
import java.awt.event.ActionListener;
6+
import java.awt.event.KeyEvent;
67
import java.io.ByteArrayOutputStream;
78
import java.io.File;
89
import java.io.FileInputStream;
@@ -14,7 +15,6 @@
1415
import java.net.URL;
1516
import java.util.ArrayList;
1617
import java.util.HashMap;
17-
import java.util.List;
1818
import java.util.Map.Entry;
1919

2020
import javax.swing.JDialog;
@@ -76,15 +76,22 @@
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
*
@@ -93,7 +100,7 @@
93100
public 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\rIt 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
}

src/the/bytecode/club/bytecodeviewer/api/PluginConsole.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void keyPressed(KeyEvent e) {
5555
field.requestFocus();
5656
}
5757

58-
BytecodeViewer.viewer.checkKey(e);
58+
BytecodeViewer.checkHotKey(e);
5959
}
6060
@Override public void keyReleased(KeyEvent arg0) { }
6161
@Override public void keyTyped(KeyEvent arg0) { }

src/the/bytecode/club/bytecodeviewer/decompilers/CFRDecompiler.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,7 @@ public class CFRDecompiler extends Decompiler {
3636

3737
@Override
3838
public void decompileToClass(String className, String classNameSaved) {
39-
String contents = decompileClassNode(BytecodeViewer.getClassNode(className));
40-
DiskWriter.replaceFile(classNameSaved, contents, false);
41-
}
42-
43-
@Override
44-
public String decompileClassNode(ClassNode cn) {
39+
ClassNode cn = BytecodeViewer.getClassNode(className);
4540
final ClassWriter cw = new ClassWriter(0);
4641
try {
4742
cn.accept(cw);
@@ -52,15 +47,20 @@ public String decompileClassNode(ClassNode cn) {
5247
cn.accept(cw);
5348
} catch (InterruptedException e1) { }
5449
}
55-
50+
String contents = decompileClassNode(cn, cw.toByteArray());
51+
DiskWriter.replaceFile(classNameSaved, contents, false);
52+
}
53+
54+
@Override
55+
public String decompileClassNode(ClassNode cn, byte[] b) {
5656
String fileStart = BytecodeViewer.tempDirectory + BytecodeViewer.fs;
5757

5858
final File tempClass = new File(MiscUtils.getUniqueName(fileStart, ".class") + ".class");
5959

6060
try {
6161
final FileOutputStream fos = new FileOutputStream(tempClass);
6262

63-
fos.write(cw.toByteArray());
63+
fos.write(b);
6464

6565
fos.close();
6666
} catch (final IOException e) {

src/the/bytecode/club/bytecodeviewer/decompilers/Decompiler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
public abstract class Decompiler {
1515

16-
public abstract String decompileClassNode(ClassNode cn);
16+
public abstract String decompileClassNode(ClassNode cn, byte[] b);
1717

1818
public abstract void decompileToZip(String zipName);
1919

src/the/bytecode/club/bytecodeviewer/decompilers/FernFlowerDecompiler.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,18 @@ public class FernFlowerDecompiler extends Decompiler {
2828

2929
@Override
3030
public void decompileToClass(String className, String classNameSaved) {
31-
String contents = decompileClassNode(BytecodeViewer.getClassNode(className));
31+
ClassNode cn = BytecodeViewer.getClassNode(className);
32+
final ClassWriter cw = new ClassWriter(0);
33+
try {
34+
cn.accept(cw);
35+
} catch(Exception e) {
36+
e.printStackTrace();
37+
try {
38+
Thread.sleep(200);
39+
cn.accept(cw);
40+
} catch (InterruptedException e1) { }
41+
}
42+
String contents = decompileClassNode(cn, cw.toByteArray());
3243
DiskWriter.replaceFile(classNameSaved, contents, false);
3344
}
3445

@@ -60,10 +71,7 @@ public void decompileToZip(String zipName) {
6071
}
6172

6273
@Override
63-
public String decompileClassNode(final ClassNode cn) {
64-
final ClassWriter cw = new ClassWriter(0);
65-
cn.accept(cw);
66-
74+
public String decompileClassNode(final ClassNode cn, byte[] b) {
6775
String start = MiscUtils.getUniqueName("", ".class");
6876

6977
final File tempClass = new File(start + ".class");
@@ -72,7 +80,7 @@ public String decompileClassNode(final ClassNode cn) {
7280
try {
7381
final FileOutputStream fos = new FileOutputStream(tempClass);
7482

75-
fos.write(cw.toByteArray());
83+
fos.write(b);
7684

7785
fos.close();
7886
} catch (final IOException e) {

src/the/bytecode/club/bytecodeviewer/decompilers/KrakatauDecompiler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
public class KrakatauDecompiler extends Decompiler {
2727

28-
public String decompileClassNode(ClassNode cn) {
28+
public String decompileClassNode(ClassNode cn, byte[] b) {
2929

3030
if(BytecodeViewer.python.equals("")) {
3131
BytecodeViewer.showMessage("You need to set your Python 2.7 executable path.");

src/the/bytecode/club/bytecodeviewer/decompilers/KrakatauDisassembler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
public class KrakatauDisassembler extends Decompiler {
2626

27-
public String decompileClassNode(ClassNode cn) {
27+
public String decompileClassNode(ClassNode cn, byte[] b) {
2828
if(BytecodeViewer.python.equals("")) {
2929
BytecodeViewer.showMessage("You need to set your Python 2.7 executable path.");
3030
BytecodeViewer.viewer.pythonC();

0 commit comments

Comments
 (0)