Refine search
@Override public JvmValue newOperation(AbstractInsnNode insn) throws AnalyzerException { switch (insn.getOpcode()) { case ACONST_NULL: return b(1, Exprs.nNull()); case ICONST_4: case ICONST_5: return b(1, Exprs.nInt(insn.getOpcode() - ICONST_0)); case LCONST_0: case LCONST_1: return b(2, Exprs.nLong(insn.getOpcode() - LCONST_0)); case FCONST_0: case FCONST_1: case FCONST_2: return b(1, Exprs.nFloat(insn.getOpcode() - FCONST_0)); case DCONST_0: case DCONST_1: return b(2, Exprs.nDouble(insn.getOpcode() - DCONST_0)); case BIPUSH: case SIPUSH: case GETSTATIC: FieldInsnNode fin = (FieldInsnNode) insn; return b(Type.getType(fin.desc).getSize(), Exprs.nStaticField("L" + fin.owner + ";", fin.name, fin.desc)); case NEW:
IrMethod convert0(String owner, MethodNode methodNode) throws AnalyzerException { this.methodNode = methodNode; target = populate(owner, methodNode); if (methodNode.instructions.size() == 0) { return target; BitSet[] exBranch = new BitSet[insnList.size()]; parentCount = new int[insnList.size()]; for (TryCatchBlockNode tcb : methodNode.tryCatchBlocks) { target.traps.add(new Trap(getLabel(tcb.start), getLabel(tcb.end), new LabelStmt[]{getLabel(tcb.handler)}, new String[]{tcb.type == null ? null : Type.getObjectType(tcb.type).getDescriptor()})); int handlerIdx = insnList.indexOf(tcb.handler); handlers.set(handlerIdx); for (AbstractInsnNode p = tcb.start.getNext(); p != tcb.end; p = p.getNext()) { BitSet x = exBranch[insnList.indexOf(p)]; if (p.getType() == AbstractInsnNode.LABEL) { stmts.add(getLabel((LabelNode) p));
@Override public void execute(AbstractInsnNode insn, Interpreter<JvmValue> interpreter) throws AnalyzerException { if (insn.getType() == AbstractInsnNode.FRAME || insn.getType() == AbstractInsnNode.LINE || insn.getType() == AbstractInsnNode.LABEL) { return; } if (insn.getOpcode() == Opcodes.RETURN) { interpreter.returnOperation(insn, null, null); } else if (insn.getOpcode() == Opcodes.GOTO) { interpreter.unaryOperation(insn, null); } else if (insn.getOpcode() == RET) { throw new RuntimeException("not support yet!"); } else { super.execute(insn, interpreter); } } }
private void initParentCount(int[] parentCount) { parentCount[0] = 1; for (AbstractInsnNode p = insnList.getFirst(); p != null; p = p.getNext()) { if (p.getType() == AbstractInsnNode.JUMP_INSN) { JumpInsnNode jump = (JumpInsnNode) p; parentCount[insnList.indexOf(jump.label)]++; int op = p.getOpcode(); if (op == Opcodes.TABLESWITCH || op == Opcodes.LOOKUPSWITCH) { if (op == Opcodes.TABLESWITCH) { TableSwitchInsnNode tsin = (TableSwitchInsnNode) p; for (LabelNode label : tsin.labels) { parentCount[insnList.indexOf(label)]++; parentCount[insnList.indexOf(tsin.dflt)]++; AbstractInsnNode next = p.getNext(); if(next!=null) { parentCount[insnList.indexOf(p.getNext())]++;
continue; Type type = Type.getType(field.getType()); logger.info("Checking replacement field variable " + field.getName()); continue; if (type.getDescriptor().equals(desc)) { logger.info("Adding replacement field variable " + field.getName()); InsnList list = new InsnList(); if (node.getOpcode() == Opcodes.GETFIELD) { list.add(new InsnNode(Opcodes.POP)); // Remove field owner from stack list.add(new FieldInsnNode(Opcodes.GETSTATIC, className.replace('.', '/'), field.getName(), type.getDescriptor())); else { list.add(new VarInsnNode(Opcodes.ALOAD, 0)); // this
Type returnType = Type.getReturnType(methodNode.desc); InsnList instructions = methodNode.instructions; for (AbstractInsnNode instruction : instructions.toArray()) { if (!deadCode) { if (instruction.getOpcode() == Opcodes.INVOKESPECIAL) { instructions.insert(instruction, new InsnNode(Opcodes.RETURN)); instructions.remove(instruction); instructions.add(new InsnNode(Opcodes.ICONST_0)); } else if (returnType.equals(Type.LONG_TYPE)) { instructions.add(new InsnNode(Opcodes.LCONST_0)); } else if (returnType.equals(Type.FLOAT_TYPE)) { instructions.add(new InsnNode(Opcodes.FCONST_0)); } else if (returnType.equals(Type.DOUBLE_TYPE)) {
values[i] = getLocal(xvalues.get(i)); if (insn.getOpcode() == MULTIANEWARRAY) { throw new UnsupportedOperationException("Not supported yet."); } else { MethodInsnNode mi = (MethodInsnNode) insn; com.googlecode.dex2jar.ir.expr.Value v = null; String ret = Type.getReturnType(mi.desc).getDescriptor(); String owner = "L" + mi.owner + ";"; String ps[] = toDescArray(Type.getArgumentTypes(mi.desc)); switch (insn.getOpcode()) { case INVOKEVIRTUAL: v = Exprs.nInvokeVirtual(values, owner, mi.name, ps, ret);
public void process(ParserClassNode classNode, RuleMethod method) throws Exception { checkArgNotNull(classNode, "classNode"); checkArgNotNull(method, "method"); InsnList instructions = method.instructions; AbstractInsnNode ret = instructions.getLast(); while (ret.getOpcode() != ARETURN) { ret = ret.getPrevious(); } // stack: <Matcher> instructions.insertBefore(ret, new TypeInsnNode(NEW, VAR_FRAMING_MATCHER.getInternalName())); // stack: <Matcher> :: <VarFramingMatcher> instructions.insertBefore(ret, new InsnNode(DUP_X1)); // stack: <VarFramingMatcher> :: <Matcher> :: <VarFramingMatcher> instructions.insertBefore(ret, new InsnNode(SWAP)); // stack: <VarFramingMatcher> :: <VarFramingMatcher> :: <Matcher> createVarFieldArray(method, instructions, ret); // stack: <VarFramingMatcher> :: <VarFramingMatcher> :: <Matcher> :: <VarFieldArray> instructions.insertBefore(ret, new MethodInsnNode(INVOKESPECIAL, VAR_FRAMING_MATCHER.getInternalName(), "<init>", '(' + RULE_DESC + '[' + VAR_DESC + ")V", false)); // stack: <VarFramingMatcher> method.setBodyRewritten(); }
private void addObjectInstrumentation(BytecodeInstruction instruction, InsnList instrumentation, MethodNode mn) { if(instruction.isLocalVariableDefinition()) { if(instruction.getASMNode().getOpcode() == Opcodes.ALOAD) { instrumentation.add(new InsnNode(Opcodes.DUP)); } else { instrumentation.add(new InsnNode(Opcodes.ACONST_NULL)); if(instruction.getASMNode().getOpcode() == Opcodes.ASTORE) { instrumentation.add(new InsnNode(Opcodes.DUP)); } else { instrumentation.add(new InsnNode(Opcodes.ACONST_NULL)); } else if(instruction.isFieldNodeDU()) { Type type = Type.getType(instruction.getFieldType()); if(type.getSort() == Type.OBJECT) { instrumentation.add(new InsnNode(Opcodes.DUP)); } else { Type type = Type.getReturnType(instruction.getMethodCallDescriptor()); if(type.getSort() == Type.OBJECT) { instrumentation.add(new InsnNode(Opcodes.DUP));
Type[] args = Type.getArgumentTypes(mn.desc); InsnList nl = new InsnList(); nl.add(new VarInsnNode(Opcodes.ALOAD, 0)); // loads the object nl.add(new FieldInsnNode(Opcodes.GETFIELD, iclname, AGENT_FIELD_NAME, Type.getDescriptor(IInternalAccess.class))); nl.add(new LdcInsnNode(belname)); nl.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "jadex/bdiv3/features/impl/BDIAgentFeature", "unobserveValue", nl.add(new InsnNode(Opcodes.ACONST_NULL)); nl.add(new InsnNode(Opcodes.ACONST_NULL)); // oldvalue ? nl.add(new InsnNode(Opcodes.ACONST_NULL)); // no index/key nl.add(new VarInsnNode(Opcodes.ALOAD, 0)); // loads the agent object nl.add(new FieldInsnNode(Opcodes.GETFIELD, iclname, AGENT_FIELD_NAME, Type.getDescriptor(IInternalAccess.class))); nl.add(new LdcInsnNode(belname)); for(n = l.getLast(); n.getOpcode()!=Opcodes.RETURN; n = n.getPrevious())
@Override public BasicValue binaryOperation(AbstractInsnNode insn, BasicValue value1, BasicValue value2) throws AnalyzerException { if(insn.getOpcode() == Opcodes.AALOAD) { Type t1 = value1.getType(); if(t1 == null || t1.getSort() != Type.ARRAY) { throw new AnalyzerException(insn, "AALOAD needs an array as first parameter"); } Type resultType = Type.getType(t1.getDescriptor().substring(1)); return new BasicValue(resultType); } return super.binaryOperation(insn, value1, value2); }
@Nullable private static MethodInsnNode findConstructorInvocation( @NonNull MethodNode method, @NonNull String className) { InsnList nodes = method.instructions; for (int i = 0, n = nodes.size(); i < n; i++) { AbstractInsnNode instruction = nodes.get(i); if (instruction.getOpcode() == Opcodes.INVOKESPECIAL) { MethodInsnNode call = (MethodInsnNode) instruction; if (className.equals(call.owner)) { return call; } } } return null; }
|| getOrCreateKotlinClass().test(node)) { String owner = Type.getReturnType(node.desc).getClassName(); AbstractInsnNode prev = node.getPrevious(); if (prev instanceof FieldInsnNode && ((MethodInsnNode) n).name.equals("toEnum")) { toType = loadType(loader, ((Type) cst).getClassName()); return loadType(loader, typeInsn.desc); } else if (n != null && Opcodes.DUP == n.getOpcode()) { AbstractInsnNode next = n.getNext(); if (next instanceof MethodInsnNode) { if (((MethodInsnNode) next).name.equals("toOptional")) {
@Override public void returnOperation(final AbstractInsnNode insn, final BasicValue value, final BasicValue expected) throws AnalyzerException { Preconditions.checkState(insn.getOpcode() == ARETURN); Preconditions.checkState(unwrap(value).getType().equals( Type.getType(Rule.class))); Preconditions.checkState(unwrap(expected).getType().equals( Type.getType(Rule.class))); Preconditions.checkState(method.getReturnInstructionNode() == null); method.setReturnInstructionNode(createNode(insn, null, value)); }
public void populateClassGraph() { String className = Type.getObjectType(classNode.name).getClassName(); logger.debug("Creating graph for class {}" , className); for (MethodNode methodNode : classNode.methods) { String methodName = methodNode.name; MethodGraph caller = new MethodGraph(className, methodName); InsnList instructions = methodNode.instructions; for (int i = 0; i < instructions.size(); i++) { AbstractInsnNode insnNode = instructions.get(i); if (insnNode.getType() == AbstractInsnNode.METHOD_INSN) { MethodInsnNode methodInsnNode = (MethodInsnNode)insnNode; String calledOwner = Type.getObjectType(methodInsnNode.owner).getClassName(); String calledName = methodInsnNode.name; MethodGraph called = new MethodGraph(calledOwner, calledName); Call call = new Call(caller, called); if (!called.getOwner().equals("java.lang.Object") && !called.getName().equals("<init>")) { logger.trace("Adding call graph: {}", call.toString()); GraphHolder.addCallGraph(call); } } } } } }
@Override public JvmValue unaryOperation(AbstractInsnNode insn, JvmValue value0) throws AnalyzerException { Local local = value0 == null ? null : getLocal(value0); switch (insn.getOpcode()) { case INEG: return b(1, Exprs.nNeg(local, "I")); Type fieldType = Type.getType(fin.desc); return b(fieldType.getSize(), Exprs.nField(local, "L" + fin.owner + ";", fin.name, fin.desc));
@Override public BasicValue naryOperation(final AbstractInsnNode insn, final List<? extends BasicValue> values) throws AnalyzerException { int opcode = insn.getOpcode(); if (opcode == MULTIANEWARRAY) { for (int i = 0; i < values.size(); ++i) { if (!BasicValue.INT_VALUE.equals(values.get(i))) { throw new AnalyzerException(insn, null, BasicValue.INT_VALUE, values.get(i)); int j = 0; if (opcode != INVOKESTATIC && opcode != INVOKEDYNAMIC) { Type owner = Type.getObjectType(((MethodInsnNode) insn).owner); if (!isSubTypeOf(values.get(i++), newValue(owner))) { throw new AnalyzerException(insn, "Method owner", Type[] args = Type.getArgumentTypes(desc); while (i < values.size()) { BasicValue expected = newValue(args[j++]);
private void resetField(FieldDescriptor field) { mv.visitVarInsn(ALOAD, 0); field.reset.accept(mv); mv.visitFieldInsn(PUTFIELD, meta.type.getInternalName(), field.name, field.desc); } }