diff --git a/libs/commons-compress-1.18.jar b/libs/commons-compress-1.18.jar new file mode 100644 index 00000000..e401046b Binary files /dev/null and b/libs/commons-compress-1.18.jar differ diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF deleted file mode 100644 index 53f4396f..00000000 --- a/src/META-INF/MANIFEST.MF +++ /dev/null @@ -1,3 +0,0 @@ -Manifest-Version: 1.0 -Main-Class: the.bytecode.club.bytecodeviewer.BytecodeViewer - diff --git a/src/the/bytecode/club/bytecodeviewer/BytecodeViewer.java b/src/the/bytecode/club/bytecodeviewer/BytecodeViewer.java index 249bfbeb..a87246d1 100644 --- a/src/the/bytecode/club/bytecodeviewer/BytecodeViewer.java +++ b/src/the/bytecode/club/bytecodeviewer/BytecodeViewer.java @@ -109,7 +109,7 @@ import the.bytecode.club.bytecodeviewer.util.*; public class BytecodeViewer { /*per version*/ - public static final String VERSION = "2.9.16"; + public static final String VERSION = "2.9.17"; public static String krakatauVersion = "12"; public static String enjarifyVersion = "4"; public static final boolean BLOCK_TAB_MENU = true; @@ -847,6 +847,13 @@ public class BytecodeViewer if (fn.endsWith(".jar") || fn.endsWith(".zip")) { try { JarUtils.put(f); + } catch (final java.util.zip.ZipException z) { + try { + JarUtils.put2(f); + } catch (final Exception e) { + new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e); + update = false; + } } catch (final Exception e) { new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e); update = false; diff --git a/src/the/bytecode/club/bytecodeviewer/gui/FileNavigationPane.java b/src/the/bytecode/club/bytecodeviewer/gui/FileNavigationPane.java index e0b40d26..73663e90 100644 --- a/src/the/bytecode/club/bytecodeviewer/gui/FileNavigationPane.java +++ b/src/the/bytecode/club/bytecodeviewer/gui/FileNavigationPane.java @@ -583,6 +583,10 @@ public class FileNavigationPane extends VisibleComponent implements if (cn != null) { openClassFileToWorkSpace(container, nameBuffer.toString(), cn); } + else + { + openFileToWorkSpace(container, nameBuffer.toString(), BytecodeViewer.getFileContents(nameBuffer.toString())); + } } else { openFileToWorkSpace(container, nameBuffer.toString(), BytecodeViewer.getFileContents(nameBuffer.toString())); } diff --git a/src/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java b/src/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java index 62c73610..a031b5dc 100644 --- a/src/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java +++ b/src/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java @@ -2387,7 +2387,7 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier }); visualSettings.add(synchronizedViewing); - showClassMethods.setSelected(true); + showClassMethods.setSelected(false); visualSettings.add(showClassMethods); diff --git a/src/the/bytecode/club/bytecodeviewer/util/JarUtils.java b/src/the/bytecode/club/bytecodeviewer/util/JarUtils.java index b290c76d..9918d676 100644 --- a/src/the/bytecode/club/bytecodeviewer/util/JarUtils.java +++ b/src/the/bytecode/club/bytecodeviewer/util/JarUtils.java @@ -1,20 +1,24 @@ package the.bytecode.club.bytecodeviewer.util; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Enumeration; import java.util.HashMap; import java.util.Map.Entry; import java.util.jar.JarOutputStream; import java.util.zip.ZipEntry; +import java.util.zip.ZipException; 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.compress.utils.IOUtils; +import org.apache.commons.io.FilenameUtils; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.tree.ClassNode; @@ -76,10 +80,14 @@ public class JarUtils { e.printStackTrace(); } } else { - System.out.println(jarFile + ">" + name + ": Header does not start with CAFEBABE, ignoring."); + if (!entry.isDirectory()) + files.put(name, bytes); + //System.out.println(jarFile + ">" + name + ": Header does not start with CAFEBABE, ignoring."); } } + } catch (ZipException e) { + //ignore cause apache unzip } catch (Exception e) { new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e); } finally { @@ -89,7 +97,57 @@ public class JarUtils { jis.close(); container.files = files; BytecodeViewer.files.add(container); + } + public static void put2(final File jarFile) throws IOException { + //TODO try zip libraries till one works, worst case import Sun's jarsigner code from JDK 7 re-sign the jar to rebuilt the CRC, should also rebuild the archive byte offsets + + FileContainer container = new FileContainer(jarFile); + HashMap 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 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 { + try (InputStream in = zipFile.getInputStream(entry)) + { + + final byte[] bytes = getBytes(in); + if (!name.endsWith(".class")) { + files.put(name, bytes); + } else { + String cafebabe = String.format("%02X", bytes[0]) + String.format("%02X", bytes[1]) + String.format("%02X", bytes[2]) + String.format("%02X", bytes[3]); + if (cafebabe.toLowerCase().equals("cafebabe")) { + try { + final ClassNode cn = getNode(bytes); + container.classes.add(cn); + } catch (Exception e) { + e.printStackTrace(); + } + } else { + files.put(name, bytes); + } + } + + } + } + } + } + + container.files = files; + BytecodeViewer.files.add(container); }