Search in sources :

Example 1 with CommentManager

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

the class TypeInstanceContainerBackend method createTypeInstance.

/**
   * Creates a new type instance and stores it in the database.
   *
   * @param name The {@link String} to name the {@link TypeInstance}.
   * @param commentString The potential comment {@link String} for the {@link TypeInstance}.
   * @param baseType The {@link BaseType} on which the {@link TypeInstance} is based.
   * @param section The {@link Section} where the {@link TypeInstance} lives.
   * @param sectionOffset The offset in the {@link Section} where the {@link TypeInstance} can be
   *        found.
   *
   * @return The newly created {@link TypeInstance}.
   *
   * @throws CouldntSaveDataException if the {@link TypeInstance} could not be saved in the
   *         database.
   * @throws CouldntLoadDataException if the necessary information for commenting the
   *         {@link TypeInstance} could not be loaded from the database.
   */
public TypeInstance createTypeInstance(final String name, final String commentString, final BaseType baseType, final Section section, final long sectionOffset) throws CouldntSaveDataException, CouldntLoadDataException {
    Preconditions.checkNotNull(name, "Error: name argument can not be null");
    Preconditions.checkNotNull(baseType, "Error: baseType argument can not be null");
    Preconditions.checkNotNull(section, "Error: section argument can not be null");
    Preconditions.checkArgument(sectionOffset >= 0, "Error: section offset must be greater or equal to zero");
    final CommentManager commentManager = CommentManager.get(provider);
    final int typeId = baseType.getId();
    final int sectionId = section.getId();
    final int instanceId = provider.createTypeInstance(module.getConfiguration().getId(), name, null, typeId, sectionId, sectionOffset);
    final TypeInstance instance = new TypeInstance(instanceId, name, baseType, section, sectionOffset, module);
    instancesById.put(instanceId, instance);
    if (commentString != null) {
        commentManager.appendTypeInstanceComment(instance, commentString);
    }
    return instance;
}
Also used : CommentManager(com.google.security.zynamics.binnavi.disassembly.CommentManager)

Example 2 with CommentManager

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

the class TypeInstanceContainerBackend method loadTypeInstance.

/**
   * Loads a single type instance from the database.
   *
   * @param typeInstanceId The {@link Integer} id of the {@link TypeInstance type instance} to load.
   * @return A {@link TypeInstance instance} if present in the database.
   *
   * @throws CouldntLoadDataException Thrown if the {@link TypeInstance type instance} could not be
   *         loaded from the database.
   */
public TypeInstance loadTypeInstance(final Integer typeInstanceId) throws CouldntLoadDataException {
    Preconditions.checkNotNull(typeInstanceId, "Error: typeInstanceId argument can not be null");
    final RawTypeInstance rawTypeInstance = provider.loadTypeInstance(module, typeInstanceId);
    final BaseType baseType = typeManager.getBaseType(rawTypeInstance.getTypeId());
    final Section section = sectionContainer.getSection(rawTypeInstance.getSectionId());
    final TypeInstance typeInstance = new TypeInstance(rawTypeInstance.getId(), rawTypeInstance.getName(), baseType, section, rawTypeInstance.getSectionOffset(), module);
    instancesById.put(typeInstance.getId(), typeInstance);
    if (rawTypeInstance.getCommentId() != null) {
        final CommentManager manager = CommentManager.get(provider);
        final List<IComment> comments = provider.loadCommentById(rawTypeInstance.getCommentId());
        manager.initializeTypeInstanceComment(typeInstance, comments);
    }
    return typeInstance;
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) CommentManager(com.google.security.zynamics.binnavi.disassembly.CommentManager)

Example 3 with CommentManager

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

the class SectionContainerBackend method loadSections.

/**
   * Loads all sections from the database.
   * 
   * @return The list of all sections.
   * @throws CouldntLoadDataException Thrown if the list of sections could not be determined.
   */
protected List<Section> loadSections() throws CouldntLoadDataException {
    final Map<Section, Integer> sectionToComment = provider.loadSections(module);
    final Map<Section, Integer> sectionWithCommemnt = Maps.filterValues(sectionToComment, new Predicate<Integer>() {

        @Override
        public boolean apply(final Integer commentId) {
            return commentId != null;
        }
    });
    final CommentManager manager = CommentManager.get(provider);
    final HashMap<Integer, ArrayList<IComment>> typeInstanceTocomments = provider.loadMultipleCommentsById(sectionWithCommemnt.values());
    for (final Entry<Section, Integer> entry : sectionWithCommemnt.entrySet()) {
        manager.initializeSectionComment(entry.getKey(), typeInstanceTocomments.get(entry.getValue()));
    }
    return Lists.newArrayList(sectionToComment.keySet());
}
Also used : CommentManager(com.google.security.zynamics.binnavi.disassembly.CommentManager) ArrayList(java.util.ArrayList)

Example 4 with CommentManager

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

the class TypeInstanceContainerBackend method loadTypeInstances.

/**
   * Load all type instances from the database.
   *
   * @return A {@link Set} of {@link TypeInstance} associated to the {@link INaviModule} the
   *         {@link TypeInstanceContainerBackend} is associated to.
   *
   * @throws CouldntLoadDataException if the {@link Set} of {@link TypeInstance} could not be loaded
   *         from the database.
   */
public Set<TypeInstance> loadTypeInstances() throws CouldntLoadDataException {
    final List<RawTypeInstance> rawInstances = provider.loadTypeInstances(module);
    final HashMap<TypeInstance, Integer> instanceToComment = Maps.newHashMap();
    for (final RawTypeInstance rawInstance : rawInstances) {
        final BaseType baseType = typeManager.getBaseType(rawInstance.getTypeId());
        final Section section = sectionContainer.getSection(rawInstance.getSectionId());
        final TypeInstance typeInstance = new TypeInstance(rawInstance.getId(), rawInstance.getName(), baseType, section, rawInstance.getSectionOffset(), module);
        instanceToComment.put(typeInstance, rawInstance.getCommentId());
        instancesById.put(typeInstance.getId(), typeInstance);
    }
    final Map<TypeInstance, Integer> typeInstanceWithComment = Maps.filterValues(instanceToComment, new Predicate<Integer>() {

        @Override
        public boolean apply(final Integer commentId) {
            return commentId != null;
        }
    });
    final CommentManager manager = CommentManager.get(provider);
    final HashMap<Integer, ArrayList<IComment>> typeInstanceTocomments = provider.loadMultipleCommentsById(typeInstanceWithComment.values());
    for (final Entry<TypeInstance, Integer> entry : typeInstanceWithComment.entrySet()) {
        manager.initializeTypeInstanceComment(entry.getKey(), typeInstanceTocomments.get(entry.getValue()));
    }
    return instanceToComment.keySet();
}
Also used : CommentManager(com.google.security.zynamics.binnavi.disassembly.CommentManager) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger)

Aggregations

CommentManager (com.google.security.zynamics.binnavi.disassembly.CommentManager)4 ArrayList (java.util.ArrayList)2 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)1 BigInteger (java.math.BigInteger)1