Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static DecompilationResult decompile(Loader apiLoader,
Map<String, String> preferences,
String engineName)
throws IOException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
return Decompilers.decompile(apiLoader, entryInternalName, preferences, engineName);
return Decompilers.decompile(apiLoader, entryInternalName.replaceFirst("^(WEB|BOOT)-INF/classes/", ""), preferences, engineName);
}

public static final class Decompilers {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ private void loadClasspathEntries() {
}

public boolean canLoad(String internalName) {
if (canLoadFunction.test(internalName)) {
if (canLoadFunction.test(internalName)
|| canLoadFunction.test("BOOT-INF/classes/" + internalName)
|| canLoadFunction.test("WEB-INF/classes/" + internalName)) {
return true;
}
if (classpathEntries != null) {
Expand All @@ -95,6 +97,14 @@ public byte[] load(String internalName) throws IOException {
if (classContents != null) {
return classContents;
}
classContents = loadFunction.apply("BOOT-INF/classes/" + internalName);
if (classContents != null) {
return classContents;
}
classContents = loadFunction.apply("WEB-INF/classes/" + internalName);
if (classContents != null) {
return classContents;
}
if (classpathEntries != null) {
loadClasspathEntries();
for (Map.Entry<String, ZipFile> entry : openedZipFiles.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,22 @@ public void testValueOf() {

@Test
public void testDecompileCFR() throws Exception {
testDecompile("/TestCompactCFR.txt", ENGINE_CFR, CFRSettings.defaults());
testDecompile("/TestCompactCFR.txt", ENGINE_CFR, CFRSettings.defaults(), "test/TestCompact", "/test-compact-expand-inline.jar");
}

@Test
public void testDecompileCFRBootInf() throws Exception {
testDecompile("/TestCompactCFRFromRootLocation.txt", ENGINE_CFR, CFRSettings.lineNumbers(), "BOOT-INF/classes/com/heliosdecompiler/transformerapi/TestCompact", "/test-boot-inf-classes.jar");
}

@Test
public void testDecompileCFRWebInf() throws Exception {
testDecompile("/TestCompactCFRFromRootLocation.txt", ENGINE_CFR, CFRSettings.lineNumbers(), "WEB-INF/classes/com/heliosdecompiler/transformerapi/TestCompact", "/test-web-inf-classes.jar");
}

@Test
public void testDecompileCFRWithLineNumbers() throws Exception {
testDecompile("/TestCompactCFRWithLineNumbers.txt", ENGINE_CFR, CFRSettings.lineNumbers());
testDecompile("/TestCompactCFRWithLineNumbers.txt", ENGINE_CFR, CFRSettings.lineNumbers(), "test/TestCompact", "/test-compact-expand-inline.jar");
}

@Test
Expand All @@ -88,12 +98,22 @@ public void testDecompileProcyonFromClassPath() throws Exception {

@Test
public void testDecompileProcyon() throws Exception {
testDecompile("/TestCompactProcyon.txt", ENGINE_PROCYON, MapDecompilerSettings.defaults());
testDecompile("/TestCompactProcyon.txt", ENGINE_PROCYON, MapDecompilerSettings.defaults(), "test/TestCompact", "/test-compact-expand-inline.jar");
}

@Test
public void testDecompileProcyonBootInf() throws Exception {
testDecompile("/TestCompactProcyonFromRootLocation.txt", ENGINE_PROCYON, MapDecompilerSettings.lineNumbers(), "BOOT-INF/classes/com/heliosdecompiler/transformerapi/TestCompact", "/test-boot-inf-classes.jar");
}

@Test
public void testDecompileProcyonWebInf() throws Exception {
testDecompile("/TestCompactProcyonFromRootLocation.txt", ENGINE_PROCYON, MapDecompilerSettings.lineNumbers(), "WEB-INF/classes/com/heliosdecompiler/transformerapi/TestCompact", "/test-web-inf-classes.jar");
}

@Test
public void testDecompileProcyonWithLineNumbers() throws Exception {
testDecompile("/TestCompactProcyonWithLineNumbers.txt", ENGINE_PROCYON, MapDecompilerSettings.lineNumbers());
testDecompile("/TestCompactProcyonWithLineNumbers.txt", ENGINE_PROCYON, MapDecompilerSettings.lineNumbers(), "test/TestCompact", "/test-compact-expand-inline.jar");
}

@Test
Expand All @@ -108,7 +128,7 @@ public void testDecompileProcyonFromRootLocation() throws Exception {

@Test
public void testDecompileProcyonByteCode() throws Exception {
testDecompile("/TestCompactProcyonByteCode.txt", ENGINE_PROCYON, MapDecompilerSettings.byteCodeSettings());
testDecompile("/TestCompactProcyonByteCode.txt", ENGINE_PROCYON, MapDecompilerSettings.byteCodeSettings(), "test/TestCompact", "/test-compact-expand-inline.jar");
}

@Test
Expand All @@ -118,12 +138,22 @@ public void testDecompileJADXFromClassPath() throws Exception {

@Test
public void testDecompileJADX() throws Exception {
testDecompile("/TestCompactJADX.txt", ENGINE_JADX, MapJadxArgs.defaults());
testDecompile("/TestCompactJADX.txt", ENGINE_JADX, MapJadxArgs.defaults(), "test/TestCompact", "/test-compact-expand-inline.jar");
}

@Test
public void testDecompileJADXBootInf() throws Exception {
testDecompile("/TestCompactJADXFromRootLocation.txt", ENGINE_JADX, MapJadxArgs.lineNumbers(), "BOOT-INF/classes/com/heliosdecompiler/transformerapi/TestCompact", "/test-boot-inf-classes.jar");
}

@Test
public void testDecompileJADXWebInf() throws Exception {
testDecompile("/TestCompactJADXFromRootLocation.txt", ENGINE_JADX, MapJadxArgs.lineNumbers(), "WEB-INF/classes/com/heliosdecompiler/transformerapi/TestCompact", "/test-web-inf-classes.jar");
}

@Test
public void testDecompileJADXWithLineNumbers() throws Exception {
testDecompile("/TestCompactJADXWithLineNumbers.txt", ENGINE_JADX, MapJadxArgs.lineNumbers());
testDecompile("/TestCompactJADXWithLineNumbers.txt", ENGINE_JADX, MapJadxArgs.lineNumbers(), "test/TestCompact", "/test-compact-expand-inline.jar");
}

@Test
Expand All @@ -138,17 +168,27 @@ public void testDecompileJADXFromRootLocation() throws Exception {

@Test
public void testDecompileFernflower() throws Exception {
testDecompile("/TestCompactFernflower.txt", ENGINE_FERNFLOWER, Collections.emptyMap());
testDecompile("/TestCompactFernflower.txt", ENGINE_FERNFLOWER, Collections.emptyMap(), "test/TestCompact", "/test-compact-expand-inline.jar");
}

@Test
public void testDecompileFernflowerBootInf() throws Exception {
testDecompile("/TestCompactFernflowerFromRootLocation.txt", ENGINE_FERNFLOWER, FernflowerSettings.lineNumbers(), "BOOT-INF/classes/com/heliosdecompiler/transformerapi/TestCompact", "/test-boot-inf-classes.jar");
}

@Test
public void testDecompileFernflowerWebInf() throws Exception {
testDecompile("/TestCompactFernflowerFromRootLocation.txt", ENGINE_FERNFLOWER, FernflowerSettings.lineNumbers(), "WEB-INF/classes/com/heliosdecompiler/transformerapi/TestCompact", "/test-web-inf-classes.jar");
}

@Test
public void testDecompileFernflowerFromClassPath() throws Exception {
testDecompileFromClassPath("/TestThrowableFernflower.txt", ENGINE_FERNFLOWER, Collections.emptyMap());
}

@Test
public void testDecompileFernflowerWithLineNumbers() throws Exception {
testDecompile("/TestCompactFernflowerWithLineNumbers.txt", ENGINE_FERNFLOWER, FernflowerSettings.lineNumbers());
testDecompile("/TestCompactFernflowerWithLineNumbers.txt", ENGINE_FERNFLOWER, FernflowerSettings.lineNumbers(), "test/TestCompact", "/test-compact-expand-inline.jar");
}

@Test
Expand All @@ -163,17 +203,27 @@ public void testDecompileFernflowerFromRootLocation() throws Exception {

@Test
public void testDecompileVineflower() throws Exception {
testDecompile("/TestCompactVineflower.txt", ENGINE_VINEFLOWER, Collections.emptyMap());
testDecompile("/TestCompactVineflower.txt", ENGINE_VINEFLOWER, Collections.emptyMap(), "test/TestCompact", "/test-compact-expand-inline.jar");
}

@Test
public void testDecompileVineflowerBootInf() throws Exception {
testDecompile("/TestCompactVineflowerFromRootLocation.txt", ENGINE_VINEFLOWER, VineflowerSettings.lineNumbers(), "BOOT-INF/classes/com/heliosdecompiler/transformerapi/TestCompact", "/test-boot-inf-classes.jar");
}

@Test
public void testDecompileVineflowerWebInf() throws Exception {
testDecompile("/TestCompactVineflowerFromRootLocation.txt", ENGINE_VINEFLOWER, VineflowerSettings.lineNumbers(), "WEB-INF/classes/com/heliosdecompiler/transformerapi/TestCompact", "/test-web-inf-classes.jar");
}

@Test
public void testDecompileVineflowerFromClassPath() throws Exception {
testDecompileFromClassPath("/TestThrowableVineflower.txt", ENGINE_VINEFLOWER, Collections.emptyMap());
}

@Test
public void testDecompileVineflowerWithLineNumbers() throws Exception {
testDecompile("/TestCompactVineflowerWithLineNumbers.txt", ENGINE_VINEFLOWER, VineflowerSettings.lineNumbers());
testDecompile("/TestCompactVineflowerWithLineNumbers.txt", ENGINE_VINEFLOWER, VineflowerSettings.lineNumbers(), "test/TestCompact", "/test-compact-expand-inline.jar");
}

@Test
Expand All @@ -188,17 +238,27 @@ public void testDecompileVineflowerFromRootLocation() throws Exception {

@Test
public void testDecompileJDCoreV0() throws Exception {
testDecompile("/TestCompactJDCoreV0.txt", ENGINE_JD_CORE_V0, JDSettings.defaults());
testDecompile("/TestCompactJDCoreV0.txt", ENGINE_JD_CORE_V0, JDSettings.defaults(), "test/TestCompact", "/test-compact-expand-inline.jar");
}

@Test
public void testDecompileJDCoreV0BootInf() throws Exception {
testDecompile("/TestCompactJDCoreV0FromRootLocation.txt", ENGINE_JD_CORE_V0, JDSettings.lineNumbers(), "BOOT-INF/classes/com/heliosdecompiler/transformerapi/TestCompact", "/test-boot-inf-classes.jar");
}

@Test
public void testDecompileJDCoreV0WebInf() throws Exception {
testDecompile("/TestCompactJDCoreV0FromRootLocation.txt", ENGINE_JD_CORE_V0, JDSettings.lineNumbers(), "WEB-INF/classes/com/heliosdecompiler/transformerapi/TestCompact", "/test-web-inf-classes.jar");
}

@Test
public void testDecompileJDCoreV0FromClassPath() throws Exception {
testDecompileFromClassPath("/TestThrowableJDCoreV0.txt", ENGINE_JD_CORE_V0, JDSettings.defaults());
}

@Test
public void testDecompileJDCoreV0WithLineNumbers() throws Exception {
testDecompile("/TestCompactJDCoreV0WithLineNumbers.txt", ENGINE_JD_CORE_V0, JDSettings.lineNumbers());
testDecompile("/TestCompactJDCoreV0WithLineNumbers.txt", ENGINE_JD_CORE_V0, JDSettings.lineNumbers(), "test/TestCompact", "/test-compact-expand-inline.jar");
}

@Test
Expand All @@ -213,17 +273,27 @@ public void testDecompileJDCoreV0FromRootLocation() throws Exception {

@Test
public void testDecompileJDCoreV1() throws Exception {
testDecompile("/TestCompactJDCoreV1.txt", ENGINE_JD_CORE_V1, JDSettings.defaults());
testDecompile("/TestCompactJDCoreV1.txt", ENGINE_JD_CORE_V1, JDSettings.defaults(), "test/TestCompact", "/test-compact-expand-inline.jar");
}

@Test
public void testDecompileJDCoreV1BootInf() throws Exception {
testDecompile("/TestCompactJDCoreV1FromRootLocation.txt", ENGINE_JD_CORE_V1, JDSettings.lineNumbers(), "BOOT-INF/classes/com/heliosdecompiler/transformerapi/TestCompact", "/test-boot-inf-classes.jar");
}

@Test
public void testDecompileJDCoreV1WebInf() throws Exception {
testDecompile("/TestCompactJDCoreV1FromRootLocation.txt", ENGINE_JD_CORE_V1, JDSettings.lineNumbers(), "WEB-INF/classes/com/heliosdecompiler/transformerapi/TestCompact", "/test-web-inf-classes.jar");
}

@Test
public void testDecompileJDCoreV1FromClassPath() throws Exception {
testDecompileFromClassPath("/TestThrowableJDCoreV1.txt", ENGINE_JD_CORE_V1, JDSettings.defaults());
}

@Test
public void testDecompileJDCoreV1WithLineNumbers() throws Exception {
testDecompile("/TestCompactJDCoreV1WithLineNumbers.txt", ENGINE_JD_CORE_V1, JDSettings.lineNumbers());
testDecompile("/TestCompactJDCoreV1WithLineNumbers.txt", ENGINE_JD_CORE_V1, JDSettings.lineNumbers(), "test/TestCompact", "/test-compact-expand-inline.jar");
}

@Test
Expand All @@ -236,12 +306,11 @@ public void testDecompileJDCoreV1FromRootLocation() throws Exception {
testDecompileFromRootLocation("/TestCompactJDCoreV1FromRootLocation.txt", JD_CORE_V1);
}

private void testDecompile(String path, String engineName, Map<String, String> preferences)
private void testDecompile(String path, String engineName, Map<String, String> preferences, String internalName, String jarPath)
throws IOException, IllegalAccessException, InvocationTargetException, URISyntaxException {
URI resource = getClass().getResource("/test-compact-expand-inline.jar").toURI();
URI resource = getClass().getResource(jarPath).toURI();
ZipLoader zipLoader = new ZipLoader(resource.toURL().openStream());
Loader loader = new Loader(zipLoader::canLoad, zipLoader::load, resource);
String internalName = "test/TestCompact";
DecompilationResult result = StandardTransformers.decompile(loader, internalName, preferences, engineName);
assertEqualsIgnoreEOL(getResourceAsString(path), result.getDecompiledOutput());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ protected String makeEntryName(String entryName) {

@Override
public byte[] load(String internalName) throws IOException {
if (internalName.endsWith(StringConstants.CLASS_FILE_SUFFIX)) {
return super.load(internalName);
}
return getMap().get(internalName + StringConstants.CLASS_FILE_SUFFIX);
}

@Override
public boolean canLoad(String internalName) {
if (internalName.endsWith(StringConstants.CLASS_FILE_SUFFIX)) {
return super.canLoad(internalName);
}
return getMap().containsKey(internalName + StringConstants.CLASS_FILE_SUFFIX);
}
}
Binary file added src/test/resources/test-boot-inf-classes.jar
Binary file not shown.
Binary file added src/test/resources/test-web-inf-classes.jar
Binary file not shown.
Loading