@Override public void execute(ExecutionNode node, MethodState mState) { HeapItem arrayItem = mState.readRegister(arrayRegister); Object array = arrayItem.getValue(); Object lengthValue = null; if (arrayItem.isUnknown()) { lengthValue = new UnknownValue(); } else if (array == null) { node.clearChildren(); return; } else if (array.getClass().isArray()) { lengthValue = Array.getLength(array); node.clearExceptions(); } else { // Won't pass DEX verifier if it's not an array class. Probably our fault, so error. if (log.isErrorEnabled()) { log.error("Unexpected non-array class: {}, {}", array.getClass(), array); } } mState.assignRegister(destRegister, lengthValue, CommonTypes.INTEGER); }
@Override public void execute(ExecutionNode node, MethodState mState) { Object constant = buildConstant(); if (constant instanceof Throwable) { node.setException((Throwable) constant); node.clearChildren(); return; } else { node.clearExceptions(); } mState.assignRegister(destRegister, constant, getConstantTypeString()); }
@Override public void execute(ExecutionNode node, MethodState mState) { HeapItem lengthItem = mState.readRegister(lengthRegister); Object instance = buildInstance(lengthItem); if (instance instanceof Throwable) { node.setException((Throwable) instance); node.clearChildren(); return; } else { node.clearExceptions(); } mState.assignRegister(destRegister, instance, arrayType); }
} else { node.clearExceptions(); Object value = Array.get(array, index); getItem = new HeapItem(value, innerType); node.clearExceptions();
@Override public void execute(ExecutionNode node, MethodState mState) { HeapItem item = mState.readRegister(targetRegister); boolean isInstance = isInstance(item, castType, classManager); if (isInstance) { node.clearExceptions(); mState.assignRegister(targetRegister, item.getValue(), castType.getName()); } else { // E.g. java.lang.ClassCastException: java.lang.String cannot be cast to java.io.File String error = ClassNameUtils.internalToBinary(item.getType()) + " cannot be cast to " + castType.getBinaryName(); Throwable exception = exceptionFactory.build(this, ClassCastException.class, error); node.setException(exception); if (!item.isUnknown()) { // Exception is certain to happen since we had all class information // exception is certain. node.clearChildren(); } } }
@Override public void execute(ExecutionNode node, MethodState mState) { HeapItem lhsItem = mState.readRegister(arg1Register); HeapItem rhsItem; if (hasLiteral) { rhsItem = new HeapItem(narrowLiteral, CommonTypes.INTEGER); } else { rhsItem = mState.readRegister(arg2Register); } Object result = null; if (!lhsItem.isUnknown() && !rhsItem.isUnknown()) { result = getResult(lhsItem.getValue(), rhsItem.getValue()); if (result instanceof Throwable) { Throwable exception = (Throwable) result; node.setException(exception); node.clearChildren(); return; } else { node.clearExceptions(); } } if (null == result) { result = new UnknownValue(); } mState.assignRegister(destRegister, result, mathOperandType.getType()); }
Object value = castValue(getName(), valueItem.getValue()); Array.set(array, index, value); node.clearExceptions();