diff --git a/src/main/java/com/heliosdecompiler/transformerapi/StandardTransformers.java b/src/main/java/com/heliosdecompiler/transformerapi/StandardTransformers.java index ec4cb49..5d34c5f 100644 --- a/src/main/java/com/heliosdecompiler/transformerapi/StandardTransformers.java +++ b/src/main/java/com/heliosdecompiler/transformerapi/StandardTransformers.java @@ -49,7 +49,7 @@ public static DecompilationResult decompile(Loader apiLoader, Map 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 { diff --git a/src/main/java/com/heliosdecompiler/transformerapi/common/Loader.java b/src/main/java/com/heliosdecompiler/transformerapi/common/Loader.java index 86ab2a9..1a9e7b3 100644 --- a/src/main/java/com/heliosdecompiler/transformerapi/common/Loader.java +++ b/src/main/java/com/heliosdecompiler/transformerapi/common/Loader.java @@ -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) { @@ -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 entry : openedZipFiles.entrySet()) { diff --git a/src/test/java/com/heliosdecompiler/transformerapi/StandardTransformersTest.java b/src/test/java/com/heliosdecompiler/transformerapi/StandardTransformersTest.java index c01f85c..ec2d66a 100644 --- a/src/test/java/com/heliosdecompiler/transformerapi/StandardTransformersTest.java +++ b/src/test/java/com/heliosdecompiler/transformerapi/StandardTransformersTest.java @@ -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 @@ -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 @@ -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 @@ -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 @@ -138,9 +168,19 @@ 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()); @@ -148,7 +188,7 @@ public void testDecompileFernflowerFromClassPath() throws Exception { @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 @@ -163,9 +203,19 @@ 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()); @@ -173,7 +223,7 @@ public void testDecompileVineflowerFromClassPath() throws Exception { @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 @@ -188,9 +238,19 @@ 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()); @@ -198,7 +258,7 @@ public void testDecompileJDCoreV0FromClassPath() throws Exception { @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 @@ -213,9 +273,19 @@ 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()); @@ -223,7 +293,7 @@ public void testDecompileJDCoreV1FromClassPath() throws Exception { @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 @@ -236,12 +306,11 @@ public void testDecompileJDCoreV1FromRootLocation() throws Exception { testDecompileFromRootLocation("/TestCompactJDCoreV1FromRootLocation.txt", JD_CORE_V1); } - private void testDecompile(String path, String engineName, Map preferences) + private void testDecompile(String path, String engineName, Map 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()); } diff --git a/src/test/java/com/heliosdecompiler/transformerapi/ZipLoader.java b/src/test/java/com/heliosdecompiler/transformerapi/ZipLoader.java index e9c2445..8474109 100644 --- a/src/test/java/com/heliosdecompiler/transformerapi/ZipLoader.java +++ b/src/test/java/com/heliosdecompiler/transformerapi/ZipLoader.java @@ -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); } } \ No newline at end of file diff --git a/src/test/resources/test-boot-inf-classes.jar b/src/test/resources/test-boot-inf-classes.jar new file mode 100644 index 0000000..1b72d96 Binary files /dev/null and b/src/test/resources/test-boot-inf-classes.jar differ diff --git a/src/test/resources/test-web-inf-classes.jar b/src/test/resources/test-web-inf-classes.jar new file mode 100644 index 0000000..3e3203f Binary files /dev/null and b/src/test/resources/test-web-inf-classes.jar differ