Skip to content

Commit b3e60ce

Browse files
committed
v2.9.17
1 parent e1e79d0 commit b3e60ce

6 files changed

Lines changed: 78 additions & 12 deletions

File tree

libs/commons-compress-1.18.jar

578 KB
Binary file not shown.

src/META-INF/MANIFEST.MF

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/the/bytecode/club/bytecodeviewer/BytecodeViewer.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
public class BytecodeViewer
110110
{
111111
/*per version*/
112-
public static final String VERSION = "2.9.16";
112+
public static final String VERSION = "2.9.17";
113113
public static String krakatauVersion = "12";
114114
public static String enjarifyVersion = "4";
115115
public static final boolean BLOCK_TAB_MENU = true;
@@ -847,6 +847,13 @@ public void run() {
847847
if (fn.endsWith(".jar") || fn.endsWith(".zip")) {
848848
try {
849849
JarUtils.put(f);
850+
} catch (final java.util.zip.ZipException z) {
851+
try {
852+
JarUtils.put2(f);
853+
} catch (final Exception e) {
854+
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
855+
update = false;
856+
}
850857
} catch (final Exception e) {
851858
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
852859
update = false;

src/the/bytecode/club/bytecodeviewer/gui/FileNavigationPane.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,10 @@ public void openPath(TreePath path)
583583
if (cn != null) {
584584
openClassFileToWorkSpace(container, nameBuffer.toString(), cn);
585585
}
586+
else
587+
{
588+
openFileToWorkSpace(container, nameBuffer.toString(), BytecodeViewer.getFileContents(nameBuffer.toString()));
589+
}
586590
} else {
587591
openFileToWorkSpace(container, nameBuffer.toString(), BytecodeViewer.getFileContents(nameBuffer.toString()));
588592
}

src/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2387,7 +2387,7 @@ public void actionPerformed(ActionEvent arg0)
23872387
});
23882388

23892389
visualSettings.add(synchronizedViewing);
2390-
showClassMethods.setSelected(true);
2390+
showClassMethods.setSelected(false);
23912391
visualSettings.add(showClassMethods);
23922392

23932393

src/the/bytecode/club/bytecodeviewer/util/JarUtils.java

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
package the.bytecode.club.bytecodeviewer.util;
22

3-
import java.io.ByteArrayOutputStream;
4-
import java.io.File;
5-
import java.io.FileInputStream;
6-
import java.io.FileOutputStream;
7-
import java.io.IOException;
8-
import java.io.InputStream;
3+
import java.io.*;
4+
import java.nio.file.Files;
5+
import java.nio.file.Path;
6+
import java.nio.file.Paths;
97
import java.util.ArrayList;
8+
import java.util.Enumeration;
109
import java.util.HashMap;
1110
import java.util.Map.Entry;
1211
import java.util.jar.JarOutputStream;
1312
import java.util.zip.ZipEntry;
13+
import java.util.zip.ZipException;
1414
import java.util.zip.ZipInputStream;
1515

1616
import me.konloch.kontainer.io.DiskWriter;
1717

18+
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
19+
import org.apache.commons.compress.archivers.zip.ZipFile;
20+
import org.apache.commons.compress.utils.IOUtils;
21+
import org.apache.commons.io.FilenameUtils;
1822
import org.objectweb.asm.ClassReader;
1923
import org.objectweb.asm.ClassWriter;
2024
import org.objectweb.asm.tree.ClassNode;
@@ -76,10 +80,14 @@ public static void put(final File jarFile) throws IOException {
7680
e.printStackTrace();
7781
}
7882
} else {
79-
System.out.println(jarFile + ">" + name + ": Header does not start with CAFEBABE, ignoring.");
83+
if (!entry.isDirectory())
84+
files.put(name, bytes);
85+
//System.out.println(jarFile + ">" + name + ": Header does not start with CAFEBABE, ignoring.");
8086
}
8187
}
8288

89+
} catch (ZipException e) {
90+
//ignore cause apache unzip
8391
} catch (Exception e) {
8492
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
8593
} finally {
@@ -89,7 +97,57 @@ public static void put(final File jarFile) throws IOException {
8997
jis.close();
9098
container.files = files;
9199
BytecodeViewer.files.add(container);
100+
}
101+
102+
public static void put2(final File jarFile) throws IOException {
103+
//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
104+
105+
FileContainer container = new FileContainer(jarFile);
106+
HashMap<String, byte[]> files = new HashMap<String, byte[]>();
107+
108+
109+
Path path = jarFile.toPath();
92110

111+
String fileBaseName = FilenameUtils.getBaseName(path.getFileName().toString());
112+
Path destFolderPath = Paths.get(path.getParent().toString(), fileBaseName);
113+
114+
try (ZipFile zipFile = new ZipFile(jarFile))
115+
{
116+
Enumeration<? extends ZipArchiveEntry> entries = zipFile.getEntries();
117+
while (entries.hasMoreElements()) {
118+
ZipArchiveEntry entry = entries.nextElement();
119+
Path entryPath = destFolderPath.resolve(entry.getName());
120+
String name = entry.getName();
121+
if (entry.isDirectory()) {
122+
//directory
123+
} else {
124+
try (InputStream in = zipFile.getInputStream(entry))
125+
{
126+
127+
final byte[] bytes = getBytes(in);
128+
if (!name.endsWith(".class")) {
129+
files.put(name, bytes);
130+
} else {
131+
String cafebabe = String.format("%02X", bytes[0]) + String.format("%02X", bytes[1]) + String.format("%02X", bytes[2]) + String.format("%02X", bytes[3]);
132+
if (cafebabe.toLowerCase().equals("cafebabe")) {
133+
try {
134+
final ClassNode cn = getNode(bytes);
135+
container.classes.add(cn);
136+
} catch (Exception e) {
137+
e.printStackTrace();
138+
}
139+
} else {
140+
files.put(name, bytes);
141+
}
142+
}
143+
144+
}
145+
}
146+
}
147+
}
148+
149+
container.files = files;
150+
BytecodeViewer.files.add(container);
93151
}
94152

95153

0 commit comments

Comments
 (0)