use of org.objectweb.asm.tree.FieldInsnNode in project maple-ir by LLVM-but-worse.
the class BasicVerifier method binaryOperation.
@Override
public BasicValue binaryOperation(final AbstractInsnNode insn, final BasicValue value1, final BasicValue value2) throws AnalyzerException {
BasicValue expected1;
BasicValue expected2;
switch(insn.opcode()) {
case IALOAD:
expected1 = newValue(Type.getType("[I"));
expected2 = BasicValue.INT_VALUE;
break;
case BALOAD:
if (isSubTypeOf(value1, newValue(Type.getType("[Z")))) {
expected1 = newValue(Type.getType("[Z"));
} else {
expected1 = newValue(Type.getType("[B"));
}
expected2 = BasicValue.INT_VALUE;
break;
case CALOAD:
expected1 = newValue(Type.getType("[C"));
expected2 = BasicValue.INT_VALUE;
break;
case SALOAD:
expected1 = newValue(Type.getType("[S"));
expected2 = BasicValue.INT_VALUE;
break;
case LALOAD:
expected1 = newValue(Type.getType("[J"));
expected2 = BasicValue.INT_VALUE;
break;
case FALOAD:
expected1 = newValue(Type.getType("[F"));
expected2 = BasicValue.INT_VALUE;
break;
case DALOAD:
expected1 = newValue(Type.getType("[D"));
expected2 = BasicValue.INT_VALUE;
break;
case AALOAD:
expected1 = newValue(Type.getType("[Ljava/lang/Object;"));
expected2 = BasicValue.INT_VALUE;
break;
case IADD:
case ISUB:
case IMUL:
case IDIV:
case IREM:
case ISHL:
case ISHR:
case IUSHR:
case IAND:
case IOR:
case IXOR:
case IF_ICMPEQ:
case IF_ICMPNE:
case IF_ICMPLT:
case IF_ICMPGE:
case IF_ICMPGT:
case IF_ICMPLE:
expected1 = BasicValue.INT_VALUE;
expected2 = BasicValue.INT_VALUE;
break;
case FADD:
case FSUB:
case FMUL:
case FDIV:
case FREM:
case FCMPL:
case FCMPG:
expected1 = BasicValue.FLOAT_VALUE;
expected2 = BasicValue.FLOAT_VALUE;
break;
case LADD:
case LSUB:
case LMUL:
case LDIV:
case LREM:
case LAND:
case LOR:
case LXOR:
case LCMP:
expected1 = BasicValue.LONG_VALUE;
expected2 = BasicValue.LONG_VALUE;
break;
case LSHL:
case LSHR:
case LUSHR:
expected1 = BasicValue.LONG_VALUE;
expected2 = BasicValue.INT_VALUE;
break;
case DADD:
case DSUB:
case DMUL:
case DDIV:
case DREM:
case DCMPL:
case DCMPG:
expected1 = BasicValue.DOUBLE_VALUE;
expected2 = BasicValue.DOUBLE_VALUE;
break;
case IF_ACMPEQ:
case IF_ACMPNE:
expected1 = BasicValue.REFERENCE_VALUE;
expected2 = BasicValue.REFERENCE_VALUE;
break;
case PUTFIELD:
FieldInsnNode fin = (FieldInsnNode) insn;
expected1 = newValue(Type.getObjectType(fin.owner));
expected2 = newValue(Type.getType(fin.desc));
break;
default:
throw new Error("Internal error.");
}
if (!isSubTypeOf(value1, expected1)) {
throw new AnalyzerException(insn, "First argument", expected1, value1);
} else if (!isSubTypeOf(value2, expected2)) {
throw new AnalyzerException(insn, "Second argument", expected2, value2);
}
if (insn.opcode() == AALOAD) {
return getElementValue(value1);
} else {
return super.binaryOperation(insn, value1, value2);
}
}
use of org.objectweb.asm.tree.FieldInsnNode in project bytecode-viewer by Konloch.
the class ASMResourceUtil method renameClassNode.
public static void renameClassNode(final String oldName, final String newName) {
for (ClassNode c : BytecodeViewer.getLoadedClasses()) {
for (InnerClassNode oo : c.innerClasses) {
if (oo.innerName != null && oo.innerName.equals(oldName))
oo.innerName = newName;
if (oo.name.equals(oldName))
oo.name = newName;
if (oo.outerName != null && oo.outerName.equals(oldName))
oo.outerName = newName;
}
if (c.signature != null)
c.signature = c.signature.replace(oldName, newName);
if (c.superName.equals(oldName))
c.superName = newName;
for (Object o : c.fields.toArray()) {
FieldNode f = (FieldNode) o;
f.desc = f.desc.replace(oldName, newName);
}
for (Object o : c.methods.toArray()) {
MethodNode m = (MethodNode) o;
if (m.localVariables != null)
for (LocalVariableNode node : m.localVariables) node.desc = node.desc.replace(oldName, newName);
if (m.signature != null)
m.signature = m.signature.replace(oldName, newName);
for (int i = 0; i < m.exceptions.size(); i++) if (m.exceptions.get(i).equals(oldName))
m.exceptions.set(i, newName);
for (AbstractInsnNode i : m.instructions.toArray()) {
if (i instanceof TypeInsnNode) {
TypeInsnNode t = (TypeInsnNode) i;
if (t.desc.equals(oldName))
t.desc = newName;
}
if (i instanceof MethodInsnNode) {
MethodInsnNode mi = (MethodInsnNode) i;
if (mi.owner.equals(oldName))
mi.owner = newName;
mi.desc = mi.desc.replace(oldName, newName);
}
if (i instanceof FieldInsnNode) {
FieldInsnNode fi = (FieldInsnNode) i;
if (fi.owner.equals(oldName))
fi.owner = newName;
fi.desc = fi.desc.replace(oldName, newName);
}
}
}
}
}
use of org.objectweb.asm.tree.FieldInsnNode in project bytecode-viewer by Konloch.
the class FieldCallSearch method search.
@Override
public void search(ResourceContainer container, String resourceWorkingName, ClassNode node, boolean exact) {
final Iterator<MethodNode> methods = node.methods.iterator();
String searchOwner = mOwner.getText();
if (searchOwner.isEmpty())
searchOwner = null;
String searchName = mName.getText();
if (searchName.isEmpty())
searchName = null;
String searchDesc = mDesc.getText();
if (searchDesc.isEmpty())
searchDesc = null;
while (methods.hasNext()) {
final MethodNode method = methods.next();
final InsnList insnlist = method.instructions;
for (AbstractInsnNode insnNode : insnlist) {
if (insnNode instanceof FieldInsnNode) {
final FieldInsnNode min = (FieldInsnNode) insnNode;
if (searchName == null && searchOwner == null && searchDesc == null)
continue;
if (exact) {
if (searchName != null && !searchName.equals(min.name))
continue;
if (searchOwner != null && !searchOwner.equals(min.owner))
continue;
if (searchDesc != null && !searchDesc.equals(min.desc))
continue;
} else {
if (searchName != null && !min.name.contains(searchName))
continue;
if (searchOwner != null && !min.owner.contains(searchOwner))
continue;
if (searchDesc != null && !min.desc.contains(searchDesc))
continue;
}
found(container, resourceWorkingName, node, method, insnNode);
}
}
}
}
use of org.objectweb.asm.tree.FieldInsnNode in project robolectric by robolectric.
the class ClassInstrumentor method extractCallToSuperConstructor.
private static InsnList extractCallToSuperConstructor(MutableClass mutableClass, MethodNode ctor) {
InsnList removedInstructions = new InsnList();
int startIndex = 0;
AbstractInsnNode[] insns = ctor.instructions.toArray();
for (int i = 0; i < insns.length; i++) {
AbstractInsnNode node = insns[i];
switch(node.getOpcode()) {
case Opcodes.ALOAD:
VarInsnNode vnode = (VarInsnNode) node;
if (vnode.var == 0) {
startIndex = i;
}
break;
case Opcodes.PUTFIELD:
FieldInsnNode pnode = (FieldInsnNode) node;
if (pnode.owner.equals(mutableClass.internalClassName) && pnode.name.equals("this$0")) {
// remove all instructions in the range startIndex..i, from aload_0 to putfield this$0
while (startIndex <= i) {
ctor.instructions.remove(insns[startIndex]);
removedInstructions.add(insns[startIndex]);
startIndex++;
}
}
break;
case Opcodes.INVOKESPECIAL:
MethodInsnNode mnode = (MethodInsnNode) node;
if (mnode.owner.equals(mutableClass.internalClassName) || mnode.owner.equals(mutableClass.classNode.superName)) {
if (!"<init>".equals(mnode.name)) {
throw new AssertionError("Invalid MethodInsnNode name");
}
// <init>
while (startIndex <= i) {
ctor.instructions.remove(insns[startIndex]);
removedInstructions.add(insns[startIndex]);
startIndex++;
}
return removedInstructions;
}
break;
case Opcodes.ATHROW:
ctor.visitCode();
ctor.visitInsn(Opcodes.RETURN);
ctor.visitEnd();
return removedInstructions;
default:
}
}
throw new RuntimeException("huh? " + ctor.name + ctor.desc);
}
Aggregations