This commit is contained in:
Konloch 2015-07-21 01:04:31 -06:00
parent 25df7fa362
commit 89bad45283
14 changed files with 200 additions and 343 deletions

Binary file not shown.

View file

@ -10,11 +10,17 @@ import java.util.List;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import org.apache.commons.io.FileUtils;
import me.konloch.kontainer.io.HTTPRequest; import me.konloch.kontainer.io.HTTPRequest;
import the.bytecode.club.bootloader.resource.EmptyExternalResource; import the.bytecode.club.bootloader.resource.EmptyExternalResource;
import the.bytecode.club.bootloader.resource.ExternalResource; import the.bytecode.club.bootloader.resource.ExternalResource;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.CommandLineInput;
import the.bytecode.club.bytecodeviewer.ZipUtils;
/** /**
* @author Konloch
* @author Bibl (don't ban me pls) * @author Bibl (don't ban me pls)
* @created 19 Jul 2015 03:22:37 * @created 19 Jul 2015 03:22:37
*/ */
@ -22,28 +28,44 @@ public class Boot {
private static InitialBootScreen screen; private static InitialBootScreen screen;
public static void main(String[] args) throws Exception { public static void boot(String[] args, int CLI) throws Exception {
if(CLI == CommandLineInput.STOP)
return;
bootstrap(); bootstrap();
ILoader<?> loader = findLoader(); ILoader<?> loader = findLoader();
screen = new InitialBootScreen(); screen = new InitialBootScreen();
if(CLI == CommandLineInput.OPEN_FILE)
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override @Override
public void run() { public void run() {
screen.setVisible(true); screen.setVisible(true);
} }
}); });
create(loader, args.length > 0 ? Boolean.valueOf(args[0]) : true); create(loader, args.length > 0 ? Boolean.valueOf(args[0]) : true);
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override @Override
public void run() { public void run() {
screen.setVisible(false); screen.setVisible(false);
} }
}); });
Class<?> klass = loader.loadClass("the.bytecode.club.bytecodeviewer.BytecodeViewer");
klass.getDeclaredMethod("main", new Class<?>[] { String[].class }).invoke(null, new Object[] { args }); /*Class<?> klass = loader.loadClass("the.bytecode.club.bytecodeviewer.BytecodeViewer");
klass.getDeclaredMethod("BOOT", new Class<?>[] { String[].class }).invoke(null, new Object[] { args });*/
if(CLI == CommandLineInput.OPEN_FILE)
BytecodeViewer.BOOT(args, false);
else {
BytecodeViewer.BOOT(args, true);
CommandLineInput.executeCommandLine(args);
}
} }
@SuppressWarnings({ "rawtypes", "unchecked" })
private static void create(ILoader<?> loader, boolean clean) throws Exception { private static void create(ILoader<?> loader, boolean clean) throws Exception {
setState("Bytecode Viewer Boot Screen - Checking Libraries..."); setState("Bytecode Viewer Boot Screen - Checking Libraries...");
@ -178,6 +200,88 @@ public class Boot {
} }
} }
setState("Bytecode Viewer Boot Screen - Checking Krakatau...");
System.out.println("Checking krakatau");
File krakatauZip = null;
for(File f : new File(BytecodeViewer.libsDirectory).listFiles()) {
if(f.getName().toLowerCase().startsWith("krakatau-")) {
BytecodeViewer.krakatauVersion = f.getName().split("-")[1].split("\\.")[0];
krakatauZip = f;
}
}
for(File f : new File(BytecodeViewer.getBCVDirectory()).listFiles()) {
if(f.getName().toLowerCase().startsWith("krakatau_") && !f.getName().split("_")[1].split("\\.")[0].equals(BytecodeViewer.krakatauVersion)) {
setState("Bytecode Viewer Boot Screen - Removing Outdated " + f.getName() + "...");
System.out.println("Removing oudated " + f.getName());
try {
FileUtils.deleteDirectory(f);
} catch (Exception e) {
e.printStackTrace();
}
}
}
BytecodeViewer.krakatauWorkingDirectory = BytecodeViewer.getBCVDirectory() + BytecodeViewer.fs + "krakatau_" + BytecodeViewer.krakatauVersion + BytecodeViewer.fs + "Krakatau-master";
File krakatauDirectory = new File(BytecodeViewer.getBCVDirectory() + BytecodeViewer.fs + "krakatau_" + BytecodeViewer.krakatauVersion);
if(!krakatauDirectory.exists()) {
try {
setState("Bytecode Viewer Boot Screen - Updating to "+krakatauDirectory.getName()+"...");
ZipUtils.unzipFilesToPath(krakatauZip.getAbsolutePath(), krakatauDirectory.getAbsolutePath());
System.out.println("Updated to krakatau v" + BytecodeViewer.krakatauVersion);
} catch(Exception e) {
BytecodeViewer.showMessage("ERROR: There was an issue unzipping Krakatau decompiler (possibly corrupt). Restart BCV."+BytecodeViewer.nl+
"If the error persists contact @Konloch.");
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
krakatauZip.delete();
}
}
completedCheck++;
screen.getProgressBar().setValue(completedCheck);
setState("Bytecode Viewer Boot Screen - Checking Enjarify...");
System.out.println("Checking enjarify");
File enjarifyZip = null;
for(File f : new File(BytecodeViewer.libsDirectory).listFiles()) {
if(f.getName().toLowerCase().startsWith("enjarify-")) {
BytecodeViewer.enjarifyVersion = f.getName().split("-")[1].split("\\.")[0];
enjarifyZip = f;
}
}
for(File f : new File(BytecodeViewer.getBCVDirectory()).listFiles()) {
if(f.getName().toLowerCase().startsWith("enjarify_") && !f.getName().split("_")[1].split("\\.")[0].equals(BytecodeViewer.enjarifyVersion)) {
setState("Bytecode Viewer Boot Screen - Removing Outdated " + f.getName() + "...");
System.out.println("Removing oudated " + f.getName());
try {
FileUtils.deleteDirectory(f);
} catch (Exception e) {
e.printStackTrace();
}
}
}
BytecodeViewer.enjarifyWorkingDirectory = BytecodeViewer.getBCVDirectory() + BytecodeViewer.fs + "enjarify_" + BytecodeViewer.enjarifyVersion + BytecodeViewer.fs + "enjarify-master";
File enjarifyDirectory = new File(BytecodeViewer.getBCVDirectory() + BytecodeViewer.fs + "enjarify_" + BytecodeViewer.enjarifyVersion);
if(!enjarifyDirectory.exists()) {
try {
setState("Bytecode Viewer Boot Screen - Updating to "+enjarifyDirectory.getName()+"...");
ZipUtils.unzipFilesToPath(enjarifyZip.getAbsolutePath(), enjarifyDirectory.getAbsolutePath());
System.out.println("Updated to enjarify v" + BytecodeViewer.enjarifyVersion);
} catch(Exception e) {
BytecodeViewer.showMessage("ERROR: There was an issue unzipping enjarify (possibly corrupt). Restart BCV."+BytecodeViewer.nl+
"If the error persists contact @Konloch.");
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
enjarifyZip.delete();
}
}
completedCheck++;
screen.getProgressBar().setValue(completedCheck);
setState("Bytecode Viewer Boot Screen - Booting!"); setState("Bytecode Viewer Boot Screen - Booting!");
} }

View file

@ -16,6 +16,7 @@ import javax.swing.text.html.HTMLEditorKit;
import the.bytecode.club.bytecodeviewer.Resources; import the.bytecode.club.bytecodeviewer.Resources;
/** /**
* @author Konloch
* @author Bibl (don't ban me pls) * @author Bibl (don't ban me pls)
* @created 19 Jul 2015 04:12:21 * @created 19 Jul 2015 04:12:21
*/ */

View file

@ -79,7 +79,6 @@ public class LibraryClassLoader extends ClassLoader implements ILoader<JarConten
return super.loadClass(name); return super.loadClass(name);
} }
@SuppressWarnings("deprecation")
protected Class<?> define(ClassNode cn) { protected Class<?> define(ClassNode cn) {
ClassWriter writer = new ResolvingClassWriter(tree); ClassWriter writer = new ResolvingClassWriter(tree);
cn.accept(cn); cn.accept(cn);

View file

@ -1,212 +0,0 @@
package the.bytecode.club.bytecodeviewer;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Toolkit;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import javax.swing.text.html.HTMLEditorKit;
import org.apache.commons.io.FileUtils;
/**
* Automatic updater for BCV libraries
*
* @author Konloch
*
*/
public class BootScreen extends JFrame {
private static final long serialVersionUID = -1098467609722393444L;
private static boolean FIRST_BOOT = false;
private JProgressBar progressBar = new JProgressBar();
public BootScreen() throws IOException {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setIconImages(Resources.iconList);
int i = (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight();
if(i >= 840)
setSize(new Dimension(600, 800));
else if(i >= 640)
setSize(new Dimension(500, 600));
else if(i >= 440)
setSize(new Dimension(400, 400));
else
setSize(Toolkit.getDefaultToolkit().getScreenSize());
setTitle("Bytecode Viewer Boot Screen - Starting Up");
GridBagLayout gridBagLayout = new GridBagLayout();
gridBagLayout.columnWidths = new int[]{0, 0};
gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
gridBagLayout.columnWeights = new double[]{1.0, Double.MIN_VALUE};
gridBagLayout.rowWeights = new double[]{1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
getContentPane().setLayout(gridBagLayout);
JScrollPane scrollPane = new JScrollPane();
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
gbc_scrollPane.gridheight = 24;
gbc_scrollPane.insets = new Insets(0, 0, 5, 0);
gbc_scrollPane.fill = GridBagConstraints.BOTH;
gbc_scrollPane.gridx = 0;
gbc_scrollPane.gridy = 0;
getContentPane().add(scrollPane, gbc_scrollPane);
JEditorPane editorPane = new JEditorPane();
editorPane.setEditorKit(new HTMLEditorKit());
editorPane.setText(convertStreamToString(BytecodeViewer.class.getClassLoader().getResourceAsStream("resources/intro.html")));
scrollPane.setViewportView(editorPane);
GridBagConstraints gbc_progressBar = new GridBagConstraints();
gbc_progressBar.fill = GridBagConstraints.HORIZONTAL;
gbc_progressBar.gridx = 0;
gbc_progressBar.gridy = 24;
getContentPane().add(progressBar, gbc_progressBar);
this.setLocationRelativeTo(null);
}
static String convertStreamToString(java.io.InputStream is) throws IOException {
@SuppressWarnings("resource")
java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
String string = s.hasNext() ? s.next() : "";
is.close();
s.close();
return string;
}
public void DO_FIRST_BOOT(String args[], int CLI) {
if(CLI == -1)
return;
if(CLI == 1)
this.setVisible(true);
if(FIRST_BOOT)
return;
FIRST_BOOT = true;
setTitle("Bytecode Viewer Boot Screen - Checking Libraries...");
System.out.println("Checking Libraries...");
try {
int completedCheck = 0;
setTitle("Bytecode Viewer Boot Screen - Checking Krakatau...");
System.out.println("Checking krakatau");
File krakatauZip = null;
for(File f : new File(BytecodeViewer.libsDirectory).listFiles()) {
if(f.getName().toLowerCase().startsWith("krakatau-")) {
BytecodeViewer.krakatauVersion = f.getName().split("-")[1].split("\\.")[0];
krakatauZip = f;
}
}
for(File f : new File(BytecodeViewer.getBCVDirectory()).listFiles()) {
if(f.getName().toLowerCase().startsWith("krakatau_") && !f.getName().split("_")[1].split("\\.")[0].equals(BytecodeViewer.krakatauVersion)) {
setTitle("Bytecode Viewer Boot Screen - Removing Outdated " + f.getName() + "...");
System.out.println("Removing oudated " + f.getName());
try {
FileUtils.deleteDirectory(f);
} catch (IOException e) {
e.printStackTrace();
}
}
}
BytecodeViewer.krakatauWorkingDirectory = BytecodeViewer.getBCVDirectory() + BytecodeViewer.fs + "krakatau_" + BytecodeViewer.krakatauVersion + BytecodeViewer.fs + "Krakatau-master";
File krakatauDirectory = new File(BytecodeViewer.getBCVDirectory() + BytecodeViewer.fs + "krakatau_" + BytecodeViewer.krakatauVersion);
if(!krakatauDirectory.exists()) {
try {
setTitle("Bytecode Viewer Boot Screen - Updating to "+krakatauDirectory.getName()+"...");
ZipUtils.unzipFilesToPath(krakatauZip.getAbsolutePath(), krakatauDirectory.getAbsolutePath());
System.out.println("Updated to krakatau v" + BytecodeViewer.krakatauVersion);
} catch(Exception e) {
BytecodeViewer.showMessage("ERROR: There was an issue unzipping Krakatau decompiler (possibly corrupt). Restart BCV."+BytecodeViewer.nl+
"If the error persists contact @Konloch.");
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
krakatauZip.delete();
}
}
completedCheck++;
progressBar.setValue(completedCheck);
setTitle("Bytecode Viewer Boot Screen - Checking Enjarify...");
System.out.println("Checking enjarify");
File enjarifyZip = null;
for(File f : new File(BytecodeViewer.libsDirectory).listFiles()) {
if(f.getName().toLowerCase().startsWith("enjarify-")) {
BytecodeViewer.enjarifyVersion = f.getName().split("-")[1].split("\\.")[0];
enjarifyZip = f;
}
}
for(File f : new File(BytecodeViewer.getBCVDirectory()).listFiles()) {
if(f.getName().toLowerCase().startsWith("enjarify_") && !f.getName().split("_")[1].split("\\.")[0].equals(BytecodeViewer.enjarifyVersion)) {
setTitle("Bytecode Viewer Boot Screen - Removing Outdated " + f.getName() + "...");
System.out.println("Removing oudated " + f.getName());
try {
FileUtils.deleteDirectory(f);
} catch (IOException e) {
e.printStackTrace();
}
}
}
BytecodeViewer.enjarifyWorkingDirectory = BytecodeViewer.getBCVDirectory() + BytecodeViewer.fs + "enjarify_" + BytecodeViewer.enjarifyVersion + BytecodeViewer.fs + "enjarify-master";
File enjarifyDirectory = new File(BytecodeViewer.getBCVDirectory() + BytecodeViewer.fs + "enjarify_" + BytecodeViewer.enjarifyVersion);
if(!enjarifyDirectory.exists()) {
try {
setTitle("Bytecode Viewer Boot Screen - Updating to "+enjarifyDirectory.getName()+"...");
ZipUtils.unzipFilesToPath(enjarifyZip.getAbsolutePath(), enjarifyDirectory.getAbsolutePath());
System.out.println("Updated to enjarify v" + BytecodeViewer.enjarifyVersion);
} catch(Exception e) {
BytecodeViewer.showMessage("ERROR: There was an issue unzipping enjarify (possibly corrupt). Restart BCV."+BytecodeViewer.nl+
"If the error persists contact @Konloch.");
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
enjarifyZip.delete();
}
}
completedCheck++;
progressBar.setValue(completedCheck);
setTitle("Bytecode Viewer Boot Screen - Booting!");
} catch(Exception e) {
Settings.saveGUI();
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
e.printStackTrace();
new the.bytecode.club.bytecodeviewer.api.ExceptionUI("Bytecode Viewer ran into an error while booting, trying to force it anyways."+ BytecodeViewer.nl+ BytecodeViewer.nl+
"Please ensure you have an active internet connection and restart BCV. If this presists please visit http://github.com/Konloch/Bytecode-Viewer or http://bytecodeviewer.com"+ BytecodeViewer.nl + BytecodeViewer.nl + sw.toString());
}
setTitle("Bytecode Viewer Boot Screen - Finished");
if(CLI == 1)
BytecodeViewer.BOOT(args, false);
else {
BytecodeViewer.BOOT(args, true);
CommandLineInput.executeCommandLine(args);
}
this.setVisible(false);
}
}

View file

@ -31,6 +31,7 @@ import me.konloch.kontainer.io.HTTPRequest;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.ClassNode;
import the.bytecode.club.bootloader.Boot;
import the.bytecode.club.bytecodeviewer.api.ClassNodeLoader; import the.bytecode.club.bytecodeviewer.api.ClassNodeLoader;
import the.bytecode.club.bytecodeviewer.gui.ClassViewer; import the.bytecode.club.bytecodeviewer.gui.ClassViewer;
import the.bytecode.club.bytecodeviewer.gui.FileNavigationPane; import the.bytecode.club.bytecodeviewer.gui.FileNavigationPane;
@ -90,23 +91,11 @@ import the.bytecode.club.bytecodeviewer.plugin.PluginManager;
* fix hook inject for EZ-Injection * fix hook inject for EZ-Injection
* fix classfile searcher * fix classfile searcher
* *
* -----2.9.7-----: * -----2.9.8-----:
* 07/02/2015 - Added ajustable font size. * 07/19/2015 - Fixed enjarify.
* 07/05/2015 - Started working on the new Boot Screen. * 07/20/2015 - Bibl sexified the boot loading time.
* 07/06/2015 - Moved the font size to be under the view menu. * 07/20/2015 - Decode APK Resources is selected by default.
* 07/06/2015 - Fixed a bug with plugins not being able to grab the currently viewed class. * 07/20/2015 - Made the security manager slightly safer, can still be targeted but not as obvious now.
* 07/07/2015 - Started adding enjarify as an optional APK converter instead of Dex2Jar.
* 07/07/2015 - Finished the new Boot Screen
* 07/09/2015 - Fixed a process leak with krakatau decompiler.
* 07/09/2015 - Finished adding enjarify.
* 07/09/2015 - Supressed syntax exceptions due to JD-GUI.
* 07/09/2015 - Fixed refresh on non-refreshable resources.
* 07/09/2015 - Fixed opening a class and the name is so big, you cannot close because the [X] does not appear.
* 07/09/2015 - Added support for smaller screens for the boot screen.
* 07/16/2015 - Removed the FileFilter classes.
* 07/16/2015 - Updated the decompiler class to make more sense.
* 07/16/2015 - Started working on BCV CLI.
* 07/16/2015 - Finished BCV CLI.
* *
* @author Konloch * @author Konloch
* *
@ -115,8 +104,8 @@ import the.bytecode.club.bytecodeviewer.plugin.PluginManager;
public class BytecodeViewer { public class BytecodeViewer {
/*per version*/ /*per version*/
public static String version = "2.9.7"; public static String version = "2.9.8";
public static boolean previewCopy = false; public static boolean previewCopy = true;
/*the rest*/ /*the rest*/
public static MainViewerGUI viewer = null; public static MainViewerGUI viewer = null;
public static ClassNodeLoader loader = new ClassNodeLoader(); //might be insecure due to assholes targeting BCV, however that's highly unlikely. public static ClassNodeLoader loader = new ClassNodeLoader(); //might be insecure due to assholes targeting BCV, however that's highly unlikely.
@ -388,7 +377,9 @@ public class BytecodeViewer {
viewer = new MainViewerGUI(); viewer = new MainViewerGUI();
Settings.loadGUI(); Settings.loadGUI();
new BootScreen().DO_FIRST_BOOT(args, CommandLineInput.parseCommandLine(args));
Boot.boot(args, CommandLineInput.parseCommandLine(args));
//new BootScreen().DO_FIRST_BOOT(args, CommandLineInput.parseCommandLine(args));
} catch (Exception e) { } catch (Exception e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e); new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
} }
@ -926,14 +917,14 @@ public class BytecodeViewer {
* @param f file you want hidden * @param f file you want hidden
*/ */
private static void hideFile(File f) { private static void hideFile(File f) {
sm.blocking = false; sm.stopBlocking();
try { try {
// Hide file by running attrib system command (on Windows) // Hide file by running attrib system command (on Windows)
Runtime.getRuntime().exec("attrib +H " + f.getAbsolutePath()); Runtime.getRuntime().exec("attrib +H " + f.getAbsolutePath());
} catch (Exception e) { } catch (Exception e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e); new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
} }
sm.blocking = true; sm.setBlocking();
} }
/** /**

View file

@ -27,6 +27,11 @@ public class CommandLineInput {
private static final Options options = new Options(); private static final Options options = new Options();
private static final CommandLineParser parser = new DefaultParser(); private static final CommandLineParser parser = new DefaultParser();
/*BECAUSE WHO DOESN'T LOVE MAGIC NUMBERS*/
public static int STOP = -1;
public static int OPEN_FILE = 0;
public static int CLI = 1;
static { static {
options.addOption("help", false, "prints the help menu."); options.addOption("help", false, "prints the help menu.");
options.addOption("list", false, "lists all the available decompilers for BCV " + BytecodeViewer.version+"."); options.addOption("list", false, "lists all the available decompilers for BCV " + BytecodeViewer.version+".");
@ -63,7 +68,7 @@ public class CommandLineInput {
public static int parseCommandLine(String[] args) { public static int parseCommandLine(String[] args) {
if(!containsCommand(args)) if(!containsCommand(args))
return 1; return OPEN_FILE;
try { try {
CommandLine cmd = parser.parse(options, args); CommandLine cmd = parser.parse(options, args);
if(cmd.hasOption("list")) { if(cmd.hasOption("list")) {
@ -74,7 +79,7 @@ public class CommandLineInput {
System.out.println("Krakatau-Bytecode"); System.out.println("Krakatau-Bytecode");
System.out.println("JD-GUI"); System.out.println("JD-GUI");
System.out.println("Smali"); System.out.println("Smali");
return -1; return STOP;
} else if(cmd.hasOption("help")) { } else if(cmd.hasOption("help")) {
for(String s : new String[] { for(String s : new String[] {
"-help Displays the help menu", "-help Displays the help menu",
@ -86,17 +91,17 @@ public class CommandLineInput {
"-nowait Doesn't wait for the user to read the CLI messages" "-nowait Doesn't wait for the user to read the CLI messages"
}) })
System.out.println(s); System.out.println(s);
return -1; return STOP;
} else { } else {
if(cmd.getOptionValue("i") == null) { if(cmd.getOptionValue("i") == null) {
System.err.println("Set the input with -i"); System.err.println("Set the input with -i");
return -1; return STOP;
} if(cmd.getOptionValue("o") == null) { } if(cmd.getOptionValue("o") == null) {
System.err.println("Set the output with -o"); System.err.println("Set the output with -o");
return -1; return STOP;
} if(cmd.getOptionValue("t") == null) { } if(cmd.getOptionValue("t") == null) {
System.err.println("Set the target with -t"); System.err.println("Set the target with -t");
return -1; return STOP;
} }
File input = new File(cmd.getOptionValue("i")); File input = new File(cmd.getOptionValue("i"));
@ -105,7 +110,7 @@ public class CommandLineInput {
if(!input.exists()) { if(!input.exists()) {
System.err.println(input.getAbsolutePath() + " does not exist."); System.err.println(input.getAbsolutePath() + " does not exist.");
return -1; return STOP;
} }
if(output.exists()) { if(output.exists()) {
@ -134,13 +139,13 @@ public class CommandLineInput {
if(!cmd.hasOption("nowait")) if(!cmd.hasOption("nowait"))
Thread.sleep(5 * 1000); Thread.sleep(5 * 1000);
return 0; return CLI;
} }
} catch(Exception e) { } catch(Exception e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e); new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
} }
return 1; return OPEN_FILE;
} }
public static void executeCommandLine(String[] args) { public static void executeCommandLine(String[] args) {

View file

@ -25,7 +25,7 @@ public class Enjarify {
BytecodeViewer.viewer.pythonC3(); BytecodeViewer.viewer.pythonC3();
} }
BytecodeViewer.sm.blocking = false; BytecodeViewer.sm.stopBlocking();
try { try {
ProcessBuilder pb = new ProcessBuilder( ProcessBuilder pb = new ProcessBuilder(
BytecodeViewer.python3, BytecodeViewer.python3,
@ -67,62 +67,6 @@ public class Enjarify {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e); new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
} }
BytecodeViewer.sm.blocking = true; BytecodeViewer.sm.setBlocking();
}
/**
* Converts a .jar to .dex
* @param input the input .jar file
* @param output the output .dex file
*/
public static synchronized void saveAsAPK(File input, File output) {
if(BytecodeViewer.python3.equals("")) {
BytecodeViewer.showMessage("You need to set your Python (or PyPy for speed) 3.x executable path.");
BytecodeViewer.viewer.pythonC3();
}
BytecodeViewer.sm.blocking = false;
try {
ProcessBuilder pb = new ProcessBuilder(
BytecodeViewer.python3,
"-O",
"-m",
"enjarify.main",
input.getAbsolutePath(),
"-o",
output.getAbsolutePath()
);
pb.directory(new File(BytecodeViewer.enjarifyWorkingDirectory));
Process process = pb.start();
BytecodeViewer.createdProcesses.add(process);
//Read out dir output
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
br.close();
is = process.getErrorStream();
isr = new InputStreamReader(is);
br = new BufferedReader(isr);
while ((line = br.readLine()) != null) {
System.out.println(line);
}
br.close();
int exitValue = process.waitFor();
System.out.println("Exit Value is " + exitValue);
} catch(Exception e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
}
BytecodeViewer.sm.blocking = true;
} }
} }

View file

@ -13,15 +13,45 @@ import java.security.Permission;
public class SecurityMan extends SecurityManager { public class SecurityMan extends SecurityManager {
public boolean blocking = true; //might be insecure due to assholes targeting BCV, however that's highly unlikely. public void setBlocking() {
blocking = true;
}
public void stopBlocking() { //slightly safer security system than just a public static boolean being toggled
String executedClass = Thread.currentThread().getStackTrace()[2].getClassName();
if( executedClass.equals("the.bytecode.club.bytecodeviewer.decompilers.KrakatauDecompiler") ||
executedClass.equals("the.bytecode.club.bytecodeviewer.decompilers.KrakatauDisassambler") ||
executedClass.equals("the.bytecode.club.bytecodeviewer.compilers.KrakatauAssembler") ||
executedClass.equals("the.bytecode.club.bytecodeviewer.BytecodeViewer"))
{
blocking = false;
} else for(StackTraceElement stackTraceElements : Thread.currentThread().getStackTrace()) {
System.out.println(stackTraceElements.getClassName());
}
}
private boolean blocking = true; //might be insecure due to assholes targeting BCV, however that's highly unlikely.
@Override @Override
public void checkExec(String cmd) { public void checkExec(String cmd) {
if(blocking) String[] whitelist = {
throw new SecurityException("BCV is awesome."); "attrib",
"python",
"pypy"
};
boolean allow = false;
for(String s : whitelist) {
if(cmd.contains(s))
allow = true;
}
if(allow && !blocking) {
System.out.println("Allowing exec:" + cmd);
} else throw new SecurityException("BCV is awesome.");
} }
@Override @Override
public void checkListen(int port) { public void checkListen(int port) {
if(blocking)
throw new SecurityException("BCV is awesome."); throw new SecurityException("BCV is awesome.");
} }
@Override @Override

View file

@ -41,7 +41,7 @@ public class KrakatauAssembler extends Compiler {
final File tempJar = new File(BytecodeViewer.tempDirectory + BytecodeViewer.fs + "temp"+MiscUtils.randomString(32)+".jar"); final File tempJar = new File(BytecodeViewer.tempDirectory + BytecodeViewer.fs + "temp"+MiscUtils.randomString(32)+".jar");
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), tempJar.getAbsolutePath()); JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), tempJar.getAbsolutePath());
BytecodeViewer.sm.blocking = false; BytecodeViewer.sm.stopBlocking();
String log = ""; String log = "";
try { try {
ProcessBuilder pb = new ProcessBuilder( ProcessBuilder pb = new ProcessBuilder(
@ -86,10 +86,10 @@ public class KrakatauAssembler extends Compiler {
} catch(Exception e) { } catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(log); new the.bytecode.club.bytecodeviewer.api.ExceptionUI(log);
} finally {
BytecodeViewer.sm.setBlocking();
} }
BytecodeViewer.sm.blocking = true;
return null; return null;
} }

View file

@ -49,7 +49,7 @@ public class KrakatauDecompiler extends Decompiler {
final File tempJar = new File(BytecodeViewer.tempDirectory + BytecodeViewer.fs + "temp"+MiscUtils.randomString(32)+".jar"); final File tempJar = new File(BytecodeViewer.tempDirectory + BytecodeViewer.fs + "temp"+MiscUtils.randomString(32)+".jar");
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), tempJar.getAbsolutePath()); JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), tempJar.getAbsolutePath());
BytecodeViewer.sm.blocking = false; BytecodeViewer.sm.stopBlocking();
try { try {
ProcessBuilder pb = new ProcessBuilder( ProcessBuilder pb = new ProcessBuilder(
BytecodeViewer.python, BytecodeViewer.python,
@ -100,10 +100,10 @@ public class KrakatauDecompiler extends Decompiler {
e.printStackTrace(new PrintWriter(sw)); e.printStackTrace(new PrintWriter(sw));
e.printStackTrace(); e.printStackTrace();
s += BytecodeViewer.nl+"Bytecode Viewer Version: " + BytecodeViewer.version + BytecodeViewer.nl + BytecodeViewer.nl + sw.toString(); s += BytecodeViewer.nl+"Bytecode Viewer Version: " + BytecodeViewer.version + BytecodeViewer.nl + BytecodeViewer.nl + sw.toString();
} finally {
BytecodeViewer.sm.setBlocking();
} }
BytecodeViewer.sm.blocking = true;
return s; return s;
} }
@ -123,7 +123,7 @@ public class KrakatauDecompiler extends Decompiler {
final File tempJar = new File(BytecodeViewer.tempDirectory + BytecodeViewer.fs + "temp.jar"); final File tempJar = new File(BytecodeViewer.tempDirectory + BytecodeViewer.fs + "temp.jar");
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), tempJar.getAbsolutePath()); JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), tempJar.getAbsolutePath());
BytecodeViewer.sm.blocking = false; BytecodeViewer.sm.stopBlocking();
try { try {
ProcessBuilder pb = new ProcessBuilder( ProcessBuilder pb = new ProcessBuilder(
BytecodeViewer.python, BytecodeViewer.python,
@ -168,9 +168,9 @@ public class KrakatauDecompiler extends Decompiler {
tempJar.delete(); tempJar.delete();
} catch(Exception e) { } catch(Exception e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e); new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
} finally {
BytecodeViewer.sm.setBlocking();
} }
BytecodeViewer.sm.blocking = true;
} }
public void decompileToClass(String className, String classNameSaved) { public void decompileToClass(String className, String classNameSaved) {
@ -188,7 +188,7 @@ public class KrakatauDecompiler extends Decompiler {
final File tempJar = new File(BytecodeViewer.tempDirectory + BytecodeViewer.fs + "temp.jar"); final File tempJar = new File(BytecodeViewer.tempDirectory + BytecodeViewer.fs + "temp.jar");
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), tempJar.getAbsolutePath()); JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), tempJar.getAbsolutePath());
BytecodeViewer.sm.blocking = false; BytecodeViewer.sm.stopBlocking();
try { try {
ProcessBuilder pb = new ProcessBuilder( ProcessBuilder pb = new ProcessBuilder(
BytecodeViewer.python, BytecodeViewer.python,
@ -231,6 +231,8 @@ public class KrakatauDecompiler extends Decompiler {
tempJar.delete(); tempJar.delete();
} catch(Exception e) { } catch(Exception e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e); new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
} finally {
BytecodeViewer.sm.setBlocking();
} }
} }

View file

@ -37,7 +37,7 @@ public class KrakatauDisassembler extends Decompiler {
final File tempJar = new File(BytecodeViewer.tempDirectory + BytecodeViewer.fs + "temp"+MiscUtils.randomString(32)+".jar"); final File tempJar = new File(BytecodeViewer.tempDirectory + BytecodeViewer.fs + "temp"+MiscUtils.randomString(32)+".jar");
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), tempJar.getAbsolutePath()); JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), tempJar.getAbsolutePath());
BytecodeViewer.sm.blocking = false; BytecodeViewer.sm.stopBlocking();
try { try {
ProcessBuilder pb = new ProcessBuilder( ProcessBuilder pb = new ProcessBuilder(
BytecodeViewer.python, BytecodeViewer.python,
@ -86,10 +86,9 @@ public class KrakatauDisassembler extends Decompiler {
e.printStackTrace(new PrintWriter(sw)); e.printStackTrace(new PrintWriter(sw));
e.printStackTrace(); e.printStackTrace();
s += BytecodeViewer.nl+"Bytecode Viewer Version: " + BytecodeViewer.version + BytecodeViewer.nl + BytecodeViewer.nl + sw.toString(); s += BytecodeViewer.nl+"Bytecode Viewer Version: " + BytecodeViewer.version + BytecodeViewer.nl + BytecodeViewer.nl + sw.toString();
} finally {
BytecodeViewer.sm.setBlocking();
} }
BytecodeViewer.sm.blocking = true;
return s; return s;
} }
@ -105,7 +104,7 @@ public class KrakatauDisassembler extends Decompiler {
final File tempJar = new File(BytecodeViewer.tempDirectory + BytecodeViewer.fs + "temp.jar"); final File tempJar = new File(BytecodeViewer.tempDirectory + BytecodeViewer.fs + "temp.jar");
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), tempJar.getAbsolutePath()); JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), tempJar.getAbsolutePath());
BytecodeViewer.sm.blocking = false; BytecodeViewer.sm.stopBlocking();
try { try {
ProcessBuilder pb = new ProcessBuilder( ProcessBuilder pb = new ProcessBuilder(
BytecodeViewer.python, BytecodeViewer.python,
@ -149,8 +148,8 @@ public class KrakatauDisassembler extends Decompiler {
tempJar.delete(); tempJar.delete();
} catch(Exception e) { } catch(Exception e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e); new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
} } finally {
BytecodeViewer.sm.setBlocking();
BytecodeViewer.sm.blocking = true; }
} }
} }

View file

@ -10,7 +10,6 @@ import org.objectweb.asm.tree.ClassNode;
import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.Dex2Jar; import the.bytecode.club.bytecodeviewer.Dex2Jar;
import the.bytecode.club.bytecodeviewer.Enjarify;
import the.bytecode.club.bytecodeviewer.MiscUtils; import the.bytecode.club.bytecodeviewer.MiscUtils;
import the.bytecode.club.bytecodeviewer.ZipUtils; import the.bytecode.club.bytecodeviewer.ZipUtils;
@ -46,10 +45,7 @@ public class SmaliDisassembler extends Decompiler {
ZipUtils.zipFile(tempClass, tempZip); ZipUtils.zipFile(tempClass, tempZip);
if(BytecodeViewer.viewer.apkConversionGroup.isSelected(BytecodeViewer.viewer.apkConversionDex.getModel()))
Dex2Jar.saveAsDex(tempZip, tempDex); Dex2Jar.saveAsDex(tempZip, tempDex);
else if(BytecodeViewer.viewer.apkConversionGroup.isSelected(BytecodeViewer.viewer.apkConversionEnjarify.getModel()))
Enjarify.saveAsAPK(tempZip, tempDex);
try { try {
org.jf.baksmali.main.main(new String[]{"-o", tempSmali.getAbsolutePath(), "-x", tempDex.getAbsolutePath()}); org.jf.baksmali.main.main(new String[]{"-o", tempSmali.getAbsolutePath(), "-x", tempDex.getAbsolutePath()});

View file

@ -892,10 +892,7 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier {
Thread t = new Thread() { Thread t = new Thread() {
@Override @Override
public void run() { public void run() {
if(BytecodeViewer.viewer.apkConversionGroup.isSelected(BytecodeViewer.viewer.apkConversionDex.getModel()))
Dex2Jar.saveAsDex(new File(input), file2); Dex2Jar.saveAsDex(new File(input), file2);
else if(BytecodeViewer.viewer.apkConversionGroup.isSelected(BytecodeViewer.viewer.apkConversionEnjarify.getModel()))
Enjarify.saveAsAPK(new File(input), file2);
BytecodeViewer.viewer.setIcon(false); BytecodeViewer.viewer.setIcon(false);
} }
@ -1484,6 +1481,7 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier {
mnSettings.add(refreshOnChange); mnSettings.add(refreshOnChange);
mnSettings.add(separator_38); mnSettings.add(separator_38);
decodeAPKResources.setSelected(true);
mnSettings.add(decodeAPKResources); mnSettings.add(decodeAPKResources);