예제 #1
0
파일: Module.java 프로젝트: m0n0ph1/binnavi
  /** 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();
  }
  /** 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));
      }
    }
  }
예제 #3
0
  @Override
  public void delete() {
    m_addressSpace.removeListener(m_addressSpaceListener);

    if (m_addressSpace.isLoaded()) {
      m_addressSpace.getContent().removeListener(m_contentListener);

      for (final INaviModule module : m_addressSpace.getContent().getModules()) {
        module.removeListener(m_modulesListener);
      }
    }
  }
예제 #4
0
  /**
   * Creates a new model object.
   *
   * @param addressSpace The address space that provides the modules.
   */
  public CProjectModulesModel(final INaviAddressSpace addressSpace) {
    Preconditions.checkNotNull(addressSpace, "IE01955: Address space argument can't be null");

    m_addressSpace = addressSpace;

    addressSpace.addListener(m_addressSpaceListener);

    if (addressSpace.isLoaded()) {
      addressSpace.getContent().addListener(m_contentListener);

      for (final INaviModule module : addressSpace.getContent().getModules()) {
        module.addListener(m_modulesListener);
      }
    }
  }
예제 #5
0
파일: Module.java 프로젝트: m0n0ph1/binnavi
  /** 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);
  }
예제 #6
0
파일: Module.java 프로젝트: m0n0ph1/binnavi
 /**
  * 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);
   }
 }
예제 #7
0
파일: Module.java 프로젝트: m0n0ph1/binnavi
 /**
  * Changes the image base of the module.
  *
  * @param address The new image base of the module.
  * @throws IllegalArgumentException Thrown if the address argument is null.
  * @throws CouldntSaveDataException Thrown if the image base of the module could not be changed.
  */
 public void setImagebase(final Address address) throws CouldntSaveDataException {
   try {
     m_module.getConfiguration().setImageBase(new CAddress(address.toLong()));
   } catch (
       final com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException e) {
     throw new CouldntSaveDataException(e);
   }
 }
예제 #8
0
파일: Module.java 프로젝트: m0n0ph1/binnavi
 /**
  * Changes the name of the module.
  *
  * @param name The new name of the module.
  * @throws IllegalArgumentException Thrown if the name argument is null.
  * @throws CouldntSaveDataException Thrown if the name of the module could not be changed.
  */
 public void setName(final String name) throws CouldntSaveDataException {
   try {
     m_module.getConfiguration().setName(name);
   } catch (
       final com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException e) {
     throw new CouldntSaveDataException(e);
   }
 }
예제 #9
0
    @Override
    public void removedModule(final INaviAddressSpace addressSpace, final INaviModule module) {
      m_cachedValues = null;

      module.removeListener(m_modulesListener);

      fireTableDataChanged();
    }
  @Override
  public void doubleClicked() {
    // Load modules on double-click

    if (!m_module.isLoaded()) {
      CModuleLoader.loadModule(m_dialog, m_module);
    }
  }
예제 #11
0
  @Override
  public void setValueAt(final Object value, final int row, final int col) {
    if ((col != NAME_COLUMN) && (col != DESCRIPTION_COLUMN)) {
      throw new IllegalStateException("IE01161: Column can not be edited");
    }

    final INaviModule module = getModules().get(row);

    if (col == NAME_COLUMN) {
      try {
        module.getConfiguration().setName((String) value);
      } catch (final CouldntSaveDataException e) {
        CUtilityFunctions.logException(e);

        final String innerMessage = "E00156: " + "Could not save address space name";
        final String innerDescription =
            CUtilityFunctions.createDescription(
                String.format(
                    "The new name of the address space '%s' could not be saved.",
                    m_addressSpace.getConfiguration().getName()),
                new String[] {"There was a problem with the database connection."},
                new String[] {"The address space keeps its old name."});

        NaviErrorDialog.show(null, innerMessage, innerDescription, e);
      }
    } else if (col == DESCRIPTION_COLUMN) {
      try {
        module.getConfiguration().setDescription((String) value);
      } catch (final CouldntSaveDataException e) {
        CUtilityFunctions.logException(e);

        final String innerMessage = "E00157: " + "Could not save address space description";
        final String innerDescription =
            CUtilityFunctions.createDescription(
                String.format(
                    "The new description of the address space '%s' could not be saved.",
                    m_addressSpace.getConfiguration().getName()),
                new String[] {"There was a problem with the database connection."},
                new String[] {"The address space keeps its old description."});

        NaviErrorDialog.show(null, innerMessage, innerDescription, e);
      }
    }
  }
예제 #12
0
파일: Module.java 프로젝트: m0n0ph1/binnavi
 /**
  * Changes the debugger template of the module.
  *
  * @param template The new debugger template.
  * @throws CouldntSaveDataException Thrown if the new debugger template could not be saved to the
  *     database.
  */
 public void setDebuggerTemplate(final DebuggerTemplate template) throws CouldntSaveDataException {
   try {
     m_module
         .getConfiguration()
         .setDebuggerTemplate(template == null ? null : template.getNative());
   } catch (
       final com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException e) {
     throw new CouldntSaveDataException(e);
   }
 }
  /**
   * Creates a new module node.
   *
   * @param parent Parent window of the dialog.
   * @param module The module represented by the node.
   * @param model Tree model of the tree the node belongs to.
   */
  public ViewSelectionModuleNode(
      final Window parent, final INaviModule module, final DefaultTreeModel model) {
    Preconditions.checkNotNull(module, "IE01821: Module argument can not be null");

    m_dialog = parent;
    m_module = module;
    m_model = model;

    m_module.addListener(m_internalModuleListener);

    createChildren();
  }
예제 #14
0
  /**
   * Generates a name list from the names of the given modules.
   *
   * @param modules The modules that provide the names.
   * @return The generated name list.
   */
  public static String getNameList(final INaviModule[] modules) {
    int count = 0;

    final StringBuilder list = new StringBuilder();

    for (final INaviModule module : modules) {
      list.append("- ");
      list.append(module.getConfiguration().getName());
      list.append('\n');

      count++;

      if ((count == MAX_LIST_LENGTH) && (modules.length != MAX_LIST_LENGTH)) {
        list.append("\n... ");
        list.append(String.format("%d others ...", modules.length - count));

        break;
      }
    }

    return list.toString();
  }
예제 #15
0
파일: Module.java 프로젝트: m0n0ph1/binnavi
  /**
   * Loads the module data from the database.
   *
   * @throws IllegalStateException Thrown if the module is already loaded.
   * @throws CouldntLoadDataException Thrown if the module data could not be loaded from the
   *     database.
   */
  public void load() throws CouldntLoadDataException {
    if (isLoaded()) {
      return;
    }

    try {
      m_module.load();
    } catch (
        final com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException e) {
      throw new CouldntLoadDataException(e);
    } catch (final LoadCancelledException e) {
      throw new CouldntLoadDataException(e);
    }
  }
예제 #16
0
파일: Module.java 프로젝트: m0n0ph1/binnavi
  /**
   * 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()));
  }
예제 #17
0
파일: Module.java 프로젝트: m0n0ph1/binnavi
  // / @endcond
  public Module(
      final Database database,
      final INaviModule module,
      final TagManager nodeTagManager,
      final TagManager viewTagManager) {
    m_database = Preconditions.checkNotNull(database, "Error: Database argument can't be null");
    m_module = Preconditions.checkNotNull(module, "Error: Module argument can't be null");
    m_nodeTagManager =
        Preconditions.checkNotNull(
            nodeTagManager, "Error: Node tag manager argument can't be null");
    m_viewTagManager =
        Preconditions.checkNotNull(
            viewTagManager, "Error: View tag manager argument can't be null");

    if (m_module.getConfiguration().getDebugger() != null) {
      m_debugger = new Debugger(m_module.getConfiguration().getDebugger());
    }

    if (module.isLoaded()) {
      convertData();
    }

    module.addListener(m_listener);
  }
예제 #18
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");
    }
  }
예제 #19
0
파일: Module.java 프로젝트: m0n0ph1/binnavi
  /**
   * 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);
    }
  }
예제 #20
0
파일: Module.java 프로젝트: m0n0ph1/binnavi
 /**
  * Closes the module. After a module is closed, using its content leads to undefined behaviour.
  */
 public void close() {
   m_module.close();
 }
예제 #21
0
파일: Module.java 프로젝트: m0n0ph1/binnavi
  /**
   * 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);
  }
예제 #22
0
파일: Module.java 프로젝트: m0n0ph1/binnavi
 /**
  * Returns a flag that indicates whether the module is loaded.
  *
  * @return True, if the module is loaded. False, otherwise.
  */
 public boolean isLoaded() {
   return m_module.isLoaded();
 }
예제 #23
0
파일: Module.java 프로젝트: m0n0ph1/binnavi
 /**
  * Returns the SHA1 hash of the original input file.
  *
  * @return The SHA1 hash of the original input file.
  */
 public String getSHA1() {
   return m_module.getConfiguration().getSha1();
 }
예제 #24
0
파일: Module.java 프로젝트: m0n0ph1/binnavi
 /**
  * Returns the name of the module.
  *
  * @return The name of the module.
  */
 public String getName() {
   return m_module.getConfiguration().getName();
 }
예제 #25
0
파일: Module.java 프로젝트: m0n0ph1/binnavi
 /**
  * Returns the modification date of the module. This is the date when the module was last written
  * to the database.
  *
  * @return The modification date of the module.
  */
 public Date getModificationDate() {
   return m_module.getConfiguration().getModificationDate();
 }
예제 #26
0
파일: Module.java 프로젝트: m0n0ph1/binnavi
 /**
  * Returns the image base of the module. This is the base address of the module as it really
  * occurs in memory after potential relocation operations.
  *
  * @return The image base of the module.
  */
 public Address getImagebase() {
   return new Address(m_module.getConfiguration().getImageBase().toBigInteger());
 }
예제 #27
0
파일: Module.java 프로젝트: m0n0ph1/binnavi
 // / @endcond
 public void dispose() {
   m_module.removeListener(m_listener);
 }
 @Override
 public Icon getIcon() {
   return m_module.isLoaded() ? ICON_MODULE : ICON_MODULE_GRAY;
 }
예제 #29
0
파일: Module.java 프로젝트: m0n0ph1/binnavi
 /**
  * Returns the database ID of the module.
  *
  * @return The database ID of the module.
  */
 public int getId() {
   return m_module.getConfiguration().getId();
 }
예제 #30
0
파일: Module.java 프로젝트: m0n0ph1/binnavi
 /**
  * Returns the description of the module.
  *
  * @return The description of the module.
  */
 public String getDescription() {
   return m_module.getConfiguration().getDescription();
 }