Search in sources :

Example 16 with INaviView

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

the class ExpensiveBaseTest method loadView.

public INaviView loadView(final INaviModule module, final String name) throws CouldntLoadDataException, CPartialLoadException, LoadCancelledException, MaybeNullException {
    final INaviView view = module.getContent().getViewContainer().getView(module.getContent().getFunctionContainer().getFunction(name));
    view.load();
    return view;
}
Also used : INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView)

Example 17 with INaviView

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

the class CPostgreSQLZyGraphTest2 method testSave.

@Test
public void testSave() throws CouldntSaveDataException, CouldntLoadDriverException, CouldntConnectException, InvalidDatabaseException, CouldntInitializeDatabaseException, CouldntLoadDataException, InvalidExporterDatabaseFormatException, InvalidDatabaseVersionException, CPartialLoadException, LoadCancelledException {
    m_view.getGraph().getNodes().get(0).setSelected(true);
    m_view.getGraph().getNodes().get(1).setColor(new Color(123));
    m_view.getGraph().getNodes().get(2).setX(456);
    m_view.getGraph().getNodes().get(3).setY(789);
    final INaviView newView = m_graph.saveAs(new CModuleContainer(m_database, m_module), "New View", "New View Description");
    m_database2.connect();
    m_database2.load();
    final INaviModule module = m_database2.getContent().getModules().get(0);
    module.load();
    final Iterable<INaviView> views = CViewFilter.getFlowgraphViews(module.getContent().getViewContainer().getViews());
    final INaviView loadedNewView = Iterables.getLast(views);
    loadedNewView.load();
    assertEquals(loadedNewView.getNodeCount(), newView.getNodeCount());
    assertEquals(true, loadedNewView.getGraph().getNodes().get(0).isSelected());
    assertEquals(0xFF00007B, loadedNewView.getGraph().getNodes().get(1).getColor().getRGB());
    assertEquals(456, loadedNewView.getGraph().getNodes().get(2).getX(), 0);
    assertEquals(789, loadedNewView.getGraph().getNodes().get(3).getY(), 0);
    m_database2.close();
}
Also used : INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) Color(java.awt.Color) CModuleContainer(com.google.security.zynamics.binnavi.disassembly.Modules.CModuleContainer) Test(org.junit.Test)

Example 18 with INaviView

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

the class PostgreSQLFunctionsLoader method parseFunctionInformation.

/**
   * This function parses a {@link ResultSet result set} from a database query and generates a
   * {@link List} of {@link INaviFunction} from it.
   *
   * @param resultSet The {@link ResultSet} in which the result from the database query is stored.
   * @param provider The {@link SQLProvider} to access the database with.
   * @param module The {@link INaviModule} to which the {@link INaviFunction function(s)} are
   *        associated.
   *
   * @return A {@link List} of {@link INaviFunction functions} parsed from the {@link ResultSet
   *         resultSet}.
   *
   * @throws SQLException if the {@link ResultSet} could not be parsed.
   * @throws CouldntLoadDataException if the associated comments could not be loaded from the
   *         database.
   */
private static List<INaviFunction> parseFunctionInformation(final ResultSet resultSet, final SQLProvider provider, final INaviModule module) throws SQLException, CouldntLoadDataException {
    final List<INaviFunction> functions = Lists.newArrayList();
    final Map<Integer, INaviFunction> commentIdToFunction = new HashMap<Integer, INaviFunction>();
    try {
        while (resultSet.next()) {
            final IAddress address = PostgreSQLHelpers.loadAddress(resultSet, "address");
            final String name = resultSet.getString("name");
            final String originalName = resultSet.getString("original_name");
            Integer globalCommentId = resultSet.getInt("global_comment");
            if (resultSet.wasNull()) {
                globalCommentId = null;
            }
            final String description = resultSet.getString("description");
            final FunctionType type = FunctionType.valueOf(resultSet.getString("type").toUpperCase());
            final String parentModuleName = resultSet.getString("parent_module_name");
            final int parentModuleId = resultSet.getInt("parent_module_id");
            final IAddress parentModuleFunction = resultSet.wasNull() ? null : PostgreSQLHelpers.loadAddress(resultSet, "parent_module_function");
            final Integer nodeCount = resultSet.getInt("bbcount");
            final Integer edgeCount = resultSet.getInt("edgeCount");
            final Integer indegree = resultSet.getInt("incount");
            final Integer outdegree = resultSet.getInt("outcount");
            Integer stackFrameId = resultSet.getInt("stack_frame");
            if (resultSet.wasNull()) {
                stackFrameId = null;
            }
            Integer prototypeId = resultSet.getInt("prototype");
            if (resultSet.wasNull()) {
                prototypeId = null;
            }
            final INaviView view = ViewManager.get(provider).getView(resultSet.getInt("view_id"));
            final BaseType stackFrame = stackFrameId == null ? null : module.getTypeManager().getBaseType(stackFrameId);
            if (stackFrameId != null) {
                module.getTypeManager().setStackFrame(stackFrame);
            }
            final BaseType prototype = prototypeId == null ? null : module.getTypeManager().getBaseType(prototypeId);
            final CFunction function = new CFunction(module, view, address, name, originalName, description, indegree, outdegree, nodeCount, edgeCount, type, parentModuleName, parentModuleId, parentModuleFunction, stackFrame, prototype, provider);
            if (globalCommentId != null) {
                commentIdToFunction.put(globalCommentId, function);
            }
            functions.add(function);
        }
    } finally {
        resultSet.close();
    }
    if (!commentIdToFunction.isEmpty()) {
        final HashMap<Integer, ArrayList<IComment>> commentIdToComments = PostgreSQLCommentFunctions.loadMultipleCommentsById(provider, commentIdToFunction.keySet());
        for (final Entry<Integer, ArrayList<IComment>> commentIdToComment : commentIdToComments.entrySet()) {
            CommentManager.get(provider).initializeGlobalFunctionComment(commentIdToFunction.get(commentIdToComment.getKey()), commentIdToComment.getValue());
        }
    }
    return functions;
}
Also used : HashMap(java.util.HashMap) FunctionType(com.google.security.zynamics.zylib.disassembly.FunctionType) ArrayList(java.util.ArrayList) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) BaseType(com.google.security.zynamics.binnavi.disassembly.types.BaseType) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction)

Example 19 with INaviView

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

the class TypeInstanceContainerBackend method loadTypeInstanceReference.

/**
   * Load a single type instance reference from the database.
   *
   * @param typeInstanceId the id of the {@link TypeInstanceReference reference}.
   * @param address The address of the {@link INaviInstruction instruction} where the
   *        {@link TypeInstanceReference reference} is associated.
   * @param position The {@link OperandTree operand tree} position in the {@link INaviInstruction
   *        instruction} the {@link TypeInstanceReference reference} is associated to.
   * @param expressionId The {@link OperandTreeNode operand tree node} id within the
   *        {@link OperandTree operand tree}.
   *
   * @return The {@link TypeInstanceReference} loaded from the database.
   * @throws CouldntLoadDataException
   */
public TypeInstanceReference loadTypeInstanceReference(final Integer typeInstanceId, final BigInteger address, final Integer position, final Integer expressionId) throws CouldntLoadDataException {
    Preconditions.checkNotNull(typeInstanceId, "Error: typeInstanceId argument can not be null");
    Preconditions.checkNotNull(address, "Error: address argument can not be null");
    Preconditions.checkNotNull(position, "Error: position argument can not be null");
    Preconditions.checkNotNull(expressionId, "Error: expressionId argument can not be null");
    final RawTypeInstanceReference rawReference = provider.loadTypeInstanceReference(module, typeInstanceId, address, position, expressionId);
    final TypeInstance typeInstance = instancesById.get(rawReference.getTypeInstanceId());
    final INaviView view = module.getContent().getViewContainer().getView(rawReference.getViewId());
    final TypeInstanceReference reference = new TypeInstanceReference(new CAddress(address), position, Optional.<INaviOperandTreeNode>absent(), typeInstance, view);
    referenceLookup.put(new InstanceReferenceLookup(new CAddress(address), position, expressionId), reference);
    return reference;
}
Also used : INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Example 20 with INaviView

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

the class CViewContainer method delete.

private void delete(final INaviView view) {
    final INaviView currentStoredView = m_customViews.get(m_customViews.indexOf(view));
    m_customViews.remove(currentStoredView);
    viewIdView.remove(view.getConfiguration().getId());
    currentStoredView.removeListener(m_viewListener);
    for (final IModuleListener listener : m_listeners) {
        try {
            listener.deletedView(m_module, currentStoredView);
        } catch (final Exception exception) {
            CUtilityFunctions.logException(exception);
        }
    }
}
Also used : INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) LoadCancelledException(com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) CPartialLoadException(com.google.security.zynamics.binnavi.Database.Exceptions.CPartialLoadException) CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)

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