Skip to content

Commit

Permalink
Support deobf of arbitrarily nested jars (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
SizableShrimp authored Jul 20, 2022
1 parent 09434e8 commit dd66a7d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/repo/
/.settings/
/bin/
/out/
.classpath
.project
*.lzma
31 changes: 25 additions & 6 deletions src/main/java/net/minecraftforge/installertools/SrgMcpRenamer.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,14 @@ public String mapMethodName(final String owner, final String name, final String
Utils.copy(zin, zout);
};

processors.add(new ZipEntryProcessor(ein -> ein.getName().startsWith("META-INF/jarjar/") && ein.getName().endsWith(".jar"),
(ein, zin, zout) -> this.processNestedJar(processors, defaultProcessor, ein, zin, zout)));

ByteArrayOutputStream memory = input.equals(output) ? new ByteArrayOutputStream() : null;
try (ZipOutputStream zout = new ZipOutputStream(memory == null ? new FileOutputStream(output) : memory);
ZipInputStream in = new ZipInputStream(new FileInputStream(input))) {

forEachZipEntry(in, (ein, zin) -> processors.stream()
.filter(it -> it.validate(ein))
.findFirst()
.map(ZipEntryProcessor::getProcessor)
.orElse(defaultProcessor)
.process(ein, zin, zout));
process(processors, defaultProcessor, in, zout);
}

if (memory != null)
Expand All @@ -151,6 +149,19 @@ public String mapMethodName(final String owner, final String name, final String
}
}

private void process(List<ZipEntryProcessor> processors, ZipWritingConsumer defaultProcessor, ZipInputStream in, ZipOutputStream zout) throws IOException {
forEachZipEntry(in, (ein, zin) -> {
for (ZipEntryProcessor processor : processors) {
if (processor.validate(ein)) {
processor.getProcessor().process(ein, zin, zout);
return;
}
}

defaultProcessor.process(ein, zin, zout);
});
}

private void forEachZipEntry(ZipInputStream zin, ZipConsumer entryConsumer) throws IOException {
String prevName = null;
ZipEntry ein;
Expand Down Expand Up @@ -197,6 +208,14 @@ private void processManifest(final ZipEntry ein, final ZipInputStream zin, final
log("Stripped Manifest of sha digests");
}

private void processNestedJar(List<ZipEntryProcessor> processors, ZipWritingConsumer defaultProcessor, ZipEntry ein, ZipInputStream in, ZipOutputStream zout) throws IOException {
zout.putNextEntry(makeNewEntry(ein));
ZipInputStream nestedIn = new ZipInputStream(in);
ZipOutputStream nestedOut = new ZipOutputStream(zout);
process(processors, defaultProcessor, nestedIn, nestedOut);
nestedOut.finish();
}

private boolean holdsSignatures(final ZipEntry ein) {
return ein.getName().startsWith("META-INF/") && (ein.getName().endsWith(".SF") || ein.getName().endsWith(".RSA"));
}
Expand Down

0 comments on commit dd66a7d

Please sign in to comment.