149 lines
5.7 KiB
Java
149 lines
5.7 KiB
Java
package com.doomsdayclient.agent;
|
|
|
|
import com.doomsdayclient.jvm.HotSpotVmStructs;
|
|
import com.doomsdayclient.jvm.classfile.AnnotationAttributeWriter;
|
|
import com.doomsdayclient.logging.ClientLog;
|
|
import com.doomsdayclient.text.ProtectedString;
|
|
import com.doomsdayclient.text.ProtectedStringBuilder;
|
|
import com.doomsdayclient.text.StringTable;
|
|
import com.doomsdayclient.util.collections.CollectionPredicate;
|
|
import com.doomsdayclient.util.collections.FastHashMap;
|
|
import com.doomsdayclient.util.collections.FastHashSet;
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.File;
|
|
import java.io.FileOutputStream;
|
|
import java.util.Iterator;
|
|
import java.util.zip.ZipEntry;
|
|
import java.util.zip.ZipOutputStream;
|
|
|
|
public class JarClassDumper extends AbstractClassDumper {
|
|
public HotSpotVmStructs hotSpotVmStructs;
|
|
|
|
@Override
|
|
public void setObject(Object hotSpotVmStructs2) {
|
|
this.hotSpotVmStructs = (HotSpotVmStructs) hotSpotVmStructs2;
|
|
}
|
|
|
|
@Override
|
|
public void setProtectedString(ProtectedString protectedString) {
|
|
File file;
|
|
(file = new File(protectedString.readString())).mkdirs();
|
|
Object[] arguments = (Object[]) this.hotSpotVmStructs.getObject();
|
|
FastHashMap fastHashMap = new FastHashMap();
|
|
FastHashMap fastHashMap2 = new FastHashMap();
|
|
FastHashMap fastHashMap3 = new FastHashMap();
|
|
FastHashSet fastHashSet = new FastHashSet();
|
|
ClientLog.setProtectedCharSeque(
|
|
new ProtectedStringBuilder(StringTable.STR_DUMP_CLASSES).appendInt(arguments.length));
|
|
FastHashSet fastHashSet2 = new FastHashSet();
|
|
|
|
for (int argumentIndex = 0; argumentIndex < arguments.length; argumentIndex++) {
|
|
Class type;
|
|
if (!(type = (Class) arguments[argumentIndex]).isArray()) {
|
|
AnnotationAttributeWriter annotationAttributeWriter =
|
|
new AnnotationAttributeWriter(type, this.hotSpotVmStructs);
|
|
ClientLog.applyProtectedStringBui(
|
|
new ProtectedStringBuilder(StringTable.STR_DUMP).appendString(type.getName()));
|
|
byte[] bytes = annotationAttributeWriter.readByteArray();
|
|
ClassLoader classLoader =
|
|
(ClassLoader) annotationAttributeWriter.readJarEntryClassSourc().readObject();
|
|
String loaderName = (String) fastHashMap3.getObject(classLoader);
|
|
String text;
|
|
if (classLoader != null) {
|
|
if ((text = (String) fastHashMap3.getObject(classLoader)) == null) {
|
|
loaderName = classLoader.getClass().getName();
|
|
String text2 = loaderName.substring(loaderName.lastIndexOf(46) + 1);
|
|
text2 = text2 + '@';
|
|
String text3;
|
|
text = text3 = text2 + classLoader.hashCode();
|
|
|
|
while (fastHashSet.matchesObject(text)) {
|
|
text = text3 = text3 + "_0";
|
|
}
|
|
|
|
fastHashMap3.createObject(classLoader, text);
|
|
fastHashSet.supportsObject(text);
|
|
}
|
|
} else {
|
|
text = "bootstrap";
|
|
}
|
|
|
|
try {
|
|
ZipOutputStream zipOutputStream;
|
|
if ((zipOutputStream = (ZipOutputStream) fastHashMap.getObject(text)) == null) {
|
|
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
zipOutputStream = new ZipOutputStream(output);
|
|
fastHashMap.createObject(text, zipOutputStream);
|
|
fastHashMap2.createObject(text, output);
|
|
}
|
|
|
|
String text4;
|
|
String text5 =
|
|
text4 = text + '/' + annotationAttributeWriter.readClassDumpWriter().toString();
|
|
|
|
for (int index = 0; fastHashSet2.matchesObject(text5 + ".class"); index++) {
|
|
text5 = text4 + '_' + index;
|
|
}
|
|
|
|
String text6 = text5 + ".class";
|
|
ClientLog.setProtectedCharSeque(
|
|
new ProtectedStringBuilder(StringTable.STR_SYMBOL_5B1).appendString(text6));
|
|
fastHashSet2.supportsObject(text6);
|
|
ZipEntry zipEntry = new ZipEntry(text6);
|
|
zipOutputStream.putNextEntry(zipEntry);
|
|
zipOutputStream.write(bytes);
|
|
zipOutputStream.closeEntry();
|
|
} catch (Exception exception) {
|
|
exception.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
|
|
try {
|
|
Iterator iterator = fastHashMap.iterator();
|
|
|
|
while (iterator.hasNext()) {
|
|
((ZipOutputStream) ((CollectionPredicate) iterator.next()).object2).close();
|
|
}
|
|
|
|
for (CollectionPredicate collectionPredicate : fastHashMap2) {
|
|
try {
|
|
File file2;
|
|
(file2 =
|
|
new File(
|
|
file,
|
|
((String) collectionPredicate.object).replace('/', '_').replace('\\', '_')
|
|
+ ".jar"))
|
|
.getParentFile()
|
|
.mkdirs();
|
|
FileOutputStream fileOutputStream = new FileOutputStream(file2);
|
|
((ByteArrayOutputStream) collectionPredicate.object2).writeTo(fileOutputStream);
|
|
fileOutputStream.close();
|
|
} catch (Throwable exception2) {
|
|
ClientLog.applyThrowable(exception2);
|
|
}
|
|
}
|
|
} catch (Throwable exception3) {
|
|
ClientLog.applyThrowable(exception3);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void applyProtectedString(ProtectedString text) {
|
|
Object[] arguments = (Object[]) this.hotSpotVmStructs.getObject();
|
|
ClientLog.setProtectedCharSeque(
|
|
new ProtectedStringBuilder(StringTable.STR_DUMP_CLASSES).appendInt(arguments.length));
|
|
|
|
for (int argumentIndex = 0; argumentIndex < arguments.length; argumentIndex++) {
|
|
Class type;
|
|
if (!(type = (Class) arguments[argumentIndex]).isArray()
|
|
&& !type.getName().startsWith("java")) {
|
|
ClientLog.applyProtectedStringBui(
|
|
new ProtectedStringBuilder(StringTable.STR_DUMP)
|
|
.appendString(type.getName())
|
|
.appendChar('\n'));
|
|
}
|
|
}
|
|
}
|
|
}
|