use of org.objectweb.asm.tree.TypeInsnNode in project robolectric by robolectric.
the class ClassInstrumentor method rewriteMethodBody.
/**
* Filters methods that might need special treatment because of various reasons
*/
private void rewriteMethodBody(MutableClass mutableClass, MethodNode callingMethod) {
ListIterator<AbstractInsnNode> instructions = callingMethod.instructions.iterator();
while (instructions.hasNext()) {
AbstractInsnNode node = instructions.next();
switch(node.getOpcode()) {
case Opcodes.NEW:
TypeInsnNode newInsnNode = (TypeInsnNode) node;
newInsnNode.desc = mutableClass.config.mappedTypeName(newInsnNode.desc);
break;
case Opcodes.GETFIELD:
/* falls through */
case Opcodes.PUTFIELD:
/* falls through */
case Opcodes.GETSTATIC:
/* falls through */
case Opcodes.PUTSTATIC:
FieldInsnNode fieldInsnNode = (FieldInsnNode) node;
// todo test
fieldInsnNode.desc = mutableClass.config.mappedTypeName(fieldInsnNode.desc);
break;
case Opcodes.INVOKESTATIC:
/* falls through */
case Opcodes.INVOKEINTERFACE:
/* falls through */
case Opcodes.INVOKESPECIAL:
/* falls through */
case Opcodes.INVOKEVIRTUAL:
MethodInsnNode targetMethod = (MethodInsnNode) node;
targetMethod.desc = mutableClass.config.remapParams(targetMethod.desc);
if (isGregorianCalendarBooleanConstructor(targetMethod)) {
replaceGregorianCalendarBooleanConstructor(instructions, targetMethod);
} else if (mutableClass.config.shouldIntercept(targetMethod)) {
interceptInvokeVirtualMethod(mutableClass, instructions, targetMethod);
}
break;
case Opcodes.INVOKEDYNAMIC:
/* no unusual behavior */
break;
default:
break;
}
}
}
use of org.objectweb.asm.tree.TypeInsnNode in project bytecode-viewer by Konloch.
the class RegexInsnFinder method getInsString.
private static String getInsString(AbstractInsnNode ain) {
String insnString = "";
switch(ain.getType()) {
case AbstractInsnNode.INT_INSN:
final IntInsnNode iin = (IntInsnNode) ain;
insnString += "{" + iin.operand + "}";
break;
case AbstractInsnNode.LDC_INSN:
final LdcInsnNode lin = (LdcInsnNode) ain;
insnString += "{" + lin.cst.toString().replace("}", "\\}") + "}";
break;
case AbstractInsnNode.VAR_INSN:
final VarInsnNode vin = (VarInsnNode) ain;
insnString += "_" + vin.var;
break;
case AbstractInsnNode.IINC_INSN:
final IincInsnNode iiin = (IincInsnNode) ain;
insnString += "{" + iiin.var + "," + iiin.incr + "}";
break;
case AbstractInsnNode.FIELD_INSN:
final FieldInsnNode fin = (FieldInsnNode) ain;
insnString += "{" + fin.desc + "," + fin.owner + "," + fin.name + "}";
break;
case AbstractInsnNode.METHOD_INSN:
final MethodInsnNode min = (MethodInsnNode) ain;
insnString += "{" + min.desc + "," + min.owner + "," + min.name + "}";
break;
case AbstractInsnNode.TYPE_INSN:
final TypeInsnNode tin = (TypeInsnNode) ain;
insnString += "{" + tin.desc + "}";
break;
case AbstractInsnNode.MULTIANEWARRAY_INSN:
final MultiANewArrayInsnNode manain = (MultiANewArrayInsnNode) ain;
insnString += "{" + manain.dims + "," + manain.desc + "}";
break;
}
return insnString;
}
use of org.objectweb.asm.tree.TypeInsnNode in project jphp by jphp-compiler.
the class ClosureValueCompiler method write.
@Override
public void write(ClosureStmtToken closure, boolean returnValue) {
if (returnValue) {
ClosureEntity entity = compiler.getModule().findClosure(closure.getId());
boolean thisExists = closure.getFunction().isThisExists();
if (entity.isStatic()) {
thisExists = false;
}
boolean staticExists = closure.getFunction().isStaticExists();
if (closure.getFunction().getUses().isEmpty() && !thisExists && !staticExists && closure.getFunction().getStaticLocal().isEmpty()) {
expr.writePushEnv();
expr.writePushConstString(compiler.getModule().getInternalName());
expr.writePushConstInt((int) entity.getId());
writeContext();
expr.writeSysDynamicCall(Environment.class, "__getSingletonClosure", Memory.class, String.class, Integer.TYPE, String.class);
} else {
add(new TypeInsnNode(NEW, entity.getInternalName()));
expr.stackPush(Memory.Type.REFERENCE);
expr.writePushDup();
expr.writePushEnv();
expr.writePushEnv();
expr.writePushConstString(compiler.getModule().getInternalName());
expr.writePushConstInt((int) entity.getId());
expr.writeSysDynamicCall(Environment.class, "__getClosure", ClassEntity.class, String.class, Integer.TYPE);
if (thisExists) {
expr.writePushThis();
} else {
expr.writePushNull();
}
writeContext();
writePushUses(closure.getFunction().getUses());
add(new MethodInsnNode(INVOKESPECIAL, entity.getInternalName(), Constants.INIT_METHOD, Type.getMethodDescriptor(Type.getType(void.class), Type.getType(Environment.class), Type.getType(ClassEntity.class), Type.getType(Memory.class), Type.getType(String.class), Type.getType(Memory[].class)), false));
expr.stackPop();
expr.stackPop();
expr.stackPop();
expr.stackPop();
expr.stackPop();
expr.stackPop();
expr.writeSysStaticCall(ObjectMemory.class, "valueOf", Memory.class, IObject.class);
}
expr.setStackPeekAsImmutable();
}
}
use of org.objectweb.asm.tree.TypeInsnNode in project Bookshelf by Darkhax-Minecraft.
the class TransformerEnchantmentHelper method transform.
public static byte[] transform(String name, String transformedName, byte[] classBytes) {
final ClassNode clazz = ASMUtils.createClassFromByteArray(classBytes);
final MethodNode method = METHOD_GET_ENCH_LEVEL.getMethodNode(clazz);
final InsnList n1 = new InsnList();
final LabelNode start = new LabelNode();
n1.add(start);
n1.add(new TypeInsnNode(Opcodes.NEW, "net/darkhax/bookshelf/events/EnchantmentModifierEvent"));
n1.add(new InsnNode(Opcodes.DUP));
n1.add(new VarInsnNode(Opcodes.ALOAD, 0));
n1.add(new VarInsnNode(Opcodes.ALOAD, 1));
n1.add(METHOD_INIT_EVENT.getMethodInsn(Opcodes.INVOKESPECIAL, false));
n1.add(new VarInsnNode(Opcodes.ASTORE, 2));
final LabelNode l1 = new LabelNode();
n1.add(l1);
n1.add(FIELD_EVENT_BUS.getFieldNode(Opcodes.GETSTATIC));
n1.add(new VarInsnNode(Opcodes.ALOAD, 2));
n1.add(METHOD_POST.getMethodInsn(Opcodes.INVOKEVIRTUAL, false));
n1.add(new InsnNode(Opcodes.POP));
final LabelNode l2 = new LabelNode();
n1.add(l2);
n1.add(new VarInsnNode(Opcodes.ALOAD, 2));
n1.add(METHOD_CANCELED.getMethodInsn(Opcodes.INVOKEVIRTUAL, false));
final LabelNode vanillaLogic = new LabelNode();
n1.add(new JumpInsnNode(Opcodes.IFEQ, vanillaLogic));
final LabelNode l4 = new LabelNode();
n1.add(l4);
n1.add(new VarInsnNode(Opcodes.ALOAD, 2));
n1.add(METHOD_GET_LEVELS.getMethodInsn(Opcodes.INVOKEVIRTUAL, false));
n1.add(new InsnNode(Opcodes.IRETURN));
n1.add(vanillaLogic);
method.instructions.insertBefore(method.instructions.getFirst(), n1);
return ASMUtils.createByteArrayFromClass(clazz, ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
}
use of org.objectweb.asm.tree.TypeInsnNode in project drill by axbaretto.
the class ReplacingInterpreter method newOperation.
@Override
public BasicValue newOperation(final AbstractInsnNode insn) throws AnalyzerException {
if (insn.getOpcode() == Opcodes.NEW) {
final TypeInsnNode t = (TypeInsnNode) insn;
// if this is for a holder class, we'll replace it
final ValueHolderIden iden = HOLDERS.get(t.desc);
if (iden != null) {
return ReplacingBasicValue.create(Type.getObjectType(t.desc), iden, index++, valueList);
}
}
return super.newOperation(insn);
}
Aggregations