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;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
@ -62,50 +63,60 @@ public class BytecodeViewer {
return cl;
}
/**
* 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
* @author Cafebabe
* @throws IOException
* @throws ClassNotFoundException
*/
public static List<Class<?>> loadClassesIntoClassLoader() {
try {
File f = new File(
the.bytecode.club.bytecodeviewer.BytecodeViewer.tempDirectory +
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())
{
JarEntry je = (JarEntry) e.nextElement();
if(je.isDirectory() || !je.getName().endsWith(".class"))
continue;
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;
}
catch(Exception e)
{
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
}
return null;
}
@SuppressWarnings("deprecation")
public static List<Class<?>> loadClassesIntoClassLoader(
ArrayList<ClassNode> nodeList) throws IOException,
ClassNotFoundException {
File f = new File(
the.bytecode.club.bytecodeviewer.BytecodeViewer.tempDirectory
+ the.bytecode.club.bytecodeviewer.BytecodeViewer.fs
+ "loaded_temp.jar");
JarUtils.saveAsJarClassesOnly(nodeList, f.getAbsolutePath());
JarFile jarFile = new JarFile("" + f.getAbsolutePath());
Enumeration<JarEntry> e = jarFile.entries();
cl = URLClassLoader.newInstance(new URL[]{ f.toURL() });
List<Class<?>> ret = new ArrayList<Class<?>>();
while (e.hasMoreElements()) {
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.

View file

@ -3,6 +3,7 @@ package the.bytecode.club.bytecodeviewer.plugin.preinstalled;
import org.objectweb.asm.tree.ClassNode;
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.PluginConsole;
@ -63,28 +64,31 @@ public class ZStringArrayDecrypter extends Plugin {
if (result == 0) {
boolean needsWarning = false;
for (Class<?> debug : the.bytecode.club.bytecodeviewer.api.BytecodeViewer.loadClassesIntoClassLoader()) {
try {
Field[] fields = debug.getDeclaredFields();
for ( Field field : fields ) {
if ( field.getName().equals("z") ) {
out.append(debug.getName() + ":" + BytecodeViewer.nl);
field.setAccessible(true);
if(field.get(null) != null && field.get(null) instanceof String[] && Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers())) {
String[] fieldVal = (String[]) field.get(null);
for ( int i = 0; i < fieldVal.length; i++ ) {
out.append(" z[" + i + "] = " + fieldVal[i] + BytecodeViewer.nl);
try {
for (Class<?> debug : the.bytecode.club.bytecodeviewer.api.BytecodeViewer.loadAllClassesIntoClassLoader()) {
try {
Field[] fields = debug.getDeclaredFields();
for ( Field field : fields ) {
if ( field.getName().equals("z") ) {
out.append(debug.getName() + ":" + BytecodeViewer.nl);
field.setAccessible(true);
if(field.get(null) != null && field.get(null) instanceof String[] && Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers())) {
String[] fieldVal = (String[]) field.get(null);
for ( int i = 0; i < fieldVal.length; i++ ) {
out.append(" z[" + i + "] = " + fieldVal[i] + BytecodeViewer.nl);
}
}
}
}
}
} catch(NoClassDefFoundError | Exception e) {
System.err.println("Failed loading class " + debug.getName());
e.printStackTrace();
needsWarning = true;
}
}
}
}
} catch(NoClassDefFoundError | Exception e) {
System.err.println("Failed loading class " + debug.getName());
e.printStackTrace();
needsWarning = true;
}
}
} catch (Exception e){
new ExceptionUI(e);
}
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.");
}