use of org.objectweb.asm.tree.LdcInsnNode in project bytecode-viewer by Konloch.
the class InstructionPattern method main.
public static void main(String[] args) {
AbstractInsnNode[] ains = new AbstractInsnNode[] { new LdcInsnNode("ldc"), new VarInsnNode(ASTORE, 0), new LdcInsnNode("ldc") };
InstructionPattern pattern = new InstructionPattern(new AbstractInsnNode[] { new LdcInsnNode("ldc"), new VarInsnNode(-1, -1) });
for (AbstractInsnNode ain : ains) {
if (pattern.accept(ain)) {
System.out.println(Arrays.toString(pattern.getLastMatch()));
}
}
}
use of org.objectweb.asm.tree.LdcInsnNode in project bytecode-viewer by Konloch.
the class ReplaceStrings method scanClassNode.
public void scanClassNode(ClassNode classNode) {
for (Object o : classNode.fields.toArray()) {
FieldNode f = (FieldNode) o;
Object v = f.value;
if (v instanceof String) {
String s = (String) v;
if (contains) {
if (s.contains(originalLDC))
f.value = ((String) f.value).replaceAll(originalLDC, newLDC);
} else {
if (s.equals(originalLDC))
f.value = newLDC;
}
}
if (v instanceof String[]) {
for (int i = 0; i < ((String[]) v).length; i++) {
String s = ((String[]) v)[i];
if (contains) {
if (s.contains(originalLDC)) {
f.value = ((String[]) f.value)[i].replaceAll(originalLDC, newLDC);
String ugh = s.replaceAll("\\n", "\\\\n").replaceAll("\\r", "\\\\r");
frame.appendText(classNode.name + "." + f.name + "" + f.desc + " -> \"" + ugh + "\" replaced with \"" + s.replaceAll(originalLDC, newLDC) + "\"");
}
} else {
if (s.equals(originalLDC)) {
((String[]) f.value)[i] = newLDC;
String ugh = s.replaceAll("\\n", "\\\\n").replaceAll("\\r", "\\\\r");
frame.appendText(classNode.name + "." + f.name + "" + f.desc + " -> \"" + ugh + "\" replaced with \"" + newLDC + "\"");
}
}
}
}
}
for (Object o : classNode.methods.toArray()) {
MethodNode m = (MethodNode) o;
InsnList iList = m.instructions;
for (AbstractInsnNode a : iList.toArray()) {
if (a instanceof LdcInsnNode) {
if (((LdcInsnNode) a).cst instanceof String) {
final String s = (String) ((LdcInsnNode) a).cst;
if (contains) {
if (s.contains(originalLDC)) {
((LdcInsnNode) a).cst = ((String) ((LdcInsnNode) a).cst).replaceAll(originalLDC, newLDC);
String ugh = s.replaceAll("\\n", "\\\\n").replaceAll("\\r", "\\\\r");
frame.appendText(classNode.name + "." + m.name + "" + m.desc + " -> \"" + ugh + "\" replaced with \"" + s.replaceAll(originalLDC, newLDC).replaceAll("\\n", "\\\\n").replaceAll("\\r", "\\\\r") + "\"");
}
} else {
if (s.equals(originalLDC)) {
((LdcInsnNode) a).cst = newLDC;
String ugh = s.replaceAll("\\n", "\\\\n").replaceAll("\\r", "\\\\r");
frame.appendText(classNode.name + "." + m.name + "" + m.desc + " -> \"" + ugh + "\" replaced with \"" + newLDC.replaceAll("\\n", "\\\\n").replaceAll("\\r", "\\\\r") + "\"");
}
}
}
}
}
}
}
use of org.objectweb.asm.tree.LdcInsnNode in project bytecode-viewer by Konloch.
the class AllatoriStringDecrypter method scanMethodNode.
public void scanMethodNode(ClassNode classNode, MethodNode methodNode) throws Exception {
InsnList iList = methodNode.instructions;
log("Scanning method " + methodNode.name + " of " + classNode.name);
LdcInsnNode laststringldconstack = null;
for (AbstractInsnNode i : iList.toArray()) {
if (i instanceof LdcInsnNode) {
LdcInsnNode ldcI = (LdcInsnNode) i;
if (ldcI.cst instanceof String)
laststringldconstack = ldcI;
continue;
} else if (i instanceof MethodInsnNode) {
MethodInsnNode methodI = (MethodInsnNode) i;
// Decryption is always a static call - 0xb8 - invokestatic
if (laststringldconstack != null && methodI.getOpcode() == 0xb8) {
String decrypterClassName = methodI.owner;
String decrypterMethodName = methodI.name;
// Decrypter is always a static method of other class's inner class
if (decrypterClassName.contains("$")) {
byte[] decrypterFileContents = activeContainer.getFileContents(decrypterClassName + ".class");
// We have to create new node for editing
// Also, one decrypter method could be used for multiple methods in code, what gives us only part of string decrypted
ClassNode decrypterClassNode = ASMUtil.bytesToNode(decrypterFileContents);
MethodNode decryptermethodnode = ASMUtil.getMethodByName(decrypterClassNode, decrypterMethodName);
if (decryptermethodnode != null) {
String keyString = (getConstantPoolSize(classNode.name) + classNode.name + methodNode.name + getConstantPoolSize(classNode.name));
int newHashCode = keyString.hashCode();
scanDecrypter(decryptermethodnode, newHashCode);
try {
System.out.println("Loading " + decrypterClassName);
Class<?> decrypterClassList = BCV.loadClassIntoClassLoader(decrypterClassNode);
String decrypted = invokeDecrypter(decrypterClassList, decrypterMethodName, (String) laststringldconstack.cst);
if (decrypted != null) {
log("Succesfully invoked decrypter method: " + decrypted);
laststringldconstack.cst = decrypted;
iList.remove(methodI);
}
} catch (IndexOutOfBoundsException | ClassNotFoundException | IOException e) {
e.printStackTrace();
log("Could not load decrypter class: " + decrypterClassName);
}
} else {
log("Could not find decrypter method (" + decrypterMethodName + ") of class " + decrypterClassName);
}
}
}
} else if (i instanceof InvokeDynamicInsnNode) {
InvokeDynamicInsnNode methodi = (InvokeDynamicInsnNode) i;
if (methodi.getOpcode() == 0xba) {
// TODO: Safe-reflection deobfuscator here
// Allatori replaces invokeinterface and invokestatic with invokedynamic
// log(methodi.bsm.getOwner()+" dot "+methodi.bsm.getName());
// iList.set(methodi, new MethodInsnNode(0xb8, methodi.bsm.getOwner(), methodi.bsm.getName(), methodi.bsm.getDesc(), false));
}
}
laststringldconstack = null;
}
}
use of org.objectweb.asm.tree.LdcInsnNode in project bytecode-viewer by Konloch.
the class AllatoriStringDecrypter method scanDecrypter.
private boolean scanDecrypter(MethodNode decryptermethodnode, int newHashCode) {
InsnList iList = decryptermethodnode.instructions;
AbstractInsnNode insn = null, removeInsn;
for (AbstractInsnNode i : iList.toArray()) {
if (i instanceof MethodInsnNode) {
MethodInsnNode methodi = ((MethodInsnNode) i);
if (// find code form this instruction
"currentThread".equals(methodi.name)) {
insn = i;
break;
}
}
}
if (insn == null)
return false;
while (insn != null) {
if (insn instanceof MethodInsnNode) {
MethodInsnNode methodi = ((MethodInsnNode) insn);
if (// to this instruction
"hashCode".equals(methodi.name))
break;
}
removeInsn = insn;
insn = insn.getNext();
// and remove it
iList.remove(removeInsn);
}
if (insn == null)
return false;
// then replace it with pre-computed key LDC
iList.set(insn, new LdcInsnNode(newHashCode));
return true;
}
use of org.objectweb.asm.tree.LdcInsnNode in project bytecode-viewer by Konloch.
the class ShowAllStrings method execute.
@Override
public void execute(List<ClassNode> classNodeList) {
PluginConsole frame = new PluginConsole("Show All Strings");
StringBuilder sb = new StringBuilder();
for (ClassNode classNode : classNodeList) {
for (Object o : classNode.fields.toArray()) {
FieldNode f = (FieldNode) o;
Object v = f.value;
if (v instanceof String) {
String s = (String) v;
if (!s.isEmpty())
sb.append(classNode.name).append(".").append(f.name).append(f.desc).append(" -> \"").append(s.replaceAll("\\n", "\\\\n").replaceAll("\\r", "\\\\r")).append("\"").append(nl);
}
if (v instanceof String[]) {
for (int i = 0; i < ((String[]) v).length; i++) {
String s = ((String[]) v)[i];
if (!s.isEmpty())
sb.append(classNode.name).append(".").append(f.name).append(f.desc).append("[").append(i).append("] -> \"").append(s.replaceAll("\\n", "\\\\n").replaceAll("\\r", "\\\\r")).append("\"").append(nl);
}
}
}
for (Object o : classNode.methods.toArray()) {
MethodNode m = (MethodNode) o;
InsnList iList = m.instructions;
for (AbstractInsnNode a : iList.toArray()) {
if (a instanceof LdcInsnNode) {
if (((LdcInsnNode) a).cst instanceof String) {
final String s = (String) ((LdcInsnNode) a).cst;
if (!s.isEmpty())
sb.append(classNode.name).append(".").append(m.name).append(m.desc).append(" -> \"").append(s.replaceAll("\\n", "\\\\n").replaceAll("\\r", "\\\\r")).append("\"").append(nl);
}
}
}
}
}
frame.setText(sb.toString());
frame.setVisible(true);
}
Aggregations