Skip to content

Commit dd66a7d

Browse files
Support deobf of arbitrarily nested jars (#12)
1 parent 09434e8 commit dd66a7d

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/repo/
55
/.settings/
66
/bin/
7+
/out/
78
.classpath
89
.project
910
*.lzma

src/main/java/net/minecraftforge/installertools/SrgMcpRenamer.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,14 @@ public String mapMethodName(final String owner, final String name, final String
129129
Utils.copy(zin, zout);
130130
};
131131

132+
processors.add(new ZipEntryProcessor(ein -> ein.getName().startsWith("META-INF/jarjar/") && ein.getName().endsWith(".jar"),
133+
(ein, zin, zout) -> this.processNestedJar(processors, defaultProcessor, ein, zin, zout)));
134+
132135
ByteArrayOutputStream memory = input.equals(output) ? new ByteArrayOutputStream() : null;
133136
try (ZipOutputStream zout = new ZipOutputStream(memory == null ? new FileOutputStream(output) : memory);
134137
ZipInputStream in = new ZipInputStream(new FileInputStream(input))) {
135138

136-
forEachZipEntry(in, (ein, zin) -> processors.stream()
137-
.filter(it -> it.validate(ein))
138-
.findFirst()
139-
.map(ZipEntryProcessor::getProcessor)
140-
.orElse(defaultProcessor)
141-
.process(ein, zin, zout));
139+
process(processors, defaultProcessor, in, zout);
142140
}
143141

144142
if (memory != null)
@@ -151,6 +149,19 @@ public String mapMethodName(final String owner, final String name, final String
151149
}
152150
}
153151

152+
private void process(List<ZipEntryProcessor> processors, ZipWritingConsumer defaultProcessor, ZipInputStream in, ZipOutputStream zout) throws IOException {
153+
forEachZipEntry(in, (ein, zin) -> {
154+
for (ZipEntryProcessor processor : processors) {
155+
if (processor.validate(ein)) {
156+
processor.getProcessor().process(ein, zin, zout);
157+
return;
158+
}
159+
}
160+
161+
defaultProcessor.process(ein, zin, zout);
162+
});
163+
}
164+
154165
private void forEachZipEntry(ZipInputStream zin, ZipConsumer entryConsumer) throws IOException {
155166
String prevName = null;
156167
ZipEntry ein;
@@ -197,6 +208,14 @@ private void processManifest(final ZipEntry ein, final ZipInputStream zin, final
197208
log("Stripped Manifest of sha digests");
198209
}
199210

211+
private void processNestedJar(List<ZipEntryProcessor> processors, ZipWritingConsumer defaultProcessor, ZipEntry ein, ZipInputStream in, ZipOutputStream zout) throws IOException {
212+
zout.putNextEntry(makeNewEntry(ein));
213+
ZipInputStream nestedIn = new ZipInputStream(in);
214+
ZipOutputStream nestedOut = new ZipOutputStream(zout);
215+
process(processors, defaultProcessor, nestedIn, nestedOut);
216+
nestedOut.finish();
217+
}
218+
200219
private boolean holdsSignatures(final ZipEntry ein) {
201220
return ein.getName().startsWith("META-INF/") && (ein.getName().endsWith(".SF") || ein.getName().endsWith(".RSA"));
202221
}

0 commit comments

Comments
 (0)