Merge pull request #299 from ThexXTURBOXx/master

Some practical things
This commit is contained in:
Kalen (Konloch) Kinloch 2021-06-22 07:24:33 -07:00 committed by GitHub
commit a00b429b8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 136 additions and 81 deletions

42
pom.xml
View file

@ -23,14 +23,14 @@
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>20.1.0</version>
<version>21.0.1</version>
</dependency>
<dependency>
<groupId>org.apktool</groupId>
<artifactId>apktool</artifactId>
<version>2.3.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/apktool_2.3.0.jar</systemPath>
<scope>system</scope>
<systemPath>${project.basedir}/libs/apktool_2.3.0.jar</systemPath>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
@ -90,7 +90,7 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.8.0</version>
<version>2.10.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
@ -105,7 +105,7 @@
<dependency>
<groupId>org.jboss.windup.decompiler</groupId>
<artifactId>decompiler-fernflower</artifactId>
<version>5.1.3.Final</version>
<version>5.1.4.Final</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
@ -115,7 +115,7 @@
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
<version>2.8.7</version>
</dependency>
<dependency>
<groupId>org.imgscalr</groupId>
@ -131,15 +131,15 @@
<groupId>com.jd</groupId>
<artifactId>jd-gui</artifactId>
<version>1.6.6</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/jd-gui-1.6.6-no-asm.jar</systemPath>
<scope>system</scope>
<systemPath>${project.basedir}/libs/jd-gui-1.6.6-no-asm-rsta.jar</systemPath>
</dependency>
<dependency>
<groupId>eu.bibl.banalysis</groupId>
<artifactId>byteanalysis</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/byteanalysis-1.0.jar</systemPath>
<scope>system</scope>
<systemPath>${project.basedir}/libs/byteanalysis-1.0.jar</systemPath>
</dependency>
<dependency>
<groupId>org.tinyjee.jgraphx</groupId>
@ -174,7 +174,7 @@
<dependency>
<groupId>com.fifesoft</groupId>
<artifactId>rsyntaxtextarea</artifactId>
<version>3.1.2</version>
<version>3.1.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
@ -228,6 +228,26 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>unpack</id>
<!-- In process resource phase such that it doesn't
override other dependencies or BCV's own files -->
<phase>process-resources</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includeScope>system</includeScope>
<outputDirectory>${basedir}/target/classes</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>

View file

@ -6,6 +6,8 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Arrays;
import java.util.stream.Collectors;
import me.konloch.kontainer.io.DiskReader;
import org.objectweb.asm.tree.ClassNode;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
@ -45,8 +47,19 @@ public class KrakatauDecompiler extends Decompiler {
public String quick() {
if (Configuration.library.isEmpty())
return "";
else
File dir = new File(Configuration.library);
if (!dir.exists())
return "";
if (!dir.isDirectory())
return ";" + Configuration.library;
File[] files = dir.listFiles();
if (files == null || files.length == 0)
return "";
return ";" + Arrays.stream(files).filter(File::isFile)
.map(File::getAbsolutePath).collect(Collectors.joining(";"));
}
public String decompileClassNode(File krakatauTempJar, File krakatauTempDir, ClassNode cn) {
@ -159,9 +172,9 @@ public class KrakatauDecompiler extends Decompiler {
final File tempDirectory = new File(Constants.tempDirectory + fs + MiscUtils.randomString(32) + fs);
tempDirectory.mkdir();
final File tempJar = new File(Constants.tempDirectory + fs + "temp" + MiscUtils.randomString(32) + ".jar");
JarUtils.saveAsJarClassesOnly(BytecodeViewer.getLoadedClasses(), tempJar.getAbsolutePath());
BytecodeViewer.sm.stopBlocking();
try {

View file

@ -1,6 +1,5 @@
package the.bytecode.club.bytecodeviewer.gui;
import the.bytecode.club.bytecodeviewer.gui.hexviewer.JHexEditor;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.KeyEvent;
@ -22,12 +21,13 @@ import javax.swing.text.DefaultHighlighter;
import javax.swing.text.Highlighter;
import javax.swing.text.JTextComponent;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import org.fife.ui.rtextarea.RTextScrollPane;
import org.imgscalr.Scalr;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.Resources;
import the.bytecode.club.bytecodeviewer.gui.hexviewer.JHexEditor;
import the.bytecode.club.bytecodeviewer.util.FileContainer;
import the.bytecode.club.bytecodeviewer.util.Language;
/***************************************************************************
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
@ -127,71 +127,8 @@ public class FileViewer extends Viewer {
}
}
if (name.endsWith(".xml") || contentsS.startsWith("<?xml") || contentsS.startsWith(("<xml"))) {
panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_XML);
panelArea.setText(contentsS);
} else if (name.endsWith(".py") || name.endsWith(".python")) {
panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_PYTHON);
panelArea.setText(contentsS);
} else if (name.endsWith(".rb") || name.endsWith(".ruby")) {
panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_RUBY);
panelArea.setText(contentsS);
} else if (name.endsWith(".java")) {
panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
panelArea.setText(contentsS);
} else if (name.endsWith(".html")) {
panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_HTML);
panelArea.setText(contentsS);
} else if (name.endsWith(".css")) {
panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_CSS);
panelArea.setText(contentsS);
} else if (name.endsWith(".properties") || name.endsWith(".mf") || name.endsWith(".sf")) {
panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_PROPERTIES_FILE);
panelArea.setText(contentsS);
} else if (name.endsWith(".php") || contentsS.startsWith("<?php")) {
panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_PHP);
panelArea.setText(contentsS);
} else if (name.endsWith(".js")) {
panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT);
panelArea.setText(contentsS);
} else if (name.endsWith(".bat")) {
panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_WINDOWS_BATCH);
panelArea.setText(contentsS);
} else if (name.endsWith(".sh")) {
panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_UNIX_SHELL);
panelArea.setText(contentsS);
} else if (name.endsWith(".c")) {
panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_C);
panelArea.setText(contentsS);
} else if (name.endsWith(".cpp")) {
panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_CPLUSPLUS);
panelArea.setText(contentsS);
} else if (name.endsWith(".scala")) {
panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_SCALA);
panelArea.setText(contentsS);
} else if (name.endsWith(".clojure")) {
panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_CLOJURE);
panelArea.setText(contentsS);
} else if (name.endsWith(".groovy")) {
panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_GROOVY);
panelArea.setText(contentsS);
} else if (name.endsWith(".lua")) {
panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_LUA);
panelArea.setText(contentsS);
} else if (name.endsWith(".sql")) {
panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_SQL);
panelArea.setText(contentsS);
} else if (name.endsWith(".json")) {
panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JSON);
panelArea.setText(contentsS);
} else if (name.endsWith(".jsp")) {
panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JSP);
panelArea.setText(contentsS);
} else {
panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_NONE);
panelArea.setText(contentsS);
}
panelArea.setSyntaxEditingStyle(Language.detectLanguage(name, contentsS).getSyntaxConstant());
panelArea.setText(contentsS);
panelArea.setCaretPosition(0);
scrollPane.setColumnHeaderView(panel);
panel2.add(scrollPane);

View file

@ -94,6 +94,18 @@ public class TabbedPane extends JPanel {
}
};
this.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON2) {
final int i = pane.indexOfTabComponent(TabbedPane.this);
if (i != -1) {
pane.remove(i);
}
}
}
});
this.add(label);
// add more space between the label and the button
label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));

View file

@ -0,0 +1,73 @@
package the.bytecode.club.bytecodeviewer.util;
import java.util.function.BiFunction;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
public enum Language {
XML(SyntaxConstants.SYNTAX_STYLE_XML, (n, c) -> n.endsWith(".xml")
|| c.startsWith("<?xml") || c.startsWith("<xml")),
PYTHON(SyntaxConstants.SYNTAX_STYLE_PYTHON, (n, c) -> n.endsWith(".py") || n.endsWith(".python")),
RUBY(SyntaxConstants.SYNTAX_STYLE_RUBY, (n, c) -> n.endsWith(".rb") || n.endsWith(".ruby")),
JAVA(SyntaxConstants.SYNTAX_STYLE_JAVA, (n, c) -> n.endsWith(".java")),
HTML(SyntaxConstants.SYNTAX_STYLE_HTML, (n, c) -> n.endsWith(".html")),
CSS(SyntaxConstants.SYNTAX_STYLE_CSS, (n, c) -> n.endsWith(".css")),
PROPERTIES(SyntaxConstants.SYNTAX_STYLE_PROPERTIES_FILE, (n, c) -> n.endsWith(".properties")
|| n.endsWith(".mf") || n.endsWith(".sf")),
PHP(SyntaxConstants.SYNTAX_STYLE_PHP, (n, c) -> n.endsWith(".php") || c.startsWith("<?php")),
JS(SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT, (n, c) -> n.endsWith(".js")),
BATCH(SyntaxConstants.SYNTAX_STYLE_WINDOWS_BATCH, (n, c) -> n.endsWith(".bat")),
SHELL(SyntaxConstants.SYNTAX_STYLE_UNIX_SHELL, (n, c) -> n.endsWith(".sh")),
C(SyntaxConstants.SYNTAX_STYLE_C, (n, c) -> n.endsWith(".c") || n.endsWith(".h")),
CPP(SyntaxConstants.SYNTAX_STYLE_CPLUSPLUS, (n, c) -> n.endsWith(".cpp") || n.endsWith(".hpp")),
SCALA(SyntaxConstants.SYNTAX_STYLE_SCALA, (n, c) -> n.endsWith(".scala")),
CLOJURE(SyntaxConstants.SYNTAX_STYLE_CLOJURE, (n, c) -> n.endsWith(".clojure")),
GROOVY(SyntaxConstants.SYNTAX_STYLE_GROOVY, (n, c) -> n.endsWith(".groovy") || n.endsWith(".gradle")),
LUA(SyntaxConstants.SYNTAX_STYLE_LUA, (n, c) -> n.endsWith(".lua")),
SQL(SyntaxConstants.SYNTAX_STYLE_SQL, (n, c) -> n.endsWith(".sql")),
JSON(SyntaxConstants.SYNTAX_STYLE_JSON, (n, c) -> n.endsWith(".json")),
JSP(SyntaxConstants.SYNTAX_STYLE_JSP, (n, c) -> n.endsWith(".jsp")),
YAML(SyntaxConstants.SYNTAX_STYLE_YAML, (n, c) -> n.endsWith(".yml") || n.endsWith(".yaml")),
CS(SyntaxConstants.SYNTAX_STYLE_CSHARP, (n, c) -> n.endsWith(".cs")),
CSV(SyntaxConstants.SYNTAX_STYLE_CSV, (n, c) -> n.endsWith(".csv")),
DOCKER(SyntaxConstants.SYNTAX_STYLE_DOCKERFILE, (n, c) -> n.endsWith(".dockerfile")),
DART(SyntaxConstants.SYNTAX_STYLE_DART, (n, c) -> n.endsWith(".dart")),
GO(SyntaxConstants.SYNTAX_STYLE_GO, (n, c) -> n.endsWith(".go")),
HTACCESS(SyntaxConstants.SYNTAX_STYLE_HTACCESS, (n, c) -> n.endsWith(".htaccess")),
INI(SyntaxConstants.SYNTAX_STYLE_INI, (n, c) -> n.endsWith(".ini")),
KOTLIN(SyntaxConstants.SYNTAX_STYLE_KOTLIN, (n, c) -> n.endsWith(".kt") || n.endsWith(".kts")),
LATEX(SyntaxConstants.SYNTAX_STYLE_LATEX, (n, c) -> n.endsWith(".tex")),
MARKDOWN(SyntaxConstants.SYNTAX_STYLE_MARKDOWN, (n, c) -> n.endsWith(".md")),
PERL(SyntaxConstants.SYNTAX_STYLE_PERL, (n, c) -> n.endsWith(".pl")),
TYPESCRIPT(SyntaxConstants.SYNTAX_STYLE_TYPESCRIPT, (n, c) -> n.endsWith(".ts")),
NONE(SyntaxConstants.SYNTAX_STYLE_NONE, (n, c) -> false);
public static final Language[] VALUES = values();
private final BiFunction<String, String, Boolean> criteria;
private final String syntaxConstant;
Language(String syntaxConstant, BiFunction<String, String, Boolean> criteria) {
this.criteria = criteria;
this.syntaxConstant = syntaxConstant;
}
public boolean isLanguage(String fileName, String content) {
return criteria.apply(fileName, content);
}
public String getSyntaxConstant() {
return syntaxConstant;
}
public static Language detectLanguage(String fileName, String content) {
for (Language lang : VALUES) {
if (lang.isLanguage(fileName, content)) {
return lang;
}
}
return NONE;
}
}