Search in sources :

Example 6 with INaviOperandTreeNode

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

the class ZyOperandBuilder method isVariableAccess.

/**
 * Determines whether a given node represents variable access.
 *
 * @param node The node to check.
 *
 * @return True, if the node represents an expression that accesses a variable. False, otherwise.
 */
private static boolean isVariableAccess(final INaviOperandTreeNode node) {
    try {
        final INaviOperandTreeNode memoryAccessNode = getMemoryAccessNode(node);
        final List<INaviOperandTreeNode> children = memoryAccessNode.getChildren();
        if (children.size() == 1) {
            final INaviOperandTreeNode child = children.get(0);
            switch(child.getType()) {
                case SIZE_PREFIX:
                    return isVariable(child.getChildren().get(0));
                case IMMEDIATE_INTEGER:
                    return isVariable(child);
                case OPERATOR:
                    return isOperatorVariableAccess(child);
                default:
                    return false;
            }
        } else {
            throw new IllegalStateException("IE00703: Invalid tree shape");
        }
    } catch (final MaybeNullException e) {
        return false;
    }
}
Also used : INaviOperandTreeNode(com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)

Example 7 with INaviOperandTreeNode

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

the class PostgreSQLTypesNotificationParser method findOperandTreeNode.

/**
 * Only used internally to find the necessary {@link INaviOperandTreeNode operand node} where a
 * {@link TypeSubstitution type substitution} is associated to.
 *
 * @param provider The {@link SQLProvider} used to differentiate between the different caches used
 *        for getting {@link INaviInstruction instructions}.
 * @param moduleId The id of the {@link INaviModule module} this {@link TypeSubstitution type
 *        substitution} is associated to.
 * @param address The {@link CAddress} of the {@link INaviInstruction instruction} where the
 *        {@link TypeSubstitution type substitution} is associated to.
 * @param position The {@link INaviOperandTree operand tree} position where the
 *        {@link TypeSubstitution type substitution} is associated to.
 * @param operandNodeId the id of the {@link INaviOperandTreeNode operand node} to which the
 *        {@link TypeSubstitution type substitution} is associated.
 * @return A {@link INaviOperandTreeNode} if it is in the cache otherwise null;
 */
private INaviOperandTreeNode findOperandTreeNode(final SQLProvider provider, final int moduleId, final CAddress address, final int position, final int operandNodeId) {
    final INaviInstruction instruction = InstructionCache.get(provider).getInstructionByAddress(address, moduleId);
    if (instruction != null) {
        final INaviOperandTree operandTree = instruction.getOperands().get(position);
        final INaviOperandTreeNode root = operandTree.getRootNode();
        final OperandOrderIterator iterator = new OperandOrderIterator(root);
        while (iterator.next()) {
            final INaviOperandTreeNode currentNode = (INaviOperandTreeNode) iterator.current();
            if (currentNode.getId() == operandNodeId) {
                return currentNode;
            }
        }
    }
    return null;
}
Also used : INaviOperandTreeNode(com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode) INaviOperandTree(com.google.security.zynamics.binnavi.disassembly.INaviOperandTree) OperandOrderIterator(com.google.security.zynamics.zylib.disassembly.OperandOrderIterator) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 8 with INaviOperandTreeNode

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

the class PostgreSQLTypesNotificationParser method informExpressionTypesNotification.

/**
 * Informs about necessary state changes related to {@link TypeSubstitution type substitutions}.
 *
 * @param container The {@link TypesNotificationContainer} holding the parsed
 *        {@link PGNotification notification} information.
 * @param provider The {@link SQLProvider} used to access the database with.
 *
 * @throws CouldntLoadDataException if the required information could not be loaded from the
 *         database.
 */
private void informExpressionTypesNotification(final TypesNotificationContainer container, final SQLProvider provider) throws CouldntLoadDataException {
    final INaviModule module = provider.findModule(container.getModuleId());
    final TypeManager typeManager = module.getTypeManager();
    final INaviOperandTreeNode node = findOperandTreeNode(provider, container.getModuleId(), new CAddress(container.getAddress().get()), container.position().get(), container.expressionId().get());
    if (node == null) {
        return;
    }
    if (container.getDatabaseOperation().equals("INSERT")) {
        final RawTypeSubstitution rawSubstitution = provider.loadTypeSubstitution(module, container.getAddress().get(), container.position().get(), container.expressionId().get());
        typeManager.initializeTypeSubstitution(node, rawSubstitution);
    } else if (container.getDatabaseOperation().equals("UPDATE")) {
        final RawTypeSubstitution rawSubstitution = provider.loadTypeSubstitution(module, container.getAddress().get(), container.position().get(), container.expressionId().get());
        typeManager.updateTypeSubstitution(node, rawSubstitution.getBaseTypeId(), rawSubstitution.getPath(), rawSubstitution.getOffset());
    } else if (container.getDatabaseOperation().equals("DELETE")) {
        typeManager.removeTypeSubstitutionInstance(node.getTypeSubstitution());
    } else {
        throw new IllegalStateException("Error: the database operation " + container.getDatabaseOperation() + " is currently not supported.");
    }
}
Also used : INaviOperandTreeNode(com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) TypeManager(com.google.security.zynamics.binnavi.disassembly.types.TypeManager) RawTypeSubstitution(com.google.security.zynamics.binnavi.disassembly.types.RawTypeSubstitution) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Example 9 with INaviOperandTreeNode

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

the class TypeManagerExpensiveTests method testCreateTypeSubstitution.

private void testCreateTypeSubstitution(final INaviModule module) throws CouldntSaveDataException, CouldntLoadDataException, CouldntDeleteException {
    final TypeManager manager = module.getTypeManager();
    final BaseType baseType = manager.createAtomicType(TypeName, 32, true);
    final INaviOperandTreeNode treeNode = new MockOperandTreeNode();
    final int offset = 0;
    final CAddress address = new CAddress(0x1000);
    final TypeSubstitution substitution = manager.createTypeSubstitution(treeNode, baseType, 0, offset, address);
    Assert.assertEquals(substitution.getAddress(), address);
    Assert.assertTrue(substitution.getBaseType() == baseType);
    Assert.assertTrue(substitution.getOffset() == offset);
    Assert.assertTrue(substitution.getOperandTreeNode() == treeNode);
    Assert.assertTrue(substitution.getExpressionId() == treeNode.getId());
    final List<RawTypeSubstitution> substitutions = getProvider().loadTypeSubstitutions(module);
    final List<RawTypeSubstitution> foundSubstitutions = findRawTypeSubstitutions(substitutions, treeNode.getId());
    Assert.assertTrue(foundSubstitutions.size() == 1);
    final RawTypeSubstitution foundSubstitution = foundSubstitutions.get(0);
    matchTypeSubstitution(substitution, foundSubstitution);
    manager.deleteType(baseType);
}
Also used : INaviOperandTreeNode(com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode) MockOperandTreeNode(com.google.security.zynamics.binnavi.disassembly.MockOperandTreeNode) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Example 10 with INaviOperandTreeNode

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

the class PostgreSQLInstructionFunctions method createExpressionTree.

/**
 * Creates a new expression tree in the database.
 *
 * @param provider The connection to the database.
 * @param nodes The nodes of the tree to be saved.
 *
 * @return The ID of the created tree in the database.
 *
 * @throws SQLException Thrown if the tree could not be created.
 */
private static int createExpressionTree(final SQLProvider provider, final Set<INaviOperandTreeNode> nodes, final INaviModule module) throws SQLException {
    final int moduleId = module.getConfiguration().getId();
    final ResultSet resultSet = provider.getConnection().executeQuery("select max(id) + 1 AS id from " + CTableNames.EXPRESSION_TREE_IDS_TABLE + " where module_id = " + moduleId, true);
    int expressionTreeId = -1;
    try {
        if (resultSet.next()) {
            expressionTreeId = resultSet.getInt("id");
        }
    } finally {
        resultSet.close();
    }
    provider.getConnection().executeUpdate(String.format("insert into " + CTableNames.EXPRESSION_TREE_IDS_TABLE + " values(%d , %d)", moduleId, expressionTreeId), true);
    for (final INaviOperandTreeNode node : nodes) {
        provider.getConnection().executeUpdate(String.format("insert into " + CTableNames.EXPRESSION_TREE_MAPPING_TABLE + " values(%d, %d, %d)", moduleId, expressionTreeId, node.getId()), true);
    }
    return expressionTreeId;
}
Also used : INaviOperandTreeNode(com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode) ResultSet(java.sql.ResultSet)

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