Skip to content

Commit

Permalink
v2.9.17
Browse files Browse the repository at this point in the history
  • Loading branch information
Konloch committed Apr 17, 2019
1 parent e1e79d0 commit b3e60ce
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 12 deletions.
Binary file added libs/commons-compress-1.18.jar
Binary file not shown.
3 changes: 0 additions & 3 deletions src/META-INF/MANIFEST.MF

This file was deleted.

9 changes: 8 additions & 1 deletion src/the/bytecode/club/bytecodeviewer/BytecodeViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
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;
Expand Down Expand Up @@ -847,6 +847,13 @@ public void run() {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,10 @@ public void openPath(TreePath path)
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()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2387,7 +2387,7 @@ public void actionPerformed(ActionEvent arg0)
});

visualSettings.add(synchronizedViewing);
showClassMethods.setSelected(true);
showClassMethods.setSelected(false);
visualSettings.add(showClassMethods);


Expand Down
72 changes: 65 additions & 7 deletions src/the/bytecode/club/bytecodeviewer/util/JarUtils.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -76,10 +80,14 @@ public static void put(final File jarFile) throws IOException {
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 {
Expand All @@ -89,7 +97,57 @@ public static void put(final File jarFile) throws IOException {
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<String, byte[]> files = new HashMap<String, byte[]>();


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 {
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);
}


Expand Down

0 comments on commit b3e60ce

Please sign in to comment.