From c0eb9e944ea7d7cc8b36bae768c917c64000a93e Mon Sep 17 00:00:00 2001 From: Konloch Date: Sun, 4 Jul 2021 01:56:25 -0700 Subject: [PATCH] Synchronized JarUtil ClassWriters This should be re-evaluated, it's most likely not needed and it will slow down multi-pane decompilation An alternative solution is generating the ClassNode List once, then storing it in a cache that can be quickly saved to disk. If a new file gets added regenerate the cache. --- .../club/bytecodeviewer/util/JarUtils.java | 58 +++++++++++-------- 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/JarUtils.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/JarUtils.java index b1baf9d8..f4624395 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/JarUtils.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/JarUtils.java @@ -17,7 +17,6 @@ import java.util.zip.ZipInputStream; import me.konloch.kontainer.io.DiskWriter; import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; import org.apache.commons.compress.archivers.zip.ZipFile; -import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bytecodeviewer.BytecodeViewer; @@ -51,8 +50,10 @@ import static the.bytecode.club.bytecodeviewer.Constants.*; * @since 09/26/2011 */ -public class JarUtils { - +public class JarUtils +{ + public static Object LOCK = new Object(); + /** * Loads the classes and resources from the input jar file * @@ -245,7 +246,10 @@ public class JarUtils { * @return the ClassNode instance */ public static ClassNode getNode(final byte[] bytez) { - return ASMUtil.getClassNode(bytez); + synchronized (LOCK) + { + return ASMUtil.getClassNode(bytez); + } } /** @@ -296,27 +300,35 @@ public class JarUtils { * @param path the exact jar output path */ public static void saveAsJarClassesOnly(ArrayList nodeList, String path) { - try { - JarOutputStream out = new JarOutputStream(new FileOutputStream(path)); - ArrayList noDupe = new ArrayList<>(); - for (ClassNode cn : nodeList) { - ClassWriter cw = new ClassWriter(0); - cn.accept(cw); - - String name = cn.name + ".class"; - - if (!noDupe.contains(name)) { - noDupe.add(name); - out.putNextEntry(new ZipEntry(name)); - out.write(cw.toByteArray()); - out.closeEntry(); + synchronized (LOCK) + { + try + { + JarOutputStream out = new JarOutputStream(new FileOutputStream(path)); + ArrayList noDupe = new ArrayList<>(); + for (ClassNode cn : nodeList) + { + ClassWriter cw = new ClassWriter(0); + cn.accept(cw); + + String name = cn.name + ".class"; + + if (!noDupe.contains(name)) + { + noDupe.add(name); + out.putNextEntry(new ZipEntry(name)); + out.write(cw.toByteArray()); + out.closeEntry(); + } } + + noDupe.clear(); + out.close(); + } + catch (IOException e) + { + new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e); } - - noDupe.clear(); - out.close(); - } catch (IOException e) { - new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e); } }