diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/regions/RegionMaker.java b/jadx-core/src/main/java/jadx/core/dex/visitors/regions/RegionMaker.java index bbe76d663..754de35cf 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/regions/RegionMaker.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/regions/RegionMaker.java @@ -338,18 +338,23 @@ public class RegionMaker { InstructionRemover.unbindInsn(mth, exitInsn); } - block = getNextBlock(block); + BlockNode body = getNextBlock(block); + if (body == null) { + mth.add(AFlag.INCONSISTENT_CODE); + LOG.warn("Unexpected end of synchronized block"); + return null; + } BlockNode exit; if (exits.size() == 1) { exit = getNextBlock(exits.iterator().next()); } else { cacheSet.clear(); - exit = traverseMonitorExitsCross(block, exits, cacheSet); + exit = traverseMonitorExitsCross(body, exits, cacheSet); } stack.push(synchRegion); stack.addExit(exit); - synchRegion.getSubBlocks().add(makeRegion(block, stack)); + synchRegion.getSubBlocks().add(makeRegion(body, stack)); stack.pop(); return exit; } diff --git a/jadx-core/src/main/java/jadx/core/utils/AsmUtils.java b/jadx-core/src/main/java/jadx/core/utils/AsmUtils.java index 840b21d5d..15c2b7cfe 100644 --- a/jadx-core/src/main/java/jadx/core/utils/AsmUtils.java +++ b/jadx-core/src/main/java/jadx/core/utils/AsmUtils.java @@ -12,9 +12,18 @@ public class AsmUtils { } public static String getNameFromClassFile(File file) throws IOException { - FileInputStream in = new FileInputStream(file); - ClassReader classReader = new ClassReader(in); - return classReader.getClassName(); + String className = null; + FileInputStream in = null; + try { + in = new FileInputStream(file); + ClassReader classReader = new ClassReader(in); + className = classReader.getClassName(); + } finally { + if (in != null) { + in.close(); + } + } + return className; } } diff --git a/jadx-core/src/main/java/jadx/core/utils/files/InputFile.java b/jadx-core/src/main/java/jadx/core/utils/files/InputFile.java index 22e5d719b..6421e2364 100644 --- a/jadx-core/src/main/java/jadx/core/utils/files/InputFile.java +++ b/jadx-core/src/main/java/jadx/core/utils/files/InputFile.java @@ -102,12 +102,24 @@ public class InputFile { private static Dex loadFromClassFile(File file) throws IOException, DecodeException { File outFile = File.createTempFile("jadx-tmp-", System.nanoTime() + ".jar"); outFile.deleteOnExit(); - FileOutputStream out = new FileOutputStream(outFile); - JarOutputStream jo = new JarOutputStream(out); - String clsName = AsmUtils.getNameFromClassFile(file); - FileUtils.addFileToJar(jo, file, clsName + ".class"); - jo.close(); - out.close(); + FileOutputStream out = null; + JarOutputStream jo = null; + try { + out = new FileOutputStream(outFile); + jo = new JarOutputStream(out); + String clsName = AsmUtils.getNameFromClassFile(file); + if (clsName == null) { + throw new IOException("Can't read class name from file: " + file); + } + FileUtils.addFileToJar(jo, file, clsName + ".class"); + } finally { + if (jo != null) { + jo.close(); + } + if (out != null) { + out.close(); + } + } return loadFromJar(outFile); }