Fix Code Style No2

This commit is contained in:
Nico Mexis 2021-04-13 00:31:22 +02:00
parent 7840b5c266
commit f528437b74
No known key found for this signature in database
GPG Key ID: 27D6E17CE092AB78

AI 샘플 코드 생성 중입니다

Loading...
96 changed files with 2497 additions and 2949 deletions

View File

@ -1,9 +1,9 @@
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>de.femtopedia</groupId>
<groupId>club.bytecode.the</groupId>
<artifactId>bytecodeviewer</artifactId>
<version>2.9.23</version>
<version>2.10.0</version>
<properties>
<java.version>8</java.version>
@ -104,6 +104,11 @@
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>com.googlecode</groupId>
<artifactId>d2jar</artifactId>

View File

@ -25,10 +25,9 @@ public class JHexEditor extends JPanel implements FocusListener,
private static final long serialVersionUID = 2289328616534802372L;
byte[] buff;
public int cursor;
protected static Font font = new Font("Monospaced", 0, 12);
protected static Font font = new Font("Monospaced", Font.PLAIN, 12);
protected int border = 2;
public boolean DEBUG = false;
private final JPanel panel;
private final JScrollBar sb;
private int inicio = 0;
private int lineas = 10;
@ -61,7 +60,7 @@ public class JHexEditor extends JPanel implements FocusListener,
p3.add(new JHexEditorASCII(this), BorderLayout.CENTER);
p3.add(new Caja(), BorderLayout.NORTH);
panel = new JPanel();
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout(1, 1));
panel.add(p1, BorderLayout.CENTER);
panel.add(p2, BorderLayout.WEST);
@ -71,6 +70,7 @@ public class JHexEditor extends JPanel implements FocusListener,
this.add(panel, BorderLayout.CENTER);
}
@Override
public void paint(Graphics g) {
FontMetrics fn = getFontMetrics(font);
Rectangle rec = this.getBounds();
@ -86,23 +86,6 @@ public class JHexEditor extends JPanel implements FocusListener,
super.paint(g);
}
protected void actualizaCursor() {
int n = (cursor / 16);
System.out.print("- " + inicio + "<" + n + "<" + (lineas + inicio)
+ "(" + lineas + ")");
if (n < inicio)
inicio = n;
else if (n >= inicio + lineas)
inicio = n - (lineas - 1);
System.out.println(" - " + inicio + "<" + n + "<" + (lineas + inicio)
+ "(" + lineas + ")");
repaint();
}
protected int getInicio() {
return inicio;
}
@ -131,14 +114,17 @@ public class JHexEditor extends JPanel implements FocusListener,
((fn.getHeight() * (y + 1)) - fn.getMaxDescent()) + border);
}
@Override
public void focusGained(FocusEvent e) {
this.repaint();
}
@Override
public void focusLost(FocusEvent e) {
this.repaint();
}
@Override
public void adjustmentValueChanged(AdjustmentEvent e) {
inicio = e.getValue();
if (inicio < 0)
@ -146,6 +132,7 @@ public class JHexEditor extends JPanel implements FocusListener,
repaint();
}
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
inicio += (e.getUnitsToScroll());
if ((inicio + lineas) >= buff.length / 16)
@ -177,10 +164,12 @@ public class JHexEditor extends JPanel implements FocusListener,
this.setLayout(new BorderLayout(1, 1));
}
@Override
public Dimension getPreferredSize() {
return getMinimumSize();
}
@Override
public Dimension getMinimumSize() {
Dimension d = new Dimension();
FontMetrics fn = getFontMetrics(font);
@ -191,6 +180,7 @@ public class JHexEditor extends JPanel implements FocusListener,
return d;
}
@Override
public void paint(Graphics g) {
Dimension d = getMinimumSize();
g.setColor(Color.white);
@ -211,10 +201,12 @@ public class JHexEditor extends JPanel implements FocusListener,
private class Caja extends JPanel {
private static final long serialVersionUID = -6124062720565016834L;
@Override
public Dimension getPreferredSize() {
return getMinimumSize();
}
@Override
public Dimension getMinimumSize() {
Dimension d = new Dimension();
FontMetrics fn = getFontMetrics(font);
@ -233,10 +225,12 @@ public class JHexEditor extends JPanel implements FocusListener,
this.setLayout(new BorderLayout(1, 1));
}
@Override
public Dimension getPreferredSize() {
return getMinimumSize();
}
@Override
public Dimension getMinimumSize() {
Dimension d = new Dimension();
FontMetrics fn = getFontMetrics(font);
@ -247,6 +241,7 @@ public class JHexEditor extends JPanel implements FocusListener,
return d;
}
@Override
public void paint(Graphics g) {
Dimension d = getMinimumSize();
g.setColor(Color.white);

View File

@ -25,11 +25,13 @@ public class JHexEditorASCII extends JComponent implements MouseListener,
addFocusListener(he);
}
@Override
public Dimension getPreferredSize() {
debug("getPreferredSize()");
return getMinimumSize();
}
@Override
public Dimension getMinimumSize() {
debug("getMinimumSize()");
@ -42,6 +44,7 @@ public class JHexEditorASCII extends JComponent implements MouseListener,
return d;
}
@Override
public void paint(Graphics g) {
debug("paint(" + g + ")");
debug("cursor=" + he.cursor + " buff.length=" + he.buff.length);
@ -102,6 +105,7 @@ public class JHexEditorASCII extends JComponent implements MouseListener,
}
// mouselistener
@Override
public void mouseClicked(MouseEvent e) {
debug("mouseClicked(" + e + ")");
he.cursor = calcularPosicionRaton(e.getX(), e.getY());
@ -109,19 +113,24 @@ public class JHexEditorASCII extends JComponent implements MouseListener,
he.repaint();
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
// KeyListener
@Override
public void keyTyped(KeyEvent e) {
/*
* debug("keyTyped("+e+")");
@ -132,20 +141,24 @@ public class JHexEditorASCII extends JComponent implements MouseListener,
*/
}
@Override
public void keyPressed(KeyEvent e) {
debug("keyPressed(" + e + ")");
he.keyPressed(e);
}
@Override
public void keyReleased(KeyEvent e) {
debug("keyReleased(" + e + ")");
}
@SuppressWarnings("deprecation")
@Override
public boolean isFocusTraversable() {
return true;
}
@Override
public boolean isFocusable() {
return true;
}

View File

@ -17,7 +17,6 @@ public class JHexEditorHEX extends JComponent implements MouseListener,
KeyListener {
private static final long serialVersionUID = 1481995655372014571L;
private final JHexEditor he;
private final int cursor = 0;
public JHexEditorHEX(JHexEditor he) {
this.he = he;
@ -31,6 +30,7 @@ public class JHexEditorHEX extends JComponent implements MouseListener,
* getMinimumSize(); }
*/
@Override
public Dimension getMaximumSize() {
debug("getMaximumSize()");
return getMinimumSize();
@ -45,6 +45,7 @@ public class JHexEditorHEX extends JComponent implements MouseListener,
* )*+((16*3)-1))+(he.border*2)+1,h*nl+(he.border*2)+1); return d; }
*/
@Override
public void paint(Graphics g) {
debug("paint(" + g + ")");
debug("cursor=" + he.cursor + " buff.length=" + he.buff.length);
@ -69,6 +70,7 @@ public class JHexEditorHEX extends JComponent implements MouseListener,
g.setColor(Color.black);
he.fondo(g, (x * 3), y, 2);
g.setColor(Color.blue);
int cursor = 0;
he.fondo(g, (x * 3) + cursor, y, 1);
} else {
g.setColor(Color.blue);
@ -108,6 +110,7 @@ public class JHexEditorHEX extends JComponent implements MouseListener,
}
// mouselistener
@Override
public void mouseClicked(MouseEvent e) {
debug("mouseClicked(" + e + ")");
he.cursor = calcularPosicionRaton(e.getX(), e.getY());
@ -115,19 +118,24 @@ public class JHexEditorHEX extends JComponent implements MouseListener,
he.repaint();
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
// KeyListener
@Override
public void keyTyped(KeyEvent e) {
debug("keyTyped(" + e + ")");
@ -145,20 +153,24 @@ public class JHexEditorHEX extends JComponent implements MouseListener,
*/
}
@Override
public void keyPressed(KeyEvent e) {
debug("keyPressed(" + e + ")");
he.keyPressed(e);
}
@Override
public void keyReleased(KeyEvent e) {
debug("keyReleased(" + e + ")");
}
@SuppressWarnings("deprecation")
@Override
public boolean isFocusTraversable() {
return true;
}
@Override
public boolean isFocusable() {
return true;
}

View File

@ -16,6 +16,7 @@ public class DirectoryLoader extends BaseLoader {
throw new LoaderException("'" + codebase + "' is not a directory");
}
@Override
public DataInputStream load(String internalPath)
throws LoaderException {
File file = new File(this.codebase, internalPath);
@ -29,6 +30,7 @@ public class DirectoryLoader extends BaseLoader {
}
}
@Override
public boolean canLoad(String internalPath) {
File file = new File(this.codebase, internalPath);
return file.exists() && file.isFile();

View File

@ -25,6 +25,7 @@ public class JarLoader extends BaseLoader {
}
}
@Override
public DataInputStream load(String internalPath)
throws LoaderException {
ZipEntry zipEntry = this.zipFile.getEntry(internalPath);
@ -40,6 +41,7 @@ public class JarLoader extends BaseLoader {
}
}
@Override
public boolean canLoad(String internalPath) {
return this.zipFile.getEntry(internalPath) != null;
}

View File

@ -12,7 +12,7 @@ public class LoaderManager {
protected Map<String, BaseLoader> map;
public LoaderManager() {
this.map = new ConcurrentHashMap<String, BaseLoader>();
this.map = new ConcurrentHashMap<>();
}
public BaseLoader getLoader(String codebase) throws LoaderException {

View File

@ -50,10 +50,12 @@ public class HtmlPrinter implements Printer {
this.sbCode = new StringBuffer(30 * 1024);
}
@Override
public void print(byte b) {
this.sbCode.append(String.valueOf(b));
}
@Override
public void print(char c) {
switch (c) {
case '<':
@ -68,20 +70,24 @@ public class HtmlPrinter implements Printer {
}
}
@Override
public void print(int i) {
this.sbCode.append(i);
}
@Override
public void print(String s) {
this.sbCode.append(s);
}
@Override
public void printNumeric(String s) {
this.sbCode.append("<u>");
this.sbCode.append(s);
this.sbCode.append("</u>");
}
@Override
public void printString(String s, String scopeInternalName) {
this.sbCode.append("<u>");
@ -102,6 +108,7 @@ public class HtmlPrinter implements Printer {
this.sbCode.append("</u>");
}
@Override
public void printKeyword(String s) {
if (this.commentJavadocErrorDepth == 0) {
this.sbCode.append("<b>");
@ -112,28 +119,34 @@ public class HtmlPrinter implements Printer {
}
}
@Override
public void printJavaWord(String s) {
printKeyword(s);
}
@Override
public void printType(String internalName, String name, String scopeInternalName) {
this.sbCode.append(name);
}
@Override
public void printTypeDeclaration(String internalName, String name) {
this.sbCode.append(name);
}
@Override
public void printTypeImport(String internalName, String name) {
this.sbCode.append(name);
}
@Override
public void printField(
String internalName, String name,
String descriptor, String scopeInternalName) {
printFieldDeclaration(internalName, name, descriptor);
}
@Override
public void printFieldDeclaration(
String internalName, String name, String descriptor) {
this.sbCode.append("<var>");
@ -141,12 +154,14 @@ public class HtmlPrinter implements Printer {
this.sbCode.append("</var>");
}
@Override
public void printStaticField(
String internalName, String name,
String descriptor, String scopeInternalName) {
printStaticFieldDeclaration(internalName, name, descriptor);
}
@Override
public void printStaticFieldDeclaration(
String internalName, String name, String descriptor) {
this.sbCode.append("<em>");
@ -154,17 +169,20 @@ public class HtmlPrinter implements Printer {
this.sbCode.append("</em>");
}
@Override
public void printConstructor(
String internalName, String name,
String descriptor, String scopeInternalName) {
this.sbCode.append(name);
}
@Override
public void printConstructorDeclaration(
String internalName, String name, String descriptor) {
this.sbCode.append(name);
}
@Override
public void printStaticConstructorDeclaration(
String internalName, String name) {
this.sbCode.append("<samp>");
@ -172,23 +190,27 @@ public class HtmlPrinter implements Printer {
this.sbCode.append("</samp>");
}
@Override
public void printMethod(
String internalName, String name,
String descriptor, String scopeInternalName) {
this.sbCode.append(name);
}
@Override
public void printMethodDeclaration(
String internalName, String name, String descriptor) {
this.sbCode.append(name);
}
@Override
public void printStaticMethod(
String internalName, String name,
String descriptor, String scopeInternalName) {
printStaticMethodDeclaration(internalName, name, descriptor);
}
@Override
public void printStaticMethodDeclaration(
String internalName, String name, String descriptor) {
this.sbCode.append("<samp>");
@ -196,6 +218,7 @@ public class HtmlPrinter implements Printer {
this.sbCode.append("</samp>");
}
@Override
public void start(int maxLineNumber, int majorVersion, int minorVersion) {
this.maxLineNumber = maxLineNumber;
this.majorVersion = majorVersion;
@ -216,7 +239,7 @@ public class HtmlPrinter implements Printer {
this.lineNumberFormatPrefix = "%" + digitCount + "d<br>";
StringBuilder sb = new StringBuilder(digitCount + 7);
sb.append("%" + (digitCount + 1) + "d:");
sb.append("%").append(digitCount + 1).append("d:");
for (int i = 0; i < digitCount; i++) sb.append(' ');
sb.append("<br>");
this.unknownLineNumberPrefix = sb.toString();
@ -269,15 +292,16 @@ public class HtmlPrinter implements Printer {
"<div id='demo'><div class='out'><div class='content'>");
}
@Override
public void end() {
if (this.maxLineNumber > 0) {
this.printStream.print("<div id='linenumber'>");
this.printStream.print(this.sbLineNumber.toString());
this.printStream.print(this.sbLineNumber);
this.printStream.print("</div>");
}
this.printStream.print("<div id='javacode'>");
this.printStream.print(this.sbCode.toString());
this.printStream.print(this.sbCode);
this.printStream.print("</div>");
this.printStream.print("<div id='metadata'>");
@ -290,15 +314,18 @@ public class HtmlPrinter implements Printer {
this.printStream.print("</div></div></div></body></html>");
}
@Override
public void indent() {
this.indentationCount++;
}
@Override
public void desindent() {
if (this.indentationCount > 0)
this.indentationCount--;
}
@Override
public void startOfLine(int lineNumber) {
this.realLineNumber++;
@ -326,10 +353,12 @@ public class HtmlPrinter implements Printer {
this.sbCode.append(" ");
}
@Override
public void endOfLine() {
this.sbCode.append("<br>");
}
@Override
public void extraLine(int count) {
if (this.maxLineNumber > 0) {
this.sbLineNumber.append("<s>");
@ -353,90 +382,110 @@ public class HtmlPrinter implements Printer {
this.sbCode.append("</s>");
}
@Override
public void startOfComment() {
this.sbCode.append("<cite>");
this.commentJavadocErrorDepth++;
}
@Override
public void endOfComment() {
this.sbCode.append("</cite>");
this.commentJavadocErrorDepth--;
}
@Override
public void startOfJavadoc() {
this.sbCode.append("<dfn>");
this.commentJavadocErrorDepth++;
}
@Override
public void endOfJavadoc() {
this.sbCode.append("</dfn>");
this.commentJavadocErrorDepth--;
}
@Override
public void startOfXdoclet() {
this.sbCode.append("<b>");
}
@Override
public void endOfXdoclet() {
this.sbCode.append("</b>");
}
@Override
public void startOfError() {
this.sbCode.append("<span>");
this.commentJavadocErrorDepth++;
}
@Override
public void endOfError() {
this.sbCode.append("</span>");
this.commentJavadocErrorDepth--;
}
@Override
public void startOfImportStatements() {
}
@Override
public void endOfImportStatements() {
}
@Override
public void startOfTypeDeclaration(String internalPath) {
}
@Override
public void endOfTypeDeclaration() {
}
@Override
public void startOfAnnotationName() {
this.sbCode.append("<del>");
}
@Override
public void endOfAnnotationName() {
this.sbCode.append("</del>");
}
@Override
public void startOfOptionalPrefix() {
this.sbCode.append("<kbd>");
}
@Override
public void endOfOptionalPrefix() {
this.sbCode.append("</kbd>");
}
@Override
public void debugStartOfLayoutBlock() {
if (DEBUG) {
this.sbCode.append("<span class='debuglayoutblock' alt='block'>");
}
}
@Override
public void debugEndOfLayoutBlock() {
if (DEBUG) {
this.sbCode.append("</span>");
}
}
@Override
public void debugStartOfSeparatorLayoutBlock() {
if (DEBUG) {
this.sbCode.append("<span class='debugseparatorlayoutblock' alr='separator'>");
}
}
@Override
public void debugEndOfSeparatorLayoutBlock(int min, int value, int max) {
if (DEBUG) {
// DEBUG // this.sb.append(min);
@ -448,12 +497,14 @@ public class HtmlPrinter implements Printer {
}
}
@Override
public void debugStartOfStatementsBlockLayoutBlock() {
if (DEBUG) {
this.sbCode.append("<span class='debugstatementblocklayoutblock' alt='statement'>");
}
}
@Override
public void debugEndOfStatementsBlockLayoutBlock(int min, int value, int max) {
if (DEBUG) {
// DEBUG // this.sb.append(min);
@ -465,30 +516,35 @@ public class HtmlPrinter implements Printer {
}
}
@Override
public void debugStartOfInstructionBlockLayoutBlock() {
if (DEBUG) {
this.sbCode.append("<span class='debugenumblocklayoutblock' alt='numeric block'>");
}
}
@Override
public void debugEndOfInstructionBlockLayoutBlock() {
if (DEBUG) {
this.sbCode.append("</span>");
}
}
@Override
public void debugStartOfCommentDeprecatedLayoutBlock() {
if (DEBUG) {
this.sbCode.append("<span class='debugcommentdeprecatedlayoutblock' alt='comment deprecated'>");
}
}
@Override
public void debugEndOfCommentDeprecatedLayoutBlock() {
if (DEBUG) {
this.sbCode.append("</span>");
}
}
@Override
public void debugMarker(String marker) {
if (DEBUG) {
// DEBUG // this.sb.append("<span class='debugmarker'>");
@ -497,12 +553,14 @@ public class HtmlPrinter implements Printer {
}
}
@Override
public void debugStartOfCaseBlockLayoutBlock() {
if (DEBUG) {
this.sbCode.append("<span class='debugcaseblocklayoutblock' alt='case block'>");
}
}
@Override
public void debugEndOfCaseBlockLayoutBlock() {
if (DEBUG) {
this.sbCode.append("</span>");

View File

@ -41,114 +41,137 @@ public class PlainTextPrinter implements Printer {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
@Override
public void print(byte b) {
this.printStream.append(String.valueOf(b));
}
@Override
public void print(int i) {
this.printStream.append(String.valueOf(i));
}
@Override
public void print(char c) {
if (this.display)
this.printStream.append(String.valueOf(c));
}
@Override
public void print(String s) {
if (this.display)
printEscape(s);
}
@Override
public void printNumeric(String s) {
this.printStream.append(s);
}
@Override
public void printString(String s, String scopeInternalName) {
this.printStream.append(s);
}
@Override
public void printKeyword(String s) {
if (this.display)
this.printStream.append(s);
}
@Override
public void printJavaWord(String s) {
this.printStream.append(s);
}
@Override
public void printType(String internalName, String name, String scopeInternalName) {
if (this.display)
printEscape(name);
}
@Override
public void printTypeDeclaration(String internalName, String name) {
printEscape(name);
}
@Override
public void printTypeImport(String internalName, String name) {
printEscape(name);
}
@Override
public void printField(
String internalName, String name,
String descriptor, String scopeInternalName) {
printEscape(name);
}
@Override
public void printFieldDeclaration(
String internalName, String name, String descriptor) {
printEscape(name);
}
@Override
public void printStaticField(
String internalName, String name,
String descriptor, String scopeInternalName) {
printEscape(name);
}
@Override
public void printStaticFieldDeclaration(
String internalName, String name, String descriptor) {
printEscape(name);
}
@Override
public void printConstructor(
String internalName, String name,
String descriptor, String scopeInternalName) {
printEscape(name);
}
@Override
public void printConstructorDeclaration(
String internalName, String name, String descriptor) {
printEscape(name);
}
@Override
public void printStaticConstructorDeclaration(
String internalName, String name) {
this.printStream.append(name);
}
@Override
public void printMethod(
String internalName, String name,
String descriptor, String scopeInternalName) {
printEscape(name);
}
@Override
public void printMethodDeclaration(
String internalName, String name, String descriptor) {
printEscape(name);
}
@Override
public void printStaticMethod(
String internalName, String name,
String descriptor, String scopeInternalName) {
printEscape(name);
}
@Override
public void printStaticMethodDeclaration(
String internalName, String name, String descriptor) {
printEscape(name);
}
@Override
public void start(int maxLineNumber, int majorVersion, int minorVersion) {
this.majorVersion = majorVersion;
this.minorVersion = minorVersion;
@ -160,15 +183,16 @@ public class PlainTextPrinter implements Printer {
if (maxLineNumber > 0) {
this.digitCount = 1;
this.unknownLineNumberPrefix = " ";
StringBuilder unknownLineNumberPrefixBuilder = new StringBuilder(" ");
int maximum = 9;
while (maximum < maxLineNumber) {
this.digitCount++;
this.unknownLineNumberPrefix += ' ';
unknownLineNumberPrefixBuilder.append(' ');
maximum = maximum * 10 + 9;
}
this.unknownLineNumberPrefix = unknownLineNumberPrefixBuilder.toString();
this.lineNumberBeginPrefix = "/* ";
this.lineNumberEndPrefix = " */ ";
} else {
@ -184,18 +208,22 @@ public class PlainTextPrinter implements Printer {
}
}
@Override
public void end() {
}
@Override
public void indent() {
this.indentationCount++;
}
@Override
public void desindent() {
if (this.indentationCount > 0)
this.indentationCount--;
}
@Override
public void startOfLine(int lineNumber) {
if (this.maxLineNumber > 0) {
this.printStream.append(this.lineNumberBeginPrefix);
@ -219,12 +247,14 @@ public class PlainTextPrinter implements Printer {
this.printStream.append(TAB);
}
@Override
public void endOfLine() {
this.printStream.append(NEWLINE);
}
@Override
public void extraLine(int count) {
if (this.preferences.isMergeEmptyLines() == false) {
if (!this.preferences.isMergeEmptyLines()) {
while (count-- > 0) {
if (this.maxLineNumber > 0) {
this.printStream.append(this.lineNumberBeginPrefix);
@ -237,95 +267,124 @@ public class PlainTextPrinter implements Printer {
}
}
@Override
public void startOfComment() {
}
@Override
public void endOfComment() {
}
@Override
public void startOfJavadoc() {
}
@Override
public void endOfJavadoc() {
}
@Override
public void startOfXdoclet() {
}
@Override
public void endOfXdoclet() {
}
@Override
public void startOfError() {
}
@Override
public void endOfError() {
}
@Override
public void startOfImportStatements() {
}
@Override
public void endOfImportStatements() {
}
@Override
public void startOfTypeDeclaration(String internalPath) {
}
@Override
public void endOfTypeDeclaration() {
}
@Override
public void startOfAnnotationName() {
}
@Override
public void endOfAnnotationName() {
}
@Override
public void startOfOptionalPrefix() {
if (this.preferences.isShowPrefixThis() == false)
if (!this.preferences.isShowPrefixThis())
this.display = false;
}
@Override
public void endOfOptionalPrefix() {
this.display = true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
@Override
public void debugStartOfLayoutBlock() {
}
@Override
public void debugEndOfLayoutBlock() {
}
@Override
public void debugStartOfSeparatorLayoutBlock() {
}
@Override
public void debugEndOfSeparatorLayoutBlock(int min, int value, int max) {
}
@Override
public void debugStartOfStatementsBlockLayoutBlock() {
}
@Override
public void debugEndOfStatementsBlockLayoutBlock(int min, int value, int max) {
}
@Override
public void debugStartOfInstructionBlockLayoutBlock() {
}
@Override
public void debugEndOfInstructionBlockLayoutBlock() {
}
@Override
public void debugStartOfCommentDeprecatedLayoutBlock() {
}
@Override
public void debugEndOfCommentDeprecatedLayoutBlock() {
}
@Override
public void debugMarker(String marker) {
}
@Override
public void debugStartOfCaseBlockLayoutBlock() {
}
@Override
public void debugEndOfCaseBlockLayoutBlock() {
}

View File

@ -4,8 +4,8 @@ import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Objects;
import jd.core.CoreConstants;
import jd.core.model.classfile.constant.Constant;
import jd.core.model.classfile.constant.ConstantClass;
@ -22,7 +22,7 @@ public class ClassFileUtil {
*/
public static String ExtractDirectoryPath(String pathToClass) {
DataInputStream dis = null;
String directoryPath = null;
String directoryPath;
try {
dis = new DataInputStream(
@ -44,7 +44,7 @@ public class ClassFileUtil {
dis.readUnsignedShort();
int this_class = dis.readUnsignedShort();
Constant c = constants[this_class];
Constant c = Objects.requireNonNull(constants)[this_class];
if ((c == null) || (c.tag != ConstantConstant.CONSTANT_Class))
throw new ClassFormatException("Invalid contant pool");
@ -63,9 +63,6 @@ public class ClassFileUtil {
throw new ClassFormatException("Invalid internal class name");
directoryPath = pathToClass.substring(0, index);
} catch (FileNotFoundException e) {
directoryPath = null;
e.printStackTrace();
} catch (IOException e) {
directoryPath = null;
e.printStackTrace();
@ -73,7 +70,7 @@ public class ClassFileUtil {
if (dis != null)
try {
dis.close();
} catch (IOException e) {
} catch (IOException ignored) {
}
}

View File

@ -2,7 +2,7 @@ package jd.cli.util;
public class VersionUtil {
public static String getJDKVersion(int majorVersion, int minorVersion) {
StringBuffer sb = new StringBuffer(20);
StringBuilder sb = new StringBuilder(20);
if (majorVersion >= 49) {
sb.append(majorVersion - (49 - 5));

View File

@ -17,14 +17,14 @@ import the.bytecode.club.bytecodeviewer.util.EncodeUtils;
public class DiskReader {
public static Random random = new Random();
public static HashMap<String, ArrayList<String>> map = new HashMap<String, ArrayList<String>>();
public static HashMap<String, ArrayList<String>> map = new HashMap<>();
/**
* Used to load from file, allows caching
*/
public synchronized static ArrayList<String> loadArrayList(String fileName,
boolean cache) {
ArrayList<String> array = new ArrayList<String>();
ArrayList<String> array = new ArrayList<>();
if (!map.containsKey(fileName)) {
try {
File file = new File(fileName);
@ -58,7 +58,7 @@ public class DiskReader {
public synchronized static String loadAsString(String fileName) throws Exception {
StringBuilder s = new StringBuilder();
BufferedReader reader = new BufferedReader(new FileReader(new File(fileName)));
BufferedReader reader = new BufferedReader(new FileReader(fileName));
for (String add = reader.readLine(); add != null; add = reader.readLine()) {
s.append(EncodeUtils.unicodeToString(add)).append(System.getProperty("line.separator"));
@ -77,7 +77,7 @@ public class DiskReader {
ArrayList<String> array;
if (!map.containsKey(fileName)) {
array = new ArrayList<String>();
array = new ArrayList<>();
File file = new File(fileName);
BufferedReader reader = new BufferedReader(new FileReader(file));

View File

@ -4,6 +4,7 @@ import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.Arrays;
/**
* This method will save to disk
@ -25,18 +26,18 @@ public class DiskWriter {
String[] babe = fileName.split("\\.");
int count = 0;
int math = babe.length;
String m = "";
StringBuilder m = new StringBuilder();
for (String s2 : babe) {
m += s2;
m.append(s2);
if (math - 2 == count)
m += difference + ".";
m.append(difference).append(".");
else if (math - 1 != count)
m += ".";
m.append(".");
count++;
}
return m;
return m.toString();
}
/**
@ -58,7 +59,7 @@ public class DiskWriter {
try {
writer = new PrintWriter(new BufferedWriter(new FileWriter(
filename, true)));
writer.println(fileContents);
writer.println(Arrays.toString(fileContents));
if (debug)
System.out.println("Saved " + filename + " to disk");
saved = true;
@ -135,7 +136,7 @@ public class DiskWriter {
try {
writer = new PrintWriter(new BufferedWriter(new FileWriter(
filename, true)));
writer.println(fileContents);
writer.println(Arrays.toString(fileContents));
if (debug)
System.out.println("Saved " + filename + " to disk");
saved = true;

View File

@ -141,7 +141,7 @@ public class HTTPRequest {
try {
setup();
st = new ArrayList<String>();
st = new ArrayList<>();
String s;
while ((s = reader.readLine()) != null)
st.add(s);
@ -154,7 +154,7 @@ public class HTTPRequest {
cleanup();
}
return st.toArray(new String[st.size()]);
return st.toArray(new String[0]);
}
/**
@ -170,7 +170,7 @@ public class HTTPRequest {
try {
setup();
st = new ArrayList<String>();
st = new ArrayList<>();
for (int i = 0; i < linesToRead; i++) {
String s = reader.readLine();
if (s != null)
@ -185,7 +185,7 @@ public class HTTPRequest {
cleanup();
}
return st.toArray(new String[st.size()]);
return st.toArray(new String[0]);
}
/**
@ -248,15 +248,15 @@ public class HTTPRequest {
private void cleanup() {
try {
reader.close();
} catch (Exception e) {
} catch (Exception ignored) {
}
try {
writer.close();
} catch (Exception e) {
} catch (Exception ignored) {
}
try {
connection.disconnect();
} catch (Exception e) {
} catch (Exception ignored) {
}
reader = null;
writer = null;

View File

@ -2982,7 +2982,7 @@ public class ClassReader {
String methodDescriptor = context.currentMethodDescriptor;
Object[] locals = context.currentFrameLocalTypes;
int numLocal = 0;
if ((context.currentMethodAccessFlags & OpcodesC_STATIC) == 0) {
if ((context.currentMethodAccessFlags & Opcodes.ACC_STATIC) == 0) {
if ("<init>".equals(context.currentMethodName)) {
locals[numLocal++] = Opcodes.UNINITIALIZED_THIS;
} else {
@ -3093,7 +3093,7 @@ public class ClassReader {
currentOffset, context.currentFrameStackTypes, 0, charBuffer, labels);
context.currentFrameType = Opcodes.F_SAME1;
context.currentFrameStackCount = 1;
} else if (frameType >= Frame.CHOP_FRAME && frameType < Frame.SAME_FRAME_EXTENDED) {
} else if (frameType < Frame.SAME_FRAME_EXTENDED) {
context.currentFrameType = Opcodes.F_CHOP;
context.currentFrameLocalCountDelta = Frame.SAME_FRAME_EXTENDED - frameType;
context.currentFrameLocalCount -= context.currentFrameLocalCountDelta;
@ -3261,7 +3261,7 @@ public class ClassReader {
private int[] readBootstrapMethodsAttribute(final int maxStringLength) {
char[] charBuffer = new char[maxStringLength];
int currentAttributeOffset = getFirstAttributeOffset();
int[] currentBootstrapMethodOffsets = null;
int[] currentBootstrapMethodOffsets;
for (int i = readUnsignedShort(currentAttributeOffset - 2); i > 0; --i) {
// Read the attribute_info's attribute_name and attribute_length fields.
String attributeName = readUTF8(currentAttributeOffset, charBuffer);

View File

@ -29,7 +29,7 @@ import the.bytecode.club.bootloader.resource.ExternalResource;
public final class AbstractLoaderFactory {
private static final String DEFAULT_KEY = "default-factory";
private static final Map<String, LoaderFactory<?>> FACTORYCACHE = new HashMap<String, LoaderFactory<?>>();
private static final Map<String, LoaderFactory<?>> FACTORY_CACHE = new HashMap<>();
public static void register(LoaderFactory<?> factory) {
register(DEFAULT_KEY, factory);
@ -40,11 +40,11 @@ public final class AbstractLoaderFactory {
throw new IllegalArgumentException("null key or factory");
}
if (FACTORYCACHE.containsKey(key)) {
if (FACTORY_CACHE.containsKey(key)) {
throw new IllegalArgumentException("factory already registered with key: " + key);
}
FACTORYCACHE.put(key, factory);
FACTORY_CACHE.put(key, factory);
}
public static void unregister(String key) {
@ -52,11 +52,11 @@ public final class AbstractLoaderFactory {
throw new IllegalArgumentException("null key");
}
if (!FACTORYCACHE.containsKey(key)) {
if (!FACTORY_CACHE.containsKey(key)) {
throw new IllegalArgumentException("factory doesn't key for key: " + key);
}
FACTORYCACHE.remove(key);
FACTORY_CACHE.remove(key);
}
public static <T extends ExternalResource<?>> LoaderFactory<T> find() {
@ -69,10 +69,10 @@ public final class AbstractLoaderFactory {
throw new IllegalArgumentException("null key");
}
if (!FACTORYCACHE.containsKey(key)) {
if (!FACTORY_CACHE.containsKey(key)) {
throw new IllegalArgumentException("factory doesn't key for key: " + key);
}
return (LoaderFactory<T>) FACTORYCACHE.get(key);
return (LoaderFactory<T>) FACTORY_CACHE.get(key);
}
}

View File

@ -6,6 +6,7 @@ import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import me.konloch.kontainer.io.HTTPRequest;
@ -47,9 +48,9 @@ public class Boot {
public static boolean downloading = false;
private static InitialBootScreen screen;
private static final List<String> libsList = new ArrayList<String>();
private static final List<String> libsFileList = new ArrayList<String>();
private static final List<String> urlList = new ArrayList<String>();
private static final List<String> libsList = new ArrayList<>();
private static final List<String> libsFileList = new ArrayList<>();
private static final List<String> urlList = new ArrayList<>();
static {
try {
@ -64,30 +65,15 @@ public class Boot {
ILoader<?> loader = findLoader();
if (!CLI)
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
screen.setVisible(true);
}
});
SwingUtilities.invokeLater(() -> screen.setVisible(true));
create(loader, args.length > 0 ? Boolean.valueOf(args[0]) : true);
create(loader, args.length <= 0 || Boolean.parseBoolean(args[0]));
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
screen.setVisible(false);
}
});
SwingUtilities.invokeLater(() -> screen.setVisible(false));
}
public static void hide() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
screen.setVisible(false);
}
});
SwingUtilities.invokeLater(() -> screen.setVisible(false));
}
@SuppressWarnings({"rawtypes", "unchecked"})
@ -244,7 +230,7 @@ public class Boot {
System.out.println("Loading library " + f.getName());
try {
ExternalResource res = new EmptyExternalResource<Object>(f.toURI().toURL());
ExternalResource res = new EmptyExternalResource<>(f.toURI().toURL());
loader.bind(res);
System.out.println("Succesfully loaded " + f.getName());
} catch (Exception e) {
@ -294,12 +280,7 @@ public class Boot {
}
private static void bootstrap() {
AbstractLoaderFactory.register(new LoaderFactory<Object>() {
@Override
public ILoader<Object> spawnLoader() {
return new ClassPathLoader();
}
});
AbstractLoaderFactory.register(ClassPathLoader::new);
}
public static void populateUrlList() throws Exception {
@ -312,8 +293,9 @@ public class Boot {
}
public static void populateLibsDirectory() {
if (libsDir() != null && libsDir().exists())
for (File f : libsDir().listFiles()) {
File libsDir = libsDir();
if (libsDir.exists())
for (File f : Objects.requireNonNull(libsDir.listFiles())) {
libsList.add(f.getName());
libsFileList.add(f.getAbsolutePath());
}
@ -340,9 +322,9 @@ public class Boot {
BytecodeViewer.class.getClassLoader().getResourceAsStream("Krakatau-" + BytecodeViewer.krakatauVersion + ".zip");
FileOutputStream baos = new FileOutputStream(temp);
int r = 0;
int r;
byte[] buffer = new byte[8192];
while ((r = is.read(buffer)) >= 0) {
while ((r = Objects.requireNonNull(is).read(buffer)) >= 0) {
baos.write(buffer, 0, r);
}
@ -377,9 +359,9 @@ public class Boot {
BytecodeViewer.class.getClassLoader().getResourceAsStream("enjarify-" + BytecodeViewer.enjarifyVersion + ".zip");
FileOutputStream baos = new FileOutputStream(temp);
int r = 0;
int r;
byte[] buffer = new byte[8192];
while ((r = is.read(buffer)) >= 0) {
while ((r = Objects.requireNonNull(is).read(buffer)) >= 0) {
baos.write(buffer, 0, r);
}
@ -472,14 +454,14 @@ public class Boot {
setState("Bytecode Viewer Boot Screen - Checking Enjarify...");
System.out.println("Checking enjarify");
File enjarifyZip = null;
for (File f : new File(BytecodeViewer.libsDirectory).listFiles()) {
for (File f : Objects.requireNonNull(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()) {
for (File f : Objects.requireNonNull(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());
@ -498,14 +480,15 @@ public class Boot {
if (!enjarifyDirectory.exists()) {
try {
setState("Bytecode Viewer Boot Screen - Updating to " + enjarifyDirectory.getName() + "...");
ZipUtils.unzipFilesToPath(enjarifyZip.getAbsolutePath(), enjarifyDirectory.getAbsolutePath());
ZipUtils.unzipFilesToPath(Objects.requireNonNull(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();
Objects.requireNonNull(enjarifyZip).delete();
}
}
@ -516,7 +499,7 @@ public class Boot {
System.out.println("Checking krakatau");
File krakatauZip = null;
for (File f : new File(BytecodeViewer.libsDirectory).listFiles()) {
for (File f : Objects.requireNonNull(new File(BytecodeViewer.libsDirectory).listFiles())) {
if (f.getName().toLowerCase().startsWith("krakatau-")) {
//System.out.println(f.getName());
BytecodeViewer.krakatauVersion = f.getName().split("-")[1].split("\\.")[0];
@ -524,7 +507,7 @@ public class Boot {
}
}
for (File f : new File(BytecodeViewer.getBCVDirectory()).listFiles()) {
for (File f : Objects.requireNonNull(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());
@ -544,14 +527,15 @@ public class Boot {
if (!krakatauDirectory.exists()) {
try {
setState("Bytecode Viewer Boot Screen - Updating to " + krakatauDirectory.getName() + "...");
ZipUtils.unzipFilesToPath(krakatauZip.getAbsolutePath(), krakatauDirectory.getAbsolutePath());
ZipUtils.unzipFilesToPath(Objects.requireNonNull(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();
Objects.requireNonNull(krakatauZip).delete();
}
}
}

View File

@ -45,8 +45,8 @@ public class LibraryClassLoader extends ClassLoader implements ILoader<JarConten
private final ClassTree tree;
public LibraryClassLoader() {
binded = new HashSet<JarContents<ClassNode>>();
classCache = new HashMap<String, Class<?>>();
binded = new HashSet<>();
classCache = new HashMap<>();
tree = new ClassTree();
}
@ -103,7 +103,7 @@ public class LibraryClassLoader extends ClassLoader implements ILoader<JarConten
return defineClass(bytes, 0, bytes.length);
}
public class ResolvingClassWriter extends ClassWriter {
public static class ResolvingClassWriter extends ClassWriter {
private final ClassTree classTree;

View File

@ -81,7 +81,7 @@ public class ExternalLibrary extends ExternalResource<JarContents<ClassNode>> {
*/
@Override
public JarContents<ClassNode> load() throws IOException {
JarContents<ClassNode> contents = new JarContents<ClassNode>();
JarContents<ClassNode> contents = new JarContents<>();
JarURLConnection con = (JarURLConnection) getLocation().openConnection();
JarFile jar = con.getJarFile();

View File

@ -45,7 +45,7 @@ public abstract class ExternalResource<T> {
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((location == null) ? 0 : location.hashCode());
result = prime * result + location.hashCode();
return result;
}
@ -58,9 +58,7 @@ public abstract class ExternalResource<T> {
if (getClass() != obj.getClass())
return false;
ExternalResource<?> other = (ExternalResource<?>) obj;
if (location == null) {
return other.location == null;
} else return location.equals(other.location);
return location.equals(other.location);
}
@Override

View File

@ -36,12 +36,12 @@ public class JarContents<C extends ClassNode> {
private final DataContainer<JarResource> resourceContents;
public JarContents() {
classContents = new ClassNodeContainer<C>();
classContents = new ClassNodeContainer<>();
resourceContents = new ResourceContainer();
}
public JarContents(DataContainer<C> classContents, DataContainer<JarResource> resourceContents) {
this.classContents = classContents == null ? new ClassNodeContainer<C>() : classContents;
this.classContents = classContents == null ? new ClassNodeContainer<>() : classContents;
this.resourceContents = resourceContents == null ? new ResourceContainer() : resourceContents;
}
@ -65,21 +65,21 @@ public class JarContents<C extends ClassNode> {
List<JarResource> r1 = resourceContents;
List<JarResource> r2 = contents.resourceContents;
List<C> c3 = new ArrayList<C>(c1.size() + c2.size());
List<C> c3 = new ArrayList<>(c1.size() + c2.size());
c3.addAll(c1);
c3.addAll(c2);
List<JarResource> r3 = new ArrayList<JarResource>(r1.size() + r2.size());
List<JarResource> r3 = new ArrayList<>(r1.size() + r2.size());
r3.addAll(r1);
r3.addAll(r2);
return new JarContents<C>(new ClassNodeContainer<>(c3), new ResourceContainer(r3));
return new JarContents<>(new ClassNodeContainer<>(c3), new ResourceContainer(r3));
}
public static class ClassNodeContainer<C extends ClassNode> extends DataContainer<C> {
private static final long serialVersionUID = -6169578803641192235L;
private Map<String, C> lastMap = new HashMap<String, C>();
private Map<String, C> lastMap = new HashMap<>();
private boolean invalidated;
public ClassNodeContainer() {
@ -116,7 +116,7 @@ public class JarContents<C extends ClassNode> {
public Map<String, C> namedMap() {
if (invalidated) {
invalidated = false;
Map<String, C> nodeMap = new HashMap<String, C>();
Map<String, C> nodeMap = new HashMap<>();
Iterator<C> it = iterator();
while (it.hasNext()) {
C cn = it.next();
@ -149,7 +149,7 @@ public class JarContents<C extends ClassNode> {
@Override
public Map<String, JarResource> namedMap() {
Map<String, JarResource> map = new HashMap<String, JarResource>();
Map<String, JarResource> map = new HashMap<>();
for (JarResource resource : this) {
map.put(resource.getName(), resource);
}

View File

@ -8,6 +8,7 @@ import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;
public class Base64 {
@ -122,14 +123,14 @@ public class Base64 {
public static class Encoder {
private final byte[] newline;
private final int linemax;
private final int line_max;
private final boolean isURL;
private final boolean doPadding;
private Encoder(boolean isURL, byte[] newline, int linemax, boolean doPadding) {
private Encoder(boolean isURL, byte[] newline, int line_max, boolean doPadding) {
this.isURL = isURL;
this.newline = newline;
this.linemax = linemax;
this.line_max = line_max;
this.doPadding = doPadding;
}
@ -166,16 +167,16 @@ public class Base64 {
static final Encoder RFC4648_URLSAFE = new Encoder(true, null, -1, true);
static final Encoder RFC2045 = new Encoder(false, CRLF, MIMELINEMAX, true);
private final int outLength(int srclen) {
int len = 0;
private int outLength(int srclen) {
int len;
if (doPadding) {
len = 4 * ((srclen + 2) / 3);
} else {
int n = srclen % 3;
len = 4 * (srclen / 3) + (n == 0 ? 0 : n + 1);
}
if (linemax > 0) // line separators
len += (len - 1) / linemax * newline.length;
if (line_max > 0) // line separators
len += (len - 1) / line_max * newline.length;
return len;
}
@ -259,7 +260,7 @@ public class Base64 {
public ByteBuffer encode(ByteBuffer buffer) {
int len = outLength(buffer.remaining());
byte[] dst = new byte[len];
int ret = 0;
int ret;
if (buffer.hasArray()) {
ret = encode0(buffer.array(),
buffer.arrayOffset() + buffer.position(),
@ -292,7 +293,7 @@ public class Base64 {
public OutputStream wrap(OutputStream os) {
Objects.requireNonNull(os);
return new EncOutputStream(os, isURL ? toBase64URL : toBase64,
newline, linemax, doPadding);
newline, line_max, doPadding);
}
/**
@ -310,7 +311,7 @@ public class Base64 {
public Encoder withoutPadding() {
if (!doPadding)
return this;
return new Encoder(isURL, newline, linemax, false);
return new Encoder(isURL, newline, line_max, false);
}
private int encode0(byte[] src, int off, int end, byte[] dst) {
@ -318,8 +319,8 @@ public class Base64 {
int sp = off;
int slen = (end - off) / 3 * 3;
int sl = off + slen;
if (linemax > 0 && slen > linemax / 4 * 3)
slen = linemax / 4 * 3;
if (line_max > 0 && slen > line_max / 4 * 3)
slen = line_max / 4 * 3;
int dp = 0;
while (sp < sl) {
int sl0 = Math.min(sp + slen, sl);
@ -335,7 +336,7 @@ public class Base64 {
int dlen = (sl0 - sp) / 3 * 4;
dp += dlen;
sp = sl0;
if (dlen == linemax && sp < end) {
if (dlen == line_max && sp < end) {
for (byte b : newline) {
dst[dp++] = b;
}
@ -351,7 +352,7 @@ public class Base64 {
dst[dp++] = '=';
}
} else {
int b1 = src[sp++] & 0xff;
int b1 = src[sp] & 0xff;
dst[dp++] = (byte) base64[(b0 << 4) & 0x3f | (b1 >> 4)];
dst[dp++] = (byte) base64[(b1 << 2) & 0x3f];
if (doPadding) {
@ -575,7 +576,7 @@ public class Base64 {
len -= (sl - sp + 1);
break;
}
if ((b = base64[b]) == -1)
if (base64[b] == -1)
n++;
}
len -= n;
@ -658,21 +659,22 @@ public class Base64 {
private static class EncOutputStream extends FilterOutputStream {
private int leftover = 0;
private int b0, b1, b2;
private int b0;
private int b1;
private boolean closed = false;
private final char[] base64; // byte->base64 mapping
private final byte[] newline; // line separator, if needed
private final int linemax;
private final int line_max;
private final boolean doPadding;// whether or not to pad
private int linepos = 0;
EncOutputStream(OutputStream os, char[] base64,
byte[] newline, int linemax, boolean doPadding) {
byte[] newline, int line_max, boolean doPadding) {
super(os);
this.base64 = base64;
this.newline = newline;
this.linemax = linemax;
this.line_max = line_max;
this.doPadding = doPadding;
}
@ -684,14 +686,14 @@ public class Base64 {
}
private void checkNewline() throws IOException {
if (linepos == linemax) {
if (linepos == line_max) {
out.write(newline);
linepos = 0;
}
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
public void write(byte @NotNull [] b, int off, int len) throws IOException {
if (closed)
throw new IOException("Stream is closed");
if (off < 0 || len < 0 || off + len > b.length)
@ -707,7 +709,7 @@ public class Base64 {
return;
}
}
b2 = b[off++] & 0xff;
int b2 = b[off++] & 0xff;
len--;
checkNewline();
out.write(base64[b0 >> 2]);
@ -730,10 +732,10 @@ public class Base64 {
linepos += 4;
}
if (leftover == 1) {
b0 = b[off++] & 0xff;
b0 = b[off] & 0xff;
} else if (leftover == 2) {
b0 = b[off++] & 0xff;
b1 = b[off++] & 0xff;
b1 = b[off] & 0xff;
}
}
@ -794,7 +796,7 @@ public class Base64 {
}
@Override
public int read(byte[] b, int off, int len) throws IOException {
public int read(byte @NotNull [] b, int off, int len) throws IOException {
if (closed)
throw new IOException("Stream is closed");
if (eof && nextout < 0) // eof and no leftover

View File

@ -31,7 +31,7 @@ import org.objectweb.asm.tree.ClassNode;
public class ClassHelper {
public static Map<String, ClassNode> convertToMap(Collection<ClassNode> classes) {
Map<String, ClassNode> map = new HashMap<String, ClassNode>();
Map<String, ClassNode> map = new HashMap<>();
for (ClassNode cn : classes) {
map.put(cn.name, cn);
}
@ -39,7 +39,7 @@ public class ClassHelper {
}
public static <T, K> Map<T, K> copyOf(Map<T, K> src) {
Map<T, K> dst = new HashMap<T, K>();
Map<T, K> dst = new HashMap<>();
copy(src, dst);
return dst;
}

View File

@ -35,16 +35,16 @@ import static the.bytecode.club.bootloader.util.ClassHelper.copyOf;
* @created 25 May 2015 (actually before this)
*/
public class ClassTree {
private static final SetCreator<ClassNode> SET_CREATOR = new SetCreator<ClassNode>();
private static final SetCreator<ClassNode> SET_CREATOR = new SetCreator<>();
private final Map<String, ClassNode> classes;
private final NullPermeableHashMap<ClassNode, Set<ClassNode>> supers;
private final NullPermeableHashMap<ClassNode, Set<ClassNode>> delgates;
public ClassTree() {
classes = new HashMap<String, ClassNode>();
supers = new NullPermeableHashMap<ClassNode, Set<ClassNode>>(SET_CREATOR);
delgates = new NullPermeableHashMap<ClassNode, Set<ClassNode>>(SET_CREATOR);
classes = new HashMap<>();
supers = new NullPermeableHashMap<>(SET_CREATOR);
delgates = new NullPermeableHashMap<>(SET_CREATOR);
}
public ClassTree(Collection<ClassNode> classes) {
@ -53,8 +53,8 @@ public class ClassTree {
public ClassTree(Map<String, ClassNode> classes_) {
classes = copyOf(classes_);
supers = new NullPermeableHashMap<ClassNode, Set<ClassNode>>(SET_CREATOR);
delgates = new NullPermeableHashMap<ClassNode, Set<ClassNode>>(SET_CREATOR);
supers = new NullPermeableHashMap<>(SET_CREATOR);
delgates = new NullPermeableHashMap<>(SET_CREATOR);
build(classes);
}
@ -69,7 +69,7 @@ public class ClassTree {
getDelegates0(ifacecs).add(node);
Set<ClassNode> superinterfaces = new HashSet<ClassNode>();
Set<ClassNode> superinterfaces = new HashSet<>();
buildSubTree(classes, superinterfaces, ifacecs);
getSupers0(node).addAll(superinterfaces);
@ -83,7 +83,7 @@ public class ClassTree {
if (ifacecs == null)
continue;
getDelegates0(ifacecs).add(currentSuper);
Set<ClassNode> superinterfaces = new HashSet<ClassNode>();
Set<ClassNode> superinterfaces = new HashSet<>();
buildSubTree(classes, superinterfaces, ifacecs);
getSupers0(currentSuper).addAll(superinterfaces);
getSupers0(node).addAll(superinterfaces);
@ -104,7 +104,7 @@ public class ClassTree {
getDelegates0(ifacecs).add(node);
Set<ClassNode> superinterfaces = new HashSet<ClassNode>();
Set<ClassNode> superinterfaces = new HashSet<>();
buildSubTree(classes, superinterfaces, ifacecs);
getSupers0(node).addAll(superinterfaces);
@ -118,7 +118,7 @@ public class ClassTree {
if (ifacecs == null)
continue;
getDelegates0(ifacecs).add(currentSuper);
Set<ClassNode> superinterfaces = new HashSet<ClassNode>();
Set<ClassNode> superinterfaces = new HashSet<>();
buildSubTree(classes, superinterfaces, ifacecs);
getSupers0(currentSuper).addAll(superinterfaces);
getSupers0(node).addAll(superinterfaces);
@ -140,14 +140,14 @@ public class ClassTree {
if (cs != null) {
getDelegates0(cs).add(current);
buildSubTree(classes, superinterfaces, cs);
} else {
// System.out.println("Null interface -> " + iface);
}
} /*else {
System.out.println("Null interface -> " + iface);
}*/
}
}
public Set<MethodNode> getMethodsFromSuper(ClassNode node, String name, String desc) {
Set<MethodNode> methods = new HashSet<MethodNode>();
Set<MethodNode> methods = new HashSet<>();
for (ClassNode super_ : getSupers(node)) {
for (MethodNode mn : super_.methods) {
if (mn.name.equals(name) && mn.desc.equals(desc)) {
@ -159,7 +159,7 @@ public class ClassTree {
}
public Set<MethodNode> getMethodsFromDelegates(ClassNode node, String name, String desc) {
Set<MethodNode> methods = new HashSet<MethodNode>();
Set<MethodNode> methods = new HashSet<>();
for (ClassNode delegate : getDelegates(node)) {
for (MethodNode mn : delegate.methods) {
if (mn.name.equals(name) && mn.desc.equals(desc)) {

View File

@ -35,7 +35,7 @@ public class NullPermeableHashMap<K, V> extends HashMap<K, V> {
}
public NullPermeableHashMap() {
this(new NullCreator<V>());
this(new NullCreator<>());
}
public V getNonNull(K k) {

View File

@ -29,6 +29,6 @@ public class SetCreator<T> implements ValueCreator<Set<T>> {
@Override
public Set<T> create() {
return new HashSet<T>();
return new HashSet<>();
}
}

View File

@ -4,8 +4,6 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import java.awt.Desktop;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.io.ByteArrayOutputStream;
import java.io.File;
@ -21,6 +19,7 @@ import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JMenuItem;
@ -37,6 +36,8 @@ import the.bytecode.club.bootloader.ILoader;
import the.bytecode.club.bootloader.resource.EmptyExternalResource;
import the.bytecode.club.bootloader.resource.ExternalResource;
import the.bytecode.club.bytecodeviewer.api.ClassNodeLoader;
import the.bytecode.club.bytecodeviewer.api.ExceptionUI;
import the.bytecode.club.bytecodeviewer.compilers.Compilers;
import the.bytecode.club.bytecodeviewer.gui.ClassViewer;
import the.bytecode.club.bytecodeviewer.gui.FileNavigationPane;
import the.bytecode.club.bytecodeviewer.gui.MainViewerGUI;
@ -117,7 +118,7 @@ import the.bytecode.club.bytecodeviewer.util.MiscUtils;
public class BytecodeViewer {
/*per version*/
public static final String VERSION = "2.9.23";
public static final String VERSION = "2.10.0";
public static String krakatauVersion = "12";
public static String enjarifyVersion = "4";
public static final boolean BLOCK_TAB_MENU = true;
@ -142,12 +143,11 @@ public class BytecodeViewer {
public static String java = "";
private static File krakatauTempDir;
private static File krakatauTempJar;
public static int krakatauHash;
public static boolean displayParentInTab = false; //also change in the main GUI
public static boolean currentlyDumping = false;
public static boolean needsReDump = true;
public static boolean warnForEditing = false;
public static List<FileContainer> files = new ArrayList<FileContainer>(); //all of BCV's loaded files/classes/etc
public static List<FileContainer> files = new ArrayList<>(); //all of BCV's loaded files/classes/etc
private static final int maxRecentFiles = 25;
public static String fs = System.getProperty("file.separator");
public static String nl = System.getProperty("line.separator");
@ -164,7 +164,7 @@ public class BytecodeViewer {
public static boolean runningObfuscation = false;
private static final long start = System.currentTimeMillis();
public static String lastDirectory = ".";
public static List<Process> createdProcesses = new ArrayList<Process>();
public static List<Process> createdProcesses = new ArrayList<>();
public static Refactorer refactorer = new Refactorer();
public static boolean pingback = false;
public static boolean deleteForeignLibraries = true;
@ -196,9 +196,7 @@ public class BytecodeViewer {
/**
* The version checker thread
*/
private static final Thread versionChecker = new Thread() {
@Override
public void run() {
private static final Thread versionChecker = new Thread(() -> {
try {
HTTPRequest r = new HTTPRequest(new URL("https://raw.githubusercontent"
+ ".com/Konloch/bytecode-viewer/master/VERSION"));
@ -208,7 +206,7 @@ public class BytecodeViewer {
int simplemaths2 = Integer.parseInt(BytecodeViewer.VERSION.replace(".", ""));
if (simplemaths2 > simplemaths)
return; //developer version
} catch (Exception e) {
} catch (Exception ignored) {
}
@ -243,7 +241,7 @@ public class BytecodeViewer {
try {
fc.setCurrentDirectory(new File(".").getAbsoluteFile()); //set the current working directory
} catch (Exception e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
new ExceptionUI(e);
}
fc.setFileFilter(new FileFilter() {
@Override
@ -284,9 +282,7 @@ public class BytecodeViewer {
}
final File finalFile = file;
Thread downloadThread = new Thread() {
@Override
public void run() {
Thread downloadThread = new Thread(() -> {
try {
InputStream is = new URL("https://github.com/Konloch/bytecode-viewer/releases"
+ "/download/v" + version + "/BytecodeViewer." + version + ".zip").openConnection().getInputStream();
@ -320,22 +316,22 @@ public class BytecodeViewer {
is.close();
}
} finally {
if (fos != null) {
fos.flush();
fos.close();
}
}
}
System.out.println("Download finished!");
showMessage("Download successful! You can find the updated program at " + finalFile.getAbsolutePath());
} catch (FileNotFoundException e) {
try {
InputStream is = new URL("https://github.com/Konloch/bytecode-viewer"
+ "/releases/download/v" + version + "/BytecodeViewer." + version + ".jar").openConnection().getInputStream();
+ "/releases/download/v" + version + "/BytecodeViewer." + version + ".jar"
).openConnection().getInputStream();
FileOutputStream fos = new FileOutputStream(finalFile);
try {
System.out.println("Downloading from https://github"
+ ".com/Konloch/bytecode-viewer/releases/download/v" + version + "/BytecodeViewer." + version + ".jar");
+ ".com/Konloch/bytecode-viewer/releases/download/v" + version +
"/BytecodeViewer." + version + ".jar");
byte[] buffer = new byte[8192];
int len;
int downloaded = 0;
@ -360,27 +356,24 @@ public class BytecodeViewer {
is.close();
}
} finally {
if (fos != null) {
fos.flush();
fos.close();
}
}
}
System.out.println("Download finished!");
showMessage("Download successful! You can find the updated program at " + finalFile.getAbsolutePath());
} catch (FileNotFoundException ex) {
showMessage("Unable to download, the zip file has not been uploaded yet, "
+ "please try again in about 10 minutes.");
} catch (Exception ex) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(ex);
new ExceptionUI(ex);
}
} catch (Exception e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
new ExceptionUI(e);
}
}
};
});
downloadThread.start();
}
}
@ -388,29 +381,23 @@ public class BytecodeViewer {
} catch (Exception e) {
e.printStackTrace();
}
}
};
});
/**
* Pings back to bytecodeviewer.com to be added into the total running statistics
*/
private static final Thread PingBack = new Thread() {
@Override
public void run() {
private static final Thread PingBack = new Thread(() -> {
try {
new HTTPRequest(new URL("https://bytecodeviewer.com/add.php")).read();
} catch (Exception e) {
pingback = false;
}
}
};
});
/**
* Downloads & installs the krakatau & enjarify zips
*/
private static final Thread InstallFatJar = new Thread() {
@Override
public void run() {
private static final Thread InstallFatJar = new Thread(() -> {
try {
if (BytecodeViewer.OFFLINE_MODE) {
Boot.dropKrakatau();
@ -425,8 +412,7 @@ public class BytecodeViewer {
} catch (Exception e) {
e.printStackTrace();
}
}
};
});
/**
* Used to check incase booting failed for some reason, this kicks in as a fail safe
@ -434,6 +420,7 @@ public class BytecodeViewer {
private static final Thread bootCheck = new Thread() {
boolean finished = false;
@Override
@SuppressWarnings({"rawtypes", "unchecked"})
public void run() {
long start = System.currentTimeMillis();
@ -441,11 +428,13 @@ public class BytecodeViewer {
while (!finished) {
if (System.currentTimeMillis() - start >= 7000) { //7 second failsafe
if (!Boot.completedboot && !Boot.downloading) {
if (Boot.libsDir() == null || Boot.libsDir().listFiles() == null || Boot.libsDir().listFiles().length <= 0) {
File libsDir = Boot.libsDir();
File[] listFiles = libsDir.listFiles();
if (listFiles == null || listFiles.length <= 0) {
BytecodeViewer.showMessage(
"Github is loading extremely slow, BCV needs to download libraries from github in"
+ " order" + nl +
"to work, please try ajusting your network settings or manually "
"to work, please try adjusting your network settings or manually "
+ "downloading these libraries" + nl +
"if this error persists.");
finished = true;
@ -455,11 +444,8 @@ public class BytecodeViewer {
Boot.setState("Bytecode Viewer Boot Screen (OFFLINE MODE) - Unable to connect to github, "
+ "force booting...");
System.out.println("Unable to connect to github, force booting...");
List<String> libsList = new ArrayList<String>();
List<String> libsFileList = new ArrayList<String>();
if (Boot.libsDir() != null)
for (File f : Boot.libsDir().listFiles()) {
libsList.add(f.getName());
List<String> libsFileList = new ArrayList<>();
for (File f : listFiles) {
libsFileList.add(f.getAbsolutePath());
}
@ -474,9 +460,9 @@ public class BytecodeViewer {
System.out.println("Force loading library " + f.getName());
try {
ExternalResource res = new EmptyExternalResource<Object>(f.toURI().toURL());
ExternalResource res = new EmptyExternalResource<>(f.toURI().toURL());
loader.bind(res);
System.out.println("Succesfully loaded " + f.getName());
System.out.println("Successfully loaded " + f.getName());
} catch (Exception e) {
e.printStackTrace();
f.delete();
@ -505,7 +491,7 @@ public class BytecodeViewer {
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
} catch (InterruptedException ignored) {
}
}
}
@ -521,9 +507,9 @@ public class BytecodeViewer {
public static byte[] getClassFile(Class<?> clazz) throws IOException {
InputStream is = clazz.getResourceAsStream("/" + clazz.getName().replace('.', '/') + ".class");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int r = 0;
int r;
byte[] buffer = new byte[8192];
while ((r = is.read(buffer)) >= 0) {
while ((r = Objects.requireNonNull(is).read(buffer)) >= 0) {
baos.write(buffer, 0, r);
}
return baos.toByteArray();
@ -581,15 +567,12 @@ public class BytecodeViewer {
*/
public static void BOOT(boolean cli) {
cleanup();
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
for (Process proc : createdProcesses)
proc.destroy();
Settings.saveSettings();
cleanup();
}
});
}));
viewer.calledAfterLoad();
resetRecentFilesMenu();
@ -632,9 +615,8 @@ public class BytecodeViewer {
try {
sm.stopBlocking();
ProcessBuilder pb = new ProcessBuilder("java", "-version");
Process p = pb.start();
pb.start();
sm.setBlocking();
if (p != null)
return "java"; //java is set
} catch (Exception e) { //ignore
sm.setBlocking();
@ -728,7 +710,7 @@ public class BytecodeViewer {
* @return the loaded classes as an array list
*/
public static ArrayList<ClassNode> getLoadedClasses() {
ArrayList<ClassNode> a = new ArrayList<ClassNode>();
ArrayList<ClassNode> a = new ArrayList<>();
for (FileContainer container : files)
for (ClassNode c : container.classes)
@ -760,7 +742,7 @@ public class BytecodeViewer {
ClassNode origNode = (ClassNode) smali[0];
String smaliText = (String) smali[1];
byte[] smaliCompiled =
the.bytecode.club.bytecodeviewer.compilers.Compiler.smali.compile(smaliText,
Compilers.smali.compile(smaliText,
origNode.name);
if (smaliCompiled != null) {
try {
@ -788,7 +770,7 @@ public class BytecodeViewer {
ClassNode origNode = (ClassNode) krakatau[0];
String krakatauText = (String) krakatau[1];
byte[] krakatauCompiled =
the.bytecode.club.bytecodeviewer.compilers.Compiler.krakatau.compile(krakatauText,
Compilers.krakatau.compile(krakatauText,
origNode.name);
if (krakatauCompiled != null) {
try {
@ -820,7 +802,7 @@ public class BytecodeViewer {
+ "decompilers cannot produce compilable classes" + nl + nl);
byte[] javaCompiled =
the.bytecode.club.bytecodeviewer.compilers.Compiler.java.compile(javaText,
Compilers.java.compile(javaText,
origNode.name);
if (javaCompiled != null) {
try {
@ -870,9 +852,7 @@ public class BytecodeViewer {
update = true;
needsReDump = true;
Thread t = new Thread() {
@Override
public void run() {
Thread t = new Thread(() -> {
try {
for (final File f : files) {
final String fn = f.getName();
@ -882,9 +862,9 @@ public class BytecodeViewer {
} else {
if (f.isDirectory()) {
FileContainer container = new FileContainer(f);
HashMap<String, byte[]> files = new HashMap<>();
HashMap<String, byte[]> files1 = new HashMap<>();
boolean finished = false;
ArrayList<File> totalFiles = new ArrayList<File>();
ArrayList<File> totalFiles = new ArrayList<>();
totalFiles.add(f);
String dir = f.getAbsolutePath();//f.getAbsolutePath().substring(0, f.getAbsolutePath
// ().length()-f.getName().length());
@ -894,7 +874,7 @@ public class BytecodeViewer {
for (int i = 0; i < totalFiles.size(); i++) {
File child = totalFiles.get(i);
if (child.listFiles() != null)
for (File rocket : child.listFiles())
for (File rocket : Objects.requireNonNull(child.listFiles()))
if (!totalFiles.contains(rocket)) {
totalFiles.add(rocket);
added = true;
@ -908,27 +888,27 @@ public class BytecodeViewer {
).replaceAll("\\\\", "\\/");
files.put(fileName,
files1.put(fileName,
Files.readAllBytes(Paths.get(child.getAbsolutePath())));
}
finished = true;
}
}
container.files = files;
container.files = files1;
BytecodeViewer.files.add(container);
} else {
if (fn.endsWith(".jar") || fn.endsWith(".zip") || fn.endsWith(".war")) {
try {
JarUtils.put(f);
} catch (java.io.IOException z) {
} catch (IOException z) {
try {
JarUtils.put2(f);
} catch (final Exception e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
new ExceptionUI(e);
update = false;
}
} catch (final Exception e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
new ExceptionUI(e);
update = false;
}
@ -949,7 +929,7 @@ public class BytecodeViewer {
update = false;
}
} catch (final Exception e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
new ExceptionUI(e);
update = false;
}
} else if (fn.endsWith(".apk")) {
@ -970,7 +950,7 @@ public class BytecodeViewer {
container.files = JarUtils.loadResources(decodedResources);
}
container.files.putAll(JarUtils.loadResources(tempCopy)); //copy and rename
Objects.requireNonNull(container.files).putAll(JarUtils.loadResources(tempCopy)); //copy and rename
// to prevent unicode filenames
String name = getRandomizedName() + ".jar";
@ -986,7 +966,7 @@ public class BytecodeViewer {
BytecodeViewer.viewer.setIcon(false);
BytecodeViewer.files.add(container);
} catch (final Exception e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
new ExceptionUI(e);
}
return;
} else if (fn.endsWith(".dex")) {
@ -1013,35 +993,34 @@ public class BytecodeViewer {
BytecodeViewer.viewer.setIcon(false);
BytecodeViewer.files.add(container);
} catch (final Exception e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
new ExceptionUI(e);
}
return;
} else {
HashMap<String, byte[]> files = new HashMap<>();
HashMap<String, byte[]> files1 = new HashMap<>();
byte[] bytes = JarUtils.getBytes(new FileInputStream(f));
files.put(f.getName(), bytes);
files1.put(f.getName(), bytes);
FileContainer container = new FileContainer(f);
container.files = files;
container.files = files1;
BytecodeViewer.files.add(container);
}
}
}
}
} catch (final Exception e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
new ExceptionUI(e);
} finally {
BytecodeViewer.viewer.setIcon(false);
if (update)
try {
MainViewerGUI.getComponent(FileNavigationPane.class).updateTree();
} catch (java.lang.NullPointerException e) {
Objects.requireNonNull(MainViewerGUI.getComponent(FileNavigationPane.class)).updateTree();
} catch (NullPointerException ignored) {
}
}
}
};
});
t.start();
}
@ -1098,13 +1077,13 @@ public class BytecodeViewer {
files.clear();
LazyNameUtil.reset();
MainViewerGUI.getComponent(FileNavigationPane.class).resetWorkspace();
MainViewerGUI.getComponent(WorkPane.class).resetWorkspace();
MainViewerGUI.getComponent(SearchingPane.class).resetWorkspace();
Objects.requireNonNull(MainViewerGUI.getComponent(FileNavigationPane.class)).resetWorkspace();
Objects.requireNonNull(MainViewerGUI.getComponent(WorkPane.class)).resetWorkspace();
Objects.requireNonNull(MainViewerGUI.getComponent(SearchingPane.class)).resetWorkspace();
the.bytecode.club.bytecodeviewer.api.BytecodeViewer.getClassNodeLoader().clear();
}
private static final List<String> killList = new ArrayList<String>();
private static final List<String> killList = new ArrayList<>();
/**
* Add the recent file
@ -1133,7 +1112,7 @@ public class BytecodeViewer {
resetRecentFilesMenu();
}
private static final List<String> killList2 = new ArrayList<String>();
private static final List<String> killList2 = new ArrayList<>();
/**
* Add to the recent plugin list
@ -1170,12 +1149,9 @@ public class BytecodeViewer {
for (String s : recentFiles)
if (!s.isEmpty()) {
JMenuItem m = new JMenuItem(s);
m.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JMenuItem m = (JMenuItem) e.getSource();
openFiles(new File[]{new File(m.getText())}, true);
}
m.addActionListener(e -> {
JMenuItem m12 = (JMenuItem) e.getSource();
openFiles(new File[]{new File(m12.getText())}, true);
});
viewer.mnRecentFiles.add(m);
}
@ -1183,35 +1159,30 @@ public class BytecodeViewer {
for (String s : recentPlugins)
if (!s.isEmpty()) {
JMenuItem m = new JMenuItem(s);
m.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JMenuItem m = (JMenuItem) e.getSource();
startPlugin(new File(m.getText()));
}
m.addActionListener(e -> {
JMenuItem m1 = (JMenuItem) e.getSource();
startPlugin(new File(m1.getText()));
});
viewer.mnRecentPlugins.add(m);
}
}
private static File tempF = null;
/**
* Clears the temp directory
*/
public static void cleanup() {
tempF = new File(tempDirectory);
File tempF = new File(tempDirectory);
try {
FileUtils.deleteDirectory(tempF);
} catch (Exception e) {
} catch (Exception ignored) {
}
while (!tempF.exists()) // keep making dirs
tempF.mkdir();
}
public static List<String> createdRandomizedNames = new ArrayList<String>();
public static List<String> createdRandomizedNames = new ArrayList<>();
/**
* Ensures it will only return a uniquely generated names, contains a dupe checker to be sure
@ -1298,7 +1269,7 @@ public class BytecodeViewer {
JFileChooser fc = new JFileChooser();
try {
fc.setSelectedFile(new File(BytecodeViewer.lastDirectory));
} catch (Exception e2) {
} catch (Exception ignored) {
}
fc.setFileFilter(new FileFilter() {
@ -1308,12 +1279,10 @@ public class BytecodeViewer {
return true;
String extension = MiscUtils.extension(f.getAbsolutePath());
if (extension != null)
return extension.equals("jar") || extension.equals("zip")
|| extension.equals("class") || extension.equals("apk")
|| extension.equals("dex");
return false;
}
@Override
@ -1340,11 +1309,7 @@ public class BytecodeViewer {
BytecodeViewer.resetWorkSpace(true);
} else if ((e.getKeyCode() == KeyEvent.VK_T) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) {
last = System.currentTimeMillis();
Thread t = new Thread() {
public void run() {
BytecodeViewer.compile(true);
}
};
Thread t = new Thread(() -> BytecodeViewer.compile(true));
t.start();
} else if ((e.getKeyCode() == KeyEvent.VK_R) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) {
last = System.currentTimeMillis();
@ -1361,8 +1326,7 @@ public class BytecodeViewer {
return;
}
Thread t = new Thread() {
public void run() {
Thread t = new Thread(() -> {
if (viewer.compileOnSave.isSelected() && !BytecodeViewer.compile(false))
return;
JFileChooser fc = new JFileChooser();
@ -1409,18 +1373,14 @@ public class BytecodeViewer {
final File file2 = file;
BytecodeViewer.viewer.setIcon(true);
Thread t = new Thread() {
@Override
public void run() {
Thread t1 = new Thread(() -> {
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(),
file2.getAbsolutePath());
BytecodeViewer.viewer.setIcon(false);
});
t1.start();
}
};
t.start();
}
}
};
});
t.start();
} else if ((e.getKeyCode() == KeyEvent.VK_W) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) {
last = System.currentTimeMillis();
@ -1462,6 +1422,7 @@ public class BytecodeViewer {
files[1] = krakatauTempDir;
return files;
}
}
currentlyDumping = true;
needsReDump = false;
@ -1469,24 +1430,12 @@ public class BytecodeViewer {
new File(BytecodeViewer.tempDirectory + BytecodeViewer.fs + MiscUtils.randomString(32) + BytecodeViewer.fs);
krakatauTempDir.mkdir();
krakatauTempJar =
new File(BytecodeViewer.tempDirectory + BytecodeViewer.fs + "temp" + MiscUtils.randomString(32) + ".jar");
new File(BytecodeViewer.tempDirectory + BytecodeViewer.fs + "temp" + MiscUtils.randomString(32) +
".jar");
//krakatauTempJar = new File(BytecodeViewer.tempDirectory + BytecodeViewer.fs + "temp" + MiscUtils
// .randomString(32) + ".jar."+container.name);
JarUtils.saveAsJarClassesOnly(container.classes, krakatauTempJar.getAbsolutePath());
currentlyDumping = false;
} else {
currentlyDumping = true;
needsReDump = false;
krakatauTempDir =
new File(BytecodeViewer.tempDirectory + BytecodeViewer.fs + MiscUtils.randomString(32) + BytecodeViewer.fs);
krakatauTempDir.mkdir();
krakatauTempJar =
new File(BytecodeViewer.tempDirectory + BytecodeViewer.fs + "temp" + MiscUtils.randomString(32) + ".jar");
//krakatauTempJar = new File(BytecodeViewer.tempDirectory + BytecodeViewer.fs + "temp" + MiscUtils
// .randomString(32) + ".jar."+container.name);
JarUtils.saveAsJarClassesOnly(container.classes, krakatauTempJar.getAbsolutePath());
currentlyDumping = false;
}
files[0] = krakatauTempJar;
files[1] = krakatauTempDir;

View File

@ -8,7 +8,7 @@ import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.Options;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.tree.ClassNode;
import the.bytecode.club.bytecodeviewer.decompilers.Decompiler;
import the.bytecode.club.bytecodeviewer.decompilers.Decompilers;
import the.bytecode.club.bytecodeviewer.util.JarUtils;
/***************************************************************************
@ -197,12 +197,12 @@ public class CommandLineInput {
Thread.sleep(5 * 1000);
if (target.equalsIgnoreCase("all")) {
Decompiler.procyon.decompileToZip(tempZip.getAbsolutePath(), output.getAbsolutePath());
Decompilers.procyon.decompileToZip(tempZip.getAbsolutePath(), output.getAbsolutePath());
} else {
try {
ClassNode cn = BytecodeViewer.getClassNode(target);
final ClassWriter cw = accept(cn);
String contents = Decompiler.procyon.decompileClassNode(cn, cw.toByteArray());
String contents = Decompilers.procyon.decompileClassNode(cn, cw.toByteArray());
DiskWriter.replaceFile(output.getAbsolutePath(), contents, false);
} catch (Exception e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
@ -215,12 +215,12 @@ public class CommandLineInput {
Thread.sleep(5 * 1000);
if (target.equalsIgnoreCase("all")) {
Decompiler.cfr.decompileToZip(tempZip.getAbsolutePath(), output.getAbsolutePath());
Decompilers.cfr.decompileToZip(tempZip.getAbsolutePath(), output.getAbsolutePath());
} else {
try {
ClassNode cn = BytecodeViewer.getClassNode(target);
final ClassWriter cw = accept(cn);
String contents = Decompiler.cfr.decompileClassNode(cn, cw.toByteArray());
String contents = Decompilers.cfr.decompileClassNode(cn, cw.toByteArray());
DiskWriter.replaceFile(output.getAbsolutePath(), contents, false);
} catch (Exception e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
@ -233,12 +233,12 @@ public class CommandLineInput {
Thread.sleep(5 * 1000);
if (target.equalsIgnoreCase("all")) {
Decompiler.fernflower.decompileToZip(tempZip.getAbsolutePath(), output.getAbsolutePath());
Decompilers.fernflower.decompileToZip(tempZip.getAbsolutePath(), output.getAbsolutePath());
} else {
try {
ClassNode cn = BytecodeViewer.getClassNode(target);
final ClassWriter cw = accept(cn);
String contents = Decompiler.fernflower.decompileClassNode(cn, cw.toByteArray());
String contents = Decompilers.fernflower.decompileClassNode(cn, cw.toByteArray());
DiskWriter.replaceFile(output.getAbsolutePath(), contents, false);
} catch (Exception e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
@ -251,12 +251,12 @@ public class CommandLineInput {
Thread.sleep(5 * 1000);
if (target.equalsIgnoreCase("all")) {
Decompiler.krakatau.decompileToZip(tempZip.getAbsolutePath(), output.getAbsolutePath());
Decompilers.krakatau.decompileToZip(tempZip.getAbsolutePath(), output.getAbsolutePath());
} else {
try {
ClassNode cn = BytecodeViewer.getClassNode(target);
final ClassWriter cw = accept(cn);
String contents = Decompiler.krakatau.decompileClassNode(cn, cw.toByteArray());
String contents = Decompilers.krakatau.decompileClassNode(cn, cw.toByteArray());
DiskWriter.replaceFile(output.getAbsolutePath(), contents, false);
} catch (Exception e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
@ -275,7 +275,7 @@ public class CommandLineInput {
try {
ClassNode cn = BytecodeViewer.getClassNode(target);
final ClassWriter cw = accept(cn);
String contents = Decompiler.krakatauDA.decompileClassNode(cn, cw.toByteArray());
String contents = Decompilers.krakatauDA.decompileClassNode(cn, cw.toByteArray());
DiskWriter.replaceFile(output.getAbsolutePath(), contents, false);
} catch (Exception e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
@ -294,7 +294,7 @@ public class CommandLineInput {
try {
ClassNode cn = BytecodeViewer.getClassNode(target);
final ClassWriter cw = accept(cn);
String contents = Decompiler.jdgui.decompileClassNode(cn, cw.toByteArray());
String contents = Decompilers.jdgui.decompileClassNode(cn, cw.toByteArray());
DiskWriter.replaceFile(output.getAbsolutePath(), contents, false);
} catch (Exception e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
@ -313,7 +313,7 @@ public class CommandLineInput {
try {
ClassNode cn = BytecodeViewer.getClassNode(target);
final ClassWriter cw = accept(cn);
String contents = Decompiler.smali.decompileClassNode(cn, cw.toByteArray());
String contents = Decompilers.smali.decompileClassNode(cn, cw.toByteArray());
DiskWriter.replaceFile(output.getAbsolutePath(), contents, false);
} catch (Exception e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
@ -323,7 +323,7 @@ public class CommandLineInput {
System.out.println("Finished.");
System.out.println("Bytecode Viewer CLI v" + BytecodeViewer.VERSION + " by @Konloch - "
+ "http://bytecodeviewer.com");
+ "https://bytecodeviewer.com");
BytecodeViewer.canExit = true;
System.exit(0);
} catch (Exception e) {
@ -340,7 +340,7 @@ public class CommandLineInput {
try {
Thread.sleep(200);
cn.accept(cw);
} catch (InterruptedException e1) {
} catch (InterruptedException ignored) {
}
}
return cw;

View File

@ -5,6 +5,7 @@ import java.io.ByteArrayInputStream;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import org.apache.commons.codec.binary.Base64;
@ -70,30 +71,30 @@ public class Resources {
prevIcon = new ImageIcon(b642IMG("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAADt3eJSAAAAMFBMVEX"
+
"///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAABnRSTlMANzlYgKhxpRi1AAAATElEQVR42mNgwAZYHIAEExA7qUAYLApMDmCGEwODCojByM/A8FEAyPi/moFh9QewYjCAM1iA+D2KqYwMrIlA6tUGFoa/Z4GMt1hsBgCe1wuKber+SwAAAABJRU5ErkJggg=="));
busyIcon = new ImageIcon(Resources.class.getResource("/1.gif"));
busyIcon = new ImageIcon(Objects.requireNonNull(Resources.class.getResource("/1.gif")));
busyB64Icon = new ImageIcon(b642IMG("R0lGODlhEAALAPQAAP"
+ "///wAAANra2tDQ0Orq6gcHBwAAAC8vL4KCgmFhYbq6uiMjI0tLS4qKimVlZb6+vicnJwUFBU9PT"
+
"+bm5tjY2PT09Dk5Odzc3PLy8ra2tqCgoMrKyu7u7gAAAAAAAAAAACH5BAkLAAAAIf4aQ3JlYXRlZCB3aXRoIGFqYXhsb2FkLmluZm8AIf8LTkVUU0NBUEUyLjADAQAAACwAAAAAEAALAAAFLSAgjmRpnqSgCuLKAq5AEIM4zDVw03ve27ifDgfkEYe04kDIDC5zrtYKRa2WQgAh+QQJCwAAACwAAAAAEAALAAAFJGBhGAVgnqhpHIeRvsDawqns0qeN5+y967tYLyicBYE7EYkYAgAh+QQJCwAAACwAAAAAEAALAAAFNiAgjothLOOIJAkiGgxjpGKiKMkbz7SN6zIawJcDwIK9W/HISxGBzdHTuBNOmcJVCyoUlk7CEAAh+QQJCwAAACwAAAAAEAALAAAFNSAgjqQIRRFUAo3jNGIkSdHqPI8Tz3V55zuaDacDyIQ+YrBH+hWPzJFzOQQaeavWi7oqnVIhACH5BAkLAAAALAAAAAAQAAsAAAUyICCOZGme1rJY5kRRk7hI0mJSVUXJtF3iOl7tltsBZsNfUegjAY3I5sgFY55KqdX1GgIAIfkECQsAAAAsAAAAABAACwAABTcgII5kaZ4kcV2EqLJipmnZhWGXaOOitm2aXQ4g7P2Ct2ER4AMul00kj5g0Al8tADY2y6C+4FIIACH5BAkLAAAALAAAAAAQAAsAAAUvICCOZGme5ERRk6iy7qpyHCVStA3gNa/7txxwlwv2isSacYUc+l4tADQGQ1mvpBAAIfkECQsAAAAsAAAAABAACwAABS8gII5kaZ7kRFGTqLLuqnIcJVK0DeA1r/u3HHCXC/aKxJpxhRz6Xi0ANAZDWa+kEAA7"));
batIcon = new ImageIcon(Resources.class.getResource("/bat.png"));
shIcon = new ImageIcon(Resources.class.getResource("/sh.png"));
csharpIcon = new ImageIcon(Resources.class.getResource("/c#.png"));
cplusplusIcon = new ImageIcon(Resources.class.getResource("/c++.png"));
configIcon = new ImageIcon(Resources.class.getResource("/config.png"));
jarIcon = new ImageIcon(Resources.class.getResource("/jar.png"));
zipIcon = new ImageIcon(Resources.class.getResource("/zip.png"));
packagesIcon = new ImageIcon(Resources.class.getResource("/package.png"));
folderIcon = new ImageIcon(Resources.class.getResource("/folder.png"));
androidIcon = new ImageIcon(Resources.class.getResource("/android.png"));
fileIcon = new ImageIcon(Resources.class.getResource("/file.png"));
textIcon = new ImageIcon(Resources.class.getResource("/text.png"));
classIcon = new ImageIcon(Resources.class.getResource("/class.png"));
imageIcon = new ImageIcon(Resources.class.getResource("/image.png"));
decodedIcon = new ImageIcon(Resources.class.getResource("/decoded.png"));
javaIcon = new ImageIcon(Resources.class.getResource("/java.png"));
batIcon = new ImageIcon(Objects.requireNonNull(Resources.class.getResource("/bat.png")));
shIcon = new ImageIcon(Objects.requireNonNull(Resources.class.getResource("/sh.png")));
csharpIcon = new ImageIcon(Objects.requireNonNull(Resources.class.getResource("/c#.png")));
cplusplusIcon = new ImageIcon(Objects.requireNonNull(Resources.class.getResource("/c++.png")));
configIcon = new ImageIcon(Objects.requireNonNull(Resources.class.getResource("/config.png")));
jarIcon = new ImageIcon(Objects.requireNonNull(Resources.class.getResource("/jar.png")));
zipIcon = new ImageIcon(Objects.requireNonNull(Resources.class.getResource("/zip.png")));
packagesIcon = new ImageIcon(Objects.requireNonNull(Resources.class.getResource("/package.png")));
folderIcon = new ImageIcon(Objects.requireNonNull(Resources.class.getResource("/folder.png")));
androidIcon = new ImageIcon(Objects.requireNonNull(Resources.class.getResource("/android.png")));
fileIcon = new ImageIcon(Objects.requireNonNull(Resources.class.getResource("/file.png")));
textIcon = new ImageIcon(Objects.requireNonNull(Resources.class.getResource("/text.png")));
classIcon = new ImageIcon(Objects.requireNonNull(Resources.class.getResource("/class.png")));
imageIcon = new ImageIcon(Objects.requireNonNull(Resources.class.getResource("/image.png")));
decodedIcon = new ImageIcon(Objects.requireNonNull(Resources.class.getResource("/decoded.png")));
javaIcon = new ImageIcon(Objects.requireNonNull(Resources.class.getResource("/java.png")));
iconList = new ArrayList<BufferedImage>();
iconList = new ArrayList<>();
int size = 16;
for (int i = 0; i < 24; i++) {
iconList.add(resize(icon, size, size));
@ -125,7 +126,7 @@ public class Resources {
}
public static String findLibrary(String nameContains) {
for (File f : new File(BytecodeViewer.libsDirectory).listFiles()) {
for (File f : Objects.requireNonNull(new File(BytecodeViewer.libsDirectory).listFiles())) {
if (f.getName().contains(nameContains))
return f.getAbsolutePath();
}

View File

@ -67,8 +67,10 @@ public class SecurityMan extends SecurityManager {
boolean allow = false;
for (String s : whitelist) {
if (cmd.contains(s))
if (cmd.contains(s)) {
allow = true;
break;
}
}
if (allow && !blocking) {

View File

@ -1,6 +1,5 @@
package the.bytecode.club.bytecodeviewer.api;
import java.util.List;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldInsnNode;
@ -82,9 +81,9 @@ public final class ASMUtil_OLD {
if (newDesc != null)
mi.desc = newDesc;
}
} else {
// System.out.println(i.getOpcode()+":"+c.name+":"+m.name);
}
} /*else {
System.out.println(i.getOpcode()+":"+c.name+":"+m.name);
}*/
}
if (m.signature != null) {
@ -111,18 +110,17 @@ public final class ASMUtil_OLD {
public static void renameClassNode(final String oldName,
final String newName) {
for (ClassNode c : BytecodeViewer.getLoadedClasses()) {
for (Object oo : c.innerClasses) {
InnerClassNode innerClassNode = (InnerClassNode) oo;
if (innerClassNode.innerName != null
&& innerClassNode.innerName.equals(oldName)) {
innerClassNode.innerName = newName;
for (InnerClassNode oo : c.innerClasses) {
if (oo.innerName != null
&& oo.innerName.equals(oldName)) {
oo.innerName = newName;
}
if (innerClassNode.name.equals(oldName)) {
innerClassNode.name = newName;
if (oo.name.equals(oldName)) {
oo.name = newName;
}
if (innerClassNode.outerName != null
&& innerClassNode.outerName.equals(oldName)) {
innerClassNode.outerName = newName;
if (oo.outerName != null
&& oo.outerName.equals(oldName)) {
oo.outerName = newName;
}
}
@ -136,10 +134,6 @@ public final class ASMUtil_OLD {
FieldNode f = (FieldNode) o;
f.desc = f.desc.replace(oldName, newName);
}
for (Object o : c.interfaces.toArray()) {
String truxerLipton = (String) o;
truxerLipton = truxerLipton.replace(oldName, newName);
}
for (Object o : c.methods.toArray()) {
MethodNode m = (MethodNode) o;

View File

@ -9,7 +9,9 @@ import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import org.objectweb.asm.tree.ClassNode;
import the.bytecode.club.bytecodeviewer.compilers.Compilers;
import the.bytecode.club.bytecodeviewer.decompilers.Decompiler;
import the.bytecode.club.bytecodeviewer.decompilers.Decompilers;
import the.bytecode.club.bytecodeviewer.plugin.preinstalled.EZInjection;
import the.bytecode.club.bytecodeviewer.util.JarUtils;
@ -77,7 +79,7 @@ public class BytecodeViewer {
Enumeration<JarEntry> e = jarFile.entries();
URL[] urls = {new URL("jar:file:" + "" + f.getAbsolutePath() + "!/")};
cl = URLClassLoader.newInstance(urls);
List<Class<?>> ret = new ArrayList<Class<?>>();
List<Class<?>> ret = new ArrayList<>();
while (e.hasMoreElements()) {
JarEntry je = e.nextElement();
@ -201,7 +203,7 @@ public class BytecodeViewer {
* @return The wrapped Krakatau Decompiler instance
*/
public static Decompiler getKrakatauDecompiler() {
return Decompiler.krakatau;
return Decompilers.krakatau;
}
/**
@ -210,7 +212,7 @@ public class BytecodeViewer {
* @return The wrapped Procyon Decompiler instance
*/
public static Decompiler getProcyonDecompiler() {
return Decompiler.procyon;
return Decompilers.procyon;
}
/**
@ -219,7 +221,7 @@ public class BytecodeViewer {
* @return The wrapped CFR Decompiler instance
*/
public static Decompiler getCFRDecompiler() {
return Decompiler.cfr;
return Decompilers.cfr;
}
/**
@ -228,7 +230,7 @@ public class BytecodeViewer {
* @return The wrapped FernFlower Decompiler instance
*/
public static Decompiler getFernFlowerDecompiler() {
return Decompiler.fernflower;
return Decompilers.fernflower;
}
/**
@ -237,7 +239,7 @@ public class BytecodeViewer {
* @return The wrapped Krakatau Disassembler instance
*/
public static Decompiler getKrakatauDisassembler() {
return Decompiler.krakatauDA;
return Decompilers.krakatauDA;
}
/**
@ -246,7 +248,7 @@ public class BytecodeViewer {
* @return The wrapped Krakatau Assembler instance
*/
public static the.bytecode.club.bytecodeviewer.compilers.Compiler getKrakatauCompiler() {
return the.bytecode.club.bytecodeviewer.compilers.Compiler.krakatau;
return Compilers.krakatau;
}
/**
@ -255,7 +257,7 @@ public class BytecodeViewer {
* @return The wrapped Smali Assembler instance
*/
public static the.bytecode.club.bytecodeviewer.compilers.Compiler getSmaliCompiler() {
return the.bytecode.club.bytecodeviewer.compilers.Compiler.smali;
return Compilers.smali;
}
/**
@ -264,6 +266,6 @@ public class BytecodeViewer {
* @return The wrapped JD-GUI Decompiler instance
*/
public static the.bytecode.club.bytecodeviewer.decompilers.Decompiler getDJGUIDecompiler() {
return the.bytecode.club.bytecodeviewer.decompilers.Decompiler.jdgui;
return Decompilers.jdgui;
}
}

View File

@ -35,7 +35,7 @@ import org.objectweb.asm.tree.ClassNode;
public final class ClassNodeLoader extends ClassLoader {
private final HashMap<String, ClassNode> classes = new HashMap<String, ClassNode>();
private final HashMap<String, ClassNode> classes = new HashMap<>();
/**
* Adds the provided class node to the class loader
@ -72,7 +72,7 @@ public final class ClassNodeLoader extends ClassLoader {
* @return All classes in this loader
*/
public Collection<Class<?>> getAllClasses() {
ArrayList<Class<?>> classes = new ArrayList<Class<?>>();
ArrayList<Class<?>> classes = new ArrayList<>();
for (String s : this.classes.keySet()) {
try {
classes.add(loadClass(s));

View File

@ -3,8 +3,6 @@ package the.bytecode.club.bytecodeviewer.api;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JButton;
@ -61,6 +59,7 @@ public class PluginConsole extends JFrame {
scrollPane.setViewportView(textArea);
textArea.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent e) {
if ((e.getKeyCode() == KeyEvent.VK_F) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) {
field.requestFocus();
@ -88,18 +87,8 @@ public class PluginConsole extends JFrame {
panel.add(buttonPane, BorderLayout.WEST);
panel.add(field, BorderLayout.CENTER);
panel.add(check, BorderLayout.EAST);
searchNext.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent arg0) {
search(field.getText(), true);
}
});
searchPrev.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent arg0) {
search(field.getText(), false);
}
});
searchNext.addActionListener(arg0 -> search(field.getText(), true));
searchPrev.addActionListener(arg0 -> search(field.getText(), false));
field.addKeyListener(new KeyListener() {
@Override
public void keyReleased(KeyEvent arg0) {
@ -136,7 +125,7 @@ public class PluginConsole extends JFrame {
.getElementIndex(area.getCaretPosition()) + 1;
int currentLine = 1;
boolean canSearch = false;
String[] test = null;
String[] test;
if (area.getText().split("\n").length >= 2)
test = area.getText().split("\n");
else

View File

@ -28,7 +28,4 @@ public abstract class Compiler {
public abstract byte[] compile(String contents, String name);
public static Compiler krakatau = new KrakatauAssembler();
public static Compiler smali = new SmaliAssembler();
public static Compiler java = new JavaCompiler();
}

View File

@ -0,0 +1,7 @@
package the.bytecode.club.bytecodeviewer.compilers;
public class Compilers {
public static Compiler krakatau = new KrakatauAssembler();
public static Compiler smali = new SmaliAssembler();
public static Compiler java = new JavaCompiler();
}

View File

@ -68,7 +68,7 @@ public class JavaCompiler extends Compiler {
boolean cont = true;
BytecodeViewer.sm.stopBlocking();
try {
String log = "";
StringBuilder log = new StringBuilder();
ProcessBuilder pb;
if (BytecodeViewer.library.isEmpty()) {
@ -91,9 +91,7 @@ public class JavaCompiler extends Compiler {
Process process = pb.start();
BytecodeViewer.createdProcesses.add(process);
Thread failSafe = new Thread() {
@Override
public void run() {
Thread failSafe = new Thread(() -> {
long started = System.currentTimeMillis();
while (System.currentTimeMillis() - started <= 10_000) {
try {
@ -107,8 +105,7 @@ public class JavaCompiler extends Compiler {
System.out.println("Force killing javac process, assuming it's gotten stuck");
process.destroyForcibly().destroy();
}
}
};
});
failSafe.start();
int exitValue = process.waitFor();
@ -119,24 +116,24 @@ public class JavaCompiler extends Compiler {
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
log += BytecodeViewer.nl + line;
log.append(BytecodeViewer.nl).append(line);
}
br.close();
log += BytecodeViewer.nl + BytecodeViewer.nl + "Error:" + BytecodeViewer.nl + BytecodeViewer.nl;
log.append(BytecodeViewer.nl).append(BytecodeViewer.nl).append("Error:").append(BytecodeViewer.nl).append(BytecodeViewer.nl);
is = process.getErrorStream();
isr = new InputStreamReader(is);
br = new BufferedReader(isr);
while ((line = br.readLine()) != null) {
log += BytecodeViewer.nl + line;
log.append(BytecodeViewer.nl).append(line);
}
br.close();
log += BytecodeViewer.nl + BytecodeViewer.nl + "Exit Value is " + exitValue;
log.append(BytecodeViewer.nl).append(BytecodeViewer.nl).append("Exit Value is ").append(exitValue);
System.out.println(log);
if (!clazz.exists())
throw new Exception(log);
throw new Exception(log.toString());
} catch (Exception e) {
cont = false;

View File

@ -65,7 +65,7 @@ public class KrakatauAssembler extends Compiler {
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), tempJar.getAbsolutePath());
BytecodeViewer.sm.stopBlocking();
String log = "";
StringBuilder log = new StringBuilder();
try {
ProcessBuilder pb = new ProcessBuilder(
BytecodeViewer.python,
@ -85,30 +85,31 @@ public class KrakatauAssembler extends Compiler {
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
log += BytecodeViewer.nl + line;
log.append(BytecodeViewer.nl).append(line);
}
br.close();
log += BytecodeViewer.nl + BytecodeViewer.nl + "Error:" + BytecodeViewer.nl + BytecodeViewer.nl;
log.append(BytecodeViewer.nl).append(BytecodeViewer.nl).append("Error:").append(BytecodeViewer.nl).append(BytecodeViewer.nl);
is = process.getErrorStream();
isr = new InputStreamReader(is);
br = new BufferedReader(isr);
while ((line = br.readLine()) != null) {
log += BytecodeViewer.nl + line;
log.append(BytecodeViewer.nl).append(line);
}
br.close();
int exitValue = process.waitFor();
log += BytecodeViewer.nl + BytecodeViewer.nl + "Exit Value is " + exitValue;
log.append(BytecodeViewer.nl).append(BytecodeViewer.nl).append("Exit Value is ").append(exitValue);
System.out.println(log);
byte[] b = org.apache.commons.io.FileUtils.readFileToByteArray(new File(tempDirectory.getAbsolutePath() + BytecodeViewer.fs + origName + ".class"));
byte[] b =
org.apache.commons.io.FileUtils.readFileToByteArray(new File(tempDirectory.getAbsolutePath() + BytecodeViewer.fs + origName + ".class"));
tempDirectory.delete();
tempJar.delete();
return b;
} catch (Exception e) {
e.printStackTrace();
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(log);
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(log.toString());
} finally {
BytecodeViewer.sm.setBlocking();
}

View File

@ -1,6 +1,7 @@
package the.bytecode.club.bytecodeviewer.compilers;
import java.io.File;
import java.util.Objects;
import me.konloch.kontainer.io.DiskWriter;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.util.Dex2Jar;
@ -76,7 +77,7 @@ public class SmaliAssembler extends Compiler {
File current = tempJarFolder;
try {
while (!found) {
File f = current.listFiles()[0];
File f = Objects.requireNonNull(current.listFiles())[0];
if (f.isDirectory())
current = f;
else {
@ -87,7 +88,7 @@ public class SmaliAssembler extends Compiler {
}
return org.apache.commons.io.FileUtils.readFileToByteArray(outputClass);
} catch (java.lang.NullPointerException e) {
} catch (java.lang.NullPointerException ignored) {
}
} catch (Exception e) {

View File

@ -11,6 +11,7 @@ import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Deque;
import java.util.LinkedList;
import java.util.Objects;
import java.util.Random;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
@ -135,31 +136,28 @@ public class CFRDecompiler extends Decompiler {
File file = new File(fuckery);
if (file.exists())
return findFile(file.listFiles());
return findFile(Objects.requireNonNull(file.listFiles()));
return "CFR error! Send the stacktrace to Konloch at http://the.bytecode.club or konloch@gmail.com" + BytecodeViewer.nl + BytecodeViewer.nl + "Suggested Fix: Click refresh class, if it fails again try another decompiler." + BytecodeViewer.nl + BytecodeViewer.nl + exception;
return "CFR error! Send the stacktrace to Konloch at https://the.bytecode.club or konloch@gmail.com" + BytecodeViewer.nl + BytecodeViewer.nl + "Suggested Fix: Click refresh class, if it fails again try another decompiler." + BytecodeViewer.nl + BytecodeViewer.nl + exception;
}
Random r = new Random();
File f;
public String fuckery(String start) {
boolean b = false;
while (!b) {
while (true) {
f = new File(start + r.nextInt(Integer.MAX_VALUE));
if (!f.exists())
return f.toString();
}
return null;
}
public String findFile(File[] fA) {
for (File f : fA) {
if (f.isDirectory())
return findFile(f.listFiles());
return findFile(Objects.requireNonNull(f.listFiles()));
else {
String s = "";
String s;
try {
s = DiskReader.loadAsString(f.getAbsolutePath());
} catch (Exception e) {
@ -169,7 +167,7 @@ public class CFRDecompiler extends Decompiler {
String exception =
"Bytecode Viewer Version: " + BytecodeViewer.VERSION + BytecodeViewer.nl + BytecodeViewer.nl + sw;
return "CFR error! Send the stacktrace to Konloch at http://the.bytecode.club or konloch@gmail"
return "CFR error! Send the stacktrace to Konloch at https://the.bytecode.club or konloch@gmail"
+ ".com" + BytecodeViewer.nl + BytecodeViewer.nl + "Suggested Fix: Click refresh class, "
+ "if it fails again try another decompiler." + BytecodeViewer.nl + BytecodeViewer.nl + exception;
}
@ -294,8 +292,6 @@ public class CFRDecompiler extends Decompiler {
.isSelected()),};
}
byte[] buffer = new byte[1024];
@Override
public void decompileToZip(String sourceJar, String zipName) {
File tempZip = new File(sourceJar);
@ -319,7 +315,7 @@ public class CFRDecompiler extends Decompiler {
@SuppressWarnings("resource")
public void zip(File directory, File zipfile) throws IOException {
java.net.URI base = directory.toURI();
Deque<File> queue = new LinkedList<File>();
Deque<File> queue = new LinkedList<>();
queue.push(directory);
OutputStream out = new FileOutputStream(zipfile);
Closeable res = out;
@ -328,7 +324,7 @@ public class CFRDecompiler extends Decompiler {
res = zout;
while (!queue.isEmpty()) {
directory = queue.pop();
for (File kid : directory.listFiles()) {
for (File kid : Objects.requireNonNull(directory.listFiles())) {
String name = base.relativize(kid.toURI()).getPath();
if (kid.isDirectory()) {
queue.push(kid);
@ -360,11 +356,8 @@ public class CFRDecompiler extends Decompiler {
}
private static void copy(File file, OutputStream out) throws IOException {
InputStream in = new FileInputStream(file);
try {
try (InputStream in = new FileInputStream(file)) {
copy(in, out);
} finally {
in.close();
}
}
}

View File

@ -1,7 +1,6 @@
package the.bytecode.club.bytecodeviewer.decompilers;
import org.objectweb.asm.tree.ClassNode;
import the.bytecode.club.bytecodeviewer.decompilers.bytecode.ClassNodeDecompiler;
/***************************************************************************
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
@ -29,18 +28,8 @@ import the.bytecode.club.bytecodeviewer.decompilers.bytecode.ClassNodeDecompiler
public abstract class Decompiler {
public final static Decompiler bytecode = new ClassNodeDecompiler();
public final static Decompiler fernflower = new FernFlowerDecompiler();
public final static Decompiler procyon = new ProcyonDecompiler();
public final static Decompiler cfr = new CFRDecompiler();
public final static KrakatauDecompiler krakatau = new KrakatauDecompiler();
public final static KrakatauDisassembler krakatauDA = new KrakatauDisassembler();
public final static SmaliDisassembler smali = new SmaliDisassembler();
public final static Decompiler jdgui = new JDGUIDecompiler();
public final static Decompiler jadx = new JADXDecompiler();
public final static Decompiler textifier = new ASMTextifierDecompiler();
public abstract String decompileClassNode(ClassNode cn, byte[] b);
public abstract void decompileToZip(String sourceJar, String zipName);
}

View File

@ -0,0 +1,18 @@
package the.bytecode.club.bytecodeviewer.decompilers;
import the.bytecode.club.bytecodeviewer.decompilers.bytecode.ClassNodeDecompiler;
public class Decompilers {
public final static Decompiler bytecode = new ClassNodeDecompiler();
public final static Decompiler fernflower = new FernFlowerDecompiler();
public final static Decompiler procyon = new ProcyonDecompiler();
public final static Decompiler cfr = new CFRDecompiler();
public final static KrakatauDecompiler krakatau = new KrakatauDecompiler();
public final static KrakatauDisassembler krakatauDA = new KrakatauDisassembler();
public final static SmaliDisassembler smali = new SmaliDisassembler();
public final static Decompiler jdgui = new JDGUIDecompiler();
public final static Decompiler jadx = new JADXDecompiler();
public final static Decompiler textifier = new ASMTextifierDecompiler();
}

View File

@ -36,7 +36,6 @@ import the.bytecode.club.bytecodeviewer.util.MiscUtils;
* @author Konloch
* @author WaterWolf
*/
public class FernFlowerDecompiler extends Decompiler {
@Override
@ -48,7 +47,7 @@ public class FernFlowerDecompiler extends Decompiler {
try {
org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler.main(generateMainMethod(tempZip.getAbsolutePath(), BytecodeViewer.tempDirectory + "./temp/"));
} catch (StackOverflowError | Exception e) {
} catch (StackOverflowError | Exception ignored) {
}
@ -132,7 +131,7 @@ public class FernFlowerDecompiler extends Decompiler {
exception += BytecodeViewer.nl + BytecodeViewer.nl + sw;
}
}
return "FernFlower error! Send the stacktrace to Konloch at http://the.bytecode.club or konloch@gmail.com" + BytecodeViewer.nl + BytecodeViewer.nl + "Suggested Fix: Click refresh class, if it fails again try another decompiler." + BytecodeViewer.nl + BytecodeViewer.nl + exception;
return "FernFlower error! Send the stacktrace to Konloch at https://the.bytecode.club or konloch@gmail.com" + BytecodeViewer.nl + BytecodeViewer.nl + "Suggested Fix: Click refresh class, if it fails again try another decompiler." + BytecodeViewer.nl + BytecodeViewer.nl + exception;
}
private String[] generateMainMethod(String className, String folder) {

View File

@ -7,6 +7,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Objects;
import java.util.Random;
import me.konloch.kontainer.io.DiskReader;
import org.objectweb.asm.tree.ClassNode;
@ -36,7 +37,6 @@ import the.bytecode.club.bytecodeviewer.util.MiscUtils;
*
* @author Konloch
*/
public class JADXDecompiler extends Decompiler {
@Override
public String decompileClassNode(ClassNode cn, byte[] b) {
@ -76,33 +76,28 @@ public class JADXDecompiler extends Decompiler {
tempClass.delete();
if (fuckery.exists())
return findFile(fuckery.listFiles());
return "JADX error! Send the stacktrace to Konloch at http://the.bytecode.club or konloch@gmail.com" + BytecodeViewer.nl + BytecodeViewer.nl + "Suggested Fix: Click refresh class, if it fails again try another decompiler." + BytecodeViewer.nl + BytecodeViewer.nl + exception;
return findFile(Objects.requireNonNull(fuckery.listFiles()));
return "JADX error! Send the stacktrace to Konloch at https://the.bytecode.club or konloch@gmail.com" + BytecodeViewer.nl + BytecodeViewer.nl + "Suggested Fix: Click refresh class, if it fails again try another decompiler." + BytecodeViewer.nl + BytecodeViewer.nl + exception;
}
Random r = new Random();
File f;
public String fuckery(String start) {
boolean b = false;
while (!b) {
while (true) {
f = new File(start + r.nextInt(Integer.MAX_VALUE));
if (!f.exists())
return f.toString();
}
return null;
}
public String findFile(File[] fA) {
for (File f : fA) {
if (f.isDirectory())
return findFile(f.listFiles());
return findFile(Objects.requireNonNull(f.listFiles()));
else {
String s = "";
String s;
try {
s = DiskReader.loadAsString(f.getAbsolutePath());
} catch (Exception e) {
@ -112,7 +107,7 @@ public class JADXDecompiler extends Decompiler {
String exception =
"Bytecode Viewer Version: " + BytecodeViewer.VERSION + BytecodeViewer.nl + BytecodeViewer.nl + sw;
return "JADX error! Send the stacktrace to Konloch at http://the.bytecode.club or konloch@gmail"
return "JADX error! Send the stacktrace to Konloch at https://the.bytecode.club or konloch@gmail"
+ ".com" + BytecodeViewer.nl + BytecodeViewer.nl + "Suggested Fix: Click refresh class, "
+ "if it fails again try another decompiler." + BytecodeViewer.nl + BytecodeViewer.nl + exception;
}

View File

@ -45,7 +45,7 @@ public class JDGUIDecompiler extends Decompiler {
@Override
public String decompileClassNode(ClassNode cn, byte[] b) {
String exception = "";
String exception;
try {
final File tempDirectory =
new File(BytecodeViewer.tempDirectory + BytecodeViewer.fs + MiscUtils.randomString(32) + BytecodeViewer.fs);
@ -102,7 +102,7 @@ public class JDGUIDecompiler extends Decompiler {
jd.core.Decompiler decompiler = new DecompilerImpl();
decompiler.decompile(preferences, loader, printer, internalPath);
String decompiledSource = "Error with decompilation.";
String decompiledSource;
decompiledSource = DiskReader.loadAsString(tempJava.getAbsolutePath());
return decompiledSource;
@ -114,7 +114,7 @@ public class JDGUIDecompiler extends Decompiler {
exception =
"Bytecode Viewer Version: " + BytecodeViewer.VERSION + BytecodeViewer.nl + BytecodeViewer.nl + sw;
}
return "JD-GUI error! Send the stacktrace to Konloch at http://the.bytecode.club or konloch@gmail.com" + BytecodeViewer.nl + BytecodeViewer.nl + "Suggested Fix: Click refresh class, if it fails again try another decompiler." + BytecodeViewer.nl + BytecodeViewer.nl + exception;
return "JD-GUI error! Send the stacktrace to Konloch at https://the.bytecode.club or konloch@gmail.com" + BytecodeViewer.nl + BytecodeViewer.nl + "Suggested Fix: Click refresh class, if it fails again try another decompiler." + BytecodeViewer.nl + BytecodeViewer.nl + exception;
}
@Override

View File

@ -46,7 +46,7 @@ public class KrakatauDecompiler extends Decompiler {
return ";" + BytecodeViewer.library;
}
public String decompileClassNode(File krakatauTempJar, File krakatauTempDir, ClassNode cn, byte[] b) {
public String decompileClassNode(File krakatauTempJar, File krakatauTempDir, ClassNode cn) {
if (BytecodeViewer.python.equals("")) {
BytecodeViewer.showMessage("You need to set your Python (or PyPy for speed) 2.7 executable path.");
BytecodeViewer.viewer.pythonC();
@ -94,25 +94,26 @@ public class KrakatauDecompiler extends Decompiler {
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String log = "Process:" + BytecodeViewer.nl + BytecodeViewer.nl;
StringBuilder log = new StringBuilder("Process:" + BytecodeViewer.nl + BytecodeViewer.nl);
String line;
while ((line = br.readLine()) != null) {
log += BytecodeViewer.nl + line;
log.append(BytecodeViewer.nl).append(line);
}
br.close();
log += BytecodeViewer.nl + BytecodeViewer.nl + "Error:" + BytecodeViewer.nl + BytecodeViewer.nl;
log.append(BytecodeViewer.nl).append(BytecodeViewer.nl).append("Error:").append(BytecodeViewer.nl)
.append(BytecodeViewer.nl);
is = process.getErrorStream();
isr = new InputStreamReader(is);
br = new BufferedReader(isr);
while ((line = br.readLine()) != null) {
log += BytecodeViewer.nl + line;
log.append(BytecodeViewer.nl).append(line);
}
br.close();
int exitValue = process.waitFor();
log += BytecodeViewer.nl + BytecodeViewer.nl + "Exit Value is " + exitValue;
s = log;
log.append(BytecodeViewer.nl).append(BytecodeViewer.nl).append("Exit Value is ").append(exitValue);
s = log.toString();
//if the motherfucker failed this'll fail, aka wont set.
s = DiskReader.loadAsString(krakatauTempDir.getAbsolutePath() + BytecodeViewer.fs + cn.name + ".java");
@ -184,25 +185,26 @@ public class KrakatauDecompiler extends Decompiler {
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String log = "Process:" + BytecodeViewer.nl + BytecodeViewer.nl;
StringBuilder log = new StringBuilder("Process:" + BytecodeViewer.nl + BytecodeViewer.nl);
String line;
while ((line = br.readLine()) != null) {
log += BytecodeViewer.nl + line;
log.append(BytecodeViewer.nl).append(line);
}
br.close();
log += BytecodeViewer.nl + BytecodeViewer.nl + "Error:" + BytecodeViewer.nl + BytecodeViewer.nl;
log.append(BytecodeViewer.nl).append(BytecodeViewer.nl).append("Error:").append(BytecodeViewer.nl)
.append(BytecodeViewer.nl);
is = process.getErrorStream();
isr = new InputStreamReader(is);
br = new BufferedReader(isr);
while ((line = br.readLine()) != null) {
log += BytecodeViewer.nl + line;
log.append(BytecodeViewer.nl).append(line);
}
br.close();
int exitValue = process.waitFor();
log += BytecodeViewer.nl + BytecodeViewer.nl + "Exit Value is " + exitValue;
s = log;
log.append(BytecodeViewer.nl).append(BytecodeViewer.nl).append("Exit Value is ").append(exitValue);
s = log.toString();
//if the motherfucker failed this'll fail, aka wont set.
s = DiskReader.loadAsString(tempDirectory.getAbsolutePath() + BytecodeViewer.fs + cn.name + ".java");
@ -220,6 +222,7 @@ public class KrakatauDecompiler extends Decompiler {
return s;
}
@Override
public void decompileToZip(String sourceJar, String zipName) {
if (BytecodeViewer.python.equals("")) {
BytecodeViewer.showMessage("You need to set your Python (or PyPy for speed) 2.7 executable path.");

View File

@ -39,7 +39,7 @@ import the.bytecode.club.bytecodeviewer.util.ZipUtils;
public class KrakatauDisassembler extends Decompiler {
public String decompileClassNode(File krakatauTempJar, File krakatauTempDir, ClassNode cn, byte[] b) {
public String decompileClassNode(File krakatauTempJar, File krakatauTempDir, ClassNode cn) {
if (BytecodeViewer.python.equals("")) {
BytecodeViewer.showMessage("You need to set your Python (or PyPy for speed) 2.7 executable path.");
BytecodeViewer.viewer.pythonC();
@ -73,25 +73,26 @@ public class KrakatauDisassembler extends Decompiler {
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String log = "Process:" + BytecodeViewer.nl + BytecodeViewer.nl;
StringBuilder log = new StringBuilder("Process:" + BytecodeViewer.nl + BytecodeViewer.nl);
String line;
while ((line = br.readLine()) != null) {
log += BytecodeViewer.nl + line;
log.append(BytecodeViewer.nl).append(line);
}
br.close();
log += BytecodeViewer.nl + BytecodeViewer.nl + "Error:" + BytecodeViewer.nl + BytecodeViewer.nl;
log.append(BytecodeViewer.nl).append(BytecodeViewer.nl).append("Error:").append(BytecodeViewer.nl)
.append(BytecodeViewer.nl);
is = process.getErrorStream();
isr = new InputStreamReader(is);
br = new BufferedReader(isr);
while ((line = br.readLine()) != null) {
log += BytecodeViewer.nl + line;
log.append(BytecodeViewer.nl).append(line);
}
br.close();
int exitValue = process.waitFor();
log += BytecodeViewer.nl + BytecodeViewer.nl + "Exit Value is " + exitValue;
s = log;
log.append(BytecodeViewer.nl).append(BytecodeViewer.nl).append("Exit Value is ").append(exitValue);
s = log.toString();
//if the motherfucker failed this'll fail, aka wont set.
s = DiskReader.loadAsString(krakatauTempDir.getAbsolutePath() + BytecodeViewer.fs + cn.name + ".j");
@ -149,25 +150,26 @@ public class KrakatauDisassembler extends Decompiler {
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String log = "Process:" + BytecodeViewer.nl + BytecodeViewer.nl;
StringBuilder log = new StringBuilder("Process:" + BytecodeViewer.nl + BytecodeViewer.nl);
String line;
while ((line = br.readLine()) != null) {
log += BytecodeViewer.nl + line;
log.append(BytecodeViewer.nl).append(line);
}
br.close();
log += BytecodeViewer.nl + BytecodeViewer.nl + "Error:" + BytecodeViewer.nl + BytecodeViewer.nl;
log.append(BytecodeViewer.nl).append(BytecodeViewer.nl).append("Error:").append(BytecodeViewer.nl)
.append(BytecodeViewer.nl);
is = process.getErrorStream();
isr = new InputStreamReader(is);
br = new BufferedReader(isr);
while ((line = br.readLine()) != null) {
log += BytecodeViewer.nl + line;
log.append(BytecodeViewer.nl).append(line);
}
br.close();
int exitValue = process.waitFor();
log += BytecodeViewer.nl + BytecodeViewer.nl + "Exit Value is " + exitValue;
s = log;
log.append(BytecodeViewer.nl).append(BytecodeViewer.nl).append("Exit Value is ").append(exitValue);
s = log.toString();
//if the motherfucker failed this'll fail, aka wont set.
s = DiskReader.loadAsString(tempDirectory.getAbsolutePath() + BytecodeViewer.fs + cn.name + ".j");

View File

@ -98,7 +98,7 @@ public class ProcyonDecompiler extends Decompiler {
@Override
public String decompileClassNode(ClassNode cn, byte[] b) {
String exception = "";
String exception;
try {
String fileStart = BytecodeViewer.tempDirectory + BytecodeViewer.fs
+ "temp";
@ -126,7 +126,7 @@ public class ProcyonDecompiler extends Decompiler {
decompilationOptions.setSettings(settings);
decompilationOptions.setFullDecompilation(true);
TypeDefinition resolvedType = null;
TypeDefinition resolvedType;
if (type == null || ((resolvedType = type.resolve()) == null)) {
throw new Exception("Unable to resolve type.");
}
@ -142,7 +142,7 @@ public class ProcyonDecompiler extends Decompiler {
exception =
"Bytecode Viewer Version: " + BytecodeViewer.VERSION + BytecodeViewer.nl + BytecodeViewer.nl + sw;
}
return "Procyon error! Send the stacktrace to Konloch at http://the.bytecode.club or konloch@gmail.com" + BytecodeViewer.nl + BytecodeViewer.nl + "Suggested Fix: Click refresh class, if it fails again try another decompiler." + BytecodeViewer.nl + BytecodeViewer.nl + exception;
return "Procyon error! Send the stacktrace to Konloch at https://the.bytecode.club or konloch@gmail.com" + BytecodeViewer.nl + BytecodeViewer.nl + "Suggested Fix: Click refresh class, if it fails again try another decompiler." + BytecodeViewer.nl + BytecodeViewer.nl + exception;
}
@Override
@ -175,7 +175,7 @@ public class ProcyonDecompiler extends Decompiler {
decompilationOptions.setFullDecompilation(true);
Enumeration<JarEntry> ent = jfile.entries();
Set<JarEntry> history = new HashSet<JarEntry>();
Set<JarEntry> history = new HashSet<>();
while (ent.hasMoreElements()) {
JarEntry entry = ent.nextElement();
if (entry.getName().endsWith(".class")) {
@ -188,7 +188,7 @@ public class ProcyonDecompiler extends Decompiler {
entry.getName(), ".class");
TypeReference type = metadataSystem
.lookupType(internalName);
TypeDefinition resolvedType = null;
TypeDefinition resolvedType;
if ((type == null)
|| ((resolvedType = type.resolve()) == null)) {
throw new Exception("Unable to resolve type.");
@ -239,11 +239,11 @@ public class ProcyonDecompiler extends Decompiler {
/**
* @author DeathMarine
*/
public final class LuytenTypeLoader implements ITypeLoader {
public static final class LuytenTypeLoader implements ITypeLoader {
private final List<ITypeLoader> _typeLoaders;
public LuytenTypeLoader() {
_typeLoaders = new ArrayList<ITypeLoader>();
_typeLoaders = new ArrayList<>();
_typeLoaders.add(new InputTypeLoader());
}

View File

@ -5,6 +5,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Objects;
import me.konloch.kontainer.io.DiskReader;
import org.apache.commons.io.FileUtils;
import org.objectweb.asm.tree.ClassNode;
@ -90,7 +91,7 @@ public class SmaliDisassembler extends Decompiler {
boolean found = false;
File current = tempSmali;
while (!found) {
File f = current.listFiles()[0];
File f = Objects.requireNonNull(current.listFiles())[0];
if (f.isDirectory())
current = f;
else {
@ -109,7 +110,7 @@ public class SmaliDisassembler extends Decompiler {
exception += "Bytecode Viewer Version: " + BytecodeViewer.VERSION + BytecodeViewer.nl + BytecodeViewer.nl + sw;
}
return "Smali Disassembler error! Send the stacktrace to Konloch at http://the.bytecode.club or konloch@gmail"
return "Smali Disassembler error! Send the stacktrace to Konloch at https://the.bytecode.club or konloch@gmail"
+ ".com" + BytecodeViewer.nl + BytecodeViewer.nl + "Suggested Fix: Click refresh class, if it fails "
+ "again try another decompiler." + BytecodeViewer.nl + BytecodeViewer.nl + exception;
}

View File

@ -36,6 +36,7 @@ import the.bytecode.club.bytecodeviewer.decompilers.Decompiler;
public class ClassNodeDecompiler extends Decompiler {
@Override
public String decompileClassNode(ClassNode cn, byte[] b) {
return decompile(new PrefixedStringBuilder(),
new ArrayList<>(), cn).toString();
@ -99,9 +100,8 @@ public class ClassNodeDecompiler extends Decompiler {
MethodNodeDecompiler.decompile(sb, mn, cn);
}
for (Object o : cn.innerClasses) {
InnerClassNode innerClassNode = (InnerClassNode) o;
String innerClassName = innerClassNode.name;
for (InnerClassNode o : cn.innerClasses) {
String innerClassName = o.name;
if ((innerClassName != null)
&& !decompiledClasses.contains(innerClassName)) {
decompiledClasses.add(innerClassName);
@ -143,7 +143,7 @@ public class ClassNodeDecompiler extends Decompiler {
}
public static String getAccessString(int access) {
List<String> tokens = new ArrayList<String>();
List<String> tokens = new ArrayList<>();
if ((access & Opcodes.ACC_PUBLIC) != 0)
tokens.add("public");
if ((access & Opcodes.ACC_PRIVATE) != 0)

View File

@ -58,7 +58,7 @@ public class FieldNodeDecompiler {
}
private static String getAccessString(int access) {
List<String> tokens = new ArrayList<String>();
List<String> tokens = new ArrayList<>();
if ((access & Opcodes.ACC_PUBLIC) != 0)
tokens.add("public");
if ((access & Opcodes.ACC_PRIVATE) != 0)

View File

@ -7,11 +7,12 @@ import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.text.StringEscapeUtils;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.FieldInsnNode;
@ -65,7 +66,6 @@ public class InstructionPrinter {
protected int[] pattern;
protected boolean match;
private InstructionSearcher searcher;
protected List<AbstractInsnNode> matchedInsns;
protected Map<LabelNode, Integer> labels;
@ -73,7 +73,7 @@ public class InstructionPrinter {
public InstructionPrinter(MethodNode m, TypeAndName[] args) {
this.args = args;
mNode = m;
labels = new HashMap<LabelNode, Integer>();
labels = new HashMap<>();
// matchedInsns = new ArrayList<AbstractInsnNode>(); // ingnored because
// match = false
match = false;
@ -83,14 +83,12 @@ public class InstructionPrinter {
TypeAndName[] args) {
this.args = args;
mNode = m;
labels = new HashMap<LabelNode, Integer>();
searcher = new InstructionSearcher(m.instructions, pattern);
labels = new HashMap<>();
InstructionSearcher searcher = new InstructionSearcher(m.instructions, pattern);
match = searcher.search();
if (match) {
for (AbstractInsnNode[] ains : searcher.getMatches()) {
for (AbstractInsnNode ain : ains) {
matchedInsns.add(ain);
}
Collections.addAll(matchedInsns, ains);
}
}
}
@ -101,28 +99,28 @@ public class InstructionPrinter {
* @return The print as an ArrayList
*/
public ArrayList<String> createPrint() {
ArrayList<String> info = new ArrayList<String>();
ArrayList<String> info = new ArrayList<>();
ListIterator<?> it = mNode.instructions.iterator();
boolean firstLabel = false;
while (it.hasNext()) {
AbstractInsnNode ain = (AbstractInsnNode) it.next();
String line = "";
if (ain instanceof VarInsnNode) {
line = printVarInsnNode((VarInsnNode) ain, it);
line = printVarInsnNode((VarInsnNode) ain);
} else if (ain instanceof IntInsnNode) {
line = printIntInsnNode((IntInsnNode) ain, it);
line = printIntInsnNode((IntInsnNode) ain);
} else if (ain instanceof FieldInsnNode) {
line = printFieldInsnNode((FieldInsnNode) ain, it);
line = printFieldInsnNode((FieldInsnNode) ain);
} else if (ain instanceof MethodInsnNode) {
line = printMethodInsnNode((MethodInsnNode) ain, it);
line = printMethodInsnNode((MethodInsnNode) ain);
} else if (ain instanceof LdcInsnNode) {
line = printLdcInsnNode((LdcInsnNode) ain, it);
line = printLdcInsnNode((LdcInsnNode) ain);
} else if (ain instanceof InsnNode) {
line = printInsnNode((InsnNode) ain, it);
line = printInsnNode((InsnNode) ain);
} else if (ain instanceof JumpInsnNode) {
line = printJumpInsnNode((JumpInsnNode) ain, it);
line = printJumpInsnNode((JumpInsnNode) ain);
} else if (ain instanceof LineNumberNode) {
line = printLineNumberNode((LineNumberNode) ain, it);
line = printLineNumberNode();
} else if (ain instanceof LabelNode) {
if (firstLabel
&& BytecodeViewer.viewer.chckbxmntmAppendBrackets
@ -168,7 +166,7 @@ public class InstructionPrinter {
return info;
}
protected String printVarInsnNode(VarInsnNode vin, ListIterator<?> it) {
protected String printVarInsnNode(VarInsnNode vin) {
StringBuilder sb = new StringBuilder();
sb.append(nameOpcode(vin.getOpcode()));
sb.append(vin.var);
@ -179,7 +177,7 @@ public class InstructionPrinter {
final int refIndex = vin.var
- (Modifier.isStatic(mNode.access) ? 0 : 1);
if (refIndex >= 0 && refIndex < args.length - 1) {
sb.append(" // reference to " + args[refIndex].name);
sb.append(" // reference to ").append(args[refIndex].name);
}
}
}
@ -187,22 +185,21 @@ public class InstructionPrinter {
return sb.toString();
}
protected String printIntInsnNode(IntInsnNode iin, ListIterator<?> it) {
protected String printIntInsnNode(IntInsnNode iin) {
return nameOpcode(iin.getOpcode()) + " " + iin.operand;
}
protected String printFieldInsnNode(FieldInsnNode fin, ListIterator<?> it) {
protected String printFieldInsnNode(FieldInsnNode fin) {
String desc = Type.getType(fin.desc).getClassName();
if (desc == null || desc.equals("null"))
if (desc.equals("null"))
desc = fin.desc;
return nameOpcode(fin.getOpcode()) + " " + fin.owner + "." + fin.name
+ ":" + desc;
}
protected String printMethodInsnNode(MethodInsnNode min, ListIterator<?> it) {
protected String printMethodInsnNode(MethodInsnNode min) {
StringBuilder sb = new StringBuilder();
sb.append(nameOpcode(min.getOpcode()) + " " + min.owner + "."
+ min.name);
sb.append(nameOpcode(min.getOpcode())).append(" ").append(min.owner).append(".").append(min.name);
String desc = min.desc;
try {
@ -222,7 +219,7 @@ public class InstructionPrinter {
return sb.toString();
}
protected String printLdcInsnNode(LdcInsnNode ldc, ListIterator<?> it) {
protected String printLdcInsnNode(LdcInsnNode ldc) {
if (ldc.cst instanceof String)
return nameOpcode(ldc.getOpcode()) + " \""
+ StringEscapeUtils.escapeJava(ldc.cst.toString()) + "\" ("
@ -233,17 +230,16 @@ public class InstructionPrinter {
+ ldc.cst.getClass().getCanonicalName() + ")";
}
protected String printInsnNode(InsnNode in, ListIterator<?> it) {
protected String printInsnNode(InsnNode in) {
return nameOpcode(in.getOpcode());
}
protected String printJumpInsnNode(JumpInsnNode jin, ListIterator<?> it) {
String line = nameOpcode(jin.getOpcode()) + " L"
protected String printJumpInsnNode(JumpInsnNode jin) {
return nameOpcode(jin.getOpcode()) + " L"
+ resolveLabel(jin.label);
return line;
}
protected String printLineNumberNode(LineNumberNode lin, ListIterator<?> it) {
protected String printLineNumberNode() {
return "";
}
@ -258,9 +254,9 @@ public class InstructionPrinter {
if (Type.getType(tin.desc) != null)
desc = Type.getType(tin.desc).getClassName();
if (desc == null || desc.equals("null"))
if (desc.equals("null"))
desc = tin.desc;
} catch (java.lang.ArrayIndexOutOfBoundsException e) {
} catch (java.lang.ArrayIndexOutOfBoundsException ignored) {
}
return nameOpcode(tin.getOpcode()) + " " + desc;
@ -274,35 +270,38 @@ public class InstructionPrinter {
}
protected String printTableSwitchInsnNode(TableSwitchInsnNode tin) {
String line = nameOpcode(tin.getOpcode()) + " \n";
StringBuilder line = new StringBuilder(nameOpcode(tin.getOpcode()) + " \n");
List<?> labels = tin.labels;
int count = 0;
for (int i = tin.min; i < tin.max + 1; i++) {
line += " val: " + i + " -> " + "L" + resolveLabel((LabelNode) labels.get(count++)) + "\n";
line.append(" val: ").append(i).append(" -> ").append("L")
.append(resolveLabel((LabelNode) labels.get(count++))).append("\n");
}
line += " default" + " -> L" + resolveLabel(tin.dflt) + "";
return line;
line.append(" default" + " -> L").append(resolveLabel(tin.dflt));
return line.toString();
}
protected String printLookupSwitchInsnNode(LookupSwitchInsnNode lin) {
String line = nameOpcode(lin.getOpcode()) + ": \n";
StringBuilder line = new StringBuilder(nameOpcode(lin.getOpcode()) + ": \n");
List<?> keys = lin.keys;
List<?> labels = lin.labels;
for (int i = 0; i < keys.size(); i++) {
int key = (Integer) keys.get(i);
LabelNode label = (LabelNode) labels.get(i);
line += " val: " + key + " -> " + "L" + resolveLabel(label) + "\n";
line.append(" val: ").append(key).append(" -> ").append("L")
.append(resolveLabel(label)).append("\n");
}
line += " default" + " -> L" + resolveLabel(lin.dflt) + "";
return line;
line.append(" default" + " -> L").append(resolveLabel(lin.dflt));
return line.toString();
}
protected String printInvokeDynamicInsNode(InvokeDynamicInsnNode idin) {
StringBuilder sb = new StringBuilder();
sb.append(nameOpcode(idin.getOpcode()) + " " + idin.bsm.getOwner() + '.' + idin.bsm.getName() + idin.bsm.getDesc()
+ " : " + idin.name + idin.desc);
sb.append(nameOpcode(idin.getOpcode())).append(" ").append(idin.bsm.getOwner()).append('.')
.append(idin.bsm.getName()).append(idin.bsm.getDesc()).append(" : ")
.append(idin.name).append(idin.desc);
if (idin.bsmArgs != null) {
for (Object o : idin.bsmArgs) {
@ -315,20 +314,17 @@ public class InstructionPrinter {
}
protected String printMultiANewArrayInsNode(MultiANewArrayInsnNode mana) {
StringBuilder sb = new StringBuilder();
sb.append(nameOpcode(mana.getOpcode()) + " " + mana.dims + " : " + mana.desc);
return sb.toString();
return nameOpcode(mana.getOpcode()) + " " + mana.dims + " : " + mana.desc;
}
private String printFrameNode(FrameNode frame) {
StringBuilder sb = new StringBuilder();
sb.append(nameOpcode(frame.getOpcode()) + " ");
sb.append(nameOpcode(frame.getOpcode())).append(" ");
sb.append("(Locals");
if (frame.local != null
&& frame.local.size() > 0) {
sb.append("[" + frame.local.size() + "]:");
sb.append("[").append(frame.local.size()).append("]:");
sb.append(" ");
sb.append(frame.local.get(0).toString());
if (frame.local.size() > 1) {
@ -345,7 +341,7 @@ public class InstructionPrinter {
sb.append("(Stack");
if (frame.stack != null
&& frame.stack.size() > 0) {
sb.append("[" + frame.stack.size() + "]:");
sb.append("[").append(frame.stack.size()).append("]:");
sb.append(" ");
sb.append(frame.stack.get(0).toString());
if (frame.stack.size() > 1) {
@ -388,4 +384,5 @@ public class InstructionPrinter {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
}
}
}

View File

@ -48,7 +48,7 @@ public class InstructionSearcher implements Opcodes {
public InstructionSearcher(InsnList insns, InstructionPattern pattern) {
this.insns = insns;
this.pattern = pattern;
matches = new ArrayList<AbstractInsnNode[]>();
matches = new ArrayList<>();
}
public boolean search() {

View File

@ -39,10 +39,8 @@ public class MethodNodeDecompiler {
public static PrefixedStringBuilder decompile(PrefixedStringBuilder sb,
MethodNode m, ClassNode cn) {
String package_ = null;
String class_;
if (cn.name.contains("/")) {
package_ = cn.name.substring(0, cn.name.lastIndexOf("/"));
class_ = cn.name.substring(cn.name.lastIndexOf("/") + 1);
} else {
class_ = cn.name;
@ -56,8 +54,7 @@ public class MethodNodeDecompiler {
if (m.name.equals("<init>")) {
sb.append(class_);
} else if (m.name.equals("<clinit>")) {
} else {
} else if (!m.name.equals("<clinit>")) {
sb.append(m.name);
}
@ -142,18 +139,17 @@ public class MethodNodeDecompiler {
addAttrList(m.visibleTypeAnnotations, "visTypeAnno", sb,
insnPrinter);
for (Object o : m.tryCatchBlocks) {
TryCatchBlockNode tcbn = (TryCatchBlockNode) o;
for (TryCatchBlockNode o : m.tryCatchBlocks) {
sb.append(" ");
sb.append("TryCatch: L");
sb.append(insnPrinter.resolveLabel(tcbn.start));
sb.append(insnPrinter.resolveLabel(o.start));
sb.append(" to L");
sb.append(insnPrinter.resolveLabel(tcbn.end));
sb.append(insnPrinter.resolveLabel(o.end));
sb.append(" handled by L");
sb.append(insnPrinter.resolveLabel(tcbn.handler));
sb.append(insnPrinter.resolveLabel(o.handler));
sb.append(": ");
if (tcbn.type != null)
sb.append(tcbn.type);
if (o.type != null)
sb.append(o.type);
else
sb.append("Type is null.");
sb.append(BytecodeViewer.nl);
@ -213,7 +209,7 @@ public class MethodNodeDecompiler {
private static String getAccessString(int access) {
// public, protected, private, abstract, static,
// final, synchronized, native & strictfp are permitted
List<String> tokens = new ArrayList<String>();
List<String> tokens = new ArrayList<>();
if ((access & Opcodes.ACC_PUBLIC) != 0)
tokens.add("public");
if ((access & Opcodes.ACC_PRIVATE) != 0)
@ -238,7 +234,7 @@ public class MethodNodeDecompiler {
tokens.add("synthetic");
if ((access & Opcodes.ACC_VARARGS) != 0)
tokens.add("varargs");
if (tokens.size() == 0)
if (tokens.isEmpty())
return "";
// hackery delimeters
StringBuilder sb = new StringBuilder(tokens.get(0));

View File

@ -22,16 +22,13 @@ public class DelayTabbedPaneThread extends Thread {
e.printStackTrace();
}
if (!stopped) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
SwingUtilities.invokeLater(() -> {
if (stopped)
return;
pane.label.setOpaque(true);
pane.label.setBackground(Color.MAGENTA);
pane.label.updateUI();
}
});
}
}

View File

@ -1,8 +1,6 @@
package the.bytecode.club.bytecodeviewer.gui;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
@ -60,20 +58,15 @@ public class ExportJar extends JFrame {
scrollPane.setViewportView(mani);
getContentPane().add(btnNewButton);
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
btnNewButton.addActionListener(arg0 -> {
BytecodeViewer.viewer.setIcon(true);
Thread t = new Thread() {
@Override
public void run() {
Thread t = new Thread(() -> {
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), jarPath,
mani.getText());
BytecodeViewer.viewer.setIcon(false);
}
};
});
t.start();
dispose();
}
});
this.setLocationRelativeTo(null);

View File

@ -8,7 +8,6 @@ import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyAdapter;
@ -20,11 +19,10 @@ import java.awt.font.FontRenderContext;
import java.awt.geom.Rectangle2D;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Objects;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JCheckBox;
@ -33,8 +31,6 @@ import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.MutableTreeNode;
@ -74,7 +70,6 @@ import the.bytecode.club.bytecodeviewer.util.LazyNameUtil;
* @author afffsdd
*/
@SuppressWarnings("serial")
public class FileNavigationPane extends VisibleComponent implements
FileDrop.Listener {
@ -101,18 +96,18 @@ public class FileNavigationPane extends VisibleComponent implements
return;
String[] path = null;
String[] path;
int found = 0;
if (qt.contains(".")) {
path = qt.split("\\.");
String[] path2 = new String[path.length];
/*String[] path2 = new String[path.length];
for (int i = 0; i < path.length; i++) {
path2[i] = path[i];
if (i + 2 == path.length) {
path2[i + 1] = "." + path[i + 1];
}
}
}*/
} else {
path = new String[]{qt};
}
@ -133,11 +128,6 @@ public class FileNavigationPane extends VisibleComponent implements
if (isLast) {
System.out.println("Found! " + curNode);
found++;
if (found >= 30) {
BytecodeViewer.showMessage("Uh oh, there could be more results but you've "
+ "triggered the 30 classes at once limit. Try refining your search.");
return;
}
final TreePath pathn = new TreePath(curNode.getPath());
tree.setSelectionPath(pathn);
tree.makeVisible(pathn);
@ -174,7 +164,7 @@ public class FileNavigationPane extends VisibleComponent implements
}
}
String fullPathString = fullPath.toString();
if (fullPathString != null && fullPathString.toLowerCase().contains(qt.toLowerCase())) {
if (fullPathString.toLowerCase().contains(qt.toLowerCase())) {
System.out.println("Found! " + node);
found++;
if (found >= 30) {
@ -208,8 +198,9 @@ public class FileNavigationPane extends VisibleComponent implements
@Override
public void actionPerformed(ActionEvent e) {
TreePath selPath = FileNavigationPane.this.tree.getPathForLocation(x, y);
DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode) selPath.getLastPathComponent();
Enumeration enumeration = treeRoot.children();
DefaultMutableTreeNode selectNode =
(DefaultMutableTreeNode) Objects.requireNonNull(selPath).getLastPathComponent();
Enumeration<?> enumeration = treeRoot.children();
while (enumeration.hasMoreElements()) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) enumeration.nextElement();
if (node.isNodeAncestor(selectNode)) {
@ -232,7 +223,7 @@ public class FileNavigationPane extends VisibleComponent implements
@Override
public void actionPerformed(ActionEvent e) {
TreePath selPath = FileNavigationPane.this.tree.getPathForLocation(x, y);
expandAll(tree, selPath, true);
expandAll(tree, Objects.requireNonNull(selPath), true);
}
});
@ -240,7 +231,7 @@ public class FileNavigationPane extends VisibleComponent implements
@Override
public void actionPerformed(ActionEvent e) {
TreePath selPath = FileNavigationPane.this.tree.getPathForLocation(x, y);
expandAll(tree, selPath, false);
expandAll(tree, Objects.requireNonNull(selPath), false);
}
});
@ -271,7 +262,7 @@ public class FileNavigationPane extends VisibleComponent implements
}
DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode) selPath.getLastPathComponent();
Enumeration enumeration = treeRoot.children();
Enumeration<?> enumeration = treeRoot.children();
while (enumeration.hasMoreElements()) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) enumeration.nextElement();
if (node.isNodeAncestor(selectNode)) {
@ -284,22 +275,16 @@ public class FileNavigationPane extends VisibleComponent implements
}
});
this.open.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
this.open.addActionListener(e -> {
final TreeNode root = (TreeNode) tree.getModel().getRoot();
expandAll(tree, new TreePath(root), true);
}
});
this.close.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
this.close.addActionListener(e -> {
final TreeNode root = (TreeNode) tree.getModel().getRoot();
final TreePath path = new TreePath(root);
expandAll(tree, path, false);
tree.expandPath(path);
}
});
this.tree.addMouseListener(new MouseAdapter() {
@ -309,15 +294,12 @@ public class FileNavigationPane extends VisibleComponent implements
}
});
this.tree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(final TreeSelectionEvent arg0) {
this.tree.addTreeSelectionListener(arg0 -> {
if (cancel) {
cancel = false;
return;
}
openPath(arg0.getPath());
}
});
this.tree.addKeyListener(new KeyListener() {
@ -531,13 +513,12 @@ public class FileNavigationPane extends VisibleComponent implements
((int) ((getWidth() / 2) - (m.getWidth(s) / 2))),
getHeight() / 2);
}
} catch (java.lang.InternalError | java.lang.NullPointerException e) {
} catch (java.lang.InternalError | java.lang.NullPointerException ignored) {
}
}
}
public class MyTreeNode extends DefaultMutableTreeNode {
public static class MyTreeNode extends DefaultMutableTreeNode {
private static final long serialVersionUID = -8817777566176729571L;
@ -556,10 +537,8 @@ public class FileNavigationPane extends VisibleComponent implements
@SuppressWarnings("unchecked")
private void recursiveSort(final MyTreeNode node) {
Collections.sort(node.children, nodeComparator);
final Iterator<MyTreeNode> it = node.children.iterator();
while (it.hasNext()) {
final MyTreeNode nextNode = it.next();
node.children.sort(nodeComparator);
for (MyTreeNode nextNode : (Iterable<MyTreeNode>) node.children) {
if (nextNode.getChildCount() > 0) {
recursiveSort(nextNode);
}
@ -583,8 +562,7 @@ public class FileNavigationPane extends VisibleComponent implements
@Override
public int hashCode() {
final int hash = 7;
return hash;
return 7;
}
};
@ -593,7 +571,7 @@ public class FileNavigationPane extends VisibleComponent implements
/**
* @author http://stackoverflow.com/a/18450804
*/
class StringMetrics {
static class StringMetrics {
Font font;
FontRenderContext context;
@ -653,7 +631,7 @@ public class FileNavigationPane extends VisibleComponent implements
String name = nameBuffer.toString();
if (name.endsWith(".class")) {
final ClassNode cn = BytecodeViewer.getClassNode(container, name.substring(0,
final ClassNode cn = BytecodeViewer.getClassNode(Objects.requireNonNull(container), name.substring(0,
name.length() - ".class".length()));
if (cn != null) {
openClassFileToWorkSpace(container, nameBuffer.toString(), cn);
@ -671,8 +649,9 @@ public class FileNavigationPane extends VisibleComponent implements
* @author http://stackoverflow.com/questions/14968005
* @author Konloch
*/
public class ImageRenderer extends DefaultTreeCellRenderer {
public static class ImageRenderer extends DefaultTreeCellRenderer {
@Override
public Component getTreeCellRendererComponent(
JTree tree,
Object value,
@ -685,7 +664,7 @@ public class FileNavigationPane extends VisibleComponent implements
Component ret = super.getTreeCellRendererComponent(tree, value,
selected, expanded, leaf, row, hasFocus);
if (value != null && value instanceof the.bytecode.club.bytecodeviewer.gui.FileNavigationPane.MyTreeNode) {
if (value instanceof MyTreeNode) {
the.bytecode.club.bytecodeviewer.gui.FileNavigationPane.MyTreeNode node =
(the.bytecode.club.bytecodeviewer.gui.FileNavigationPane.MyTreeNode) value;
String name = node.toString().toLowerCase();
@ -720,8 +699,8 @@ public class FileNavigationPane extends VisibleComponent implements
} else if (node.getChildCount() <= 0) { //random file
setIcon(Resources.fileIcon);
} else { //folder
ArrayList<TreeNode> nodes = new ArrayList<TreeNode>();
ArrayList<TreeNode> totalNodes = new ArrayList<TreeNode>();
ArrayList<TreeNode> nodes = new ArrayList<>();
ArrayList<TreeNode> totalNodes = new ArrayList<>();
nodes.add(node);
totalNodes.add(node);

View File

@ -3,16 +3,11 @@ package the.bytecode.club.bytecodeviewer.gui;
import com.jhe.hexed.JHexEditor;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.StandardCharsets;
import javax.imageio.ImageIO;
@ -79,6 +74,7 @@ public class FileViewer extends Viewer {
panelArea.setAntiAliasingEnabled(true);
RTextScrollPane scrollPane = new RTextScrollPane(panelArea);
panelArea.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent e) {
if ((e.getKeyCode() == KeyEvent.VK_F) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) {
field.requestFocus();
@ -106,9 +102,7 @@ public class FileViewer extends Viewer {
image = ImageIO.read(new ByteArrayInputStream(contents)); //gifs fail cause of this
JLabel label = new JLabel("", new ImageIcon(image), JLabel.CENTER);
panel2.add(label, BorderLayout.CENTER);
panel2.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
panel2.addMouseWheelListener(e -> {
int notches = e.getWheelRotation();
if (notches < 0) {
image = Scalr.resize(image, Scalr.Method.SPEED, image.getWidth() + 10,
@ -118,10 +112,9 @@ public class FileViewer extends Viewer {
image.getHeight() - 10);
}
panel2.removeAll();
JLabel label = new JLabel("", new ImageIcon(image), JLabel.CENTER);
panel2.add(label, BorderLayout.CENTER);
JLabel label1 = new JLabel("", new ImageIcon(image), JLabel.CENTER);
panel2.add(label1, BorderLayout.CENTER);
panel2.updateUI();
}
});
return;
} catch (Exception e) {
@ -229,18 +222,8 @@ public class FileViewer extends Viewer {
panel.add(buttonPane, BorderLayout.WEST);
panel.add(field, BorderLayout.CENTER);
panel.add(check, BorderLayout.EAST);
searchNext.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent arg0) {
search(field.getText(), true);
}
});
searchPrev.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent arg0) {
search(field.getText(), false);
}
});
searchNext.addActionListener(arg0 -> search(field.getText(), true));
searchPrev.addActionListener(arg0 -> search(field.getText(), false));
field.addKeyListener(new KeyListener() {
@Override
public void keyReleased(KeyEvent arg0) {
@ -277,7 +260,7 @@ public class FileViewer extends Viewer {
.getElementIndex(area.getCaretPosition()) + 1;
int currentLine = 1;
boolean canSearch = false;
String[] test = null;
String[] test;
if (area.getText().split("\n").length >= 2)
test = area.getText().split("\n");
else

View File

@ -31,11 +31,11 @@ import the.bytecode.club.bytecodeviewer.Resources;
* @author Konloch
*/
public class GraphicialReflectionKit extends JFrame {
public GraphicialReflectionKit() {
public class GraphicalReflectionKit extends JFrame {
public GraphicalReflectionKit() {
this.setIconImages(Resources.iconList);
setSize(new Dimension(382, 356));
setTitle("Graphicial Reflection Kit");
setTitle("Graphical Reflection Kit");
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
getContentPane().add(tabbedPane, BorderLayout.CENTER);

View File

@ -100,8 +100,7 @@ public class MaliciousCodeScannerOptions extends JFrame {
getContentPane().add(chckbxJavaawtrobot);
JButton btnNewButton = new JButton("Start Scanning");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
btnNewButton.addActionListener(arg0 -> {
PluginManager.runPlugin(new MaliciousCodeScanner(
chckbxJavalangreflection.isSelected(),
chckbxJavalangruntime.isSelected(),
@ -114,7 +113,6 @@ public class MaliciousCodeScannerOptions extends JFrame {
chckbxNullSecMan.isSelected(),
chckbxJavaawtrobot.isSelected()));
dispose();
}
});
btnNewButton.setBounds(6, 264, 232, 23);

View File

@ -21,11 +21,8 @@ package the.bytecode.club.bytecodeviewer.gui;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.util.Objects;
import java.util.regex.Matcher;
import javax.swing.JComboBox;
import javax.swing.JLabel;
@ -73,9 +70,7 @@ public abstract class PaneUpdaterThread extends Thread {
if (scrollPane == null)
return;
scrollPane.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
scrollPane.addMouseWheelListener(e -> {
if (panelArea == null || panelArea.getText().isEmpty())
return;
@ -89,7 +84,6 @@ public abstract class PaneUpdaterThread extends Thread {
}
}
e.consume();
}
});
}
@ -102,7 +96,7 @@ public abstract class PaneUpdaterThread extends Thread {
if (methodLine != -1) {
if (BytecodeViewer.viewer.showClassMethods.isSelected()) {
if (methodsList != null) {
if (methodLine != (int) methodsList.getSelectedItem()) {
if (methodLine != (int) Objects.requireNonNull(methodsList.getSelectedItem())) {
methodsList.setSelectedItem(methodLine);
}
}
@ -196,6 +190,7 @@ public abstract class PaneUpdaterThread extends Thread {
setOpaque(true);
}
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected,
boolean cellHasFocus) {
MethodParser methods = viewer.methods.get(paneId);
@ -228,10 +223,8 @@ public abstract class PaneUpdaterThread extends Thread {
methodsList.addItem(line);
}
methodsList.setRenderer(new PaneUpdaterThread.MethodsRenderer());
methodsList.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int line = (int) methodsList.getSelectedItem();
methodsList.addActionListener(e -> {
int line = (int) Objects.requireNonNull(methodsList.getSelectedItem());
RSyntaxTextArea area = null;
switch (paneId) {
@ -248,7 +241,6 @@ public abstract class PaneUpdaterThread extends Thread {
if (area != null)
ClassViewer.selectMethod(area, line);
}
});
JPanel panel = new JPanel(new BorderLayout());

View File

@ -84,13 +84,11 @@ public class ReplaceStringsOptions extends JFrame {
+ " it contains, then replace the original LDC part of the string.");
chckbxNewCheckBox.setBounds(6, 7, 232, 23);
getContentPane().add(chckbxNewCheckBox);
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
btnNewButton.addActionListener(arg0 -> {
PluginManager.runPlugin(new ReplaceStrings(textField.getText(),
textField_1.getText(), textField_2.getText(),
chckbxNewCheckBox.isSelected()));
dispose();
}
});
this.setLocationRelativeTo(null);
}

View File

@ -133,8 +133,7 @@ public class RunOptions extends JFrame {
chckbxPrintToTerminal.setBounds(6, 315, 232, 23);
getContentPane().add(chckbxPrintToTerminal);
this.setLocationRelativeTo(null);
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
btnNewButton.addActionListener(arg0 -> {
PluginManager.runPlugin(new EZInjection(accessModifiers
.isSelected(), injectHooks.isSelected(),
debugMethodCalls.isSelected(), invokeMethod
@ -145,7 +144,6 @@ public class RunOptions extends JFrame {
launchReflectionKit.isSelected(), console.isSelected(),
chckbxPrintToTerminal.isSelected()));
dispose();
}
});
}

View File

@ -2,10 +2,8 @@ package the.bytecode.club.bytecodeviewer.gui;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.Objects;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import javax.swing.DefaultComboBoxModel;
@ -16,8 +14,6 @@ import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
import org.objectweb.asm.tree.ClassNode;
@ -62,6 +58,8 @@ import the.bytecode.club.bytecodeviewer.util.FileContainer;
public class SearchingPane extends VisibleComponent {
private static final long serialVersionUID = -1098524689236993932L;
public static final SearchRadius[] SEARCH_RADII = SearchRadius.values();
public static final SearchType[] SEARCH_TYPES = SearchType.values();
FileChangeNotifier fcn;
@ -97,7 +95,7 @@ public class SearchingPane extends VisibleComponent {
searchRadiusOpt.add(new JLabel("Search from "), BorderLayout.WEST);
DefaultComboBoxModel model = new DefaultComboBoxModel();
for (final SearchRadius st : SearchRadius.values()) {
for (final SearchRadius st : SEARCH_RADII) {
model.addElement(st);
}
@ -108,23 +106,20 @@ public class SearchingPane extends VisibleComponent {
searchOpts.add(searchRadiusOpt);
model = new DefaultComboBoxModel();
for (final SearchType st : SearchType.values()) {
for (final SearchType st : SEARCH_TYPES) {
model.addElement(st);
}
typeBox = new JComboBox(model);
final JPanel searchOptPanel = new JPanel();
final ItemListener il = new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent arg0) {
final ItemListener il = arg0 -> {
searchOptPanel.removeAll();
searchType = (SearchType) typeBox.getSelectedItem();
searchOptPanel.add(searchType.details.getPanel());
searchOptPanel.add(Objects.requireNonNull(searchType).details.getPanel());
searchOptPanel.revalidate();
searchOptPanel.repaint();
}
};
typeBox.addItemListener(il);
@ -143,12 +138,7 @@ public class SearchingPane extends VisibleComponent {
optionPanel.add(p2, BorderLayout.CENTER);
search.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent arg0) {
search();
}
});
search.addActionListener(arg0 -> search());
optionPanel.add(search, BorderLayout.SOUTH);
@ -159,13 +149,11 @@ public class SearchingPane extends VisibleComponent {
getContentPane().add(new JScrollPane(optionPanel), BorderLayout.NORTH);
getContentPane().add(new JScrollPane(tree), BorderLayout.CENTER);
this.tree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(final TreeSelectionEvent arg0) {
this.tree.addTreeSelectionListener(arg0 -> {
if (arg0.getPath().getPathComponent(0).equals("Results"))
return;
String cheapHax = arg0.getPath().getPathComponent(1).toString();
arg0.getPath().getPathComponent(1);
String path = arg0.getPath().getPathComponent(1).toString();
@ -173,12 +161,11 @@ public class SearchingPane extends VisibleComponent {
String className = path.split(">", 2)[1].split("\\.")[0];
FileContainer container = BytecodeViewer.getFileContainer(containerName);
final ClassNode fN = container.getClassNode(className);
final ClassNode fN = Objects.requireNonNull(container).getClassNode(className);
if (fN != null) {
MainViewerGUI.getComponent(FileNavigationPane.class).openClassFileToWorkSpace(container,
className + ".class", fN);
}
Objects.requireNonNull(MainViewerGUI.getComponent(FileNavigationPane.class))
.openClassFileToWorkSpace(container, className + ".class", fN);
}
});
@ -191,12 +178,7 @@ public class SearchingPane extends VisibleComponent {
searchType = (SearchType) typeBox.getSelectedItem();
final SearchRadius radius = (SearchRadius) searchRadiusBox
.getSelectedItem();
final SearchResultNotifier srn = new SearchResultNotifier() {
@Override
public void notifyOfResult(String debug) {
treeRoot.add(new DefaultMutableTreeNode(debug));
}
};
final SearchResultNotifier srn = debug -> treeRoot.add(new DefaultMutableTreeNode(debug));
if (radius == SearchRadius.All_Classes) {
if (t.finished) {
t = new BackgroundSearchThread() {
@ -214,16 +196,17 @@ public class SearchingPane extends VisibleComponent {
for (ClassNode c : container.classes)
searchType.details.search(container, c, srn, exact.isSelected());
MainViewerGUI.getComponent(SearchingPane.class).search.setEnabled(true);
MainViewerGUI.getComponent(SearchingPane.class).search.setText("Search");
Objects.requireNonNull(MainViewerGUI.getComponent(SearchingPane.class)).search.setEnabled(true);
Objects.requireNonNull(MainViewerGUI.getComponent(SearchingPane.class)).search.setText(
"Search");
tree.expandPath(new TreePath(tree.getModel().getRoot()));
tree.updateUI();
}
};
MainViewerGUI.getComponent(SearchingPane.class).search
Objects.requireNonNull(MainViewerGUI.getComponent(SearchingPane.class)).search
.setEnabled(false);
MainViewerGUI.getComponent(SearchingPane.class).search
Objects.requireNonNull(MainViewerGUI.getComponent(SearchingPane.class)).search
.setText("Searching, please wait..");
t.start();
} else { // this should really never be called.
@ -232,7 +215,7 @@ public class SearchingPane extends VisibleComponent {
+ "to finish.");
}
} else if (radius == SearchRadius.Current_Class) {
final Viewer cv = MainViewerGUI.getComponent(WorkPane.class).getCurrentViewer();
final Viewer cv = Objects.requireNonNull(MainViewerGUI.getComponent(WorkPane.class)).getCurrentViewer();
if (cv != null) {
searchType.details.search(cv.container, cv.cn, srn, exact.isSelected());
}

View File

@ -3,8 +3,6 @@ package the.bytecode.club.bytecodeviewer.gui;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.IOException;
@ -65,6 +63,7 @@ public class SystemErrConsole extends JFrame {
scrollPane.setViewportView(textArea);
textArea.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent e) {
if ((e.getKeyCode() == KeyEvent.VK_F) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) {
field.requestFocus();
@ -92,19 +91,9 @@ public class SystemErrConsole extends JFrame {
panel.add(buttonPane, BorderLayout.WEST);
panel.add(field, BorderLayout.CENTER);
panel.add(check, BorderLayout.EAST);
searchNext.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent arg0) {
search(field.getText(), true);
}
});
searchNext.addActionListener(arg0 -> search(field.getText(), true));
searchPrev.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent arg0) {
search(field.getText(), false);
}
});
searchPrev.addActionListener(arg0 -> search(field.getText(), false));
field.addKeyListener(new KeyListener() {
@Override
public void keyReleased(KeyEvent arg0) {
@ -137,22 +126,22 @@ public class SystemErrConsole extends JFrame {
public void pretty() {
s.update();
String[] test = null;
String[] test;
if (textArea.getText().split("\n").length >= 2)
test = textArea.getText().split("\n");
else
test = textArea.getText().split("\r");
String replace = "";
StringBuilder replace = new StringBuilder();
for (String s : test) {
if (s.startsWith("File '")) {
String[] split = s.split("'");
String start = split[0] + "'" + split[1] + "', ";
s = s.substring(start.length());
}
replace += s + BytecodeViewer.nl;
replace.append(s).append(BytecodeViewer.nl);
}
setText(replace);
setText(replace.toString());
}
/**
@ -172,7 +161,7 @@ public class SystemErrConsole extends JFrame {
.getElementIndex(area.getCaretPosition()) + 1;
int currentLine = 1;
boolean canSearch = false;
String[] test = null;
String[] test;
if (area.getText().split("\n").length >= 2)
test = area.getText().split("\n");
else
@ -304,7 +293,7 @@ public class SystemErrConsole extends JFrame {
textArea.setCaretPosition(0);
}
class CustomOutputStream extends OutputStream {
static class CustomOutputStream extends OutputStream {
private final StringBuilder sb = new StringBuilder();
private final JTextArea textArea;

View File

@ -10,6 +10,7 @@ import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
@ -54,12 +55,7 @@ public class TabbedPane extends JPanel {
public static final Color BLANK = new Color(0, 0, 0, 0);
private final JTabbedPane pane;
public final JLabel label;
private final JButton button = new TabButton();
private static long zero = System.currentTimeMillis();
private final long startedDragging = 0;
private boolean dragging = false;
private DelayTabbedPaneThread probablyABadIdea;
private final TabbedPane THIS = this;
public String tabName;
public String fileContainerName;
@ -102,30 +98,24 @@ public class TabbedPane extends JPanel {
// add more space between the label and the button
label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
// tab button
JButton button = new TabButton();
this.add(button);
// add more space to the top of the component
setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));
JPopupMenu pop_up = new JPopupMenu();
JMenuItem closealltab = new JMenuItem("Close All But This: " + name);
JMenuItem closetab = new JMenuItem("Close Tab: " + name);
closetab.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String name = e.getActionCommand().split(": ")[1];
final int i = pane.indexOfTab(name);
closetab.addActionListener(e -> {
String name1 = e.getActionCommand().split(": ")[1];
final int i = pane.indexOfTab(name1);
if (i != -1)
pane.remove(i);
}
});
closealltab.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String name = e.getActionCommand().split(": ")[1];
boolean removedAll = false;
while (!removedAll) {
int thisID = pane.indexOfTab(name);
closealltab.addActionListener(e -> {
String name12 = e.getActionCommand().split(": ")[1];
while (true) {
int thisID = pane.indexOfTab(name12);
if (pane.getTabCount() <= 1) {
removedAll = true;
return;
}
if (thisID != 0)
@ -133,7 +123,6 @@ public class TabbedPane extends JPanel {
else
pane.remove(1);
}
}
});
pop_up.add(closealltab);
@ -144,7 +133,7 @@ public class TabbedPane extends JPanel {
button.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getModifiers() == 8) {
if (e.getModifiers() == InputEvent.ALT_MASK) {
if (System.currentTimeMillis() - zero >= 100) {
zero = System.currentTimeMillis();
final int i = pane.indexOfTabComponent(TabbedPane.this);
@ -211,6 +200,7 @@ public class TabbedPane extends JPanel {
}
private void stopDragging(int mouseX, int mouseY) {
long startedDragging = 0;
if (System.currentTimeMillis() - startedDragging >= 210) {
Rectangle bounds = new Rectangle(1, 1, mouseX, mouseY);
System.out.println("debug-5: " + mouseX + ", " + mouseY);
@ -238,11 +228,7 @@ public class TabbedPane extends JPanel {
BytecodeViewer.viewer.workPane.tabs.setTabComponentAt(index, this);
}
}
dragging = false;
label.setBackground(BLANK);
if (probablyABadIdea != null) {
probablyABadIdea.stopped = true;
}
label.updateUI();
}
@ -269,6 +255,7 @@ public class TabbedPane extends JPanel {
addActionListener(this);
}
@Override
public void actionPerformed(final ActionEvent e) {
final int i = pane.indexOfTabComponent(TabbedPane.this);
if (i != -1) {

View File

@ -17,8 +17,6 @@ import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JTabbedPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.objectweb.asm.tree.ClassNode;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.util.FileChangeNotifier;
@ -59,9 +57,7 @@ public class WorkPane extends VisibleComponent implements ActionListener {
JPanel buttonPanel;
JButton refreshClass;
HashMap<String, Integer> workingOn = new HashMap<String, Integer>();
public static int SyntaxFontHeight = 12;
HashMap<String, Integer> workingOn = new HashMap<>();
public WorkPane(final FileChangeNotifier fcn) {
super("WorkPanel");
@ -79,25 +75,18 @@ public class WorkPane extends VisibleComponent implements ActionListener {
};
JMenuItem closealltab = new JMenuItem("Close All But This");
JMenuItem closetab = new JMenuItem("Close Tab");
closetab.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
closetab.addActionListener(e -> {
/*String name = e.getActionCommand().split(": ")[1];
final int i = pane.indexOfTab(name);
if (i != -1)
pane.remove(i);*/
}
});
closealltab.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
closealltab.addActionListener(e -> {
String name = e.getActionCommand().split(": ")[1];
System.out.println("debug-3: " + name);
boolean removedAll = false;
while (!removedAll) {
while (true) {
int thisID = tabs.indexOfTab(name);
if (tabs.getTabCount() <= 1) {
removedAll = true;
return;
}
if (thisID != 0)
@ -105,7 +94,6 @@ public class WorkPane extends VisibleComponent implements ActionListener {
else
tabs.remove(1);
}
}
});
tabs.addMouseListener(new MouseListener() {
@Override
@ -204,19 +192,12 @@ public class WorkPane extends VisibleComponent implements ActionListener {
}
});
tabs.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(final ChangeEvent arg0) {
buttonPanel.setVisible(tabs.getSelectedIndex() != -1);
}
});
tabs.addChangeListener(arg0 -> buttonPanel.setVisible(tabs.getSelectedIndex() != -1));
this.setVisible(true);
}
int tabCount = 0;
public void addWorkingFile(final FileContainer container, String name, final ClassNode cn) {
String workingName = container.name + ">" + name;
String containerName = name;
@ -225,12 +206,12 @@ public class WorkPane extends VisibleComponent implements ActionListener {
containerName = container.name + ">" + name;
if (!workingOn.containsKey(workingName)) {
final JPanel tabComp = new ClassViewer(container, containerName, cn);
final ClassViewer tabComp = new ClassViewer(container, containerName, cn);
tabs.add(tabComp);
final int tabCount = tabs.indexOfComponent(tabComp);
workingOn.put(workingName, tabCount);
TabbedPane tabbedPane = new TabbedPane(container.name, name, tabs);
((ClassViewer) tabComp).tabbedPane = tabbedPane;
tabComp.tabbedPane = tabbedPane;
tabs.setTabComponentAt(tabCount, tabbedPane);
tabs.setSelectedIndex(tabCount);
} else {
@ -248,22 +229,20 @@ public class WorkPane extends VisibleComponent implements ActionListener {
return;
if (!workingOn.containsKey(workingName)) {
final Component tabComp = new FileViewer(container, name, contents);
final FileViewer tabComp = new FileViewer(container, name, contents);
tabs.add(tabComp);
final int tabCount = tabs.indexOfComponent(tabComp);
workingOn.put(workingName, tabCount);
TabbedPane tabbedPane = new TabbedPane(null, name, tabs);
((FileViewer) tabComp).tabbedPane = tabbedPane;
tabComp.tabbedPane = tabbedPane;
tabs.setTabComponentAt(tabCount, tabbedPane);
tabs.setSelectedIndex(tabCount);
} else {
try {
tabs.setSelectedIndex(workingOn.get(workingName));
} catch (java.lang.IndexOutOfBoundsException e) {
//workingOn.remove(workingName);
e.printStackTrace();
} catch (Exception e) {
//workingOn.remove(workingName);
e.printStackTrace();
}
}
@ -289,13 +268,12 @@ public class WorkPane extends VisibleComponent implements ActionListener {
@Override
public void actionPerformed(final ActionEvent arg0) {
Thread t = new Thread() {
public void run() {
Thread t = new Thread(() -> {
if (BytecodeViewer.viewer.autoCompileOnRefresh.isSelected())
try {
if (!BytecodeViewer.compile(false))
return;
} catch (java.lang.NullPointerException e) {
} catch (NullPointerException ignored) {
}
final JButton src = (JButton) arg0.getSource();
@ -315,8 +293,7 @@ public class WorkPane extends VisibleComponent implements ActionListener {
}
}
}
}
};
});
t.start();
}

View File

@ -52,7 +52,7 @@ public abstract class JavaObfuscator extends Thread {
public static int MAX_STRING_LENGTH = 25;
public static int MIN_STRING_LENGTH = 5;
private final ArrayList<String> names = new ArrayList<String>();
private final ArrayList<String> names = new ArrayList<>();
protected String generateUniqueName(int length) {
boolean found = false;

View File

@ -31,9 +31,9 @@ public class HookMap {
protected List<MethodMappingData> methods;
public HookMap() {
classes = new ArrayList<MappingData>();
fields = new ArrayList<FieldMappingData>();
methods = new ArrayList<MethodMappingData>();
classes = new ArrayList<>();
fields = new ArrayList<>();
methods = new ArrayList<>();
}
public void addClass(MappingData clazz) {

View File

@ -1,7 +1,5 @@
package the.bytecode.club.bytecodeviewer.obfuscators.mapping;
import java.util.HashMap;
import java.util.Map;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.tree.ClassNode;
@ -45,9 +43,9 @@ public class Refactorer {
return;
RefactorMapper mapper = new RefactorMapper(getHooks());
Map<String, ClassNode> refactored = new HashMap<>();
//Map<String, ClassNode> refactored = new HashMap<>();
for (ClassNode cn : BytecodeViewer.getLoadedClasses()) {
String oldName = cn.name;
//String oldName = cn.name;
ClassReader cr = new ClassReader(getClassNodeBytes(cn));
ClassWriter cw = new ClassWriter(cr, 0);
RemappingClassAdapter rca = new RemappingClassAdapter(cw, mapper);
@ -55,7 +53,7 @@ public class Refactorer {
cr = new ClassReader(cw.toByteArray());
cn = new ClassNode();
cr.accept(cn, 0);
refactored.put(oldName, cn);
//refactored.put(oldName, cn);
}
/*for (Map.Entry<String, ClassNode> factor : refactored.entrySet()) {
BytecodeViewer.relocate(factor.getKey(), factor.getValue());
@ -66,7 +64,6 @@ public class Refactorer {
private byte[] getClassNodeBytes(ClassNode cn) {
ClassWriter cw = new ClassWriter(0);
cn.accept(cw);
byte[] b = cw.toByteArray();
return b;
return cw.toByteArray();
}
}

View File

@ -31,6 +31,7 @@
package the.bytecode.club.bytecodeviewer.obfuscators.mapping;
import org.objectweb.asm.Handle;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.signature.SignatureReader;
import org.objectweb.asm.signature.SignatureVisitor;
@ -50,15 +51,16 @@ import org.objectweb.asm.signature.SignatureWriter;
*/
public abstract class Remapper extends org.objectweb.asm.commons.Remapper {
@Override
public String mapDesc(String desc) {
Type t = Type.getType(desc);
switch (t.getSort()) {
case Type.ARRAY:
String s = mapDesc(t.getElementType().getDescriptor());
StringBuilder s = new StringBuilder(mapDesc(t.getElementType().getDescriptor()));
for (int i = 0; i < t.getDimensions(); ++i) {
s = '[' + s;
s.insert(0, '[');
}
return s;
return s.toString();
case Type.OBJECT:
String newType = map(t.getInternalName());
if (newType != null) {
@ -71,20 +73,21 @@ public abstract class Remapper extends org.objectweb.asm.commons.Remapper {
private Type mapType(Type t) {
switch (t.getSort()) {
case Type.ARRAY:
String s = mapDesc(t.getElementType().getDescriptor());
StringBuilder s = new StringBuilder(mapDesc(t.getElementType().getDescriptor()));
for (int i = 0; i < t.getDimensions(); ++i) {
s = '[' + s;
s.insert(0, '[');
}
return Type.getType(s);
return Type.getType(s.toString());
case Type.OBJECT:
s = map(t.getInternalName());
return s != null ? Type.getObjectType(s) : t;
s = new StringBuilder(map(t.getInternalName()));
return Type.getObjectType(s.toString());
case Type.METHOD:
return Type.getMethodType(mapMethodDesc(t.getDescriptor()));
}
return t;
}
@Override
public String mapType(String type) {
if (type == null) {
return null;
@ -92,6 +95,7 @@ public abstract class Remapper extends org.objectweb.asm.commons.Remapper {
return mapType(Type.getObjectType(type)).getInternalName();
}
@Override
public String[] mapTypes(String[] types) {
String[] newTypes = null;
boolean needMapping = false;
@ -112,6 +116,7 @@ public abstract class Remapper extends org.objectweb.asm.commons.Remapper {
return needMapping ? newTypes : types;
}
@Override
public String mapMethodDesc(String desc) {
if ("()V".equals(desc)) {
return desc;
@ -119,8 +124,8 @@ public abstract class Remapper extends org.objectweb.asm.commons.Remapper {
Type[] args = Type.getArgumentTypes(desc);
StringBuilder sb = new StringBuilder("(");
for (int i = 0; i < args.length; i++) {
sb.append(mapDesc(args[i].getDescriptor()));
for (Type arg : args) {
sb.append(mapDesc(arg.getDescriptor()));
}
Type returnType = Type.getReturnType(desc);
if (returnType == Type.VOID_TYPE) {
@ -131,6 +136,7 @@ public abstract class Remapper extends org.objectweb.asm.commons.Remapper {
return sb.toString();
}
@Override
public Object mapValue(Object value) {
if (value instanceof Type) {
return mapType((Type) value);
@ -139,7 +145,7 @@ public abstract class Remapper extends org.objectweb.asm.commons.Remapper {
Handle h = (Handle) value;
return new Handle(h.getTag(), mapType(h.getOwner()), mapMethodName(
h.getOwner(), h.getName(), h.getDesc()),
mapMethodDesc(h.getDesc()));
mapMethodDesc(h.getDesc()), h.getTag() == Opcodes.H_INVOKEINTERFACE);
}
return value;
}
@ -149,13 +155,14 @@ public abstract class Remapper extends org.objectweb.asm.commons.Remapper {
* signature parameter of the ClassVisitor.visitField or
* MethodVisitor.visitLocalVariable methods
*/
@Override
public String mapSignature(String signature, boolean typeSignature) {
if (signature == null) {
return null;
}
SignatureReader r = new SignatureReader(signature);
SignatureWriter w = new SignatureWriter();
SignatureVisitor a = createRemappingSignatureAdapter(w);
SignatureVisitor a = createSignatureRemapper(w);
if (typeSignature) {
r.acceptType(a);
} else {
@ -164,8 +171,8 @@ public abstract class Remapper extends org.objectweb.asm.commons.Remapper {
return w.toString();
}
protected SignatureVisitor createRemappingSignatureAdapter(
SignatureVisitor v) {
@Override
protected SignatureVisitor createSignatureRemapper(SignatureVisitor v) {
return new RemappingSignatureAdapter(v, this);
}
@ -177,6 +184,7 @@ public abstract class Remapper extends org.objectweb.asm.commons.Remapper {
* @param desc descriptor of the method.
* @return new name of the method
*/
@Override
public String mapMethodName(String owner, String name, String desc) {
return name;
}
@ -188,6 +196,7 @@ public abstract class Remapper extends org.objectweb.asm.commons.Remapper {
* @param desc descriptor of the invokedynamic.
* @return new invokdynamic name.
*/
@Override
public String mapInvokeDynamicMethodName(String name, String desc) {
return name;
}
@ -200,6 +209,7 @@ public abstract class Remapper extends org.objectweb.asm.commons.Remapper {
* @param desc descriptor of the field
* @return new name of the field.
*/
@Override
public String mapFieldName(String owner, String name, String desc) {
return name;
}
@ -207,6 +217,7 @@ public abstract class Remapper extends org.objectweb.asm.commons.Remapper {
/**
* Map type name to the new name. Subclasses can override.
*/
@Override
public String map(String typeName) {
return typeName;
}

View File

@ -62,14 +62,14 @@ public class RemappingMethodAdapter extends LocalVariablesSorter {
@Override
public AnnotationVisitor visitAnnotationDefault() {
AnnotationVisitor av = super.visitAnnotationDefault();
return av == null ? av : new RemappingAnnotationAdapter(av, remapper);
return av == null ? null : new RemappingAnnotationAdapter(av, remapper);
}
@Override
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
AnnotationVisitor av = super.visitAnnotation(remapper.mapDesc(desc),
visible);
return av == null ? av : new RemappingAnnotationAdapter(av, remapper);
return av == null ? null : new RemappingAnnotationAdapter(av, remapper);
}
@Override
@ -77,7 +77,7 @@ public class RemappingMethodAdapter extends LocalVariablesSorter {
TypePath typePath, String desc, boolean visible) {
AnnotationVisitor av = super.visitTypeAnnotation(typeRef, typePath,
remapper.mapDesc(desc), visible);
return av == null ? av : new RemappingAnnotationAdapter(av, remapper);
return av == null ? null : new RemappingAnnotationAdapter(av, remapper);
}
@Override
@ -85,7 +85,7 @@ public class RemappingMethodAdapter extends LocalVariablesSorter {
String desc, boolean visible) {
AnnotationVisitor av = super.visitParameterAnnotation(parameter,
remapper.mapDesc(desc), visible);
return av == null ? av : new RemappingAnnotationAdapter(av, remapper);
return av == null ? null : new RemappingAnnotationAdapter(av, remapper);
}
@Override
@ -190,7 +190,7 @@ public class RemappingMethodAdapter extends LocalVariablesSorter {
TypePath typePath, String desc, boolean visible) {
AnnotationVisitor av = super.visitInsnAnnotation(typeRef, typePath,
remapper.mapDesc(desc), visible);
return av == null ? av : new RemappingAnnotationAdapter(av, remapper);
return av == null ? null : new RemappingAnnotationAdapter(av, remapper);
}
@Override
@ -205,7 +205,7 @@ public class RemappingMethodAdapter extends LocalVariablesSorter {
TypePath typePath, String desc, boolean visible) {
AnnotationVisitor av = super.visitTryCatchAnnotation(typeRef, typePath,
remapper.mapDesc(desc), visible);
return av == null ? av : new RemappingAnnotationAdapter(av, remapper);
return av == null ? null : new RemappingAnnotationAdapter(av, remapper);
}
@Override
@ -221,6 +221,6 @@ public class RemappingMethodAdapter extends LocalVariablesSorter {
String desc, boolean visible) {
AnnotationVisitor av = super.visitLocalVariableAnnotation(typeRef,
typePath, start, end, index, remapper.mapDesc(desc), visible);
return av == null ? av : new RemappingAnnotationAdapter(av, remapper);
return av == null ? null : new RemappingAnnotationAdapter(av, remapper);
}
}

View File

@ -41,17 +41,15 @@ public class RenameClasses extends JavaObfuscator {
classLoop:
for (ClassNode c : BytecodeViewer.getLoadedClasses()) {
/** As we dont want to rename classes that contain native dll methods */
for (Object o : c.methods) {
MethodNode m = (MethodNode) o;
/** As we dont want to rename any main-classes */
if (m.name.equals("main") && m.desc.equals("([Ljava/lang/String;)V")
|| m.name.equals("init") && c.superName.equals("java/applet/Applet"))
/* As we dont want to rename classes that contain native dll methods */
for (MethodNode o : c.methods) {
/* As we dont want to rename any main-classes */
if (o.name.equals("main") && o.desc.equals("([Ljava/lang/String;)V")
|| o.name.equals("init") && c.superName.equals("java/applet/Applet"))
continue classLoop;
/* As we dont want to rename native dll methods */
if ((m.access & Opcodes.ACC_NATIVE) != 0)
if ((o.access & Opcodes.ACC_NATIVE) != 0)
continue classLoop;
}

View File

@ -40,13 +40,12 @@ public class RenameMethods extends JavaObfuscator {
System.out.println("Obfuscating method names...");
for (ClassNode c : BytecodeViewer.getLoadedClasses()) {
methodLoop:
for (Object o : c.methods.toArray()) {
MethodNode m = (MethodNode) o;
/* As we dont want to rename native dll methods */
if ((m.access & Opcodes.ACC_NATIVE) != 0)
continue methodLoop;
continue;
if (m.access != Opcodes.ACC_ABSTRACT
&& m.access != Opcodes.ACC_ABSTRACT

View File

@ -43,8 +43,7 @@ import the.bytecode.club.bytecodeviewer.util.MiscUtils;
*/
public final class PluginManager {
private static final Map<String, PluginLaunchStrategy> launchStrategies = new HashMap<String,
PluginLaunchStrategy>();
private static final Map<String, PluginLaunchStrategy> launchStrategies = new HashMap<>();
private static final PluginFileFilter filter = new PluginFileFilter();
private static Plugin pluginInstance;

View File

@ -54,7 +54,7 @@ public class CodeSequenceDiagram extends Plugin {
BytecodeViewer.showMessage("ClassNode is null for CodeSequenceDiagram. Please report to @Konloch");
return;
}
JFrame frame = null;
JFrame frame;
if (c.name != null)
frame = new JFrame("Code Sequence Diagram - " + c.name);
else
@ -85,9 +85,8 @@ public class CodeSequenceDiagram extends Plugin {
for (MethodNode m : c.methods) {
String mIdentifier = c.name + "." + m.name + m.desc;
Object node = graph.insertVertex(parent, null, mIdentifier, testX, testY,
Object attach = graph.insertVertex(parent, null, mIdentifier, testX, testY,
mIdentifier.length() * magicNumber, 30);
Object attach = node;
testX += (int) (font.getStringBounds(mIdentifier, frc).getWidth()) + 60;
for (AbstractInsnNode i : m.instructions.toArray()) {
if (i instanceof MethodInsnNode) {

View File

@ -14,7 +14,7 @@ import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.api.BytecodeHook;
import the.bytecode.club.bytecodeviewer.api.Plugin;
import the.bytecode.club.bytecodeviewer.api.PluginConsole;
import the.bytecode.club.bytecodeviewer.gui.GraphicialReflectionKit;
import the.bytecode.club.bytecodeviewer.gui.GraphicalReflectionKit;
/***************************************************************************
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
@ -46,7 +46,7 @@ import the.bytecode.club.bytecodeviewer.gui.GraphicialReflectionKit;
public class EZInjection extends Plugin {
public static ArrayList<BytecodeHook> hookArray = new ArrayList<BytecodeHook>();
public static ArrayList<BytecodeHook> hookArray = new ArrayList<>();
private static final String version = "1.0";
private static final PluginConsole gui = new PluginConsole("EZ Injection v" + version);
private final boolean accessModifiers;
@ -111,8 +111,10 @@ public class EZInjection extends Plugin {
if (!all && debugClasses.length >= 1) {
for (String s : debugClasses) {
if (info.split("\\.")[0].equals(s.replaceAll("\\.", "/")))
if (info.split("\\.")[0].equals(s.replaceAll("\\.", "/"))) {
print = true;
break;
}
}
}
@ -129,7 +131,6 @@ public class EZInjection extends Plugin {
gui.appendText(message);
}
@SuppressWarnings("deprecation")
@Override
public void execute(ArrayList<ClassNode> classNodeList) {
BytecodeViewer.viewer.setIcon(true);
@ -290,7 +291,7 @@ public class EZInjection extends Plugin {
.newInstance(),
(Object[]) new String[1]);
if (launchKit)
new GraphicialReflectionKit()
new GraphicalReflectionKit()
.setVisible(true);
} catch (Exception e) {
StringWriter sw = new StringWriter();

View File

@ -79,9 +79,8 @@ public class MaliciousCodeScanner extends Plugin {
|| (ROB && s.contains("java/awt/Robot"))
|| (LIP && s
.matches("\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b")))
sb.append("Found LDC \"" + s + "\" at field "
+ classNode.name + "." + f.name + "(" + f.desc
+ ")" + BytecodeViewer.nl);
sb.append("Found LDC \"").append(s).append("\" at field ").append(classNode.name).append(".")
.append(f.name).append("(").append(f.desc).append(")").append(BytecodeViewer.nl);
}
if (v instanceof String[]) {
for (int i = 0; i < ((String[]) v).length; i++) {
@ -95,9 +94,9 @@ public class MaliciousCodeScanner extends Plugin {
|| (ROB && s.contains("java/awt/Robot"))
|| (LIP && s
.matches("\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b")))
sb.append("Found LDC \"" + s + "\" at field "
+ classNode.name + "." + f.name + "("
+ f.desc + ")" + BytecodeViewer.nl);
sb.append("Found LDC \"").append(s).append("\" at field ").append(classNode.name)
.append(".").append(f.name).append("(").append(f.desc).append(")")
.append(BytecodeViewer.nl);
}
}
}
@ -116,10 +115,9 @@ public class MaliciousCodeScanner extends Plugin {
|| (ORU && min.owner.equals("java/lang/Runtime"))
|| (ROB && min.owner.equals("java/awt/Robot"))
|| (OIO && min.owner.startsWith("java/io"))) {
sb.append("Found Method call to " + min.owner + "."
+ min.name + "(" + min.desc + ") at "
+ classNode.name + "." + m.name + "("
+ m.desc + ")" + BytecodeViewer.nl);
sb.append("Found Method call to ").append(min.owner).append(".").append(min.name)
.append("(").append(min.desc).append(") at ").append(classNode.name).append(".")
.append(m.name).append("(").append(m.desc).append(")").append(BytecodeViewer.nl);
}
}
if (a instanceof LdcInsnNode) {
@ -134,9 +132,9 @@ public class MaliciousCodeScanner extends Plugin {
|| (ROB && s.contains("java/awt/Robot"))
|| (LIP && s
.matches("\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b"))) {
sb.append("Found LDC \"" + s + "\" at method "
+ classNode.name + "." + m.name + "("
+ m.desc + ")" + BytecodeViewer.nl);
sb.append("Found LDC \"").append(s).append("\" at method ").append(classNode.name)
.append(".").append(m.name).append("(").append(m.desc).append(")")
.append(BytecodeViewer.nl);
}
}
}
@ -152,12 +150,9 @@ public class MaliciousCodeScanner extends Plugin {
if ((NSM && prevInsn_aconst_null
&& owner.equals("java/lang/System") && name
.equals("setSecurityManager"))) {
sb.append("Found Security Manager set to null at method "
+ classNode.name
+ "."
+ m.name
+ "("
+ m.desc + ")" + BytecodeViewer.nl);
sb.append("Found Security Manager set to null at method ").append(classNode.name)
.append(".").append(m.name).append("(").append(m.desc).append(")")
.append(BytecodeViewer.nl);
prevInsn_aconst_null = false;
}
} else {

View File

@ -48,31 +48,17 @@ public class ShowAllStrings extends Plugin {
if (v instanceof String) {
String s = (String) v;
if (!s.isEmpty())
sb.append(classNode.name
+ "."
+ f.name
+ ""
+ f.desc
+ " -> \""
+ s.replaceAll("\\n", "\\\\n").replaceAll(
"\\r", "\\\\r") + "\""
+ BytecodeViewer.nl);
sb.append(classNode.name).append(".").append(f.name).append(f.desc).append(" -> \"")
.append(s.replaceAll("\\n", "\\\\n").replaceAll("\\r", "\\\\r"))
.append("\"").append(BytecodeViewer.nl);
}
if (v instanceof String[]) {
for (int i = 0; i < ((String[]) v).length; i++) {
String s = ((String[]) v)[i];
if (!s.isEmpty())
sb.append(classNode.name
+ "."
+ f.name
+ ""
+ f.desc
+ "["
+ i
+ "] -> \""
+ s.replaceAll("\\n", "\\\\n").replaceAll(
"\\r", "\\\\r") + "\""
+ BytecodeViewer.nl);
sb.append(classNode.name).append(".").append(f.name).append(f.desc).append("[").append(i)
.append("] -> \"").append(s.replaceAll("\\n", "\\\\n").replaceAll("\\r", "\\\\r"))
.append("\"").append(BytecodeViewer.nl);
}
}
}
@ -86,15 +72,9 @@ public class ShowAllStrings extends Plugin {
if (((LdcInsnNode) a).cst instanceof String) {
final String s = (String) ((LdcInsnNode) a).cst;
if (!s.isEmpty())
sb.append(classNode.name
+ "."
+ m.name
+ ""
+ m.desc
+ " -> \""
+ s.replaceAll("\\n", "\\\\n")
.replaceAll("\\r", "\\\\r")
+ "\"" + BytecodeViewer.nl);
sb.append(classNode.name).append(".").append(m.name).append(m.desc).append(" -> \"")
.append(s.replaceAll("\\n", "\\\\n").replaceAll("\\r", "\\\\r"))
.append("\"").append(BytecodeViewer.nl);
}
}
}

View File

@ -3,6 +3,7 @@ package the.bytecode.club.bytecodeviewer.plugin.preinstalled;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Objects;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import org.objectweb.asm.tree.ClassNode;
@ -59,17 +60,18 @@ public class ZStringArrayDecrypter extends Plugin {
if (result == 0) {
boolean needsWarning = false;
for (Class<?> debug : the.bytecode.club.bytecodeviewer.api.BytecodeViewer.loadClassesIntoClassLoader()) {
for (Class<?> debug :
Objects.requireNonNull(the.bytecode.club.bytecodeviewer.api.BytecodeViewer.loadClassesIntoClassLoader())) {
try {
Field[] fields = debug.getDeclaredFields();
for (Field field : fields) {
if (field.getName().equals("z")) {
out.append(debug.getName() + ":" + BytecodeViewer.nl);
out.append(debug.getName()).append(":").append(BytecodeViewer.nl);
field.setAccessible(true);
if (field.get(null) != null && field.get(null) instanceof String[] && Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers())) {
String[] fieldVal = (String[]) field.get(null);
for (int i = 0; i < fieldVal.length; i++) {
out.append(" z[" + i + "] = " + fieldVal[i] + BytecodeViewer.nl);
out.append(" z[").append(i).append("] = ").append(fieldVal[i]).append(BytecodeViewer.nl);
}
}
}

View File

@ -41,7 +41,7 @@ public class CompiledJavaPluginLaunchStrategy implements PluginLaunchStrategy {
private static final String PLUGIN_CLASS_NAME = Plugin.class.getCanonicalName().replace(".", "/");
private final Set<LoadedPluginData> loaded = new HashSet<LoadedPluginData>();
private final Set<LoadedPluginData> loaded = new HashSet<>();
@Override
public Plugin run(File file) throws Throwable {
@ -75,7 +75,7 @@ public class CompiledJavaPluginLaunchStrategy implements PluginLaunchStrategy {
ZipInputStream jis = new ZipInputStream(new FileInputStream(jarFile));
ZipEntry entry;
Set<LoadedNodeData> set = new HashSet<LoadedNodeData>();
Set<LoadedNodeData> set = new HashSet<>();
while ((entry = jis.getNextEntry()) != null) {
try {
@ -152,8 +152,8 @@ public class CompiledJavaPluginLaunchStrategy implements PluginLaunchStrategy {
public LoadingClassLoader(LoadedNodeData data, Set<LoadedNodeData> set) throws Throwable {
this.data = data;
cache = new HashMap<String, LoadedNodeData>();
ccache = new HashMap<String, Class<?>>();
cache = new HashMap<>();
ccache = new HashMap<>();
for (LoadedNodeData d : set) {
cache.put(d.node.name, d);

View File

@ -3,7 +3,6 @@ package the.bytecode.club.bytecodeviewer.searching;
import eu.bibl.banalysis.asm.desc.OpcodeInfo;
import java.awt.GridLayout;
import java.util.Iterator;
import java.util.ListIterator;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
@ -42,7 +41,9 @@ import the.bytecode.club.bytecodeviewer.util.FileContainer;
public class FieldCallSearch implements SearchTypeDetails {
JTextField mOwner = new JTextField(""), mName = new JTextField(""), mDesc = new JTextField("");
JTextField mOwner;
JTextField mName;
JTextField mDesc;
JPanel myPanel = null;
@ -90,10 +91,7 @@ public class FieldCallSearch implements SearchTypeDetails {
final MethodNode method = methods.next();
final InsnList insnlist = method.instructions;
final ListIterator<AbstractInsnNode> instructions = insnlist
.iterator();
while (instructions.hasNext()) {
final AbstractInsnNode insnNode = instructions.next();
for (AbstractInsnNode insnNode : insnlist) {
if (insnNode instanceof FieldInsnNode) {
final FieldInsnNode min = (FieldInsnNode) insnNode;
if (name == null && owner == null && desc == null)
@ -111,9 +109,9 @@ public class FieldCallSearch implements SearchTypeDetails {
String desc2 = method.desc;
try {
desc2 = Type.getType(method.desc).toString();
if (desc2 == null || desc2.equals("null"))
if (desc2.equals("null"))
desc2 = method.desc;
} catch (java.lang.ArrayIndexOutOfBoundsException e) {
} catch (ArrayIndexOutOfBoundsException ignored) {
}
srn.notifyOfResult(container.name + ">" + node.name
@ -137,9 +135,9 @@ public class FieldCallSearch implements SearchTypeDetails {
String desc2 = method.desc;
try {
desc2 = Type.getType(method.desc).toString();
if (desc2 == null || desc2.equals("null"))
if (desc2.equals("null"))
desc2 = method.desc;
} catch (java.lang.ArrayIndexOutOfBoundsException e) {
} catch (ArrayIndexOutOfBoundsException ignored) {
}
srn.notifyOfResult(container.name + ">" + node.name

View File

@ -2,7 +2,6 @@ package the.bytecode.club.bytecodeviewer.searching;
import java.awt.GridLayout;
import java.util.Iterator;
import java.util.ListIterator;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
@ -42,7 +41,7 @@ import the.bytecode.club.bytecodeviewer.util.FileContainer;
public class LDCSearch implements SearchTypeDetails {
JTextField searchText = null;
JTextField searchText;
JPanel myPanel = null;
public LDCSearch() {
@ -72,19 +71,16 @@ public class LDCSearch implements SearchTypeDetails {
final MethodNode method = methods.next();
final InsnList insnlist = method.instructions;
final ListIterator<AbstractInsnNode> instructions = insnlist
.iterator();
while (instructions.hasNext()) {
final AbstractInsnNode insnNode = instructions.next();
for (AbstractInsnNode insnNode : insnlist) {
if (insnNode instanceof LdcInsnNode) {
final LdcInsnNode ldcObject = ((LdcInsnNode) insnNode);
final String ldcString = ldcObject.cst.toString();
String desc2 = method.desc;
try {
desc2 = Type.getType(method.desc).toString();
if (desc2 == null || desc2.equals("null"))
if (desc2.equals("null"))
desc2 = method.desc;
} catch (java.lang.ArrayIndexOutOfBoundsException e) {
} catch (ArrayIndexOutOfBoundsException ignored) {
}
@ -103,9 +99,9 @@ public class LDCSearch implements SearchTypeDetails {
String desc2 = field.desc;
try {
desc2 = Type.getType(field.desc).toString();
if (desc2 == null || desc2.equals("null"))
if (desc2.equals("null"))
desc2 = field.desc;
} catch (java.lang.ArrayIndexOutOfBoundsException e) {
} catch (java.lang.ArrayIndexOutOfBoundsException ignored) {
}
if (field.value instanceof String) {

View File

@ -3,7 +3,6 @@ package the.bytecode.club.bytecodeviewer.searching;
import eu.bibl.banalysis.asm.desc.OpcodeInfo;
import java.awt.GridLayout;
import java.util.Iterator;
import java.util.ListIterator;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
@ -42,7 +41,9 @@ import the.bytecode.club.bytecodeviewer.util.FileContainer;
public class MethodCallSearch implements SearchTypeDetails {
JTextField mOwner = new JTextField(""), mName = new JTextField(""), mDesc = new JTextField("");
JTextField mOwner;
JTextField mName;
JTextField mDesc;
JPanel myPanel = null;
public MethodCallSearch() {
@ -90,10 +91,7 @@ public class MethodCallSearch implements SearchTypeDetails {
final MethodNode method = methods.next();
final InsnList insnlist = method.instructions;
final ListIterator<AbstractInsnNode> instructions = insnlist
.iterator();
while (instructions.hasNext()) {
final AbstractInsnNode insnNode = instructions.next();
for (AbstractInsnNode insnNode : insnlist) {
if (insnNode instanceof MethodInsnNode) {
final MethodInsnNode min = (MethodInsnNode) insnNode;
if (name == null && owner == null && desc == null)
@ -111,9 +109,9 @@ public class MethodCallSearch implements SearchTypeDetails {
String desc2 = method.desc;
try {
desc2 = Type.getType(method.desc).toString();
if (desc2 == null || desc2.equals("null"))
if (desc2.equals("null"))
desc2 = method.desc;
} catch (java.lang.ArrayIndexOutOfBoundsException e) {
} catch (ArrayIndexOutOfBoundsException ignored) {
}
srn.notifyOfResult(container.name + ">" + node.name
@ -136,9 +134,9 @@ public class MethodCallSearch implements SearchTypeDetails {
String desc2 = method.desc;
try {
desc2 = Type.getType(method.desc).toString();
if (desc2 == null || desc2.equals("null"))
if (desc2.equals("null"))
desc2 = method.desc;
} catch (java.lang.ArrayIndexOutOfBoundsException e) {
} catch (ArrayIndexOutOfBoundsException ignored) {
}
srn.notifyOfResult(container.name + ">" + node.name

View File

@ -2,7 +2,6 @@ package the.bytecode.club.bytecodeviewer.searching;
import java.rmi.UnexpectedException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -141,13 +140,13 @@ public class RegexInsnFinder {
final boolean capture, final boolean stdRepl) {
if (items.length == 0)
return "()";
String result = (stdRepl ? "\\b" : "") + "(" + (capture ? "" : "?:")
+ items[0];
StringBuilder result = new StringBuilder((stdRepl ? "\\b" : "") + "(" + (capture ? "" : "?:")
+ items[0]);
for (int i = 1; i < items.length; i++) {
result += "|" + items[i];
result.append("|").append(items[i]);
}
result += ")";
return result;
result.append(")");
return result.toString();
}
private static String buildRegexItems(final String[] items) {
@ -158,43 +157,43 @@ public class RegexInsnFinder {
String result = regex.trim();
result = result.replaceAll("\\bANYINSN *", opcodesAnys);
result = result.replaceAll(opcodesInts
+ "\\\\\\{\\s*(\\d+)\\s*\\\\\\} *", "$1\\\\{$2\\\\} ");
+ "\\\\\\{\\s*(\\d+)\\s*\\\\} *", "$1\\\\{$2\\\\} ");
result = result.replaceAll(opcodesInts + " *", "$1\\\\{\\\\d+\\\\} ");
result = result.replaceAll(
"\\bLDC\\\\\\{(.*?)\\\\\\}(?<!\\\\\\\\\\}) *",
"\\bLDC\\\\\\{(.*?)\\\\}(?<!\\\\\\\\}) *",
"LDC\\\\{$1\\\\}(?<!\\\\\\\\\\\\}) ");
result = result.replaceAll("\\bLDC *",
"LDC\\\\{.*?\\\\}(?<!\\\\\\\\\\\\}) ");
result = result.replaceAll(opcodeVars + "(_\\d+) *", "$1$2 ");
result = result.replaceAll(opcodeVars + "(?!_) *", "$1_\\\\d+ ");
result = result.replaceAll(
"\\bIINC\\\\\\{\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\\\\\} *",
"\\bIINC\\\\\\{\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\\\} *",
"IINC\\\\{$1,$2\\\\} ");
result = result.replaceAll("\\bIINC\\\\\\{\\s*(\\d+)\\s*\\\\\\} *",
result = result.replaceAll("\\bIINC\\\\\\{\\s*(\\d+)\\s*\\\\} *",
"IINC\\\\{\\d+,$1\\\\} ");
result = result.replaceAll("\\bIINC *", "IINC\\\\{\\d+,\\d+\\\\} ");
result = result.replaceAll(opcodesFields
+ "\\\\\\{\\s*(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*\\\\\\} *",
+ "\\\\\\{\\s*(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*\\\\} *",
"$1\\\\{$2,$3,$4\\\\} ");
result = result.replaceAll(opcodesFields
+ "\\\\\\{((?:.(?!,))*)\\\\\\} *", "$1\\\\{$2,.*?,.*?\\\\} ");
+ "\\\\\\{((?:.(?!,))*)\\\\} *", "$1\\\\{$2,.*?,.*?\\\\} ");
result = result.replaceAll(opcodesFields + " *", "$1\\\\{.*?\\\\} ");
result = result.replaceAll(opcodesMethods
+ "\\\\\\{\\s*(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*\\\\\\} *",
+ "\\\\\\{\\s*(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*\\\\} *",
"$1\\\\{$2,$3,$4\\\\} ");
result = result.replaceAll(opcodesMethods
+ "\\\\\\{((?:.(?!,))*)\\\\\\} *", "$1\\\\{$2,.*?,.*?\\\\} ");
+ "\\\\\\{((?:.(?!,))*)\\\\} *", "$1\\\\{$2,.*?,.*?\\\\} ");
result = result.replaceAll(opcodesMethods + " *",
"$1\\\\{.*?,.*?,.*?\\\\} ");
result = result.replaceAll(opcodesTypes
+ "\\\\\\{\\s*(.*?)\\s*\\\\\\} +", "$1\\\\{$2\\\\} ");
+ "\\\\\\{\\s*(.*?)\\s*\\\\} +", "$1\\\\{$2\\\\} ");
result = result.replaceAll(opcodesTypes + " +", "$1\\\\{\\\\.*?\\\\} ");
result = result
.replaceAll(
"\\bMULTIANEWARRAY\\\\\\{\\s*(\\d+)\\s*,\\s*(.*?)\\s*\\\\\\} *",
"\\bMULTIANEWARRAY\\\\\\{\\s*(\\d+)\\s*,\\s*(.*?)\\s*\\\\} *",
"MULTIANEWARRAY\\\\{$1,$2\\\\} ");
result = result.replaceAll(
"\\bMULTIANEWARRAY\\\\\\{\\s*(.*?)\\s*\\\\\\} *",
"\\bMULTIANEWARRAY\\\\\\{\\s*(.*?)\\s*\\\\} *",
"MULTIANEWARRAY\\\\{\\d+,$1\\\\} ");
result = result.replaceAll("\\bMULTIANEWARRAY *",
"MULTIANEWARRAY\\\\{\\\\\\d+,.*?\\\\} ");
@ -204,7 +203,6 @@ public class RegexInsnFinder {
private MethodNode mn;
private AbstractInsnNode[] origInstructions;
private AbstractInsnNode[] instructions;
private int[] offsets;
private String insnString;
@ -213,16 +211,14 @@ public class RegexInsnFinder {
}
private AbstractInsnNode[] cleanInsn(final InsnList insnList) {
final List<AbstractInsnNode> il = new ArrayList<AbstractInsnNode>();
final List<AbstractInsnNode> il = new ArrayList<>();
final Iterator<AbstractInsnNode> iIt = insnList.iterator();
while (iIt.hasNext()) {
final AbstractInsnNode node = iIt.next();
for (AbstractInsnNode node : insnList) {
if (node.getOpcode() >= 0) {
il.add(node);
}
}
return il.toArray(new AbstractInsnNode[il.size()]);
return il.toArray(new AbstractInsnNode[0]);
}
/**
@ -231,14 +227,14 @@ public class RegexInsnFinder {
*/
public void refresh() {
origInstructions = cleanInsn(mn.instructions);
final List<AbstractInsnNode> il = new ArrayList<AbstractInsnNode>();
final List<AbstractInsnNode> il = new ArrayList<>();
for (final AbstractInsnNode ain : mn.instructions.toArray())
if (ain.getOpcode() >= 0) {
il.add(ain);
}
instructions = il.toArray(new AbstractInsnNode[il.size()]);
AbstractInsnNode[] instructions = il.toArray(new AbstractInsnNode[0]);
offsets = new int[instructions.length];
insnString = "";
StringBuilder insnStringBuilder = new StringBuilder();
for (int i = 0; i < instructions.length; i++) {
offsets[i] = -1;
final AbstractInsnNode ain = instructions[i];
@ -252,18 +248,19 @@ public class RegexInsnFinder {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
}
}
offsets[i] = insnString.length();
insnString += opcodes[ain.getOpcode()];
insnString = getInsString(ain);
insnString += " ";
offsets[i] = insnStringBuilder.length();
insnStringBuilder.append(opcodes[ain.getOpcode()]);
insnStringBuilder = new StringBuilder(getInsString(ain));
insnStringBuilder.append(" ");
}
}
insnString = insnStringBuilder.toString();
}
// Do a pattern check against each instruction directly,
// without building a string of the whole method.
public static boolean staticScan(ClassNode node, MethodNode mn, Pattern pattern) {
final List<AbstractInsnNode> il = new ArrayList<AbstractInsnNode>();
final List<AbstractInsnNode> il = new ArrayList<>();
for (final AbstractInsnNode ain : mn.instructions.toArray())
if (ain.getOpcode() >= 0) {
il.add(ain);
@ -280,8 +277,7 @@ public class RegexInsnFinder {
}
}
String insnString = getInsString(ain);
boolean result = pattern.matcher(insnString).find();
return result;
return pattern.matcher(insnString).find();
}
return false;
});
@ -381,7 +377,7 @@ public class RegexInsnFinder {
* @return a list with all sets of matching instructions
*/
public List<AbstractInsnNode[]> findAll(final String regex) {
final List<AbstractInsnNode[]> results = new ArrayList<AbstractInsnNode[]>();
final List<AbstractInsnNode[]> results = new ArrayList<>();
try {
final Matcher regexMatcher = Pattern.compile(processRegex(regex),
Pattern.MULTILINE).matcher(insnString);
@ -428,7 +424,7 @@ public class RegexInsnFinder {
* @return a list with all sets of groups with matching instructions
*/
public List<AbstractInsnNode[][]> findAllGroups(final String regex) {
final List<AbstractInsnNode[][]> results = new ArrayList<AbstractInsnNode[][]>();
final List<AbstractInsnNode[][]> results = new ArrayList<>();
try {
final Matcher regexMatcher = Pattern.compile(processRegex(regex),
Pattern.MULTILINE).matcher(insnString);

View File

@ -48,8 +48,6 @@ public class RegexSearch implements SearchTypeDetails {
searchText.addKeyListener(EnterKeyEvent.SINGLETON);
}
private static RegexInsnFinder regexFinder;
@Override
public JPanel getPanel() {
if (myPanel == null) {
@ -79,9 +77,9 @@ public class RegexSearch implements SearchTypeDetails {
try {
desc2 = Type.getType(method.desc).toString();
if (desc2 == null || desc2.equals("null"))
if (desc2.equals("null"))
desc2 = method.desc;
} catch (java.lang.ArrayIndexOutOfBoundsException e) {
} catch (java.lang.ArrayIndexOutOfBoundsException ignored) {
}

View File

@ -52,7 +52,6 @@ public class APKTool {
}
public static synchronized void buildAPK(File input, File output, FileContainer container) {
String name = container.file.getName().toLowerCase();
String temp = BytecodeViewer.tempDirectory + BytecodeViewer.fs;
File tempDir = new File(temp + BytecodeViewer.fs + BytecodeViewer.getRandomizedName() + BytecodeViewer.fs);
tempDir.mkdirs();

View File

@ -59,7 +59,7 @@ public class EncodeUtils {
char c;
for (int i = 0; i < s.length(); i++) {
c = s.charAt(i);
if (c >= 0 && c <= 255) {
if (c <= 255) {
sb.append(c);
} else {
byte[] b;

View File

@ -132,7 +132,6 @@ public class FileDrop {
* parameter <tt>out</tt> will result in no debugging output.
*
* @param out PrintStream to record debugging info or null for no debugging.
* @param out
* @param c Component on which files will be dropped.
* @param listener Listens for <tt>filesDropped</tt>.
* @since 1.0
@ -157,7 +156,6 @@ public class FileDrop {
* parameter <tt>out</tt> will result in no debugging output.
*
* @param out PrintStream to record debugging info or null for no debugging.
* @param out
* @param c Component on which files will be dropped.
* @param recursive Recursively set children as drop targets.
* @param listener Listens for <tt>filesDropped</tt>.
@ -250,6 +248,7 @@ public class FileDrop {
if (supportsDnD()) { // Make a drop listener
dropListener = new java.awt.dnd.DropTargetListener() {
@Override
public void dragEnter(final java.awt.dnd.DropTargetDragEvent evt) {
log(out, "FileDrop: dragEnter event.");
@ -276,6 +275,7 @@ public class FileDrop {
} // end else: drag not ok
} // end dragEnter
@Override
public void dragOver(final java.awt.dnd.DropTargetDragEvent evt) { // This
// is
// called
@ -292,6 +292,7 @@ public class FileDrop {
// target.
} // end dragOver
@Override
public void drop(final java.awt.dnd.DropTargetDropEvent evt) {
log(out, "FileDrop: drop event.");
try { // Get whatever was dropped
@ -316,11 +317,10 @@ public class FileDrop {
final java.io.File[] filesTemp = new java.io.File[fileList
.size()];
fileList.toArray(filesTemp);
final java.io.File[] files = filesTemp;
// Alert listener to drop.
if (listener != null) {
listener.filesDropped(files);
listener.filesDropped(filesTemp);
}
// Mark that drop is completed.
@ -335,8 +335,8 @@ public class FileDrop {
final DataFlavor[] flavors = tr
.getTransferDataFlavors();
boolean handled = false;
for (int zz = 0; zz < flavors.length; zz++) {
if (flavors[zz].isRepresentationClassReader()) {
for (DataFlavor flavor : flavors) {
if (flavor.isRepresentationClassReader()) {
// Say we'll take it.
// evt.acceptDrop (
// java.awt.dnd.DnDConstants.ACTION_COPY_OR_MOVE
@ -344,7 +344,7 @@ public class FileDrop {
evt.acceptDrop(java.awt.dnd.DnDConstants.ACTION_COPY);
log(out, "FileDrop: reader accepted.");
final Reader reader = flavors[zz]
final Reader reader = flavor
.getReaderForText(tr);
final BufferedReader br = new BufferedReader(
@ -394,6 +394,7 @@ public class FileDrop {
} // end finally
} // end drop
@Override
public void dragExit(final java.awt.dnd.DropTargetEvent evt) {
log(out, "FileDrop: dragExit event.");
// If it's a Swing component, reset its border
@ -404,6 +405,7 @@ public class FileDrop {
} // end if: JComponent
} // end dragExit
@Override
public void dropActionChanged(
final java.awt.dnd.DropTargetDragEvent evt) {
log(out, "FileDrop: dropActionChanged event.");
@ -431,7 +433,7 @@ public class FileDrop {
private static boolean supportsDnD() { // Static Boolean
if (supportsDnD == null) {
boolean support = false;
boolean support;
try {
final Class arbitraryDndClass = Class
.forName("java.awt.dnd.DnDConstants");
@ -440,9 +442,9 @@ public class FileDrop {
catch (final Exception e) {
support = false;
} // end catch
supportsDnD = new Boolean(support);
supportsDnD = support;
} // end if: first time through
return supportsDnD.booleanValue();
return supportsDnD;
} // end supportsDnD
// BEGIN 2007-09-12 Nathan Blomquist -- Linux (KDE/Gnome) support added.
@ -452,7 +454,7 @@ public class FileDrop {
final PrintStream out) {
try {
final java.util.List list = new java.util.ArrayList();
java.lang.String line = null;
java.lang.String line;
while ((line = bReader.readLine()) != null) {
try {
// kde seems to append a 0 char to the end of the reader
@ -468,7 +470,7 @@ public class FileDrop {
}
}
return (java.io.File[]) list.toArray(new File[list.size()]);
return (java.io.File[]) list.toArray(new File[0]);
} catch (final IOException ex) {
log(out, "FileDrop: IOException");
}
@ -492,8 +494,8 @@ public class FileDrop {
// Listen for hierarchy changes and remove the drop target when the
// parent gets cleared out.
c.addHierarchyListener(new java.awt.event.HierarchyListener() {
public void hierarchyChanged(final java.awt.event.HierarchyEvent evt) {
// end hierarchyChanged
c.addHierarchyListener(evt -> {
log(out, "FileDrop: Hierarchy changed.");
final java.awt.Component parent = c.getParent();
if (parent == null) {
@ -504,7 +506,6 @@ public class FileDrop {
new java.awt.dnd.DropTarget(c, dropListener);
log(out, "FileDrop: Drop target added to component.");
} // end else: parent not null
} // end hierarchyChanged
}); // end hierarchy listener
if (c.getParent() != null) {
new java.awt.dnd.DropTarget(c, dropListener);
@ -518,8 +519,8 @@ public class FileDrop {
final java.awt.Component[] comps = cont.getComponents();
// Set it's components as listeners also
for (int i = 0; i < comps.length; i++) {
makeDropTarget(out, comps[i], recursive);
for (java.awt.Component comp : comps) {
makeDropTarget(out, comp, true);
}
} // end if: recursively set components as listener
} // end dropListener
@ -613,8 +614,8 @@ public class FileDrop {
if (recursive && (c instanceof java.awt.Container)) {
final java.awt.Component[] comps = ((java.awt.Container) c)
.getComponents();
for (int i = 0; i < comps.length; i++) {
remove(out, comps[i], recursive);
for (java.awt.Component comp : comps) {
remove(out, comp, true);
}
return true;
} // end if: recursive
@ -657,8 +658,8 @@ public class FileDrop {
/**
* This is the event that is passed to the
* {@link FileDropListener#filesDropped filesDropped(...)} method in your
* {@link FileDropListener} when files are dropped onto a registered drop
* FileDropListener#filesDropped filesDropped(...) method in your
* FileDropListener when files are dropped onto a registered drop
* target.
* <p>
* <p>
@ -846,11 +847,12 @@ public class FileDrop {
* data flavor, if one was created in the constructors, second the
* default {@link #DATA_FLAVOR} associated with
* {@link TransferableObject}, and third the
* {@link java.awt.datatransfer.DataFlavor.stringFlavor}.
* java.awt.datatransfer.DataFlavor.stringFlavor.
*
* @return An array of supported data flavors
* @since 1.1
*/
@Override
public java.awt.datatransfer.DataFlavor[] getTransferDataFlavors() {
if (customFlavor != null)
return new java.awt.datatransfer.DataFlavor[]{customFlavor,
@ -876,10 +878,10 @@ public class FileDrop {
* @return The dropped data
* @since 1.1
*/
@Override
public Object getTransferData(
final java.awt.datatransfer.DataFlavor flavor)
throws java.awt.datatransfer.UnsupportedFlavorException,
java.io.IOException {
throws java.awt.datatransfer.UnsupportedFlavorException {
// Native object
if (flavor.equals(DATA_FLAVOR))
return fetcher == null ? data : fetcher.getObject();
@ -902,6 +904,7 @@ public class FileDrop {
* @return Whether or not the flavor is supported
* @since 1.1
*/
@Override
public boolean isDataFlavorSupported(
final java.awt.datatransfer.DataFlavor flavor) {
// Native object

View File

@ -6,8 +6,6 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
@ -19,7 +17,6 @@ import java.util.zip.ZipInputStream;
import me.konloch.kontainer.io.DiskWriter;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipFile;
import org.apache.commons.io.FilenameUtils;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.tree.ClassNode;
@ -110,20 +107,12 @@ public class JarUtils {
FileContainer container = new FileContainer(jarFile);
HashMap<String, byte[]> files = new HashMap<>();
Path path = jarFile.toPath();
String fileBaseName = FilenameUtils.getBaseName(path.getFileName().toString());
Path destFolderPath = Paths.get(path.getParent().toString(), fileBaseName);
try (ZipFile zipFile = new ZipFile(jarFile)) {
Enumeration<? extends ZipArchiveEntry> entries = zipFile.getEntries();
while (entries.hasMoreElements()) {
ZipArchiveEntry entry = entries.nextElement();
Path entryPath = destFolderPath.resolve(entry.getName());
String name = entry.getName();
if (entry.isDirectory()) {
//directory
} else {
if (!entry.isDirectory()) {
try (InputStream in = zipFile.getInputStream(entry)) {
final byte[] bytes = getBytes(in);
@ -155,7 +144,7 @@ public class JarUtils {
public static ArrayList<ClassNode> loadClasses(final File jarFile) throws IOException {
ArrayList<ClassNode> classes = new ArrayList<ClassNode>();
ArrayList<ClassNode> classes = new ArrayList<>();
ZipInputStream jis = new ZipInputStream(new FileInputStream(jarFile));
ZipEntry entry;
while ((entry = jis.getNextEntry()) != null) {
@ -210,7 +199,6 @@ public class JarUtils {
files.put(name, getBytes(jis));
jis.closeEntry();
continue;
}
} catch (Exception e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
@ -234,12 +222,11 @@ public class JarUtils {
public static byte[] getBytes(final InputStream is) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int a = 0;
int a;
while ((a = is.read(buffer)) != -1) {
baos.write(buffer, 0, a);
}
baos.close();
buffer = null;
return baos.toByteArray();
}
@ -249,19 +236,14 @@ public class JarUtils {
* @param bytez the class file's byte[]
* @return the ClassNode instance
*/
public static ClassNode getNode(final byte[] bytez) throws Exception {
public static ClassNode getNode(final byte[] bytez) {
ClassReader cr = new ClassReader(bytez);
ClassNode cn = new ClassNode();
try {
cr.accept(cn, ClassReader.EXPAND_FRAMES);
} catch (Exception e) {
try {
cr.accept(cn, ClassReader.SKIP_FRAMES);
} catch (Exception e2) {
throw e2;
}
}
cr = null;
return cn;
}
@ -315,7 +297,7 @@ public class JarUtils {
public static void saveAsJarClassesOnly(ArrayList<ClassNode> nodeList, String path) {
try {
JarOutputStream out = new JarOutputStream(new FileOutputStream(path));
ArrayList<String> noDupe = new ArrayList<String>();
ArrayList<String> noDupe = new ArrayList<>();
for (ClassNode cn : nodeList) {
ClassWriter cw = new ClassWriter(0);
cn.accept(cw);
@ -369,7 +351,7 @@ public class JarUtils {
public static void saveAsJar(ArrayList<ClassNode> nodeList, String path) {
try {
JarOutputStream out = new JarOutputStream(new FileOutputStream(path));
ArrayList<String> noDupe = new ArrayList<String>();
ArrayList<String> noDupe = new ArrayList<>();
for (ClassNode cn : nodeList) {
ClassWriter cw = new ClassWriter(0);
cn.accept(cw);

View File

@ -22,6 +22,7 @@ public class MethodParser {
this.params = params;
}
@Override
public String toString() {
String params = this.params.toString();
return this.name + "(" + params.substring(1, params.length() - 1) + ")";

View File

@ -93,8 +93,8 @@ public class MiscUtils {
public static String getUniqueName(String start, String ext) {
String s = null;
boolean b = true;
File f = null;
String m = null;
File f;
String m;
while (b) {
m = MiscUtils.randomString(32);
f = new File(start + m + ext);

View File

@ -3,8 +3,8 @@ package the.bytecode.club.bytecodeviewer.util;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import org.jetbrains.annotations.NotNull;
/***************************************************************************
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
@ -33,7 +33,7 @@ import java.nio.charset.StandardCharsets;
* for the purpose of (e.g.) saving the message to a local file.
*/
public class NewlineOutputStream extends FilterOutputStream {
private int lastb = -1;
private int lastByte = -1;
private static byte[] newline;
public NewlineOutputStream(OutputStream os) {
@ -46,23 +46,26 @@ public class NewlineOutputStream extends FilterOutputStream {
}
}
@Override
public void write(int b) throws IOException {
if (b == '\r') {
out.write(newline);
} else if (b == '\n') {
if (lastb != '\r')
if (lastByte != '\r')
out.write(newline);
} else {
out.write(b);
}
lastb = b;
lastByte = b;
}
public void write(byte[] b) throws IOException {
@Override
public void write(byte @NotNull [] b) throws IOException {
write(b, 0, b.length);
}
public void write(byte[] b, int off, int len) throws IOException {
@Override
public void write(byte @NotNull [] b, int off, int len) throws IOException {
for (int i = 0; i < len; i++) {
write(b[off + i]);
}

View File

@ -6,6 +6,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Objects;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
@ -87,7 +88,7 @@ public final class ZipUtils {
try {
jar.close();
} catch (Exception e) {
} catch (Exception ignored) {
}
}
@ -117,8 +118,8 @@ public final class ZipUtils {
}
public static void zipFolder(String srcFolder, String destZipFile, String ignore) throws Exception {
ZipOutputStream zip = null;
FileOutputStream fileWriter = null;
ZipOutputStream zip;
FileOutputStream fileWriter;
fileWriter = new FileOutputStream(destZipFile);
zip = new ZipOutputStream(fileWriter);
@ -129,8 +130,8 @@ public final class ZipUtils {
}
public static void zipFolderAPKTool(String srcFolder, String destZipFile) throws Exception {
ZipOutputStream zip = null;
FileOutputStream fileWriter = null;
ZipOutputStream zip;
FileOutputStream fileWriter;
fileWriter = new FileOutputStream(destZipFile);
zip = new ZipOutputStream(fileWriter);
@ -150,7 +151,7 @@ public final class ZipUtils {
byte[] buf = new byte[1024];
int len;
FileInputStream in = new FileInputStream(srcFile);
ZipEntry entry = null;
ZipEntry entry;
if (ignore == null)
entry = new ZipEntry(path + "/" + folder.getName());
else
@ -183,7 +184,7 @@ public final class ZipUtils {
byte[] buf = new byte[1024];
int len;
FileInputStream in = new FileInputStream(srcFile);
ZipEntry entry = null;
ZipEntry entry;
entry = new ZipEntry(path + "/" + folder.getName());
zip.putNextEntry(entry);
@ -199,7 +200,7 @@ public final class ZipUtils {
throws Exception {
File folder = new File(srcFolder);
for (String fileName : folder.list()) {
for (String fileName : Objects.requireNonNull(folder.list())) {
if (path.equals("")) {
addFileToZip(folder.getName(), srcFolder + "/" + fileName, zip, ignore);
} else {
@ -211,7 +212,7 @@ public final class ZipUtils {
public static void addFolderToZipAPKTool(String path, String srcFolder, ZipOutputStream zip) throws Exception {
File folder = new File(srcFolder);
for (String fileName : folder.list()) {
for (String fileName : Objects.requireNonNull(folder.list())) {
if (path.equals("")) {
addFileToZipAPKTool(folder.getName(), srcFolder + "/" + fileName, zip);
} else {