Search in sources :

Example 1 with INaviOperandTreeNode

use of com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode in project binnavi by google.

the class CExpressionEvaluator method evaluateOperator.

/**
 * Evaluates an operator node.
 *
 * @param node The operator node to evaluate.
 * @param registers Register values to use during expression evaluation.
 * @param debugger The active debugger.
 * @param module The module the node belongs to.
 *
 * @return The evaluated value.
 *
 * @throws CExpressionEvaluationException Thrown if the expression could not be evaluated.
 */
private static BigInteger evaluateOperator(final INaviOperandTreeNode node, final ImmutableList<RegisterValue> registers, final IDebugger debugger, final INaviModule module) throws CExpressionEvaluationException {
    final List<INaviOperandTreeNode> children = node.getChildren();
    BigInteger initial = evaluateExpression(children.get(0), registers, debugger, module);
    for (int i = 1; i < children.size(); i++) {
        if (node.getValue().equals("+")) {
            initial = initial.add(evaluateExpression(children.get(i), registers, debugger, module));
        } else if (node.getValue().equals("-")) {
            initial = initial.subtract(evaluateExpression(children.get(i), registers, debugger, module));
        } else if (node.getValue().equals("*")) {
            initial = initial.multiply(evaluateExpression(children.get(i), registers, debugger, module));
        } else {
            throw new CExpressionEvaluationException(String.format("Unknown operand '%s'", node.getValue()));
        }
    }
    return initial;
}
Also used : INaviOperandTreeNode(com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode) BigInteger(java.math.BigInteger)

Example 2 with INaviOperandTreeNode

use of com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode in project binnavi by google.

the class CCodeNodeUpdater method initializeListeners.

/**
 * Initializes the listeners that are responsible for updating the code node.
 */
private void initializeListeners() {
    try {
        codeNode.getParentFunction().addListener(functionUpdater);
        codeNode.getParentFunction().getModule().addListener(moduleUpdater);
    } catch (final MaybeNullException exception) {
    // The code nodes does not have a parent function, therefore the information
    // about the parent function is not shown in the code and does not have to
    // be processed when updating.
    }
    final HashMap<INaviInstruction, INaviFunction> referenceMap = CReferenceFinder.getCodeReferenceMap(codeNode);
    for (final INaviFunction functionReference : Sets.newHashSet(referenceMap.values())) {
        functionReference.addListener(functionUpdater);
    }
    codeNode.addListener(codeNodeListener);
    for (final INaviInstruction instruction : codeNode.getInstructions()) {
        instruction.addListener(instructionUpdater);
        for (final COperandTree tree : instruction.getOperands()) {
            for (final INaviOperandTreeNode currentNode : tree.getNodes()) {
                currentNode.addListener(operandTreeUpdater);
            }
        }
    }
    final Iterator<CTag> it = codeNode.getTagsIterator();
    while (it.hasNext()) {
        it.next().addListener(tagUpdater);
    }
    for (final IDebugger debugger : provider.getDebuggers()) {
        debugger.getProcessManager().addListener(debuggerUpdater);
    }
    provider.addListener(debuggerProviderListener);
    graph.getSettings().getDisplaySettings().addListener(settingsUpdater);
    try {
        codeNode.getParentFunction().getModule().getTypeManager().addListener(substitutionsUpdater);
    } catch (final MaybeNullException exception) {
    // If the code node doesn't have a a parent function, it is not in the database and therefore
    // cannot receive type substitutions.
    }
}
Also used : INaviOperandTreeNode(com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) IDebugger(com.google.security.zynamics.binnavi.debug.debugger.interfaces.IDebugger) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 3 with INaviOperandTreeNode

use of com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode in project binnavi by google.

the class BaseTypeTransferHandler method createOrUpdateTypeSubstitution.

/**
 * Locate operand tree node and use type manager to assign type substitution.
 */
private boolean createOrUpdateTypeSubstitution(final DragAndDropSupportWrapper wrapper) throws UnsupportedFlavorException, IOException, CouldntSaveDataException {
    final INaviOperandTreeNode node = wrapper.determineDropNode();
    if (!isLegalDropNode(node)) {
        return false;
    }
    final BaseType baseType = wrapper.getDroppedBaseType();
    if (node.getTypeSubstitution() != null) {
        typeManager.updateTypeSubstitution(node, node.getTypeSubstitution(), baseType, new ArrayList<TypeMember>(), 0);
    } else {
        // When creating a substitution via drag and drop, the offset is always zero to have a
        // better workflow for the user (otherwise we would need an additional dialog each time).
        typeManager.createTypeSubstitution(node, baseType, node.getOperandPosition(), 0, /* offset */
        node.getInstructionAddress());
    }
    return true;
}
Also used : INaviOperandTreeNode(com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode) BaseType(com.google.security.zynamics.binnavi.disassembly.types.BaseType) TypeMember(com.google.security.zynamics.binnavi.disassembly.types.TypeMember)

Example 4 with INaviOperandTreeNode

use of com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode in project binnavi by google.

the class ZyOperandBuilder method getUnsignedBigIntegerString.

private static String getUnsignedBigIntegerString(final BigInteger value, final COperandTreeNode node, final int radix) {
    // We only need to take care of values which are less than zero.
    if (value.signum() != -1) {
        return value.toString(radix);
    }
    INaviOperandTreeNode currentNode = node.getParent();
    while (currentNode.getType() != ExpressionType.SIZE_PREFIX) {
        if (currentNode.getParent() == null) {
            throw new IllegalStateException("Error: could not determine size of operand.");
        }
        currentNode = currentNode.getParent();
    }
    final BigInteger twosComplement = value.abs().not().add(BigInteger.ONE);
    // information of an operand node need to be stored in different fields. b/11566525
    switch(currentNode.getValue()) {
        case "byte":
            return twosComplement.and(new BigInteger("FF", 16)).toString(radix);
        case "word":
            return twosComplement.and(new BigInteger("FFFF", 16)).toString(radix);
        case "dword":
            return twosComplement.and(new BigInteger("FFFFFFFF", 16)).toString(radix);
        case "fword":
            return twosComplement.and(new BigInteger("FFFFFFFFFFFF", 16)).toString(radix);
        case "qword":
            return twosComplement.and(new BigInteger("FFFFFFFFFFFFFFFF", 16)).toString(radix);
        case "oword":
            return twosComplement.and(new BigInteger("FFFFFFFFFFFFFFFFFFFF", 16)).toString(radix);
        default:
            throw new IllegalStateException("Error: size of operand tree node is not supported.");
    }
}
Also used : INaviOperandTreeNode(com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode) BigInteger(java.math.BigInteger)

Example 5 with INaviOperandTreeNode

use of com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode in project binnavi by google.

the class ZyOperandBuilder method isOperatorVariableAccess.

/**
 * Determines whether a given node is a variable access node that can be simplified.
 *
 * @param node The node to check.
 *
 * @return True, if the node can be simplified. False, otherwise.
 */
private static boolean isOperatorVariableAccess(final INaviOperandTreeNode node) {
    final List<INaviOperandTreeNode> children = node.getChildren();
    if (children.size() == 2) {
        // An expression can be simplified if it is of the form 'REGISTER + VARIABLE'
        final INaviOperandTreeNode child0 = children.get(0);
        final INaviOperandTreeNode child1 = children.get(1);
        return isVariable(child0) ^ isVariable(child1);
    } else {
        return false;
    }
}
Also used : INaviOperandTreeNode(com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode)

Aggregations

INaviOperandTreeNode (com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode)25 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)9 Test (org.junit.Test)8 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)7 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)7 COperandTree (com.google.security.zynamics.binnavi.disassembly.COperandTree)6 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)6 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)6 IBlockNode (com.google.security.zynamics.binnavi.disassembly.IBlockNode)5 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)5 BigInteger (java.math.BigInteger)4 MockOperandTreeNode (com.google.security.zynamics.binnavi.disassembly.MockOperandTreeNode)3 ReferenceType (com.google.security.zynamics.zylib.disassembly.ReferenceType)3 MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)2 INaviOperandTree (com.google.security.zynamics.binnavi.disassembly.INaviOperandTree)2 TypeInstanceContainer (com.google.security.zynamics.binnavi.disassembly.types.TypeInstanceContainer)2 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)2 OperandOrderIterator (com.google.security.zynamics.zylib.disassembly.OperandOrderIterator)2 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)1 CGotoOperandExpressionAction (com.google.security.zynamics.binnavi.ZyGraph.Menus.Actions.CGotoOperandExpressionAction)1