Skip to content

Commit 5dab52b

Browse files
committed
Code Cleanup
1 parent fb82558 commit 5dab52b

22 files changed

+126
-67
lines changed

src/main/java/the/bytecode/club/bytecodeviewer/Configuration.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ public class Configuration
4242
public static boolean python3Extra = false;
4343
public static String rt = "";
4444
public static String library = "";
45-
public static String java = Constants.JAVA_BINARY.exists() ? Constants.JAVA_BINARY.getAbsolutePath() : Constants.JAVA_BINARY_NIX.exists() ? Constants.JAVA_BINARY_NIX.getAbsolutePath() : "";
45+
public static String java = Constants.JAVA_BINARY.exists()
46+
? Constants.JAVA_BINARY.getAbsolutePath()
47+
: Constants.JAVA_BINARY_NIX.exists()
48+
? Constants.JAVA_BINARY_NIX.getAbsolutePath()
49+
: "";
4650
public static String javac = "";
4751
public static String javaTools = "";
4852
public static File krakatauTempDir;

src/main/java/the/bytecode/club/bytecodeviewer/Constants.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,11 @@ public class Constants
6060

6161
//version is set via maven
6262
public static final String VERSION = getVersion(BytecodeViewer.class.getPackage().getImplementationVersion());
63+
64+
//CHECKSTYLE:OFF
6365
//dev mode is just a check for running via IDE
6466
public static boolean DEV_MODE;
67+
//CHECKSTYLE:ON
6568

6669
//if true the version checker will prompt and ask how you would like to proceed
6770
public static final boolean FORCE_VERSION_CHECKER_PROMPT = false;
@@ -71,7 +74,7 @@ public class Constants
7174
public static final String[] SUPPORTED_FILE_EXTENSIONS = ResourceType.SUPPORTED_BCV_EXTENSION_MAP.keySet().toArray(new String[0]);
7275
public static final int ASM_VERSION = Opcodes.ASM9;
7376

74-
public static final File BCVDir = resolveBCVRoot();
77+
public static final File BCV_DIR = resolveBCVRoot();
7578
public static final File RT_JAR = new File(System.getProperty("java.home") + FS + "lib" + FS + "rt.jar");
7679
public static final File JAVA_BINARY = new File(System.getProperty("java.home") + FS + "bin" + FS + "java.exe");
7780
public static final File JAVA_BINARY_NIX = new File(System.getProperty("java.home") + FS + "bin" + FS + "java");
@@ -119,18 +122,18 @@ public static File resolveBCVRoot()
119122
*/
120123
public static String getBCVDirectory()
121124
{
122-
while (!BCVDir.exists())
123-
BCVDir.mkdirs();
125+
while (!BCV_DIR.exists())
126+
BCV_DIR.mkdirs();
124127

125128
//hides the BCV directory
126-
if (isWindows() && !BCVDir.isHidden())
129+
if (isWindows() && !BCV_DIR.isHidden())
127130
{
128131
new Thread(() ->
129132
{
130133
try
131134
{
132135
// Hide file by running attrib system command (on Windows)
133-
Process p = new ProcessBuilder("attrib", "+H", BCVDir.getAbsolutePath()).start();
136+
Process p = new ProcessBuilder("attrib", "+H", BCV_DIR.getAbsolutePath()).start();
134137
}
135138
catch (Exception e)
136139
{
@@ -139,7 +142,7 @@ public static String getBCVDirectory()
139142
}, "Hide BCV Dir").start();
140143
}
141144

142-
return BCVDir.getAbsolutePath();
145+
return BCV_DIR.getAbsolutePath();
143146
}
144147

145148
/**

src/main/java/the/bytecode/club/bytecodeviewer/api/ExceptionUI.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ public static String buildErrorLogHeader(String author)
141141

142142
return TranslatedStrings.PLEASE_SEND_THIS_ERROR_LOG_TO + " " + author + "\n"
143143
+ TranslatedStrings.PLEASE_SEND_RESOURCES
144-
+ "\nBytecode Viewer Version: " + VERSION + fatJar + ", OS: " + System.getProperty("os.name") + ", Java: " + System.getProperty("java.version");
144+
+ "\nBytecode Viewer Version: " + VERSION + fatJar
145+
+ ", OS: " + System.getProperty("os.name")
146+
+ ", Java: " + System.getProperty("java.version");
145147
}
146148

147149
private static final long serialVersionUID = -5230501978224926296L;

src/main/java/the/bytecode/club/bytecodeviewer/bootloader/Boot.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,8 @@ public static void dropKrakatau()
331331
while (temp.exists())
332332
temp.delete();
333333

334-
try (InputStream is = BytecodeViewer.class.getClassLoader().getResourceAsStream("Krakatau-" + krakatauVersion + ".zip"); FileOutputStream baos = new FileOutputStream(temp))
334+
try (InputStream is = BytecodeViewer.class.getClassLoader().getResourceAsStream("Krakatau-" + krakatauVersion + ".zip");
335+
FileOutputStream baos = new FileOutputStream(temp))
335336
{
336337
int r;
337338
byte[] buffer = new byte[8192];
@@ -368,7 +369,8 @@ public static void dropEnjarify()
368369
while (temp.exists())
369370
temp.delete();
370371

371-
try (InputStream is = BytecodeViewer.class.getClassLoader().getResourceAsStream("enjarify-" + Constants.enjarifyVersion + ".zip"); FileOutputStream baos = new FileOutputStream(temp))
372+
try (InputStream is = BytecodeViewer.class.getClassLoader().getResourceAsStream("enjarify-" + Constants.enjarifyVersion + ".zip");
373+
FileOutputStream baos = new FileOutputStream(temp))
372374
{
373375
int r;
374376
byte[] buffer = new byte[8192];
@@ -405,7 +407,8 @@ public static void downloadZipsOnly()
405407
setState("Bytecode Viewer Boot Screen - Downloading " + fileName + "...");
406408
System.out.println("Downloading " + fileName);
407409

408-
try (InputStream is = new URL("https://github.com/Konloch/bytecode-viewer/raw/master/libs/" + fileName).openConnection().getInputStream(); FileOutputStream fos = new FileOutputStream(file))
410+
try (InputStream is = new URL("https://github.com/Konloch/bytecode-viewer/raw/master/libs/" + fileName).openConnection().getInputStream();
411+
FileOutputStream fos = new FileOutputStream(file))
409412
{
410413
System.out.println("Downloading from " + s);
411414
byte[] buffer = new byte[8192];

src/main/java/the/bytecode/club/bytecodeviewer/bootloader/UpdateCheck.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ public void run()
118118
if (Desktop.isDesktopSupported())
119119
Desktop.getDesktop().browse(new URI("https://github.com/Konloch/bytecode-viewer/releases"));
120120
else
121-
BytecodeViewer.showMessage("Cannot open the page, please manually type it." + NL + "https://github.com/Konloch/bytecode-viewer/releases");
121+
BytecodeViewer.showMessage("Cannot open the page, please manually type it."
122+
+ NL + "https://github.com/Konloch/bytecode-viewer/releases");
122123
}
123124
else if (result == 1)
124125
{
@@ -176,7 +177,7 @@ public static File promptFileSave(String description, String extension) throws I
176177
}
177178

178179
//used to download all released versions of BCV
179-
/*public static void main(String[] args)
180+
/*public static void main(String[] args)
180181
{
181182
BytecodeViewer.viewer = new MainViewerGUI();
182183
for(String version : BCV_VERSIONS)
@@ -234,7 +235,8 @@ private static boolean validURl(String url) throws Exception
234235
private static void download(String url, File saveTo, Runnable onFinish) throws Exception
235236
{
236237
BCV.log("Downloading from: " + url);
237-
BytecodeViewer.showMessage("Downloading the jar in the background, when it's finished you will be alerted with another message box." + NL + NL + "Expect this to take several minutes.");
238+
BytecodeViewer.showMessage("Downloading the jar in the background, when it's finished you will be alerted with another message box."
239+
+ NL + NL + "Expect this to take several minutes.");
238240

239241
try (InputStream is = new URL(url).openConnection().getInputStream(); FileOutputStream fos = new FileOutputStream(saveTo))
240242
{

src/main/java/the/bytecode/club/bytecodeviewer/cli/CommandLineInput.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,15 @@ else if (cmd.hasOption("help"))
178178
//if its zip/jar/apk/dex attempt unzip as whole zip
179179
//if its just class allow any
180180

181-
if (decompiler != null && !decompiler.equalsIgnoreCase("procyon") && !decompiler.equalsIgnoreCase("cfr") && !decompiler.equalsIgnoreCase("fernflower") && !decompiler.equalsIgnoreCase("krakatau") && !decompiler.equalsIgnoreCase("krakatau-bytecode") && !decompiler.equalsIgnoreCase("jd-gui") && !decompiler.equalsIgnoreCase("smali") && !decompiler.equalsIgnoreCase("asmifier"))
181+
if (decompiler != null
182+
&& !decompiler.equalsIgnoreCase("procyon")
183+
&& !decompiler.equalsIgnoreCase("cfr")
184+
&& !decompiler.equalsIgnoreCase("fernflower")
185+
&& !decompiler.equalsIgnoreCase("krakatau")
186+
&& !decompiler.equalsIgnoreCase("krakatau-bytecode")
187+
&& !decompiler.equalsIgnoreCase("jd-gui")
188+
&& !decompiler.equalsIgnoreCase("smali")
189+
&& !decompiler.equalsIgnoreCase("asmifier"))
182190
{
183191
System.out.println("Error, no decompiler called '" + decompiler + "' found. Type -list" + " for the list");
184192
}

src/main/java/the/bytecode/club/bytecodeviewer/decompilers/bytecode/InstructionPrinter.java

+14-6
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public InstructionPrinter(MethodNode m, InstructionPattern pattern, TypeAndName[
6969
this(m, args);
7070
InstructionSearcher searcher = new InstructionSearcher(m.instructions, pattern);
7171
match = searcher.search();
72+
7273
if (match)
7374
{
7475
for (AbstractInsnNode[] ains : searcher.getMatches())
@@ -102,6 +103,7 @@ public List<String> createPrint()
102103
{
103104
firstLabel = false;
104105
info.clear();
106+
105107
for (AbstractInsnNode ain : mNode.instructions)
106108
{
107109
String line = printInstruction(ain);
@@ -114,8 +116,10 @@ public List<String> createPrint()
114116
info.add(line);
115117
}
116118
}
119+
117120
if (firstLabel && BytecodeViewer.viewer.appendBracketsToLabels.isSelected())
118121
info.add("}");
122+
119123
return info;
120124
}
121125

@@ -169,16 +173,12 @@ protected String printVarInsnNode(VarInsnNode vin)
169173
if (BytecodeViewer.viewer.debugHelpers.isSelected())
170174
{
171175
if (vin.var == 0 && !Modifier.isStatic(mNode.access))
172-
{
173176
sb.append(" // reference to self");
174-
}
175177
else
176178
{
177179
final int refIndex = vin.var - (Modifier.isStatic(mNode.access) ? 0 : 1);
178180
if (refIndex >= 0 && refIndex < args.length - 1)
179-
{
180181
sb.append(" // reference to ").append(args[refIndex].name);
181-
}
182182
}
183183
}
184184

@@ -229,9 +229,11 @@ protected String printMethodInsnNode(MethodInsnNode min)
229229
protected String printLdcInsnNode(LdcInsnNode ldc)
230230
{
231231
if (ldc.cst instanceof String)
232-
return nameOpcode(ldc.getOpcode()) + " \"" + StringEscapeUtils.escapeJava(ldc.cst.toString()) + "\" (" + ldc.cst.getClass().getCanonicalName() + ")";
232+
return nameOpcode(ldc.getOpcode()) + " \"" + StringEscapeUtils.escapeJava(ldc.cst.toString())
233+
+ "\" (" + ldc.cst.getClass().getCanonicalName() + ")";
233234

234-
return nameOpcode(ldc.getOpcode()) + " " + StringEscapeUtils.escapeJava(ldc.cst.toString()) + " (" + ldc.cst.getClass().getCanonicalName() + ")";
235+
return nameOpcode(ldc.getOpcode()) + " " + StringEscapeUtils.escapeJava(ldc.cst.toString())
236+
+ " (" + ldc.cst.getClass().getCanonicalName() + ")";
235237
}
236238

237239
protected String printInsnNode(InsnNode in)
@@ -270,6 +272,7 @@ protected String printLabelNode(LabelNode label)
270272
String starting = tcbs.stream().filter(tcb -> tcb.start == label).map(tcb -> "start TCB" + tcbs.indexOf(tcb)).collect(Collectors.joining(", "));
271273
String ending = tcbs.stream().filter(tcb -> tcb.end == label).map(tcb -> "end TCB" + tcbs.indexOf(tcb)).collect(Collectors.joining(", "));
272274
String handlers = tcbs.stream().filter(tcb -> tcb.handler == label).map(tcb -> "handle TCB" + tcbs.indexOf(tcb)).collect(Collectors.joining(", "));
275+
273276
if (!ending.isEmpty())
274277
info.add("// " + ending);
275278
if (!starting.isEmpty())
@@ -325,10 +328,12 @@ protected String printTableSwitchInsnNode(TableSwitchInsnNode tin)
325328
StringBuilder line = new StringBuilder(nameOpcode(tin.getOpcode()) + " \n");
326329
List<?> labels = tin.labels;
327330
int count = 0;
331+
328332
for (int i = tin.min; i < tin.max + 1; i++)
329333
{
330334
line.append(" val: ").append(i).append(" -> ").append("L").append(resolveLabel((LabelNode) labels.get(count++))).append("\n");
331335
}
336+
332337
line.append(" default" + " -> L").append(resolveLabel(tin.dflt));
333338
return line.toString();
334339
}
@@ -408,6 +413,7 @@ private String printFrameObject(Object obj)
408413
{
409414
if (obj instanceof LabelNode)
410415
return "label [L" + resolveLabel((LabelNode) obj) + "]";
416+
411417
if (obj instanceof Integer)
412418
{
413419
switch ((int) obj)
@@ -430,8 +436,10 @@ private String printFrameObject(Object obj)
430436
return "unknown";
431437
}
432438
}
439+
433440
if (obj instanceof String)
434441
return obj.toString();
442+
435443
return "unknown [" + obj.toString() + "]";
436444
}
437445

src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/ASMTextifierDisassembler.java

-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,5 @@ public String decompileClassNode(ClassNode cn, byte[] bytes)
4444
@Override
4545
public void decompileToZip(String sourceJar, String zipName)
4646
{
47-
4847
}
4948
}

src/main/java/the/bytecode/club/bytecodeviewer/gui/components/HTMLPane.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static HTMLPane fromString(String text)
5959
text = text.replace("{fatJar}", String.valueOf(FAT_JAR));
6060
text = text.replace("{java}", Configuration.java);
6161
text = text.replace("{javac}", Configuration.javac);
62-
text = text.replace("{bcvDir}", BCVDir.getAbsolutePath());
62+
text = text.replace("{bcvDir}", BCV_DIR.getAbsolutePath());
6363
text = text.replace("{python}", Configuration.python2 + " " + (Configuration.python2Extra ? "-2" : ""));
6464
text = text.replace("{python3}", Configuration.python3 + " " + (Configuration.python3Extra ? "-3" : ""));
6565
text = text.replace("{rt}", Configuration.rt);

src/main/java/the/bytecode/club/bytecodeviewer/gui/theme/LAFTheme.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ public enum LAFTheme
4949
SOLARIZED_DARK("Solarized Dark Theme", RSTATheme.THEME_MATCH, TranslatedComponents.SOLARIZED_DARK_THEME),
5050
SOLARIZED_LIGHT("Solarized Light Theme", RSTATheme.THEME_MATCH, TranslatedComponents.SOLARIZED_LIGHT_THEME),
5151
HIGH_CONTRAST_DARK("High Contrast Dark Theme", RSTATheme.THEME_MATCH, TranslatedComponents.HIGH_CONTRAST_DARK_THEME),
52-
HIGH_CONTRAST_LIGHT("High Contrast Light Theme", RSTATheme.THEME_MATCH, TranslatedComponents.HIGH_CONTRAST_LIGHT_THEME),
53-
;
52+
HIGH_CONTRAST_LIGHT("High Contrast Light Theme", RSTATheme.THEME_MATCH, TranslatedComponents.HIGH_CONTRAST_LIGHT_THEME);
5453

5554
private final String readableName;
5655
private final RSTATheme rstaTheme;

src/main/java/the/bytecode/club/bytecodeviewer/gui/theme/RSTATheme.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ public enum RSTATheme
3838
THEME_MATCH("Theme Match (Recommended)", null, TranslatedComponents.THEME_MATCH), //uses the default theme from RSyntaxTextArea
3939
DEFAULT("Default (Recommended Light)", "/org/fife/ui/rsyntaxtextarea/themes/default.xml", TranslatedComponents.DEFAULT_RECOMMENDED_LIGHT), //uses the default dark theme from RSyntaxTextArea
4040
DARK("Dark (Recommended Dark)", "/org/fife/ui/rsyntaxtextarea/themes/dark.xml", TranslatedComponents.DARK),
41-
DEFAULT_ALT("Default-Alt", "/org/fife/ui/rsyntaxtextarea/themes/default-alt.xml", TranslatedComponents.DEFAULT_ALT), ECLIPSE("Eclipse", "/org/fife/ui/rsyntaxtextarea/themes/eclipse.xml", TranslatedComponents.ECLIPSE), IDEA("IntelliJ", "/org/fife/ui/rsyntaxtextarea/themes/idea.xml", TranslatedComponents.INTELLIJ), VS("Visual Studio", "/org/fife/ui/rsyntaxtextarea/themes/vs.xml", TranslatedComponents.VISUAL_STUDIO), DRUID("Druid (Dark)", "/org/fife/ui/rsyntaxtextarea/themes/druid.xml", TranslatedComponents.DRUID_DARK), MONOKAI("Monokai (Dark)", "/org/fife/ui/rsyntaxtextarea/themes/monokai.xml", TranslatedComponents.MONOKAI_DARK);
41+
DEFAULT_ALT("Default-Alt", "/org/fife/ui/rsyntaxtextarea/themes/default-alt.xml", TranslatedComponents.DEFAULT_ALT),
42+
ECLIPSE("Eclipse", "/org/fife/ui/rsyntaxtextarea/themes/eclipse.xml", TranslatedComponents.ECLIPSE),
43+
IDEA("IntelliJ", "/org/fife/ui/rsyntaxtextarea/themes/idea.xml", TranslatedComponents.INTELLIJ),
44+
VS("Visual Studio", "/org/fife/ui/rsyntaxtextarea/themes/vs.xml", TranslatedComponents.VISUAL_STUDIO),
45+
DRUID("Druid (Dark)", "/org/fife/ui/rsyntaxtextarea/themes/druid.xml", TranslatedComponents.DRUID_DARK),
46+
MONOKAI("Monokai (Dark)", "/org/fife/ui/rsyntaxtextarea/themes/monokai.xml", TranslatedComponents.MONOKAI_DARK);
4247

4348
private final String readableName;
4449
private final String file;

src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameFields.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ public void obfuscate()
4545
{
4646
FieldNode f = (FieldNode) o;
4747
String newName = generateUniqueName(stringLength);
48-
ASMResourceUtil.renameFieldNode(c.name, f.name, f.desc, null, newName, null);
48+
ASMResourceUtil.renameFieldNode(c.name, f.name, f.desc,
49+
null, newName, null);
4950
f.name = newName;
5051
}
5152
}

src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameMethods.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ public void obfuscate()
5050
if (!m.name.equals("main") && !m.name.equals("<init>") && !m.name.equals("<clinit>"))
5151
{
5252
String newName = generateUniqueName(stringLength);
53-
ASMResourceUtil.renameMethodNode(c.name, m.name, m.desc, null, newName, null);
53+
ASMResourceUtil.renameMethodNode(c.name, m.name, m.desc,
54+
null, newName, null);
5455
}
5556
}
5657
}

src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/Remapper.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,11 @@ public Object mapValue(Object value)
176176
if (value instanceof Handle)
177177
{
178178
Handle h = (Handle) value;
179-
return new Handle(h.getTag(), mapType(h.getOwner()), mapMethodName(h.getOwner(), h.getName(), h.getDesc()), mapMethodDesc(h.getDesc()), h.getTag() == Opcodes.H_INVOKEINTERFACE);
179+
return new Handle(h.getTag(),
180+
mapType(h.getOwner()),
181+
mapMethodName(h.getOwner(), h.getName(), h.getDesc()),
182+
mapMethodDesc(h.getDesc()),
183+
h.getTag() == Opcodes.H_INVOKEINTERFACE);
180184
}
181185

182186
return value;

src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameClasses.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static void open()
3939
{
4040
if (Configuration.runningObfuscation)
4141
{
42-
BytecodeViewer.showMessage("You're currently running an obfuscation task, wait for this to finish" + ".");
42+
BytecodeViewer.showMessage("You're currently running an obfuscation task, wait for this to finish.");
4343
return;
4444
}
4545

@@ -75,9 +75,6 @@ public void obfuscate()
7575
String newName = generateUniqueName(stringLength);
7676

7777
BytecodeViewer.refactorer.getHooks().addClass(new MappingData(c.name, newName));
78-
79-
/*ASMUtil_OLD.renameClassNode(c.name, newName);
80-
c.name = newName;*/
8178
}
8279

8380
System.out.println("Obfuscated class names.");

src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameFields.java

-3
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ public void obfuscate()
6464
String newName = generateUniqueName(stringLength);
6565

6666
BytecodeViewer.refactorer.getHooks().addField(new FieldMappingData(c.name, new MappingData(f.name, newName), f.desc));
67-
68-
/*ASMUtil_OLD.renameFieldNode(c.name, f.name, f.desc, null, newName, null);
69-
f.name = newName;*/
7067
}
7168
}
7269

0 commit comments

Comments
 (0)