From 1494eca99eeb1f7be417fb2868bcc87057a6c040 Mon Sep 17 00:00:00 2001 From: Konloch Date: Sat, 5 Oct 2024 00:09:19 -0600 Subject: [PATCH] Replaced Old Disk-Lib Library --- .../club/bytecodeviewer/BytecodeViewer.java | 4 +- .../club/bytecodeviewer/Settings.java | 46 +++++++++++++++---- .../bytecodeviewer/SettingsSerializer.java | 35 ++++++++------ .../bytecodeviewer/cli/CommandLineInput.java | 20 ++++---- .../compilers/impl/JavaCompiler.java | 14 +++--- .../compilers/impl/KrakatauAssembler.java | 17 ++++--- .../compilers/impl/SmaliAssembler.java | 4 +- .../decompilers/impl/BlankDecompilerBase.java | 4 +- .../impl/FernFlowerDecompiler.java | 4 +- .../decompilers/impl/JADXDecompiler.java | 4 +- .../decompilers/impl/JDGUIDecompiler.java | 4 +- .../decompilers/impl/JavapDisassembler.java | 4 +- .../decompilers/impl/KrakatauDecompiler.java | 4 +- .../impl/KrakatauDisassembler.java | 4 +- .../decompilers/impl/SmaliDisassembler.java | 4 +- .../gui/components/JFrameConsole.java | 20 +++++--- .../gui/resourcelist/ResourceListPane.java | 6 +-- .../bytecodeviewer/plugin/PluginWriter.java | 20 +++++--- .../resources/ResourceDecompiling.java | 9 ++-- .../importing/impl/XAPKResourceImporter.java | 11 ++--- .../club/bytecodeviewer/util/JarUtils.java | 4 +- 21 files changed, 144 insertions(+), 98 deletions(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java index d258498f8..ae474d787 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java @@ -20,8 +20,8 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.konloch.disklib.DiskReader; import com.konloch.taskmanager.TaskManager; -import me.konloch.kontainer.io.DiskReader; import org.apache.commons.io.FileUtils; import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bytecodeviewer.api.BCV; @@ -588,7 +588,7 @@ public static void startPlugin(File file) try { - PluginWriter writer = new PluginWriter(DiskReader.loadAsString(file.getAbsolutePath()), file.getName()); + PluginWriter writer = new PluginWriter(DiskReader.readString(file.getAbsolutePath()), file.getName()); writer.setSourceFile(file); writer.setVisible(true); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/Settings.java b/src/main/java/the/bytecode/club/bytecodeviewer/Settings.java index cee5038cf..f00e531ee 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/Settings.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/Settings.java @@ -19,13 +19,15 @@ package the.bytecode.club.bytecodeviewer; import com.google.gson.reflect.TypeToken; -import me.konloch.kontainer.io.DiskReader; -import me.konloch.kontainer.io.DiskWriter; +import com.konloch.disklib.DiskReader; +import com.konloch.disklib.DiskWriter; import the.bytecode.club.bytecodeviewer.util.MiscUtils; import javax.swing.*; import java.io.File; +import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import static the.bytecode.club.bytecodeviewer.BytecodeViewer.gson; @@ -52,14 +54,14 @@ public class Settings try { if (new File(FILES_NAME).exists()) - recentFiles = gson.fromJson(DiskReader.loadAsString(FILES_NAME), new TypeToken>() {}.getType()); + recentFiles = gson.fromJson(DiskReader.readString(FILES_NAME), new TypeToken>() {}.getType()); else - recentFiles = DiskReader.loadArrayList(getBCVDirectory() + FS + "recentfiles.bcv", false); + recentFiles = Arrays.asList(DiskReader.readArray(getBCVDirectory() + FS + "recentfiles.bcv")); if (new File(PLUGINS_NAME).exists()) - recentPlugins = gson.fromJson(DiskReader.loadAsString(PLUGINS_NAME), new TypeToken>() {}.getType()); + recentPlugins = gson.fromJson(DiskReader.readString(PLUGINS_NAME), new TypeToken>() {}.getType()); else - recentPlugins = DiskReader.loadArrayList(getBCVDirectory() + FS + "recentplugins.bcv", false); + recentPlugins = Arrays.asList(DiskReader.readArray(getBCVDirectory() + FS + "recentplugins.bcv")); MiscUtils.deduplicateAndTrim(recentFiles, maxRecentFiles); MiscUtils.deduplicateAndTrim(recentPlugins, maxRecentFiles); @@ -80,7 +82,7 @@ public static synchronized void addRecentFile(File f) recentFiles.remove(f.getAbsolutePath()); // already added on the list recentFiles.add(0, f.getAbsolutePath()); MiscUtils.deduplicateAndTrim(recentFiles, maxRecentFiles); - DiskWriter.replaceFile(FILES_NAME, MiscUtils.listToString(recentFiles), false); + saveRecentFiles(); resetRecentFilesMenu(); } @@ -88,11 +90,23 @@ public static synchronized void removeRecentFile(File f) { if (recentFiles.remove(f.getAbsolutePath())) { - DiskWriter.replaceFile(FILES_NAME, MiscUtils.listToString(recentFiles), false); + saveRecentFiles(); resetRecentFilesMenu(); } } + private static void saveRecentFiles() + { + try + { + DiskWriter.write(FILES_NAME, MiscUtils.listToString(recentFiles)); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + public static String getRecentFile() { if (recentFiles.isEmpty()) @@ -111,7 +125,7 @@ public static synchronized void addRecentPlugin(File f) recentPlugins.remove(f.getAbsolutePath()); // already added on the list recentPlugins.add(0, f.getAbsolutePath()); MiscUtils.deduplicateAndTrim(recentPlugins, maxRecentFiles); - DiskWriter.replaceFile(PLUGINS_NAME, MiscUtils.listToString(recentPlugins), false); + saveRecentPlugins(); resetRecentFilesMenu(); } @@ -119,11 +133,23 @@ public static synchronized void removeRecentPlugin(File f) { if (recentPlugins.remove(f.getAbsolutePath())) { - DiskWriter.replaceFile(PLUGINS_NAME, MiscUtils.listToString(recentPlugins), false); + saveRecentPlugins(); resetRecentFilesMenu(); } } + private static void saveRecentPlugins() + { + try + { + DiskWriter.write(PLUGINS_NAME, MiscUtils.listToString(recentPlugins)); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + /** * resets the recent files menu */ diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/SettingsSerializer.java b/src/main/java/the/bytecode/club/bytecodeviewer/SettingsSerializer.java index 2e5ca80b8..2c154fd62 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/SettingsSerializer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/SettingsSerializer.java @@ -18,8 +18,8 @@ package the.bytecode.club.bytecodeviewer; -import me.konloch.kontainer.io.DiskReader; -import me.konloch.kontainer.io.DiskWriter; +import com.konloch.disklib.DiskReader; +import com.konloch.disklib.DiskWriter; import the.bytecode.club.bytecodeviewer.decompilers.Decompiler; import the.bytecode.club.bytecodeviewer.gui.theme.LAFTheme; import the.bytecode.club.bytecodeviewer.gui.theme.RSTATheme; @@ -27,6 +27,7 @@ import javax.swing.*; import java.io.File; +import java.io.IOException; import static the.bytecode.club.bytecodeviewer.Constants.VERSION; import static the.bytecode.club.bytecodeviewer.Constants.SETTINGS_NAME; @@ -40,6 +41,7 @@ public class SettingsSerializer { private static boolean settingsFileExists; + private static String[] settings; public static void saveSettingsAsync() { @@ -53,7 +55,7 @@ public static synchronized void saveSettings() try { - DiskWriter.replaceFile(SETTINGS_NAME, "BCV: " + VERSION, false); + DiskWriter.write(SETTINGS_NAME, "BCV: " + VERSION, true); save(BytecodeViewer.viewer.rbr.isSelected()); save(BytecodeViewer.viewer.rsy.isSelected()); save(BytecodeViewer.viewer.din.isSelected()); @@ -169,9 +171,9 @@ public static synchronized void saveSettings() save(Configuration.deleteForeignLibraries); if (BytecodeViewer.viewer.apkConversionGroup.isSelected(BytecodeViewer.viewer.apkConversionDex.getModel())) - DiskWriter.writeNewLine(SETTINGS_NAME, "0"); + DiskWriter.append(SETTINGS_NAME, "0", true); else if (BytecodeViewer.viewer.apkConversionGroup.isSelected(BytecodeViewer.viewer.apkConversionEnjarify.getModel())) - DiskWriter.writeNewLine(SETTINGS_NAME, "1"); + DiskWriter.append(SETTINGS_NAME, "1", true); save(Configuration.python3); save(Configuration.javac); @@ -224,7 +226,7 @@ public static void preloadSettingsFile() return; //precache the file - DiskReader.loadString(SETTINGS_NAME, 0, true); + settings = DiskReader.readArray(SETTINGS_NAME); //process the cached file Configuration.lafTheme = LAFTheme.valueOf(asString(127)); @@ -425,21 +427,28 @@ public static void loadSettings() public static void save(Object o) { - DiskWriter.writeNewLine(SETTINGS_NAME, String.valueOf(o), false); + try + { + DiskWriter.append(SETTINGS_NAME, String.valueOf(o), true); + } + catch (IOException e) + { + e.printStackTrace(); + } } - public static String asString(int lineNumber) throws Exception + public static String asString(int lineNumber) { - return DiskReader.loadString(SETTINGS_NAME, lineNumber, false); + return settings[lineNumber]; } - public static boolean asBoolean(int lineNumber) throws Exception + public static boolean asBoolean(int lineNumber) { - return Boolean.parseBoolean(DiskReader.loadString(SETTINGS_NAME, lineNumber, false)); + return Boolean.parseBoolean(settings[lineNumber]); } - public static int asInt(int lineNumber) throws Exception + public static int asInt(int lineNumber) { - return Integer.parseInt(DiskReader.loadString(SETTINGS_NAME, lineNumber, false)); + return Integer.parseInt(settings[lineNumber]); } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/cli/CommandLineInput.java b/src/main/java/the/bytecode/club/bytecodeviewer/cli/CommandLineInput.java index 6aa20a79a..76a44706d 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/cli/CommandLineInput.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/cli/CommandLineInput.java @@ -18,7 +18,7 @@ package the.bytecode.club.bytecodeviewer.cli; -import me.konloch.kontainer.io.DiskWriter; +import com.konloch.disklib.DiskWriter; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.DefaultParser; @@ -250,7 +250,7 @@ public static void executeCommandLine(String[] args) ClassNode cn = BytecodeViewer.blindlySearchForClassNode(target); final ClassWriter cw = accept(cn); String contents = Decompiler.PROCYON_DECOMPILER.getDecompiler().decompileClassNode(cn, cw.toByteArray()); - DiskWriter.replaceFile(output.getAbsolutePath(), contents, false); + DiskWriter.write(output.getAbsolutePath(), contents); } catch (Exception e) { @@ -276,7 +276,7 @@ else if (decompiler.equalsIgnoreCase("cfr")) ClassNode cn = BytecodeViewer.blindlySearchForClassNode(target); final ClassWriter cw = accept(cn); String contents = Decompiler.CFR_DECOMPILER.getDecompiler().decompileClassNode(cn, cw.toByteArray()); - DiskWriter.replaceFile(output.getAbsolutePath(), contents, false); + DiskWriter.write(output.getAbsolutePath(), contents); } catch (Exception e) { @@ -302,7 +302,7 @@ else if (decompiler.equalsIgnoreCase("fernflower")) ClassNode cn = BytecodeViewer.blindlySearchForClassNode(target); final ClassWriter cw = accept(cn); String contents = Decompiler.FERNFLOWER_DECOMPILER.getDecompiler().decompileClassNode(cn, cw.toByteArray()); - DiskWriter.replaceFile(output.getAbsolutePath(), contents, false); + DiskWriter.write(output.getAbsolutePath(), contents); } catch (Exception e) { @@ -328,7 +328,7 @@ else if (decompiler.equalsIgnoreCase("krakatau")) ClassNode cn = BytecodeViewer.blindlySearchForClassNode(target); final ClassWriter cw = accept(cn); String contents = Decompiler.KRAKATAU_DECOMPILER.getDecompiler().decompileClassNode(cn, cw.toByteArray()); - DiskWriter.replaceFile(output.getAbsolutePath(), contents, false); + DiskWriter.write(output.getAbsolutePath(), contents); } catch (Exception e) { @@ -355,7 +355,7 @@ else if (decompiler.equalsIgnoreCase("krakatau-bytecode")) ClassNode cn = BytecodeViewer.blindlySearchForClassNode(target); final ClassWriter cw = accept(cn); String contents = Decompiler.KRAKATAU_DISASSEMBLER.getDecompiler().decompileClassNode(cn, cw.toByteArray()); - DiskWriter.replaceFile(output.getAbsolutePath(), contents, false); + DiskWriter.write(output.getAbsolutePath(), contents); } catch (Exception e) { @@ -382,7 +382,7 @@ else if (decompiler.equalsIgnoreCase("jd-gui")) ClassNode cn = BytecodeViewer.blindlySearchForClassNode(target); final ClassWriter cw = accept(cn); String contents = Decompiler.JD_DECOMPILER.getDecompiler().decompileClassNode(cn, cw.toByteArray()); - DiskWriter.replaceFile(output.getAbsolutePath(), contents, false); + DiskWriter.write(output.getAbsolutePath(), contents); } catch (Exception e) { @@ -409,7 +409,7 @@ else if (decompiler.equalsIgnoreCase("smali")) ClassNode cn = BytecodeViewer.blindlySearchForClassNode(target); final ClassWriter cw = accept(cn); String contents = Decompiler.SMALI_DISASSEMBLER.getDecompiler().decompileClassNode(cn, cw.toByteArray()); - DiskWriter.replaceFile(output.getAbsolutePath(), contents, false); + DiskWriter.write(output.getAbsolutePath(), contents); } catch (Exception e) { @@ -436,7 +436,7 @@ else if (decompiler.equalsIgnoreCase("jadx")) ClassNode cn = BytecodeViewer.blindlySearchForClassNode(target); final ClassWriter cw = accept(cn); String contents = Decompiler.JADX_DECOMPILER.getDecompiler().decompileClassNode(cn, cw.toByteArray()); - DiskWriter.replaceFile(output.getAbsolutePath(), contents, false); + DiskWriter.write(output.getAbsolutePath(), contents); } catch (Exception e) { @@ -463,7 +463,7 @@ else if (decompiler.equalsIgnoreCase("asmifier")) ClassNode cn = BytecodeViewer.blindlySearchForClassNode(target); final ClassWriter cw = accept(cn); String contents = Decompiler.ASMIFIER_CODE_GEN.getDecompiler().decompileClassNode(cn, cw.toByteArray()); - DiskWriter.replaceFile(output.getAbsolutePath(), contents, false); + DiskWriter.write(output.getAbsolutePath(), contents); } catch (Exception e) { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/JavaCompiler.java b/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/JavaCompiler.java index 0b58a216b..823eb4af5 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/JavaCompiler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/JavaCompiler.java @@ -18,7 +18,7 @@ package the.bytecode.club.bytecodeviewer.compilers.impl; -import me.konloch.kontainer.io.DiskWriter; +import com.konloch.disklib.DiskWriter; import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.Configuration; import the.bytecode.club.bytecodeviewer.compilers.AbstractCompiler; @@ -69,15 +69,15 @@ public byte[] compile(String contents, String fullyQualifiedName) return null; } - //write the file we're assembling to disk - DiskWriter.replaceFile(javaFile.getAbsolutePath(), contents, false); - - //write the entire temporary classpath to disk - JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), classPath.getAbsolutePath()); - boolean cont = true; try { + //write the file we're assembling to disk + DiskWriter.write(javaFile.getAbsolutePath(), contents); + + //write the entire temporary classpath to disk + JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), classPath.getAbsolutePath()); + StringBuilder log = new StringBuilder(); ProcessBuilder pb; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/KrakatauAssembler.java b/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/KrakatauAssembler.java index 5474eb164..20a8a207f 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/KrakatauAssembler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/KrakatauAssembler.java @@ -18,7 +18,7 @@ package the.bytecode.club.bytecodeviewer.compilers.impl; -import me.konloch.kontainer.io.DiskWriter; +import com.konloch.disklib.DiskWriter; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.ArrayUtils; import the.bytecode.club.bytecodeviewer.BytecodeViewer; @@ -55,21 +55,20 @@ public byte[] compile(String contents, String fullyQualifiedName) final File tempDirectory2 = new File(Constants.TEMP_DIRECTORY + FS + MiscUtils.randomString(32) + FS); final File javaFile = new File(tempDirectory1.getAbsolutePath() + FS + fullyQualifiedName + ".j"); final File tempJar = new File(Constants.TEMP_DIRECTORY + FS + "temp" + MiscUtils.randomString(32) + ".jar"); + final StringBuilder log = new StringBuilder(); //create the temp directories tempDirectory1.mkdir(); tempDirectory2.mkdir(); - //write the file we're assembling to disk - DiskWriter.replaceFile(javaFile.getAbsolutePath(), contents, true); - - //write the entire temporary classpath to disk - JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), tempJar.getAbsolutePath()); - - StringBuilder log = new StringBuilder(); - try { + //write the file we're assembling to disk + DiskWriter.write(javaFile.getAbsolutePath(), contents); + + //write the entire temporary classpath to disk + JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), tempJar.getAbsolutePath()); + String[] pythonCommands = new String[]{Configuration.python2}; if (Configuration.python2Extra) pythonCommands = ArrayUtils.addAll(pythonCommands, "-2"); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/SmaliAssembler.java b/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/SmaliAssembler.java index 6fd5e0432..1aba6a460 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/SmaliAssembler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/SmaliAssembler.java @@ -18,7 +18,7 @@ package the.bytecode.club.bytecodeviewer.compilers.impl; -import me.konloch.kontainer.io.DiskWriter; +import com.konloch.disklib.DiskWriter; import org.apache.commons.io.FileUtils; import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.compilers.AbstractCompiler; @@ -59,7 +59,7 @@ public byte[] compile(String contents, String fullyQualifiedName) try { //write the file we're assembling to disk - DiskWriter.replaceFile(tempSmali.getAbsolutePath(), contents, false); + DiskWriter.write(tempSmali.getAbsolutePath(), contents); } catch (Exception e) { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/BlankDecompilerBase.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/BlankDecompilerBase.java index 30477d123..65e782f4d 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/BlankDecompilerBase.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/BlankDecompilerBase.java @@ -18,7 +18,7 @@ package the.bytecode.club.bytecodeviewer.decompilers.impl; -import me.konloch.kontainer.io.DiskReader; +import com.konloch.disklib.DiskReader; import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bytecodeviewer.Constants; import the.bytecode.club.bytecodeviewer.api.ExceptionUI; @@ -75,7 +75,7 @@ public String decompileClassNode(ClassNode cn, byte[] bytes) //if the output file is found, read it if (tempOutputJavaFile.exists()) - return DiskReader.loadAsString(tempOutputJavaFile.getAbsolutePath()); + return DiskReader.readString(tempOutputJavaFile.getAbsolutePath()); else exception = getDecompilerName() + " " + ERROR + "! " + tempOutputJavaFile.getAbsolutePath() + " does not exist."; } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/FernFlowerDecompiler.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/FernFlowerDecompiler.java index 2b8b63159..b16b9c95d 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/FernFlowerDecompiler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/FernFlowerDecompiler.java @@ -18,7 +18,7 @@ package the.bytecode.club.bytecodeviewer.decompilers.impl; -import me.konloch.kontainer.io.DiskReader; +import com.konloch.disklib.DiskReader; import org.apache.commons.lang3.ArrayUtils; import org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler; import org.objectweb.asm.tree.ClassNode; @@ -99,7 +99,7 @@ public String decompileClassNode(ClassNode cn, byte[] bytes) //if the output file is found, read it if (tempOutputJavaFile.exists() && !Constants.DEV_FLAG_DECOMPILERS_SIMULATED_ERRORS) - return DiskReader.loadAsString(tempOutputJavaFile.getAbsolutePath()); + return DiskReader.readString(tempOutputJavaFile.getAbsolutePath()); else exception = FERNFLOWER + " " + ERROR + "! " + tempOutputJavaFile.getAbsolutePath() + " does not exist."; } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/JADXDecompiler.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/JADXDecompiler.java index 12069f1d3..edc999eff 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/JADXDecompiler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/JADXDecompiler.java @@ -18,9 +18,9 @@ package the.bytecode.club.bytecodeviewer.decompilers.impl; +import com.konloch.disklib.DiskReader; import jadx.api.JadxArgs; import jadx.api.JadxDecompiler; -import me.konloch.kontainer.io.DiskReader; import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bytecodeviewer.Constants; import the.bytecode.club.bytecodeviewer.Settings; @@ -112,7 +112,7 @@ public String searchForJavaFile(File[] files) throws Exception return searchForJavaFile(MiscUtils.listFiles(file)); else if(file.getName().toLowerCase().endsWith(".java")) { - String contents = DiskReader.loadAsString(file.getAbsolutePath()); + String contents = DiskReader.readString(file.getAbsolutePath()); //cleanup if(Settings.DECOMPILERS_AUTOMATICALLY_CLEANUP) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/JDGUIDecompiler.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/JDGUIDecompiler.java index 95bd7ee84..4395bc91a 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/JDGUIDecompiler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/JDGUIDecompiler.java @@ -18,7 +18,7 @@ package the.bytecode.club.bytecodeviewer.decompilers.impl; -import me.konloch.kontainer.io.DiskReader; +import com.konloch.disklib.DiskReader; import org.jd.core.v1.ClassFileToJavaSourceDecompiler; import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bytecodeviewer.Constants; @@ -109,7 +109,7 @@ public boolean isMergeEmptyLines() throw new RuntimeException(DEV_MODE_SIMULATED_ERROR.toString()); //read the java file - return DiskReader.loadAsString(tempJavaFile.getAbsolutePath()); + return DiskReader.readString(tempJavaFile.getAbsolutePath()); } catch (Throwable e) { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/JavapDisassembler.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/JavapDisassembler.java index 1b68a445f..7aebd92ba 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/JavapDisassembler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/JavapDisassembler.java @@ -18,7 +18,7 @@ package the.bytecode.club.bytecodeviewer.decompilers.impl; -import me.konloch.kontainer.io.DiskWriter; +import com.konloch.disklib.DiskWriter; import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.Configuration; @@ -80,7 +80,7 @@ private synchronized String disassembleJavaP(ClassNode cn, byte[] bytes) File tempClassFile = tempFile.getFile(); //write the bytes to the class-file - DiskWriter.replaceFileBytes(tempClassFile.getAbsolutePath(), bytes, false); + DiskWriter.write(tempClassFile.getAbsolutePath(), bytes); //load java tools into a temporary classloader URLClassLoader child = new URLClassLoader(new URL[]{new File(Configuration.javaTools).toURI().toURL()}, this.getClass().getClassLoader()); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/KrakatauDecompiler.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/KrakatauDecompiler.java index 5a146d875..bf87a6a76 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/KrakatauDecompiler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/KrakatauDecompiler.java @@ -18,7 +18,7 @@ package the.bytecode.club.bytecodeviewer.decompilers.impl; -import me.konloch.kontainer.io.DiskReader; +import com.konloch.disklib.DiskReader; import org.apache.commons.lang3.ArrayUtils; import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bytecodeviewer.BytecodeViewer; @@ -142,7 +142,7 @@ public String decompileClassNode(ClassNode cn, byte[] bytes) throw new RuntimeException(DEV_MODE_SIMULATED_ERROR.toString()); // read the java file on a successful disassemble - return DiskReader.loadAsString(tempOutputJavaFile.getAbsolutePath()); + return DiskReader.readString(tempOutputJavaFile.getAbsolutePath()); } catch (Throwable e) { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/KrakatauDisassembler.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/KrakatauDisassembler.java index 3f3a64fbf..dc3085cc7 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/KrakatauDisassembler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/KrakatauDisassembler.java @@ -18,7 +18,7 @@ package the.bytecode.club.bytecodeviewer.decompilers.impl; -import me.konloch.kontainer.io.DiskReader; +import com.konloch.disklib.DiskReader; import org.apache.commons.lang3.ArrayUtils; import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bytecodeviewer.BytecodeViewer; @@ -111,7 +111,7 @@ public String decompileClassNode(ClassNode cn, byte[] bytes) throw new RuntimeException(DEV_MODE_SIMULATED_ERROR.toString()); // update the string on a successful disassemble - returnString = DiskReader.loadAsString(tempDirectory.getAbsolutePath() + FS + cn.name + ".j"); + returnString = DiskReader.readString(tempDirectory.getAbsolutePath() + FS + cn.name + ".j"); } catch (Exception e) { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/SmaliDisassembler.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/SmaliDisassembler.java index 030bee439..6a2d62a6b 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/SmaliDisassembler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/SmaliDisassembler.java @@ -19,7 +19,7 @@ package the.bytecode.club.bytecodeviewer.decompilers.impl; import com.googlecode.d2j.smali.BaksmaliCmd; -import me.konloch.kontainer.io.DiskReader; +import com.konloch.disklib.DiskReader; import org.apache.commons.io.FileUtils; import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bytecodeviewer.BytecodeViewer; @@ -115,7 +115,7 @@ public String decompileClassNode(ClassNode cn, byte[] bytes) } try { - return DiskReader.loadAsString(outputSmali.getAbsolutePath()); + return DiskReader.readString(outputSmali.getAbsolutePath()); } catch (Exception e) { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/JFrameConsole.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/JFrameConsole.java index 91d60fe58..88c938565 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/JFrameConsole.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/JFrameConsole.java @@ -18,12 +18,13 @@ package the.bytecode.club.bytecodeviewer.gui.components; -import me.konloch.kontainer.io.DiskWriter; +import com.konloch.disklib.DiskWriter; import the.bytecode.club.bytecodeviewer.resources.IconResources; import javax.swing.*; import java.awt.*; import java.io.File; +import java.io.IOException; import static the.bytecode.club.bytecodeviewer.Constants.TEMP_DIRECTORY; @@ -120,9 +121,9 @@ public void setContainerName(String containerName) /** * Trims the console text to prevent killing the swing thread */ - public String trimConsoleText(String s) + public String trimConsoleText(String text) { - int len = s.length(); + int len = text.length(); //TODO this should also be a setting eventually int max = 500_000; @@ -136,12 +137,19 @@ public String trimConsoleText(String s) new Thread(() -> { //save to disk - DiskWriter.replaceFile(tempFile.getAbsolutePath(), s, false); + try + { + DiskWriter.write(tempFile.getAbsolutePath(), text); + } + catch (IOException e) + { + e.printStackTrace(); + } }, "Console Log Saving").start(); //trim int skipped = len - max; - String trimmed = s.substring(0, max); + String trimmed = text.substring(0, max); if (!trimmed.startsWith("WARNING: Skipping")) trimmed = ("WARNING: Skipping " + skipped + " chars, allowing " + max + "\n\r") @@ -150,7 +158,7 @@ public String trimConsoleText(String s) return trimmed; } - return s; + return text; } private static final long serialVersionUID = -5056940543411437508L; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/ResourceListPane.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/ResourceListPane.java index 7bec79456..6944252d9 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/ResourceListPane.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/ResourceListPane.java @@ -18,7 +18,7 @@ package the.bytecode.club.bytecodeviewer.gui.resourcelist; -import me.konloch.kontainer.io.DiskWriter; +import com.konloch.disklib.DiskWriter; import org.apache.commons.io.FilenameUtils; import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.Configuration; @@ -382,10 +382,10 @@ else if (container.resourceFiles.containsKey(name)) File tempFile = new File(TEMP_DIRECTORY + FS + hash + FS + name + "." + extension); if (!tempFile.exists()) { - DiskWriter.replaceFileBytes(tempFile.getAbsolutePath(), content, false); - try { + DiskWriter.write(tempFile.getAbsolutePath(), content); + imp.getImporter().open(tempFile); } catch (Exception e) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/PluginWriter.java b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/PluginWriter.java index 3eab06b04..4d70a8c9d 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/PluginWriter.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/PluginWriter.java @@ -19,10 +19,8 @@ package the.bytecode.club.bytecodeviewer.plugin; import com.google.common.io.Files; -import com.konloch.taskmanager.Task; -import com.konloch.taskmanager.TaskRunnable; -import me.konloch.kontainer.io.DiskReader; -import me.konloch.kontainer.io.DiskWriter; +import com.konloch.disklib.DiskReader; +import com.konloch.disklib.DiskWriter; import org.apache.commons.compress.utils.FileNameUtils; import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.Configuration; @@ -188,7 +186,7 @@ public void openPlugin() try { - area.setText(DiskReader.loadAsString(file.getAbsolutePath())); + area.setText(DiskReader.readString(file.getAbsolutePath())); area.setCaretPosition(0); } catch (Exception e) @@ -269,7 +267,15 @@ public void save() } } - DiskWriter.replaceFile(savePath.getAbsolutePath(), area.getText(), false); + try + { + DiskWriter.write(savePath.getAbsolutePath(), area.getText()); + } + catch (IOException e) + { + e.printStackTrace(); + } + addRecentPlugin(savePath); }, "Plugin Editor Save"); @@ -306,7 +312,7 @@ public synchronized void updateUIFromDiskChanges(File tempFile) else { //update content from latest disk data - content = DiskReader.loadAsString(savePath.getAbsolutePath()); + content = DiskReader.readString(savePath.getAbsolutePath()); //update plugin writer UI on disk update SwingUtilities.invokeLater(() -> diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceDecompiling.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceDecompiling.java index 29c28f646..229aee5e9 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceDecompiling.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceDecompiling.java @@ -18,7 +18,7 @@ package the.bytecode.club.bytecodeviewer.resources; -import me.konloch.kontainer.io.DiskWriter; +import com.konloch.disklib.DiskWriter; import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.Configuration; import the.bytecode.club.bytecodeviewer.api.BCV; @@ -31,6 +31,7 @@ import javax.swing.*; import java.io.File; +import java.io.IOException; import static the.bytecode.club.bytecodeviewer.Constants.FS; import static the.bytecode.club.bytecodeviewer.Constants.TEMP_DIRECTORY; @@ -264,14 +265,14 @@ public static void decompileSaveAll(Decompiler decompiler, File targetJar, File BytecodeViewer.updateBusyStatus(false); } - public static void decompileCurrentlyOpenedResource(Decompiler decompiler, File outputFile, boolean saveAll) + public static void decompileCurrentlyOpenedResource(Decompiler decompiler, File outputFile, boolean saveAll) throws IOException { //signal to the user that BCV is performing an action in the background BytecodeViewer.updateBusyStatus(true); //decompile the currently opened resource and save it to the specified file - DiskWriter.replaceFile(saveAll ? MiscUtils.append(outputFile, - "-" + decompiler.getDecompilerNameProgrammatic() + ".java") : outputFile.getAbsolutePath(), BCV.decompileCurrentlyOpenedClassNode(decompiler), false); + DiskWriter.write(saveAll ? MiscUtils.append(outputFile, + "-" + decompiler.getDecompilerNameProgrammatic() + ".java") : outputFile.getAbsolutePath(), BCV.decompileCurrentlyOpenedClassNode(decompiler)); //signal to the user that BCV is finished performing that action BytecodeViewer.updateBusyStatus(false); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/XAPKResourceImporter.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/XAPKResourceImporter.java index c5de84a22..7ebec8438 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/XAPKResourceImporter.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/XAPKResourceImporter.java @@ -18,7 +18,7 @@ package the.bytecode.club.bytecodeviewer.resources.importing.impl; -import me.konloch.kontainer.io.DiskWriter; +import com.konloch.disklib.DiskWriter; import org.apache.commons.io.IOUtils; import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.Configuration; @@ -27,10 +27,7 @@ import the.bytecode.club.bytecodeviewer.resources.importing.Importer; import the.bytecode.club.bytecodeviewer.util.MiscUtils; -import java.io.File; -import java.io.FileOutputStream; -import java.io.InputStream; -import java.io.OutputStream; +import java.io.*; import java.util.Enumeration; import java.util.LinkedHashMap; import java.util.Map; @@ -96,10 +93,10 @@ public void open(File file) throws Exception BytecodeViewer.addResourceContainer(container); //add the resource container to BCV's total loaded files } - public File exportTo(File original, String extension, byte[] bytes) + public File exportTo(File original, String extension, byte[] bytes) throws IOException { File file = new File(original.getAbsolutePath() + extension); - DiskWriter.replaceFileBytes(file.getAbsolutePath(), bytes, false); + DiskWriter.write(file.getAbsolutePath(), bytes); return file; } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/JarUtils.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/JarUtils.java index 33efba1f7..ac1018832 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/JarUtils.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/JarUtils.java @@ -18,7 +18,7 @@ package the.bytecode.club.bytecodeviewer.util; -import me.konloch.kontainer.io.DiskWriter; +import com.konloch.disklib.DiskWriter; import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; import org.apache.commons.compress.archivers.zip.ZipFile; import org.apache.commons.io.FilenameUtils; @@ -390,7 +390,7 @@ public static void saveAsJarClassesOnlyToDir(List nodeList, String di File f = new File(name); f.mkdirs(); - DiskWriter.replaceFileBytes(name, cw.toByteArray(), false); + DiskWriter.write(name, cw.toByteArray()); } } catch (Exception e)