setLastUpdate(dbc.getRegisterOperand(), dbc.getPC()); precomputation(dbc); needToMerge = true; try { if (isTop()) { encountedTop = true; return; pushByLocalObjectLoad(dbc, dbc.getRegisterOperand()); break; case Const.ALOAD_2: case Const.ALOAD_3: pushByLocalObjectLoad(dbc, seen - Const.ALOAD_0); break; pushByLocalLoad("D", dbc.getRegisterOperand()); break; case Const.DLOAD_2: case Const.DLOAD_3: pushByLocalLoad("D", seen - Const.DLOAD_0); break; pushByLocalLoad("F", dbc.getRegisterOperand()); break; case Const.FLOAD_2:
/** return an int on the stack, or 'defaultValue' if can't determine */ private int getIntValue(int stackDepth, int defaultValue) { if (stack.getStackDepth() < stackDepth) { return defaultValue; } OpcodeStack.Item it = stack.getStackItem(stackDepth); Object value = it.getConstant(); if (value == null || !(value instanceof Integer)) { return defaultValue; } return ((Number) value).intValue(); }
@Override public final void visitCode(Code obj) { if (!shouldVisitCode(obj)) { return; } stack = new OpcodeStack(); stack.resetForMethodEntry(this); super.visitCode(obj); stack = null; }
@Override public void sawOpcode(int seen) { stack.precomputation(this); if (DEBUG1) { System.out.printf("%4d %-15s %s%n", getPC(), Const.getOpcodeName(seen), stack); } try { stack.sawOpcode(this, seen); } catch (RuntimeException e) { throw e; } } }
@Override @OverridingMethodsMustInvokeSuper public boolean beforeOpcode(int seen) { stack.precomputation(this); return !stack.isTop(); }
/** * handle {@code <init>} blocks by looking for putfield calls referencing synchronized collections * * @param seen * the opcode of the currently parsed instruction */ private void sawInitOpcode(int seen) { boolean isSyncCollection = false; try { stack.mergeJumps(this); isSyncCollection = isSyncCollectionCreation(seen); if (seen == PUTFIELD) { processCollectionStore(); } } finally { stack.sawOpcode(this, seen); if (isSyncCollection && (stack.getStackDepth() > 0)) { OpcodeStack.Item item = stack.getStackItem(0); item.setUserValue(Boolean.TRUE); } } }
/** * overrides the visitor to look conflated use of resources and files */ @Override public void sawOpcode(int seen) { boolean sawResource = false; try { stack.precomputation(this); if (seen == INVOKEVIRTUAL) { sawResource = processInvokeVirtual(); } else if (seen == INVOKESPECIAL) { sawResource = processInvokeSpecial(); } } finally { stack.sawOpcode(this, seen); if (sawResource && (stack.getStackDepth() > 0)) { OpcodeStack.Item item = stack.getStackItem(0); item.setUserValue(Boolean.TRUE); } } }
String sig = getSigConstantOperand(); if ((name.startsWith("set") || name.startsWith("update")) || sig.endsWith(")V")) { Item invokedOn = stack.getItemMethodInvokedOn(this); if (invokedOn.isInitialParameter() && invokedOn.getRegisterNumber() == 0) { updates++; OpcodeStack.Item rv = stack.getStackItem(0); if (rv.isNull()) { break; case Const.PUTFIELD: { OpcodeStack.Item rv = stack.getStackItem(1); if (rv.getRegisterNumber() == 0 && rv.isInitialParameter()) { if (inferredMethod != null) {
if (previousMethodCall != null && !stack.isJumpTarget(getPC())) { if ("toString".equals(called.getName()) && "java/lang/Integer".equals(called.getClassDescriptor().getClassName()) ) { String primitiveType = ClassName.getPrimitiveType(called.getClassDescriptor().getClassName()); XMethod rvo = stack.getStackItem(1).getReturnValueOf(); XField field = stack.getStackItem(1).getXField(); String signature; if (rvo != null) { OpcodeStack.Item left = stack.getStackItem(1); OpcodeStack.Item right = stack.getStackItem(0); checkForCompatibleLongComparison(left, right); checkForCompatibleLongComparison(right, left); if (stack.getStackDepth() >= 2) { switch (seen) { case Const.IF_ICMPEQ: case Const.IF_ICMPLT: case Const.IF_ICMPGT: OpcodeStack.Item item0 = stack.getStackItem(0); OpcodeStack.Item item1 = stack.getStackItem(1); if (item0.getConstant() instanceof Integer) { OpcodeStack.Item tmp = item0; if (seen == Const.IFLT && stack.getStackDepth() > 0 && stack.getStackItem(0).getSpecialKind() == OpcodeStack.Item.SIGNED_BYTE) { sawCheckForNonNegativeSignedByte = getPC();
private void pushByInvoke(DismantleBytecode dbc, boolean popThis) { String signature = dbc.getSigConstantOperand(); if (Const.CONSTRUCTOR_NAME.equals(dbc.getNameConstantOperand()) && signature.endsWith(")V") && popThis) { pop(PreorderVisitor.getNumberArguments(signature)); Item constructed = pop(); if (getStackDepth() > 0) { Item next = getStackItem(0); if (constructed.equals(next)) { next = new Item(next); next.source = XFactory.createReferencedXMethod(dbc); next.pc = dbc.getPC(); replace(0, next); } } return; } pop(PreorderVisitor.getNumberArguments(signature) + (popThis ? 1 : 0)); pushBySignature(new SignatureParser(signature).getReturnTypeSignature(), dbc); }
pop(); top = false; OpcodeStack.Item item = new Item("I"); push(item); if (!isTop() && (convertJumpToOneZeroState == 3 || convertJumpToZeroOneState == 3)) { pop(); Item topItem = new Item("I"); topItem.setCouldBeZero(true); push(topItem); convertJumpToOneZeroState = convertJumpToZeroOneState = 0; stackUpdated = true; boolean wasReachOnlyByBranch = isReachOnlyByBranch(); if (jumpEntry != null) { setReachOnlyByBranch(false); List<Item> jumpStackEntry = jumpStackEntries.get(Integer.valueOf(dbc.getPC())); if (isTop()) { lvValues = new ArrayList<>(jumpEntry); if (jumpStackEntry != null) { setTop(false); return; if (isReachOnlyByBranch()) { setTop(false); lvValues = new ArrayList<>(jumpEntry);
private boolean checkItem(int n) { if(bitresultItem != null) { for (int i = 0; i < n; i++) { if (stack.getStackItem(i) == bitresultItem) { return true; } } } arg1 = arg2 = null; bitresultItem = null; return false; }
@Override public void sawOpcode(int seen) { if (seen == Const.INVOKEVIRTUAL) { String methodName = getNameConstantOperand(); if (Values.HASHCODE.equals(methodName) && SignatureBuilder.SIG_VOID_TO_INT.equals(getSigConstantOperand()) && (stack.getStackDepth() > 0)) { String calledClass = stack.getStackItem(0).getSignature(); if (LANG3_HASH_CODE_BUILDER.equals(calledClass) || LANG_HASH_CODE_BUILDER.equals(calledClass)) { bugReporter.reportBug(new BugInstance(this, "CHTH_COMMONS_HASHCODE_BUILDER_TOHASHCODE", HIGH_PRIORITY).addClass(this).addMethod(this) .addSourceLine(this)); } } } super.sawOpcode(seen); stack.sawOpcode(this, seen); } }
/** * Factory method to create a MethodAnnotation from a method called by the * instruction the given visitor is currently visiting. * * @param visitor * the visitor * @return the MethodAnnotation representing the called method */ public static MethodAnnotation fromCalledMethod(DismantleBytecode visitor) { String className = visitor.getDottedClassConstantOperand(); String methodName = visitor.getNameConstantOperand(); String methodSig = visitor.getSigConstantOperand(); if (visitor instanceof OpcodeStackDetector && visitor.getOpcode() != Const.INVOKESTATIC) { int params = PreorderVisitor.getNumberArguments(methodSig); OpcodeStackDetector oVisitor = (OpcodeStackDetector) visitor; if (!oVisitor.getStack().isTop() && oVisitor.getStack().getStackDepth() > params) { OpcodeStack.Item item = oVisitor.getStack().getStackItem(params); String cName = ClassName.fromFieldSignature(item.getSignature()); if (cName != null) { className = cName; } } } return fromCalledMethod(className, methodName, methodSig, visitor.getOpcode() == Const.INVOKESTATIC); }
@Override public void sawOpcode(int seen) { stack.precomputation(this); stack.sawOpcode(this, seen); pw.println(String.format("After executing: %-16s at PC: %-5d Stack Size: %-3d", Constants.OPCODE_NAMES[getOpcode()], Integer.valueOf(getPC()), Integer.valueOf(stack.getStackDepth()))); } }
public static @CheckForNull BugAnnotation getSomeSource(ClassContext classContext, Method method, Location location, OpcodeStack stack, int stackPos) { if (stack.isTop()) { return null; } int pc = location.getHandle().getPosition(); try { BugAnnotation result = ValueNumberSourceInfo.getFromValueNumber(classContext, method, location, stackPos); if (result != null) { return result; } } catch (DataflowAnalysisException e) { AnalysisContext.logError("Couldn't find value source", e); } catch (CFGBuilderException e) { AnalysisContext.logError("Couldn't find value source", e); } return getValueSource(stack.getStackItem(stackPos), method, pc); }
/** * implements the visitor to reset the opcode stack for a new method * * @param obj * the currently parsed method */ @Override public void visitMethod(Method obj) { stack.resetForMethodEntry(this); }
/** * constructs a CHTH detector given the reporter to report bugs on. * * @param bugReporter * the sync of bug reports */ public CommonsHashcodeBuilderToHashcode(final BugReporter bugReporter) { stack = new OpcodeStack(); this.bugReporter = bugReporter; }
stack.mergeJumps(this); stack.sawOpcode(this, seen);
/** * <p>Note that stack might be TOP when this method is called.</p> * @see #sawOpcode(int) */ @Override @OverridingMethodsMustInvokeSuper public void afterOpcode(int seen) { stack.sawOpcode(this, seen); }