use of org.objectweb.asm.tree.MethodNode in project bytecode-viewer by Konloch.
the class ClassNodeDecompiler method decompile.
public static PrefixedStringBuilder decompile(PrefixedStringBuilder sb, List<String> decompiledClasses, ClassNode cn) {
List<String> unableToDecompile = new ArrayList<>();
decompiledClasses.add(cn.name);
sb.append(getAccessString(cn.access));
sb.append(" ");
sb.append(cn.name);
if (cn.superName != null && !cn.superName.equals("java/lang/Object")) {
sb.append(" extends ");
sb.append(cn.superName);
}
int amountOfInterfaces = cn.interfaces.size();
if (amountOfInterfaces > 0) {
sb.append(" implements ");
sb.append(cn.interfaces.get(0));
for (int i = 1; i < amountOfInterfaces; i++) {
sb.append(", ");
sb.append(cn.interfaces.get(i));
}
}
sb.append(" {");
sb.append(nl);
sb.append(" ");
sb.append("<ClassVersion=" + cn.version + ">");
sb.append(nl);
if (cn.sourceDebug != null) {
sb.append(" ");
sb.append("<SourceDebug=" + cn.sourceDebug + ">");
sb.append(nl);
}
if (cn.sourceFile != null) {
sb.append(" ");
sb.append("<SourceFile=" + cn.sourceFile + ">");
sb.append(nl);
}
if (cn.signature != null) {
sb.append(" ");
sb.append("<Sig=" + cn.signature + ">");
}
for (FieldNode fn : cn.fields) {
sb.append(nl);
sb.append(" ");
FieldNodeDecompiler.decompile(sb, fn);
}
if (cn.fields.size() > 0) {
sb.append(nl);
}
for (MethodNode mn : cn.methods) {
sb.append(nl);
MethodNodeDecompiler.decompile(sb, mn, cn);
}
for (InnerClassNode o : cn.innerClasses) {
String innerClassName = o.name;
if ((innerClassName != null) && !decompiledClasses.contains(innerClassName)) {
decompiledClasses.add(innerClassName);
ClassNode cn1 = BytecodeViewer.blindlySearchForClassNode(innerClassName);
if (cn1 != null) {
sb.appendPrefix(" ");
sb.append(nl + nl);
sb = decompile(sb, decompiledClasses, cn1);
sb.trimPrefix(5);
sb.append(nl);
} else {
unableToDecompile.add(innerClassName);
}
}
}
if (!unableToDecompile.isEmpty()) {
sb.append("// The following inner classes couldn't be decompiled: ");
for (String s : unableToDecompile) {
sb.append(s);
sb.append(" ");
}
sb.append(nl);
}
if (cn.attrs != null) {
sb.append(nl);
for (Attribute attr : cn.attrs) {
// TODO: finish attributes
// + attr.content.toString());
sb.append(attr.type + ": ");
}
}
// sb.append(BytecodeViewer.nl);
sb.append("}");
// " with prefix length: " + sb.prefix.length());
return sb;
}
use of org.objectweb.asm.tree.MethodNode in project bytecode-viewer by Konloch.
the class RenameMethods method obfuscate.
@Override
public void obfuscate() {
int stringLength = getStringLength();
System.out.println("Obfuscating method names...");
for (ClassNode c : BytecodeViewer.getLoadedClasses()) {
for (Object o : c.methods.toArray()) {
MethodNode m = (MethodNode) o;
/* As we dont want to rename native dll methods */
if ((m.access & Opcodes.ACC_NATIVE) != 0)
continue;
if (m.access != Opcodes.ACC_ABSTRACT && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_STATIC && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_STATIC + Opcodes.ACC_PUBLIC && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_STATIC + Opcodes.ACC_PRIVATE && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_STATIC + Opcodes.ACC_PROTECTED && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_PUBLIC && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_PRIVATE && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_PROTECTED) {
if (!m.name.equals("main") && !m.name.equals("<init>") && !m.name.equals("<clinit>")) {
String newName = generateUniqueName(stringLength);
BytecodeViewer.refactorer.getHooks().addMethod(new MethodMappingData(c.name, new MappingData(m.name, newName), m.desc));
/*ASMUtil_OLD.renameMethodNode(c.name, m.name, m.desc,
null, newName, null);*/
}
}
}
}
System.out.println("Obfuscated method names.");
}
use of org.objectweb.asm.tree.MethodNode in project bytecode-viewer by Konloch.
the class LDCSearch method search.
public void search(final ResourceContainer container, final String resourceWorkingName, final ClassNode node, boolean caseSensitive) {
final Iterator<MethodNode> methods = node.methods.iterator();
final String srchText = searchText.getText();
final String srchTextLowerCase = searchText.getText().toLowerCase();
if (srchText.isEmpty())
return;
while (methods.hasNext()) {
final MethodNode method = methods.next();
final InsnList insnlist = method.instructions;
for (AbstractInsnNode insnNode : insnlist) {
if (insnNode instanceof LdcInsnNode) {
final LdcInsnNode ldcObject = ((LdcInsnNode) insnNode);
final String ldcString = ldcObject.cst.toString();
// TODO re-add this at some point when the search pane is redone
boolean exact = false;
final boolean exactMatch = exact && ldcString.equals(srchText);
final boolean caseInsensitiveMatch = !exact && caseSensitive && ldcString.contains(srchText);
final boolean caseSensitiveMatch = !exact && !caseSensitive && ldcString.toLowerCase().contains(srchTextLowerCase);
final boolean anyMatch = exactMatch || caseInsensitiveMatch || caseSensitiveMatch;
if (anyMatch) {
BytecodeViewer.viewer.searchBoxPane.treeRoot.add(new LDCSearchTreeNodeResult(container, resourceWorkingName, node, method, null, ldcString, ldcObject.cst.getClass().getCanonicalName()));
}
}
}
}
final Iterator<FieldNode> fields = node.fields.iterator();
while (methods.hasNext()) {
final FieldNode field = fields.next();
if (field.value instanceof String) {
BytecodeViewer.viewer.resourcePane.treeRoot.add(new LDCSearchTreeNodeResult(container, resourceWorkingName, node, null, field, String.valueOf(field.value), field.value.getClass().getCanonicalName()));
}
}
}
use of org.objectweb.asm.tree.MethodNode in project bytecode-viewer by Konloch.
the class ShowMainMethods method execute.
@Override
public void execute(List<ClassNode> classNodeList) {
PluginConsole frame = new PluginConsole("Show Main Methods");
StringBuilder sb = new StringBuilder();
for (ClassNode classNode : classNodeList) {
for (Object o : classNode.methods.toArray()) {
MethodNode m = (MethodNode) o;
if ((m.access & (PUBLIC_STATIC)) == PUBLIC_STATIC) {
if (m.name.equals("main") && m.desc.equals("([Ljava/lang/String;)V")) {
sb.append(classNode.name);
sb.append(".");
sb.append(m.name);
sb.append(m.desc);
sb.append("\n");
}
}
}
}
if (sb.length() == 0)
frame.appendText("No main methods found.");
else
frame.appendText(sb.toString());
frame.setVisible(true);
}
use of org.objectweb.asm.tree.MethodNode in project bytecode-viewer by Konloch.
the class RenameMethods method obfuscate.
@Override
public void obfuscate() {
int stringLength = getStringLength();
System.out.println("Obfuscating method names...");
for (ClassNode c : BytecodeViewer.getLoadedClasses()) {
for (Object o : c.methods.toArray()) {
MethodNode m = (MethodNode) o;
if (m.access != Opcodes.ACC_ABSTRACT && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_STATIC && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_STATIC + Opcodes.ACC_PUBLIC && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_STATIC + Opcodes.ACC_PRIVATE && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_STATIC + Opcodes.ACC_PROTECTED && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_PUBLIC && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_PRIVATE && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_PROTECTED) {
if (!m.name.equals("main") && !m.name.equals("<init>") && !m.name.equals("<clinit>")) {
String newName = generateUniqueName(stringLength);
ASMResourceUtil.renameMethodNode(c.name, m.name, m.desc, null, newName, null);
}
}
}
}
System.out.println("Obfuscated method names.");
}
Aggregations