Java Code Examples for org.objectweb.asm.tree.AbstractInsnNode#METHOD_INSN

The following examples show how to use org.objectweb.asm.tree.AbstractInsnNode#METHOD_INSN . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ControlFlowGraph.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/** Adds an exception try block node to this graph */
protected void exception(@NonNull AbstractInsnNode from, @NonNull TryCatchBlockNode tcb) {
    // Add tcb's to all instructions in the range
    LabelNode start = tcb.start;
    LabelNode end = tcb.end; // exclusive

    // Add exception edges for all method calls in the range
    AbstractInsnNode curr = start;
    Node handlerNode = getNode(tcb.handler);
    while (curr != end && curr != null) {
        if (curr.getType() == AbstractInsnNode.METHOD_INSN) {
            // Method call; add exception edge to handler
            if (tcb.type == null) {
                // finally block: not an exception path
                getNode(curr).addSuccessor(handlerNode);
            }
            getNode(curr).addExceptionPath(handlerNode);
        }
        curr = curr.getNext();
    }
}
 
Example 2
Source File: ClickableViewAccessibilityDetector.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked") // ASM API
@Nullable
private static AbstractInsnNode findMethodCallInstruction(
        @NonNull InsnList instructions,
        @NonNull String owner,
        @NonNull String name,
        @NonNull String desc) {
    ListIterator<AbstractInsnNode> iterator = instructions.iterator();

    while (iterator.hasNext()) {
        AbstractInsnNode insnNode = iterator.next();
        if (insnNode.getType() == AbstractInsnNode.METHOD_INSN) {
            MethodInsnNode methodInsnNode = (MethodInsnNode) insnNode;
            if ((methodInsnNode.owner.equals(owner))
                    && (methodInsnNode.name.equals(name))
                    && (methodInsnNode.desc.equals(desc))) {
                return methodInsnNode;
            }
        }
    }

    return null;
}
 
Example 3
Source File: AsmInsertImpl.java    From Robust with Apache License 2.0 6 votes vote down vote up
public byte[] transformCode(byte[] b1, String className) throws IOException {
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    ClassReader cr = new ClassReader(b1);
    ClassNode classNode = new ClassNode();
    Map<String, Boolean> methodInstructionTypeMap = new HashMap<>();
    cr.accept(classNode, 0);
    final List<MethodNode> methods = classNode.methods;
    for (MethodNode m : methods) {
        InsnList inList = m.instructions;
        boolean isMethodInvoke = false;
        for (int i = 0; i < inList.size(); i++) {
            if (inList.get(i).getType() == AbstractInsnNode.METHOD_INSN) {
                isMethodInvoke = true;
            }
        }
        methodInstructionTypeMap.put(m.name + m.desc, isMethodInvoke);
    }
    InsertMethodBodyAdapter insertMethodBodyAdapter = new InsertMethodBodyAdapter(cw, className, methodInstructionTypeMap);
    cr.accept(insertMethodBodyAdapter, ClassReader.EXPAND_FRAMES);
    return cw.toByteArray();
}
 
Example 4
Source File: ClickableViewAccessibilityDetector.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked") // ASM API
public static void scanForAndCheckSetOnTouchListenerCalls(
        ClassContext context,
        ClassNode classNode) {
    List<MethodNode> methods = classNode.methods;
    for (MethodNode methodNode : methods) {
        ListIterator<AbstractInsnNode> iterator = methodNode.instructions.iterator();
        while (iterator.hasNext()) {
            AbstractInsnNode abstractInsnNode = iterator.next();
            if (abstractInsnNode.getType() == AbstractInsnNode.METHOD_INSN) {
                MethodInsnNode methodInsnNode = (MethodInsnNode) abstractInsnNode;
                if (methodInsnNode.name.equals(SET_ON_TOUCH_LISTENER)
                        && methodInsnNode.desc.equals(SET_ON_TOUCH_LISTENER_SIG)) {
                    checkSetOnTouchListenerCall(context, methodNode, methodInsnNode);
                }
            }
        }
    }
}
 
Example 5
Source File: OpcodeFormatting.java    From Cafebabe with GNU General Public License v3.0 5 votes vote down vote up
public static String toString(AbstractInsnNode ain) {
	String s = getOpcodeText(ain.getOpcode());
	switch (ain.getType()) {
	case AbstractInsnNode.FIELD_INSN:
		FieldInsnNode fin = (FieldInsnNode) ain;
		return s + " " + fin.owner + "#" + fin.name + " " + fin.desc;
	case AbstractInsnNode.METHOD_INSN:
		MethodInsnNode min = (MethodInsnNode) ain;
		return s + " " + min.owner + "#" + min.name + min.desc;
	case AbstractInsnNode.VAR_INSN:
		VarInsnNode vin = (VarInsnNode) ain;
		return s + " " + vin.var;
	case AbstractInsnNode.TYPE_INSN:
		TypeInsnNode tin = (TypeInsnNode) ain;
		return s + " " + tin.desc;
	case AbstractInsnNode.MULTIANEWARRAY_INSN:
		MultiANewArrayInsnNode mnin = (MultiANewArrayInsnNode) ain;
		return s + " " + mnin.dims + " " + mnin.desc;
	case AbstractInsnNode.JUMP_INSN:
		JumpInsnNode jin = (JumpInsnNode) ain;
		return s + " " + getIndex(jin.label);
	case AbstractInsnNode.LDC_INSN:
		LdcInsnNode ldc = (LdcInsnNode) ain;
		return s + " " + ldc.cst.toString();
	case AbstractInsnNode.INT_INSN:
		return s + " " + getIntValue(ain);
	case AbstractInsnNode.IINC_INSN:
		IincInsnNode iinc = (IincInsnNode) ain;
		return s + " " + iinc.var + " +" + iinc.incr;
	case AbstractInsnNode.FRAME:
		FrameNode fn = (FrameNode) ain;
		return s + " " + getOpcodeText(fn.type) + " " + fn.local.size() + " " + fn.stack.size();
	case AbstractInsnNode.LABEL:
		LabelNode ln = (LabelNode) ain;
		return s + " " + getIndex(ln);
	}
	return s;
}
 
Example 6
Source File: OpUtils.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
public static String toString(AbstractInsnNode ain) {
  String s = getOpcodeText(ain.getOpcode());
  switch (ain.getType()) {
  case AbstractInsnNode.FIELD_INSN:
    FieldInsnNode fin = (FieldInsnNode) ain;
    return s + " " + fin.owner + "#" + fin.name + " " + fin.desc;
  case AbstractInsnNode.METHOD_INSN:
    MethodInsnNode min = (MethodInsnNode) ain;
    return s + " " + min.owner + "#" + min.name + min.desc;
  case AbstractInsnNode.VAR_INSN:
    VarInsnNode vin = (VarInsnNode) ain;
    return s + " " + vin.var;
  case AbstractInsnNode.TYPE_INSN:
    TypeInsnNode tin = (TypeInsnNode) ain;
    return s + " " + tin.desc;
  case AbstractInsnNode.MULTIANEWARRAY_INSN:
    MultiANewArrayInsnNode mnin = (MultiANewArrayInsnNode) ain;
    return s + " " + mnin.dims + " " + mnin.desc;
  case AbstractInsnNode.JUMP_INSN:
    JumpInsnNode jin = (JumpInsnNode) ain;
    return s + " " + getIndex(jin.label);
  case AbstractInsnNode.LDC_INSN:
    LdcInsnNode ldc = (LdcInsnNode) ain;
    return s + " " + ldc.cst.toString();
  case AbstractInsnNode.INT_INSN:
    return s + " " + getIntValue(ain);
  case AbstractInsnNode.IINC_INSN:
    IincInsnNode iinc = (IincInsnNode) ain;
    return s + " " + iinc.var + " +" + iinc.incr;
  case AbstractInsnNode.FRAME:
    FrameNode fn = (FrameNode) ain;
    return s + " " + getOpcodeText(fn.type) + " " + fn.local.size() + " " + fn.stack.size();
  case AbstractInsnNode.LABEL:
    LabelNode ln = (LabelNode) ain;
    return s + " " + getIndex(ln);
  }
  return s;
}
 
Example 7
Source File: InsnComparator.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Respects {@link #INT_WILDCARD} and {@link #WILDCARD} instruction properties.
 * Always returns true if {@code a} and {@code b} are label, line number, or frame instructions.
 * 
 * @return Whether or not the given instructions are equivalent.
 */
public boolean areInsnsEqual(AbstractInsnNode a, AbstractInsnNode b)
{
	if (a == b)
		return true;

	if (a == null || b == null)
		return false;

	if (a.equals(b))
		return true;

	if (a.getOpcode() != b.getOpcode())
		return false;

	switch (a.getType())
	{
		case AbstractInsnNode.VAR_INSN:
			return areVarInsnsEqual((VarInsnNode) a, (VarInsnNode) b);
		case AbstractInsnNode.TYPE_INSN:
			return areTypeInsnsEqual((TypeInsnNode) a, (TypeInsnNode) b);
		case AbstractInsnNode.FIELD_INSN:
			return areFieldInsnsEqual((FieldInsnNode) a, (FieldInsnNode) b);
		case AbstractInsnNode.METHOD_INSN:
			return areMethodInsnsEqual((MethodInsnNode) a, (MethodInsnNode) b);
		case AbstractInsnNode.LDC_INSN:
			return areLdcInsnsEqual((LdcInsnNode) a, (LdcInsnNode) b);
		case AbstractInsnNode.IINC_INSN:
			return areIincInsnsEqual((IincInsnNode) a, (IincInsnNode) b);
		case AbstractInsnNode.INT_INSN:
			return areIntInsnsEqual((IntInsnNode) a, (IntInsnNode) b);
		default:
			return true;
	}
}
 
Example 8
Source File: ClassCallGraph.java    From custom-bytecode-analyzer with GNU General Public License v3.0 5 votes vote down vote up
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);
        }
      }
    }
  }
}
 
Example 9
Source File: CustomMethodInvocationVisitor.java    From custom-bytecode-analyzer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void process() {
  for (MethodNode methodNode : getClassNode().methods) {
    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;
        processMethodInsnNode(methodNode, methodInsnNode);
      }
    }
  }
}
 
Example 10
Source File: OpUtils.java    From zelixkiller with GNU General Public License v3.0 5 votes vote down vote up
public static String toString(AbstractInsnNode ain) {
	String s = getOpcodeText(ain.getOpcode());
	switch (ain.getType()) {
	case AbstractInsnNode.FIELD_INSN:
		FieldInsnNode fin = (FieldInsnNode) ain;
		return s + " " + fin.owner + "#" + fin.name + " " + fin.desc;
	case AbstractInsnNode.METHOD_INSN:
		MethodInsnNode min = (MethodInsnNode) ain;
		return s + " " + min.owner + "#" + min.name + min.desc;
	case AbstractInsnNode.VAR_INSN:
		VarInsnNode vin = (VarInsnNode) ain;
		return s + " " + vin.var;
	case AbstractInsnNode.TYPE_INSN:
		TypeInsnNode tin = (TypeInsnNode) ain;
		return s + " " + tin.desc;
	case AbstractInsnNode.JUMP_INSN:
		JumpInsnNode jin = (JumpInsnNode) ain;
		return s + " " + getIndex(jin.label);
	case AbstractInsnNode.LDC_INSN:
		LdcInsnNode ldc = (LdcInsnNode) ain;
		return s + " " + ldc.cst.toString();
	case AbstractInsnNode.INT_INSN:
		return s + " " + getIntValue(ain);
	case AbstractInsnNode.IINC_INSN:
		IincInsnNode iinc = (IincInsnNode) ain;
		return s + " " + iinc.var + " +" + iinc.incr;
	case AbstractInsnNode.FRAME:
		FrameNode fn = (FrameNode) ain;
		return s + " " + getOpcodeText(fn.type) + " " + fn.local.size() + " " + fn.stack.size();
	case AbstractInsnNode.LABEL:
		LabelNode ln = (LabelNode) ain;
		return s + " " + getIndex(ln);
	}
	return s;
}
 
Example 11
Source File: ReferenceUtils.java    From zelixkiller with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Finds references to the class's method in the given method.
 * 
 * @param target
 * @param targetMethod
 * @param method
 * @return
 */
public static List<Reference> getReferences(ClassNode target, MethodNode targetMethod, ClassNode inThisNode, MethodNode method) {
	List<Reference> references = new ArrayList<Reference>();
	for (AbstractInsnNode ain : method.instructions.toArray()) {
		if (ain.getType() == AbstractInsnNode.METHOD_INSN) {
			MethodInsnNode min = (MethodInsnNode) ain;
			if (min.owner.contains(target.name) && min.name.equals(targetMethod.name) && min.desc.equals(targetMethod.desc)) {
				references.add(new Reference(inThisNode, method, ain));
			}
		}
	}
	return references;
}
 
Example 12
Source File: ReferenceUtils.java    From zelixkiller with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Finds references to the class in the given method.
 * 
 * @param target
 * @param method
 * @return
 */
public static List<Reference> getReferences(ClassNode target, ClassNode inThisNode, MethodNode method) {
	String targetDesc = target.name;
	List<Reference> references = new ArrayList<Reference>();
	for (AbstractInsnNode ain : method.instructions.toArray()) {
		switch (ain.getType()) {
		case AbstractInsnNode.METHOD_INSN:
			MethodInsnNode min = (MethodInsnNode) ain;
			if (min.desc.contains(targetDesc) || min.owner.contains(targetDesc)) {
				references.add(new Reference(inThisNode, method, ain));
			}
			break;
		case AbstractInsnNode.FIELD_INSN:
			FieldInsnNode fin = (FieldInsnNode) ain;
			if (fin.desc.contains(targetDesc) || fin.owner.contains(targetDesc)) {
				references.add(new Reference(inThisNode, method, ain));
			}
			break;
		case AbstractInsnNode.TYPE_INSN:
			TypeInsnNode tin = (TypeInsnNode) ain;
			if (tin.desc.contains(targetDesc)) {
				references.add(new Reference(inThisNode, method, ain));
			}
			break;
		}
	}
	return references;
}
 
Example 13
Source File: CorrelationMapper.java    From zelixkiller with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get's a member's class types from its description. Best for methods.
 * 
 * @param member
 * @param map
 * @return
 */
private static List<MappedClass> getTypesFromMember(MappedMember member, Map<String, MappedClass> map) {
	List<String> names = RegexUtils.matchDescriptionClasses(member.getDesc());
	if (member.isMethod()) {
		for (AbstractInsnNode ain : member.getMethodNode().instructions.toArray()) {
			if (ain.getType() == AbstractInsnNode.METHOD_INSN) {
				MethodInsnNode min = (MethodInsnNode) ain;
				names.addAll(RegexUtils.matchDescriptionClasses(min.desc));
				names.add(min.owner);
			} else if (ain.getType() == AbstractInsnNode.FIELD_INSN) {
				FieldInsnNode fin = (FieldInsnNode) ain;
				names.addAll(RegexUtils.matchDescriptionClasses(fin.desc));
				names.add(fin.owner);
			} else if (ain.getType() == AbstractInsnNode.TYPE_INSN) {
				TypeInsnNode tin = (TypeInsnNode) ain;
				names.addAll(RegexUtils.matchDescriptionClasses(tin.desc));
			} else if (ain.getType() == AbstractInsnNode.LDC_INSN) {
				LdcInsnNode ldc = (LdcInsnNode) ain;
				if (ldc.cst instanceof Type) {
					Type t = (Type) ldc.cst;
					names.add(t.getClassName().replace(".", "/"));
				}
			}
		}
	}
	if (names.size() == 0) {
		return null;
	}
	List<MappedClass> classes = new ArrayList<MappedClass>();
	for (String name : names) {
		if (!map.containsKey(name)) {
			continue;
		}
		classes.add(map.get(name));
	}
	return classes;
}
 
Example 14
Source File: SuperClassRedirection.java    From Stark with Apache License 2.0 5 votes vote down vote up
public static void redirect(ClassNode classNode) {
    if (SUPER_REDIRECT_MAP.keySet().contains(classNode.superName)) {
        if (SUPER_REDIRECT_MAP.values().contains(classNode.name)) {
            return;
        }
        String originSuper = classNode.superName;
        String redirectSuper = SUPER_REDIRECT_MAP.get(classNode.superName);
        classNode.superName = redirectSuper;
        for (MethodNode methodNode : (List<MethodNode>) classNode.methods) {
            AbstractInsnNode insn = methodNode.instructions.getFirst();
            while (insn != null) {
                switch (insn.getType()) {
                    case AbstractInsnNode.FIELD_INSN:
                        FieldInsnNode fieldInsnNode = (FieldInsnNode) insn;
                        if (fieldInsnNode.owner.equals(originSuper)) {
                            fieldInsnNode.owner = redirectSuper;
                        }
                        break;
                    case AbstractInsnNode.METHOD_INSN:
                        MethodInsnNode methodInsnNode = (MethodInsnNode) insn;
                        if (methodInsnNode.owner.equals(originSuper)) {
                            methodInsnNode.owner = redirectSuper;
                        }
                        break;
                    case AbstractInsnNode.INVOKE_DYNAMIC_INSN:
                        break;
                }
                insn = insn.getNext();
            }
        }
    }
}
 
Example 15
Source File: WakelockDetector.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
private static void checkFlow(@NonNull ClassContext context, @NonNull ClassNode classNode,
        @NonNull MethodNode method, @NonNull MethodInsnNode acquire) {
    // Track allocations such that we know whether the type of the call
    // is on a SecureRandom rather than a Random
    final InsnList instructions = method.instructions;
    MethodInsnNode release = null;

    // Find release call
    for (int i = 0, n = instructions.size(); i < n; i++) {
        AbstractInsnNode instruction = instructions.get(i);
        int type = instruction.getType();
        if (type == AbstractInsnNode.METHOD_INSN) {
            MethodInsnNode call = (MethodInsnNode) instruction;
            if (call.name.equals(RELEASE_METHOD) &&
                    call.owner.equals(WAKELOCK_OWNER)) {
                release = call;
                break;
            }
        }
    }

    if (release == null) {
        // Didn't find both acquire and release in this method; no point in doing
        // local flow analysis
        return;
    }

    try {
        MyGraph graph = new MyGraph();
        ControlFlowGraph.create(graph, classNode, method);

        if (DEBUG) {
            // Requires util package
            //ClassNode clazz = classNode;
            //clazz.accept(new TraceClassVisitor(new PrintWriter(System.out)));
            System.out.println(graph.toString(graph.getNode(acquire)));
        }

        int status = dfs(graph.getNode(acquire));
        if ((status & SEEN_RETURN) != 0) {
            String message;
            if ((status & SEEN_EXCEPTION) != 0) {
                message = "The `release()` call is not always reached (via exceptional flow)";
            } else {
                message = "The `release()` call is not always reached";
            }

            context.report(ISSUE, method, acquire,
                    context.getLocation(release), message);
        }
    } catch (AnalyzerException e) {
        context.log(e, null);
    }
}
 
Example 16
Source File: FieldGetterDetector.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@Override
public int[] getApplicableAsmNodeTypes() {
    return new int[] { AbstractInsnNode.METHOD_INSN };
}
 
Example 17
Source File: ControlFlowGraph.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Represents this instruction as a string, for debugging purposes
 *
 * @param includeAdjacent whether it should include a display of
 *            adjacent nodes as well
 * @return a string representation
 */
@NonNull
public String toString(boolean includeAdjacent) {
    StringBuilder sb = new StringBuilder(100);

    sb.append(getId(instruction));
    sb.append(':');

    if (instruction instanceof LabelNode) {
        //LabelNode l = (LabelNode) instruction;
        //sb.append('L' + l.getLabel().getOffset() + ":");
        //sb.append('L' + l.getLabel().info + ":");
        sb.append("LABEL");
    } else if (instruction instanceof LineNumberNode) {
        sb.append("LINENUMBER ").append(((LineNumberNode)instruction).line);
    } else if (instruction instanceof FrameNode) {
        sb.append("FRAME");
    } else {
        int opcode = instruction.getOpcode();
        String opcodeName = getOpcodeName(opcode);
        sb.append(opcodeName);
        if (instruction.getType() == AbstractInsnNode.METHOD_INSN) {
            sb.append('(').append(((MethodInsnNode)instruction).name).append(')');
        }
    }

    if (includeAdjacent) {
        if (successors != null && !successors.isEmpty()) {
            sb.append(" Next:");
            for (Node successor : successors) {
                sb.append(' ');
                sb.append(successor.toString(false));
            }
        }

        if (exceptions != null && !exceptions.isEmpty()) {
            sb.append(" Exceptions:");
            for (Node exception : exceptions) {
                sb.append(' ');
                sb.append(exception.toString(false));
            }
        }
        sb.append('\n');
    }

    return sb.toString();
}
 
Example 18
Source File: InstrUtils.java    From JByteMod-Beta with GNU General Public License v2.0 4 votes vote down vote up
public static String toEasyString(AbstractInsnNode ain) {
	String opc = OpUtils.getOpcodeText(ain.getOpcode()).toLowerCase() + " ";
	switch (ain.getType()) {
	case AbstractInsnNode.LABEL:
		opc = "label " + OpUtils.getLabelIndex((LabelNode) ain);
		break;
	case AbstractInsnNode.LINE:
		opc = "line " + ((LineNumberNode) ain).line;
		break;
	case AbstractInsnNode.FIELD_INSN:
		FieldInsnNode fin = (FieldInsnNode) ain;
		opc += getDisplayType(fin.desc, false) + " " + getDisplayClassEasy(fin.owner) + "." + fin.name;
		break;
	case AbstractInsnNode.METHOD_INSN:
		MethodInsnNode min = (MethodInsnNode) ain;
		opc += getDisplayType(min.desc.split("\\)")[1], false) + " " + getDisplayClassEasy(min.owner) + "." + min.name
				+ "(" + getDisplayArgsEasy(min.desc) + ")";
		break;
	case AbstractInsnNode.VAR_INSN:
		VarInsnNode vin = (VarInsnNode) ain;
		opc += vin.var;
		break;
	case AbstractInsnNode.MULTIANEWARRAY_INSN:
		MultiANewArrayInsnNode mnin = (MultiANewArrayInsnNode) ain;
		opc += mnin.dims + " " + getDisplayType(mnin.desc, false);
		break;
	case AbstractInsnNode.TYPE_INSN:
		TypeInsnNode tin = (TypeInsnNode) ain;
		String esc = tin.desc;
		if (esc.endsWith(";") && esc.startsWith("L")) {
			opc += esc;
		} else {
			opc += getDisplayClassEasy(esc);
		}
		break;
	case AbstractInsnNode.JUMP_INSN:
		JumpInsnNode jin = (JumpInsnNode) ain;
		opc += OpUtils.getLabelIndex(jin.label);
		break;
	case AbstractInsnNode.LDC_INSN:
		LdcInsnNode ldc = (LdcInsnNode) ain;
		opc += ldc.cst.getClass().getSimpleName() + " ";
		if (ldc.cst instanceof String)
			opc += "\"" + ldc.cst.toString() + "\"";
		else {
			opc += ldc.cst.toString();
		}
		break;
	case AbstractInsnNode.INT_INSN:
		opc += OpUtils.getIntValue(ain);
		break;
	case AbstractInsnNode.IINC_INSN:
		IincInsnNode iinc = (IincInsnNode) ain;
		opc += iinc.var + " " + iinc.incr;
		break;
	case AbstractInsnNode.FRAME:
		FrameNode fn = (FrameNode) ain;
		opc = OpUtils.getOpcodeText(fn.type).toLowerCase() + " " + fn.local.size() + " " + fn.stack.size();
		break;
	case AbstractInsnNode.TABLESWITCH_INSN:
		TableSwitchInsnNode tsin = (TableSwitchInsnNode) ain;
		if (tsin.dflt != null) {
			opc += "L" + OpUtils.getLabelIndex(tsin.dflt);
		}
		if (tsin.labels.size() < 20) {
			for (LabelNode l : tsin.labels) {
				opc += " " + "L" + OpUtils.getLabelIndex(l);
			}
		} else {
			opc += " " + tsin.labels.size() + " cases";
		}
		break;
	case AbstractInsnNode.INVOKE_DYNAMIC_INSN:
		InvokeDynamicInsnNode idin = (InvokeDynamicInsnNode) ain;
		opc += idin.name + " " + idin.desc;
		break;
	}
	return opc;
}
 
Example 19
Source File: StaticAnalysis.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public boolean walkMethod(ClassNode clinit_cn, MethodNode mn, HashSet<MethodNode> method_callees) {
    boolean safe = true;
    InsnList insns = mn.instructions;

    for (int i = 0; safe && i < insns.size(); i++) {
        AbstractInsnNode ain = insns.get(i);

        switch (ain.getType()) {
        case AbstractInsnNode.FIELD_INSN:
            FieldInsnNode fin = (FieldInsnNode) ain;
            safe = handleField(clinit_cn, fin);
            break;

        case AbstractInsnNode.METHOD_INSN:
            MethodInsnNode min = (MethodInsnNode) ain;
            HashSet<MethodNode> invoke_callees = handleInvoke(clinit_cn, min);
            if (invoke_callees == null) {
                safe = false;
            } else {
                for (MethodNode callee : invoke_callees)
                    method_callees.add(callee);
            }
            break;

        // deals with java.lang.invoke.MethodHandle
        // I think this is like function pointer aka not safe
        case AbstractInsnNode.INVOKE_DYNAMIC_INSN:
            safe = false;
            bad_invoke_dynamic++;
            if (log_enable)
                log_ln("[unsafe] class: " + clinit_cn.name + " [cause:invoke_dynamic]");
            break;

        case AbstractInsnNode.INSN:
            // throwing things can hurt people so not safe
            // most likely throw logic depends on a reference, so we should
            // already handle this implicitly, but no harm in safety first
            if (ain.getOpcode() == ATHROW) {
                safe = false;
                bad_throw++;
                if (log_enable)
                    log_ln("[unsafe] class: " + clinit_cn.name + " [cause:throw]");
            }
            break;

        default:
            break;
        }
    }
    return safe;
}
 
Example 20
Source File: Colors.java    From Cafebabe with GNU General Public License v3.0 4 votes vote down vote up
public static String getColor(int type, int opcode) {
	switch (opcode) {
	case ATHROW:
	case IRETURN:
	case LRETURN:
	case FRETURN:
	case DRETURN:
	case ARETURN:
	case RETURN:
		return "#4d0000";
	case ACONST_NULL:
	case ICONST_M1:
	case ICONST_0:
	case ICONST_1:
	case ICONST_2:
	case ICONST_3:
	case ICONST_4:
	case ICONST_5:
	case LCONST_0:
	case LCONST_1:
	case FCONST_0:
	case FCONST_1:
	case FCONST_2:
	case DCONST_0:
	case DCONST_1:
		return "#005733";
	}
	switch (type) {
	case AbstractInsnNode.FIELD_INSN:
		return "#44004d";
	case AbstractInsnNode.METHOD_INSN:
		return "#14004d";
	case AbstractInsnNode.INT_INSN:
	case AbstractInsnNode.LDC_INSN:
		return "#004d40";
	case AbstractInsnNode.VAR_INSN:
		return "#6a3e3e";
	case AbstractInsnNode.JUMP_INSN:
		return "#003d4d";
	case AbstractInsnNode.TYPE_INSN:
		return "#474d00";
	default:
		return "#000";
	}
}