Exemplo n.º 1
0
  /** Converts internal module data to API module data. */
  private void convertData() {
    m_traces = new ArrayList<Trace>();

    for (final TraceList trace : m_module.getContent().getTraceContainer().getTraces()) {
      m_traces.add(new Trace(trace));
    }

    m_module.getContent().getTraceContainer().addListener(m_traceListener);

    m_functions = new ArrayList<Function>();

    for (final INaviFunction function :
        m_module.getContent().getFunctionContainer().getFunctions()) {
      m_functions.add(new Function(this, function));
    }

    for (final Function function : m_functions) {
      m_functionMap.put(function.getNative(), function);
    }

    m_views = new ArrayList<View>();

    for (final INaviView view : m_module.getContent().getViewContainer().getViews()) {
      m_views.add(new View(this, view, m_nodeTagManager, m_viewTagManager));
    }

    createCallgraph();
  }
Exemplo n.º 2
0
  /** Creates the native call graph. */
  private void createCallgraph() {
    final DirectedGraph<ICallgraphNode, ICallgraphEdge> graph =
        m_module.getContent().getNativeCallgraph();

    final List<FunctionBlock> blocks = new ArrayList<FunctionBlock>();
    final List<FunctionEdge> edges = new ArrayList<FunctionEdge>();

    final HashMap<ICallgraphNode, FunctionBlock> blockMap =
        new HashMap<ICallgraphNode, FunctionBlock>();

    final HashMap<INaviFunction, Function> functionMap = new HashMap<INaviFunction, Function>();

    for (final Function function : m_functions) {
      functionMap.put(function.getNative(), function);
    }

    for (final ICallgraphNode block : graph.getNodes()) {
      final FunctionBlock newBlock = new FunctionBlock(functionMap.get(block.getFunction()));

      blockMap.put(block, newBlock);

      blocks.add(newBlock);
    }

    for (final ICallgraphEdge edge : graph.getEdges()) {
      final FunctionBlock source = blockMap.get(edge.getSource());
      final FunctionBlock target = blockMap.get(edge.getTarget());

      edges.add(new FunctionEdge(source, target));
    }

    m_callgraph = new Callgraph(blocks, edges);
  }
Exemplo n.º 3
0
 /**
  * Creates a new Trace and saves it to the database.
  *
  * @param name The name of the trace.
  * @param description Each trace can have a description.
  * @return The trace that was created.
  * @throws CouldntSaveDataException Thrown if the trace couldn't be saved to the database.
  */
 public Trace createTrace(String name, String description) throws CouldntSaveDataException {
   try {
     return new Trace(m_module.getContent().getTraceContainer().createTrace(name, description));
   } catch (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException e) {
     throw new CouldntSaveDataException(e);
   }
 }
  /** Creates the children of the node. */
  private void createChildren() {
    if (m_module.isLoaded()) {
      for (final INaviView view : m_module.getContent().getViewContainer().getViews()) {
        if (view.getNodeCount() == 0) {
          continue;
        }

        add(new CViewIconNode(view));
      }
    }
  }
Exemplo n.º 5
0
  /**
   * Returns the function associated with a view.
   *
   * @param view The view whose associated function is returned. Please note that this view must be
   *     a native view because only native views have associated functions.
   * @return The associated function.
   */
  public Function getFunction(final View view) {
    Preconditions.checkNotNull(view, "Error: View argument can not be null");

    if (!m_views.contains(view)) {
      throw new IllegalArgumentException("Error: View is not part of this module");
    }

    if (view.getType() != ViewType.Native) {
      throw new IllegalArgumentException("Error: View is not a native view");
    }

    return m_functionMap.get(
        m_module.getContent().getViewContainer().getFunction(view.getNative()));
  }
Exemplo n.º 6
0
  @Override
  public Object getValueAt(final int row, final int col) {
    final INaviModule module = getModules().get(row);

    switch (col) {
      case NAME_COLUMN:
        return module.getConfiguration().getName();
      case DESCRIPTION_COLUMN:
        return module.getConfiguration().getDescription();
      case VIEWS_COLUMN:
        return module.isLoaded()
            ? module.getContent().getViewContainer().getViews().size()
            : module.getCustomViewCount() + module.getFunctionCount() + 1;
      case CREATION_DATE_COLUMN:
        return module.getConfiguration().getCreationDate();
      case MODIFICATION_DATE_COLUMN:
        return module.getConfiguration().getModificationDate();
      default:
        throw new IllegalStateException("IE01160: Invalid column");
    }
  }
Exemplo n.º 7
0
  /**
   * Deletes a non-native view from the module and from the database.
   *
   * @param view The view to delete.
   * @throws CouldntDeleteException Thrown if the view could not be deleted.
   */
  public void deleteView(final View view) throws CouldntDeleteException {
    Preconditions.checkNotNull(view, "Error: View argument can not be null");

    if (view.getType() == ViewType.Native) {
      throw new IllegalArgumentException("Error: Native views can not be deleted");
    }

    if (!isLoaded()) {
      throw new IllegalArgumentException(
          "Error: Module must be opened before views can be deleted");
    }

    if (!m_views.contains(view)) {
      throw new IllegalArgumentException("Error: View does not belong to this module");
    }

    try {
      m_module.getContent().getViewContainer().deleteView(view.getNative());
    } catch (
        final com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException
            exception) {
      throw new CouldntDeleteException(exception);
    }
  }
Exemplo n.º 8
0
  /**
   * Creates a new view that is added to the module.
   *
   * @param name The name of the new view.
   * @param description The description of the new view.
   * @return The newly created view.
   * @throws IllegalArgumentException Thrown if any of the arguments are null.
   */
  @Override
  public View createView(final String name, final String description) {
    final CView newView = m_module.getContent().getViewContainer().createView(name, description);

    return ObjectFinders.getObject(newView, m_views);
  }