Search in sources :

Example 56 with INaviView

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

the class CResultColorTest method testFirst.

@Test
public void testFirst() throws InternalTranslationException {
    final MockSqlProvider mockProvider = new MockSqlProvider();
    final MockModule mockModule = new MockModule(mockProvider);
    // str 6, , t1
    final COperandTreeNode rootNode1 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTreeNode childNode1 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_IMMEDIATE_INT_ID, "6", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    COperandTreeNode.link(rootNode1, childNode1);
    final COperandTreeNode rootNode2 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTreeNode childNode2 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SYMBOL_ID, ",", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    COperandTreeNode.link(rootNode2, childNode2);
    final COperandTreeNode rootNode3 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTreeNode childNode3 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_REGISTER_ID, "t1", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    COperandTreeNode.link(rootNode3, childNode3);
    final COperandTree operand1 = new COperandTree(rootNode1, mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTree operand2 = new COperandTree(rootNode2, mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTree operand3 = new COperandTree(rootNode3, mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final List<COperandTree> operands1 = Lists.newArrayList(operand1, operand2, operand3);
    final INaviInstruction instruction1 = new CInstruction(false, mockModule, new CAddress(1), "str", operands1, new byte[0], "REIL", mockProvider);
    // str 5, , t0
    final COperandTreeNode rootNode4 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTreeNode childNode4 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_IMMEDIATE_INT_ID, "5", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    COperandTreeNode.link(rootNode4, childNode4);
    final COperandTreeNode rootNode5 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTreeNode childNode5 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SYMBOL_ID, ",", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    COperandTreeNode.link(rootNode5, childNode5);
    final COperandTreeNode rootNode6 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTreeNode childNode6 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_REGISTER_ID, "t0", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    COperandTreeNode.link(rootNode6, childNode6);
    final COperandTree operand4 = new COperandTree(rootNode4, mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTree operand5 = new COperandTree(rootNode5, mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTree operand6 = new COperandTree(rootNode6, mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final List<COperandTree> operands2 = Lists.newArrayList(operand4, operand5, operand6);
    final INaviInstruction instruction2 = new CInstruction(false, mockModule, new CAddress(2), "str", operands2, new byte[0], "REIL", mockProvider);
    // add t0, t1, t2
    final COperandTreeNode rootNode7 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTreeNode childNode7 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_REGISTER_ID, "t0", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    COperandTreeNode.link(rootNode7, childNode7);
    final COperandTreeNode rootNode8 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTreeNode childNode8 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_REGISTER_ID, "t1", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    COperandTreeNode.link(rootNode8, childNode8);
    final COperandTreeNode rootNode9 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTreeNode childNode9 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_REGISTER_ID, "t2", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    COperandTreeNode.link(rootNode9, childNode9);
    final COperandTree operand7 = new COperandTree(rootNode7, mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTree operand8 = new COperandTree(rootNode8, mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTree operand9 = new COperandTree(rootNode9, mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final List<COperandTree> operands3 = Lists.newArrayList(operand7, operand8, operand9);
    final INaviInstruction instruction3 = new CInstruction(false, mockModule, new CAddress(3), "add", operands3, new byte[0], "REIL", mockProvider);
    final INaviView view = mockModule.getContent().getViewContainer().createView("", "");
    final List<INaviInstruction> instructions = Lists.newArrayList(instruction1, instruction2, instruction3);
    view.getContent().createCodeNode(null, instructions);
    final RegisterTrackingOptions options = new RegisterTrackingOptions(true, new HashSet<String>(), false, AnalysisDirection.UP);
    final CTrackingResult results = CTracking.track(view, instruction3, "t2", options);
    for (final CInstructionResult result : results.getResults()) {
        if (result.getInstruction() == instruction1) {
            assertEquals(Color.RED, CResultColor.determineBackgroundColor(instruction3, "t2", result));
        } else if (result.getInstruction() == instruction2) {
            assertEquals(Color.CYAN, CResultColor.determineBackgroundColor(instruction3, "t2", result));
        } else if (result.getInstruction() == instruction3) {
            assertEquals(Color.GREEN, CResultColor.determineBackgroundColor(instruction3, "t2", result));
        }
    }
}
Also used : RegisterTrackingOptions(com.google.security.zynamics.reil.algorithms.mono2.registertracking.RegisterTrackingOptions) COperandTreeNode(com.google.security.zynamics.binnavi.disassembly.COperandTreeNode) CInstruction(com.google.security.zynamics.binnavi.disassembly.CInstruction) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) CTrackingResult(com.google.security.zynamics.binnavi.Gui.GraphWindows.BottomPanel.RegisterTracker.CTrackingResult) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) CInstructionResult(com.google.security.zynamics.binnavi.Gui.GraphWindows.BottomPanel.RegisterTracker.CInstructionResult) IReference(com.google.security.zynamics.zylib.disassembly.IReference) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) Test(org.junit.Test)

Example 57 with INaviView

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

the class PostgreSQLViewFunctions method getDerivedViews.

/**
   * Returns the derived views of the given view.
   * 
   * @param provider Provides the connection to the database.
   * @param view The view whose derived views are returned.
   * 
   * @return The derived views.
   * 
   * @throws CouldntLoadDataException Thrown if the derived views could not be determined.
   */
public static List<INaviView> getDerivedViews(final AbstractSQLProvider provider, final INaviView view) throws CouldntLoadDataException {
    checkArguments(provider, view);
    final List<INaviView> views = new ArrayList<INaviView>();
    // currently project views can not have derived views.
    if (view.getConfiguration().getModule() == null) {
        return views;
    }
    final String query = "SELECT * FROM get_derived_views(?)";
    try (PreparedStatement statement = provider.getConnection().getConnection().prepareStatement(query)) {
        // TODO(timkornau): this should be changed to the ViewManager.
        final List<INaviView> moduleViews = view.getConfiguration().getModule().getContent().getViewContainer().getViews();
        statement.setInt(1, view.getConfiguration().getId());
        final ResultSet resultSet = statement.executeQuery();
        if (resultSet == null) {
            return views;
        }
        while (resultSet.next()) {
            final int viewId = resultSet.getInt(1);
            if (viewId != view.getConfiguration().getId()) {
                for (final INaviView moduleView : moduleViews) {
                    if (moduleView.getConfiguration().getId() == viewId) {
                        views.add(moduleView);
                        break;
                    }
                }
            }
        }
        return views;
    } catch (final SQLException e) {
        throw new CouldntLoadDataException(e);
    }
}
Also used : INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 58 with INaviView

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

the class PostgreSQLViewNotificationParser method informModuleNotification.

/**
   * The inform function for notifications from the bn_module_views table. This function is used
   * when a module view is created or deleted.
   *
   * @param moduleViewNotificationContainer The {@link ViewNotificationContainer} to use as data
   *        source.
   * @param provider The {@link SQLProvider} to access the database.
   * @throws CouldntLoadDataException if the information could not be loaded from the database.
   */
private void informModuleNotification(final ViewNotificationContainer moduleViewNotificationContainer, final SQLProvider provider) throws CouldntLoadDataException {
    if (moduleViewNotificationContainer.getDatabaseOperation().equals("INSERT")) {
        final INaviModule module = moduleViewNotificationContainer.getNotificationModule().get();
        if (!module.isLoaded()) {
            return;
        }
        final Integer viewId = moduleViewNotificationContainer.getViewId();
        final ImmutableNaviViewConfiguration databaseViewConfiguration = provider.loadFlowGraphInformation(module, viewId);
        final CModuleViewGenerator generator = new CModuleViewGenerator(provider, module);
        final INaviView view = generator.generate(databaseViewConfiguration, GraphType.FLOWGRAPH);
        module.getContent().getViewContainer().addView(view);
    }
    if (moduleViewNotificationContainer.getDatabaseOperation().equals("UPDATE")) {
        // updates will not happen as this is only a mapping of id to id.
        return;
    }
    if (moduleViewNotificationContainer.getDatabaseOperation().equals("DELETE")) {
        final INaviModule module = moduleViewNotificationContainer.getNotificationModule().get();
        if (!module.isLoaded()) {
            return;
        }
        final Integer viewId = moduleViewNotificationContainer.getViewId();
        final INaviView view = ViewManager.get(provider).getView(viewId);
        module.getContent().getViewContainer().deleteViewInternal(view);
    }
}
Also used : ImmutableNaviViewConfiguration(com.google.security.zynamics.binnavi.disassembly.views.ImmutableNaviViewConfiguration) CModuleViewGenerator(com.google.security.zynamics.binnavi.Database.CModuleViewGenerator) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule)

Example 59 with INaviView

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

the class PostgreSQLViewsLoader method loadViewFunctionMapping.

/**
   * Loads the view -> function mapping from the database.
   * 
   * @param provider The SQL provider that provides the connection.
   * @param flowgraphs List of all native Flow graph views of a module.
   * @param functions List of all functions of a module.
   * @param module The module from which to load the mapping.
   * 
   * @return A view -> function mapping and a function -> view mapping.
   * 
   * @throws CouldntLoadDataException Thrown if the mapping could not be loaded.
   */
public static final ImmutableBiMap<INaviView, INaviFunction> loadViewFunctionMapping(final AbstractSQLProvider provider, final List<IFlowgraphView> flowgraphs, final List<INaviFunction> functions, final CModule module) throws CouldntLoadDataException {
    checkArguments(provider, module, flowgraphs, functions);
    final HashMap<Integer, INaviView> viewmap = new HashMap<Integer, INaviView>();
    for (final IFlowgraphView view : flowgraphs) {
        viewmap.put(view.getConfiguration().getId(), view);
    }
    final HashMap<IAddress, INaviFunction> functionMap = new HashMap<IAddress, INaviFunction>();
    for (final INaviFunction function : functions) {
        functionMap.put(function.getAddress(), function);
    }
    final CConnection connection = provider.getConnection();
    final String query = "SELECT view_id, function FROM " + CTableNames.FUNCTION_VIEWS_TABLE + " WHERE module_id = " + module.getConfiguration().getId();
    final HashMap<INaviView, INaviFunction> viewFunctionMap = new HashMap<INaviView, INaviFunction>();
    try {
        final ResultSet resultSet = connection.executeQuery(query, true);
        try {
            while (resultSet.next()) {
                final INaviView view = viewmap.get(resultSet.getInt("view_id"));
                final INaviFunction function = functionMap.get(PostgreSQLHelpers.loadAddress(resultSet, "function"));
                if ((view != null) && (function != null)) {
                    viewFunctionMap.put(view, function);
                }
            }
        } finally {
            resultSet.close();
        }
        return new ImmutableBiMap.Builder<INaviView, INaviFunction>().putAll(viewFunctionMap).build();
    } catch (final SQLException e) {
        throw new CouldntLoadDataException(e);
    }
}
Also used : IFlowgraphView(com.google.security.zynamics.binnavi.disassembly.IFlowgraphView) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) CConnection(com.google.security.zynamics.binnavi.Database.CConnection) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) ResultSet(java.sql.ResultSet) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction)

Example 60 with INaviView

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

the class PostgreSQLViewNotificationParser method informViewNotification.

/**
   * The inform function for notifications from the bn_views table. This function is used when a
   * view gets edited. But this function will not perform any action when a view is deleted or
   * created.
   *
   * @param viewNotificationContainer The {@link ViewNotificationContainer} to use as data source.
   * @param provider The {@link SQLProvider} to access the database with.
   * @throws CouldntLoadDataException if the information could not be loaded from the database.
   */
private void informViewNotification(final ViewNotificationContainer viewNotificationContainer, final SQLProvider provider) throws CouldntLoadDataException {
    if (viewNotificationContainer.getDatabaseOperation().equals("INSERT")) {
        // we ignore inserts as we need to know if this was a module or project view.
        return;
    }
    if (viewNotificationContainer.getDatabaseOperation().equals("UPDATE")) {
        final Integer viewId = viewNotificationContainer.getViewId();
        final INaviView view = viewNotificationContainer.getView().get();
        final ImmutableNaviViewConfiguration databaseViewConfiguration = view.getConfiguration().getModule() == null ? provider.loadFlowGraphInformation(view.getConfiguration().getProject(), viewId) : provider.loadFlowGraphInformation(view.getConfiguration().getModule(), viewId);
        if (databaseViewConfiguration == null) {
            return;
        }
        if (!databaseViewConfiguration.getName().equals(view.getConfiguration().getName())) {
            view.getConfiguration().setNameInternal(databaseViewConfiguration.getName());
        }
        if (databaseViewConfiguration.getDescription() != view.getConfiguration().getDescription() && !databaseViewConfiguration.getDescription().equals(view.getConfiguration().getDescription())) {
            view.getConfiguration().setDescriptionInternal(databaseViewConfiguration.getDescription());
        }
        if (databaseViewConfiguration.getStarState() != view.getConfiguration().isStared()) {
            view.getConfiguration().setStaredInternal(databaseViewConfiguration.getStarState());
        }
        view.getConfiguration().setModificationDateInternal(databaseViewConfiguration.getModificationDate());
    }
    if (viewNotificationContainer.getDatabaseOperation().equals("DELETE")) {
        // we ignore deletes as we need to know if this was a module or project view.
        return;
    }
}
Also used : ImmutableNaviViewConfiguration(com.google.security.zynamics.binnavi.disassembly.views.ImmutableNaviViewConfiguration) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView)

Aggregations

INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)121 Test (org.junit.Test)54 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)29 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)26 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)18 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)14 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)13 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)11 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)10 CView (com.google.security.zynamics.binnavi.disassembly.views.CView)10 ArrayList (java.util.ArrayList)10 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)9 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)8 HashMap (java.util.HashMap)8 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)7 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)7 CProjectContainer (com.google.security.zynamics.binnavi.disassembly.CProjectContainer)7 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)7 FilledList (com.google.security.zynamics.zylib.types.lists.FilledList)7 MockTagManager (com.google.security.zynamics.binnavi.Tagging.MockTagManager)6