Skip to content

Commit

Permalink
Mostly solved memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
ThisTestUser committed Jun 10, 2018
1 parent 8060c46 commit bf89d42
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,7 @@ public void run()
textPane.setText(stringWriter.toString());
newFrame.setVisible(true);
}
deob.clearClasses();
}
});
thread.start();
Expand All @@ -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();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand All @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit bf89d42

Please sign in to comment.