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,50 +63,60 @@ 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(
File f = new File( ArrayList<ClassNode> nodeList) throws IOException,
the.bytecode.club.bytecodeviewer.BytecodeViewer.tempDirectory + ClassNotFoundException {
the.bytecode.club.bytecodeviewer.BytecodeViewer.fs +
"loaded_temp.jar");
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), f.getAbsolutePath());
JarFile jarFile = new JarFile(""+f.getAbsolutePath());
Enumeration<JarEntry> e = jarFile.entries();
URL[] urls = { new URL("jar:file:" + ""+f.getAbsolutePath()+"!/") };
cl = URLClassLoader.newInstance(urls);
List<Class<?>> ret = new ArrayList<Class<?>>();
while (e.hasMoreElements()) File f = new File(
{ the.bytecode.club.bytecodeviewer.BytecodeViewer.tempDirectory
JarEntry je = (JarEntry) e.nextElement(); + the.bytecode.club.bytecodeviewer.BytecodeViewer.fs
if(je.isDirectory() || !je.getName().endsWith(".class")) + "loaded_temp.jar");
continue; JarUtils.saveAsJarClassesOnly(nodeList, f.getAbsolutePath());
String className = je.getName().replace("/", ".").replace(".class", "");
className = className.replace('/', '.');
try{
ret.add(cl.loadClass(className));
}
catch(Exception e2)
{
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e2);
}
}
jarFile.close();
return ret; JarFile jarFile = new JarFile("" + f.getAbsolutePath());
} Enumeration<JarEntry> e = jarFile.entries();
catch(Exception e) cl = URLClassLoader.newInstance(new URL[]{ f.toURL() });
{ List<Class<?>> ret = new ArrayList<Class<?>>();
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
} while (e.hasMoreElements()) {
return null; JarEntry je = (JarEntry) e.nextElement();
} if (je.isDirectory() || !je.getName().endsWith(".class"))
continue;
String className = je.getName().replace("/", ".").replace(".class", "");
className = className.replace('/', '.');
ret.add(cl.loadClass(className));
}
jarFile.close();
return ret;
}
/**
* Re-instances the URLClassLoader and loads a jar to it.
* @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());
}
/** /**
* Creates a new instance of the ClassNode loader. * Creates a new instance of the ClassNode loader.

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,28 +64,31 @@ 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 {
try { for (Class<?> debug : the.bytecode.club.bytecodeviewer.api.BytecodeViewer.loadAllClassesIntoClassLoader()) {
Field[] fields = debug.getDeclaredFields(); try {
for ( Field field : fields ) { Field[] fields = debug.getDeclaredFields();
if ( field.getName().equals("z") ) { for ( Field field : fields ) {
out.append(debug.getName() + ":" + BytecodeViewer.nl); if ( field.getName().equals("z") ) {
field.setAccessible(true); out.append(debug.getName() + ":" + BytecodeViewer.nl);
if(field.get(null) != null && field.get(null) instanceof String[] && Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers())) { field.setAccessible(true);
String[] fieldVal = (String[]) field.get(null); if(field.get(null) != null && field.get(null) instanceof String[] && Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers())) {
for ( int i = 0; i < fieldVal.length; i++ ) { String[] fieldVal = (String[]) field.get(null);
out.append(" z[" + i + "] = " + fieldVal[i] + BytecodeViewer.nl); for ( int i = 0; i < fieldVal.length; i++ ) {
out.append(" z[" + i + "] = " + fieldVal[i] + BytecodeViewer.nl);
}
} }
} }
} }
} } catch(NoClassDefFoundError | Exception e) {
} catch(NoClassDefFoundError | Exception e) { System.err.println("Failed loading class " + debug.getName());
System.err.println("Failed loading class " + debug.getName()); e.printStackTrace();
e.printStackTrace(); 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.");
} }