|
16 | 16 | import java.nio.file.Files; |
17 | 17 | import java.nio.file.Paths; |
18 | 18 | import java.util.ArrayList; |
| 19 | +import java.util.Enumeration; |
19 | 20 | import java.util.HashMap; |
20 | 21 | import java.util.List; |
| 22 | +import java.util.jar.JarEntry; |
| 23 | +import java.util.jar.JarFile; |
| 24 | +import java.util.jar.JarOutputStream; |
21 | 25 |
|
22 | 26 | import javax.swing.JDialog; |
23 | 27 | import javax.swing.JFileChooser; |
|
26 | 30 | import javax.swing.UIManager; |
27 | 31 | import javax.swing.filechooser.FileFilter; |
28 | 32 |
|
| 33 | +import com.google.gson.reflect.TypeToken; |
29 | 34 | import me.konloch.kontainer.io.DiskReader; |
30 | 35 | import me.konloch.kontainer.io.DiskWriter; |
31 | 36 | import me.konloch.kontainer.io.HTTPRequest; |
32 | 37 |
|
33 | 38 | import org.apache.commons.io.FileUtils; |
34 | 39 | import org.objectweb.asm.tree.ClassNode; |
| 40 | +import com.google.gson.*; |
35 | 41 |
|
36 | 42 | import the.bytecode.club.bootloader.Boot; |
37 | 43 | import the.bytecode.club.bootloader.ILoader; |
|
68 | 74 | ***************************************************************************/ |
69 | 75 |
|
70 | 76 | /** |
| 77 | + * TODO: |
| 78 | + * open as folder doesn't actually work |
| 79 | + * smali compile |
| 80 | + * |
71 | 81 | * A lightweight Java Reverse Engineering suite, developed by Konloch - http://konloch.me |
72 | 82 | * |
73 | 83 | * All you have to do is add a jar or class file into the workspace, |
|
109 | 119 | public class BytecodeViewer |
110 | 120 | { |
111 | 121 | /*per version*/ |
112 | | - public static final String VERSION = "2.9.17"; |
| 122 | + public static final String VERSION = "2.9.18"; |
113 | 123 | public static String krakatauVersion = "12"; |
114 | 124 | public static String enjarifyVersion = "4"; |
115 | 125 | public static final boolean BLOCK_TAB_MENU = true; |
@@ -142,22 +152,46 @@ public class BytecodeViewer |
142 | 152 | public static String nl = System.getProperty("line.separator"); |
143 | 153 | private static File BCVDir = new File(System.getProperty("user.home") + fs + ".Bytecode-Viewer"); |
144 | 154 | public static File RJ_JAR = new File(System.getProperty("java.home") + fs + "lib" + fs + "rt.jar"); |
145 | | - private static String filesName = getBCVDirectory() + fs + "recentfiles.bcv"; |
146 | | - private static String pluginsName = getBCVDirectory() + fs + "recentplugins.bcv"; |
| 155 | + private static String filesName = getBCVDirectory() + fs + "recentfiles.json"; |
| 156 | + private static String pluginsName = getBCVDirectory() + fs + "recentplugins.json"; |
147 | 157 | public static String settingsName = getBCVDirectory() + fs + "settings.bcv"; |
148 | 158 | public static String tempDirectory = getBCVDirectory() + fs + "bcv_temp" + fs; |
149 | 159 | public static String libsDirectory = getBCVDirectory() + fs + "libs" + fs; |
150 | 160 | public static String krakatauWorkingDirectory = getBCVDirectory() + fs + "krakatau_" + krakatauVersion; |
151 | 161 | public static String enjarifyWorkingDirectory = getBCVDirectory() + fs + "enjarify_" + enjarifyVersion; |
152 | | - private static ArrayList<String> recentFiles = DiskReader.loadArrayList(filesName, false); |
153 | | - private static ArrayList<String> recentPlugins = DiskReader.loadArrayList(pluginsName, false); |
154 | 162 | public static boolean runningObfuscation = false; |
155 | 163 | private static long start = System.currentTimeMillis(); |
156 | | - public static String lastDirectory = ""; |
| 164 | + public static String lastDirectory = "."; |
157 | 165 | public static ArrayList<Process> createdProcesses = new ArrayList<Process>(); |
158 | 166 | public static Refactorer refactorer = new Refactorer(); |
159 | 167 | public static boolean pingback = false; |
160 | 168 | public static boolean deleteForeignLibraries = true; |
| 169 | + public static boolean canExit = false; |
| 170 | + public static Gson gson; |
| 171 | + |
| 172 | + private static ArrayList<String> recentPlugins; |
| 173 | + private static ArrayList<String> recentFiles; |
| 174 | + |
| 175 | + static |
| 176 | + { |
| 177 | + try |
| 178 | + { |
| 179 | + gson = new GsonBuilder().setPrettyPrinting().create(); |
| 180 | + if(new File(filesName).exists()) |
| 181 | + recentFiles = gson.fromJson(DiskReader.loadAsString(filesName), new TypeToken<ArrayList<String>>() {}.getType()); |
| 182 | + else |
| 183 | + recentFiles = DiskReader.loadArrayList(getBCVDirectory() + fs + "recentfiles.bcv", false); |
| 184 | + |
| 185 | + if(new File(pluginsName).exists()) |
| 186 | + recentPlugins = gson.fromJson(DiskReader.loadAsString(pluginsName), new TypeToken<ArrayList<String>>() {}.getType()); |
| 187 | + else |
| 188 | + recentPlugins = DiskReader.loadArrayList(getBCVDirectory() + fs + "recentplugins.bcv", false); |
| 189 | + } |
| 190 | + catch (Exception e) |
| 191 | + { |
| 192 | + e.printStackTrace(); |
| 193 | + } |
| 194 | + } |
161 | 195 |
|
162 | 196 | /** |
163 | 197 | * The version checker thread |
@@ -812,7 +846,7 @@ public void run() { |
812 | 846 | } else { |
813 | 847 | if (f.isDirectory()) { |
814 | 848 | FileContainer container = new FileContainer(f); |
815 | | - HashMap<String, byte[]> files = new HashMap<String, byte[]>(); |
| 849 | + HashMap<String, byte[]> files = new HashMap<>(); |
816 | 850 | boolean finished = false; |
817 | 851 | ArrayList<File> totalFiles = new ArrayList<File>(); |
818 | 852 | totalFiles.add(f); |
@@ -844,10 +878,10 @@ public void run() { |
844 | 878 | container.files = files; |
845 | 879 | BytecodeViewer.files.add(container); |
846 | 880 | } else { |
847 | | - if (fn.endsWith(".jar") || fn.endsWith(".zip")) { |
| 881 | + if (fn.endsWith(".jar") || fn.endsWith(".zip") || fn.endsWith(".war")) { |
848 | 882 | try { |
849 | 883 | JarUtils.put(f); |
850 | | - } catch (final java.util.zip.ZipException z) { |
| 884 | + } catch (java.io.IOException z) { |
851 | 885 | try { |
852 | 886 | JarUtils.put2(f); |
853 | 887 | } catch (final Exception e) { |
@@ -938,7 +972,7 @@ else if (BytecodeViewer.viewer.apkConversionGroup.isSelected(BytecodeViewer.view |
938 | 972 | } |
939 | 973 | return; |
940 | 974 | } else { |
941 | | - HashMap<String, byte[]> files = new HashMap<String, byte[]>(); |
| 975 | + HashMap<String, byte[]> files = new HashMap<>(); |
942 | 976 | byte[] bytes = JarUtils.getBytes(new FileInputStream(f)); |
943 | 977 | files.put(f.getName(), bytes); |
944 | 978 |
|
@@ -1201,10 +1235,7 @@ private static void hideFile(File f) { |
1201 | 1235 | * @return string with newline per array object |
1202 | 1236 | */ |
1203 | 1237 | private static String quickConvert(ArrayList<String> a) { |
1204 | | - String s = ""; |
1205 | | - for (String r : a) |
1206 | | - s += r + nl; |
1207 | | - return s; |
| 1238 | + return gson.toJson(a); |
1208 | 1239 | } |
1209 | 1240 |
|
1210 | 1241 | private static long last = System.currentTimeMillis(); |
|
0 commit comments