Skip to content

Commit

Permalink
Replaced Old Disk-Lib Library
Browse files Browse the repository at this point in the history
  • Loading branch information
Konloch committed Oct 5, 2024
1 parent 17d9736 commit 1494eca
Show file tree
Hide file tree
Showing 21 changed files with 144 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
46 changes: 36 additions & 10 deletions src/main/java/the/bytecode/club/bytecodeviewer/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -52,14 +54,14 @@ public class Settings
try
{
if (new File(FILES_NAME).exists())
recentFiles = gson.fromJson(DiskReader.loadAsString(FILES_NAME), new TypeToken<ArrayList<String>>() {}.getType());
recentFiles = gson.fromJson(DiskReader.readString(FILES_NAME), new TypeToken<ArrayList<String>>() {}.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<ArrayList<String>>() {}.getType());
recentPlugins = gson.fromJson(DiskReader.readString(PLUGINS_NAME), new TypeToken<ArrayList<String>>() {}.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);
Expand All @@ -80,19 +82,31 @@ 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();
}

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())
Expand All @@ -111,19 +125,31 @@ 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();
}

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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@

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;
import the.bytecode.club.bytecodeviewer.translation.Language;

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;
Expand All @@ -40,6 +41,7 @@
public class SettingsSerializer
{
private static boolean settingsFileExists;
private static String[] settings;

public static void saveSettingsAsync()
{
Expand All @@ -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());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down
Loading

0 comments on commit 1494eca

Please sign in to comment.