From bf89d42128ad552ac364317bcfb095e1b4f181fc Mon Sep 17 00:00:00 2001 From: ThisTestUser Date: Sat, 9 Jun 2018 22:27:13 -0400 Subject: [PATCH] Mostly solved memory leak --- .../deobfuscator/ui/SwingWindow.java | 4 ++ .../deobfuscator/ui/wrap/Deobfuscator.java | 50 +++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/src/java/com/javadeobfuscator/deobfuscator/ui/SwingWindow.java b/src/java/com/javadeobfuscator/deobfuscator/ui/SwingWindow.java index 5e1c8ee..875a314 100644 --- a/src/java/com/javadeobfuscator/deobfuscator/ui/SwingWindow.java +++ b/src/java/com/javadeobfuscator/deobfuscator/ui/SwingWindow.java @@ -871,6 +871,7 @@ public void run() textPane.setText(stringWriter.toString()); newFrame.setVisible(true); } + deob.clearClasses(); } }); thread.start(); @@ -883,7 +884,10 @@ public void windowClosing(WindowEvent e) area.setText(null); run.setEnabled(true); if(thread.isAlive()) + { thread.stop(); + deob.clearClasses(); + } e.getWindow().dispose(); } }); diff --git a/src/java/com/javadeobfuscator/deobfuscator/ui/wrap/Deobfuscator.java b/src/java/com/javadeobfuscator/deobfuscator/ui/wrap/Deobfuscator.java index 61deb7c..21bcb97 100644 --- a/src/java/com/javadeobfuscator/deobfuscator/ui/wrap/Deobfuscator.java +++ b/src/java/com/javadeobfuscator/deobfuscator/ui/wrap/Deobfuscator.java @@ -2,7 +2,10 @@ import java.io.*; import java.lang.reflect.Constructor; +import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.util.Map; +import java.util.Set; import com.javadeobfuscator.deobfuscator.ui.util.*; @@ -15,6 +18,10 @@ public class Deobfuscator { * Config wrapper to use in deobfuscator. */ private Config config; + /** + * The deobfuscator instance. + */ + private Object instance; Deobfuscator(ByteLoader loader) { this.loader = loader; @@ -62,10 +69,53 @@ public void run() throws Exception { Config conf = getConfig(); Constructor con = main.getDeclaredConstructor(conf.get().getClass()); Object deob = con.newInstance(conf.get()); + instance = deob; Method start = main.getMethod("start"); start.invoke(deob); } + /** + * Clears the classes in the main deobfuscator class. + * + * @throws Exception + * Thrown for any failure in the deobfuscator. + */ + public void clearClasses() + { + try + { + if(instance != null) + { + Class main = loader.findClass("com.javadeobfuscator.deobfuscator.Deobfuscator"); + Field cp = main.getDeclaredField("classpath"); + cp.setAccessible(true); + ((Map)cp.get(instance)).clear(); + Field c = main.getDeclaredField("classes"); + c.setAccessible(true); + ((Map)c.get(instance)).clear(); + Field h = main.getDeclaredField("hierachy"); + h.setAccessible(true); + ((Map)h.get(instance)).clear(); + Field ip = main.getDeclaredField("inputPassthrough"); + ip.setAccessible(true); + ((Map)ip.get(instance)).clear(); + Field cps = main.getDeclaredField("constantPools"); + cps.setAccessible(true); + ((Map)cps.get(instance)).clear(); + Field r = main.getDeclaredField("readers"); + r.setAccessible(true); + ((Map)r.get(instance)).clear(); + Field lc = main.getDeclaredField("libraryClassnodes"); + lc.setAccessible(true); + ((Set)lc.get(instance)).clear(); + instance = null; + } + }catch(Exception e) + { + e.printStackTrace(); + } + } + /** * Intercept logging calls. *