modified loadClassesIntoClassLoader

loadClassesIntoClassLoader is now using specified list of ClassNode
This commit is contained in:
Szperak 2015-08-31 16:32:25 +02:00
parent 198d0f2ddd
commit 91f42e91d0
2 changed files with 75 additions and 60 deletions

View file

@ -1,6 +1,7 @@
package the.bytecode.club.bytecodeviewer.api; package the.bytecode.club.bytecodeviewer.api;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import java.util.ArrayList; import java.util.ArrayList;
@ -62,49 +63,59 @@ public class BytecodeViewer {
return cl; return cl;
} }
/** /**
* Re-instances the URLClassLoader and loads a jar to it. * Re-instances the URLClassLoader and loads a jar to it.
* @param path *
* @param nodeList
* The list of ClassNodes to be loaded
* @return The loaded classes into the new URLClassLoader instance * @return The loaded classes into the new URLClassLoader instance
* @author Cafebabe * @author Cafebabe
* @throws IOException
* @throws ClassNotFoundException
*/ */
public static List<Class<?>> loadClassesIntoClassLoader() { @SuppressWarnings("deprecation")
try { public static List<Class<?>> loadClassesIntoClassLoader(
ArrayList<ClassNode> nodeList) throws IOException,
ClassNotFoundException {
File f = new File( File f = new File(
the.bytecode.club.bytecodeviewer.BytecodeViewer.tempDirectory + the.bytecode.club.bytecodeviewer.BytecodeViewer.tempDirectory
the.bytecode.club.bytecodeviewer.BytecodeViewer.fs + + the.bytecode.club.bytecodeviewer.BytecodeViewer.fs
"loaded_temp.jar"); + "loaded_temp.jar");
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), f.getAbsolutePath()); JarUtils.saveAsJarClassesOnly(nodeList, f.getAbsolutePath());
JarFile jarFile = new JarFile(""+f.getAbsolutePath());
JarFile jarFile = new JarFile("" + f.getAbsolutePath());
Enumeration<JarEntry> e = jarFile.entries(); Enumeration<JarEntry> e = jarFile.entries();
URL[] urls = { new URL("jar:file:" + ""+f.getAbsolutePath()+"!/") }; cl = URLClassLoader.newInstance(new URL[]{ f.toURL() });
cl = URLClassLoader.newInstance(urls);
List<Class<?>> ret = new ArrayList<Class<?>>(); List<Class<?>> ret = new ArrayList<Class<?>>();
while (e.hasMoreElements()) while (e.hasMoreElements()) {
{
JarEntry je = (JarEntry) e.nextElement(); JarEntry je = (JarEntry) e.nextElement();
if(je.isDirectory() || !je.getName().endsWith(".class")) if (je.isDirectory() || !je.getName().endsWith(".class"))
continue; continue;
String className = je.getName().replace("/", ".").replace(".class", ""); String className = je.getName().replace("/", ".").replace(".class", "");
className = className.replace('/', '.'); className = className.replace('/', '.');
try{
ret.add(cl.loadClass(className)); ret.add(cl.loadClass(className));
}
catch(Exception e2)
{
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e2);
}
} }
jarFile.close(); jarFile.close();
return ret; return ret;
} }
catch(Exception e)
{
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e); /**
} * Re-instances the URLClassLoader and loads a jar to it.
return null; * @return The loaded classes into the new URLClassLoader instance
* @author Cafebabe
* @throws IOException
* @throws ClassNotFoundException
*/
public static List<Class<?>> loadAllClassesIntoClassLoader() throws ClassNotFoundException, IOException {
return loadClassesIntoClassLoader(getLoadedClasses());
} }
/** /**

View file

@ -3,6 +3,7 @@ package the.bytecode.club.bytecodeviewer.plugin.preinstalled;
import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.ClassNode;
import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.api.ExceptionUI;
import the.bytecode.club.bytecodeviewer.api.Plugin; import the.bytecode.club.bytecodeviewer.api.Plugin;
import the.bytecode.club.bytecodeviewer.api.PluginConsole; import the.bytecode.club.bytecodeviewer.api.PluginConsole;
@ -63,7 +64,8 @@ public class ZStringArrayDecrypter extends Plugin {
if (result == 0) { if (result == 0) {
boolean needsWarning = false; boolean needsWarning = false;
for (Class<?> debug : the.bytecode.club.bytecodeviewer.api.BytecodeViewer.loadClassesIntoClassLoader()) { try {
for (Class<?> debug : the.bytecode.club.bytecodeviewer.api.BytecodeViewer.loadAllClassesIntoClassLoader()) {
try { try {
Field[] fields = debug.getDeclaredFields(); Field[] fields = debug.getDeclaredFields();
for ( Field field : fields ) { for ( Field field : fields ) {
@ -84,7 +86,9 @@ public class ZStringArrayDecrypter extends Plugin {
needsWarning = true; needsWarning = true;
} }
} }
} catch (Exception e){
new ExceptionUI(e);
}
if(needsWarning) { if(needsWarning) {
BytecodeViewer.showMessage("Some classes failed to decrypt, if you'd like to decrypt all of them"+BytecodeViewer.nl+"makes sure you include ALL the libraries it requires."); BytecodeViewer.showMessage("Some classes failed to decrypt, if you'd like to decrypt all of them"+BytecodeViewer.nl+"makes sure you include ALL the libraries it requires.");
} }