Skip to content

Commit c404204

Browse files
author
GraxCode
committed
fix jbytemod changing empty file names and removing empty directories
(#62)
1 parent 64e9628 commit c404204

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

src/main/java/me/grax/jbytemod/decompiler/KrakatauDecompiler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private String escape(String absolutePath) {
9999

100100
private File createTempJar(byte[] b) {
101101
File temp = new File(tempDir, b.hashCode() + ".jar");
102-
JarUtils.saveAsJar(Collections.singletonMap(cn.name, b), temp.getAbsolutePath());
102+
JarUtils.saveAsJar(Collections.singletonMap(cn.name + ".class", b), temp.getAbsolutePath());
103103
return temp;
104104
}
105105

src/main/java/me/grax/jbytemod/utils/task/LoadTask.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ private void readJar(JarFile jar, JarEntry en, Map<String, ClassNode> classes, M
9090
publish((int) (((float) loaded++ / (float) jarSize) * 100f));
9191
String name = en.getName();
9292
try (InputStream jis = jar.getInputStream(en)) {
93+
System.out.println(name + " " + en.isDirectory());
9394
if (name.endsWith(".class")) {
9495
byte[] bytes = IOUtils.toByteArray(jis);
9596
String cafebabe = String.format("%02X%02X%02X%02X", bytes[0], bytes[1], bytes[2], bytes[3]);
@@ -104,9 +105,13 @@ private void readJar(JarFile jar, JarEntry en, Map<String, ClassNode> classes, M
104105
JByteMod.LOGGER.err("Failed loading class file " + name);
105106
}
106107
}
107-
} else if (!en.isDirectory()) {
108-
byte[] bytes = IOUtils.toByteArray(jis);
109-
otherFiles.put(name, bytes);
108+
} else {
109+
if (!en.isDirectory()) {
110+
byte[] bytes = IOUtils.toByteArray(jis);
111+
otherFiles.put(name, bytes);
112+
} else {
113+
otherFiles.put(name, new byte[0]);
114+
}
110115
}
111116
if (memoryWarning) {
112117
long timeDif = System.currentTimeMillis() - ms;

src/main/java/me/grax/jbytemod/utils/task/SaveTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected Void doInBackground() throws Exception {
5353
ClassNode node = classes.get(s);
5454
ClassWriter writer = new ClassWriter(flags);
5555
node.accept(writer);
56-
outputBytes.put(s, writer.toByteArray());
56+
outputBytes.put(s + ".class", writer.toByteArray());
5757
publish((int) ((i++ / size) * 50d));
5858
}
5959
publish(50);

src/main/java/me/lpk/util/JarUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ public static void saveAsJar(Map<String, byte[]> outBytes, String fileName) {
128128
try {
129129
JarOutputStream out = new JarOutputStream(new java.io.FileOutputStream(fileName));
130130
for (String entry : outBytes.keySet()) {
131-
String ext = entry.contains(".") ? "" : ".class";
132-
out.putNextEntry(new ZipEntry(entry + ext));
133-
out.write(outBytes.get(entry));
131+
out.putNextEntry(new ZipEntry(entry));
132+
if (!entry.endsWith("/"))
133+
out.write(outBytes.get(entry));
134134
out.closeEntry();
135135
}
136136
out.close();

0 commit comments

Comments
 (0)