use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment 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;
}
use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment in project binnavi by google.
the class CommentManager method appendComment.
/**
* This function provides the append comment functionality for any given Implementation of a
* {@link CommentingStrategy}. It uses the methods of the interface to only have one algorithm
* with different objects that can be commented.
*
* @param strategy The {@link CommentingStrategy} which holds the function forwarders.
* @param commentText The commenting text to append.
*
* @return The generated comment.
*
* @throws CouldntSaveDataException if the comment could not be stored in the database.
* @throws CouldntLoadDataException if the list of comments now associated with the commented
* object could not be loaded from the database.
*/
private synchronized List<IComment> appendComment(final CommentingStrategy strategy, final String commentText) throws CouldntSaveDataException, CouldntLoadDataException {
final IUser user = CUserManager.get(provider).getCurrentActiveUser();
final List<IComment> currentComments = new ArrayList<IComment>();
if (strategy.isStored()) {
currentComments.addAll(strategy.appendComment(commentText, user.getUserId()));
} else {
currentComments.addAll(strategy.getComments() == null ? new ArrayList<IComment>() : Lists.newArrayList(strategy.getComments()));
final IComment parent = currentComments.isEmpty() ? null : Iterables.getLast(currentComments);
final IComment newComment = new CComment(null, user, parent, commentText);
currentComments.add(newComment);
}
strategy.saveComments(currentComments);
for (final IComment comment : currentComments) {
commentIdToComment.put(comment.getId(), comment);
}
for (final CommentListener listener : listeners) {
try {
strategy.sendAppendedCommentNotifcation(listener, Iterables.getLast(currentComments));
} catch (final Exception exception) {
CUtilityFunctions.logException(exception);
}
}
return currentComments;
}
use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment in project binnavi by google.
the class CommentManager method unloadComment.
/**
* Unloads a comment and removes the items it references from the internal storage.
*
* @param strategy The {@link CommentingStrategy} which holds the function forwarders.
* @param comments The List of {@link IComment} to be unloaded.
*/
private synchronized void unloadComment(final CommentingStrategy strategy, final List<IComment> comments) {
Preconditions.checkNotNull(strategy, "Error: strategy argument can not be null");
if (comments == null) {
return;
}
strategy.removeComments(comments);
for (final IComment comment : comments) {
commentIdToComment.remove(comment.getId());
}
}
use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment in project binnavi by google.
the class CGraphGrouper method determineNodeText.
/**
* Determines the text to be displayed in a group node, if the given node is inside a collapsed
* group node.
*
* @param node The node whose text is determined.
*
* @return The string to be displayed for the given node.
*/
private static String determineNodeText(final NaviNode node) {
if (node.getRawNode() instanceof INaviCodeNode) {
final INaviCodeNode cnode = (INaviCodeNode) node.getRawNode();
return String.format("Basic Block: %s", cnode.getAddress().toHexString());
} else if (node.getRawNode() instanceof INaviFunctionNode) {
final INaviFunctionNode fnode = (INaviFunctionNode) node.getRawNode();
return String.format("Function: %s (%s)", fnode.getFunction().getName(), fnode.getFunction().getAddress().toHexString());
} else if (node.getRawNode() instanceof INaviTextNode) {
// Display up to 15 characters of the first line of
// the comment for comment nodes.
final INaviTextNode tnode = (INaviTextNode) node.getRawNode();
final List<IComment> comment = tnode.getComments();
final String firstLine = (comment.isEmpty()) ? "" : comment.get(1).getComment();
final int firstLineBreak = Math.min(firstLine.indexOf('\n'), firstLine.indexOf('\r'));
final int toDisplay = Math.min(Math.min(15, firstLineBreak == -1 ? Integer.MAX_VALUE : firstLineBreak), firstLine.length());
return String.format("Text: %s", firstLine.substring(0, toDisplay));
} else if (node.getRawNode() instanceof INaviGroupNode) {
// Display up to 15 characters of the first line of
// the comment for group nodes.
final INaviGroupNode gnode = (INaviGroupNode) node.getRawNode();
final List<IComment> comment = gnode.getComments();
final String firstLine = (comment.isEmpty()) ? "" : comment.get(0).getComment();
final int firstLineBreak = Math.min(firstLine.indexOf('\n'), firstLine.indexOf('\r'));
final int toDisplay = Math.min(Math.min(15, firstLineBreak == -1 ? Integer.MAX_VALUE : firstLineBreak), firstLine.length());
return String.format("Group: %s", firstLine.substring(0, toDisplay));
} else {
throw new IllegalStateException("IE01150: Unknown node type");
}
}
use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment in project binnavi by google.
the class ZyCodeNodeBuilder method createLines.
/**
* Creates the instructions lines for a code node.
*
* @param node The node that provides the instructions.
* @param lines The created lines will be stored here.
* @param commentsToLineAssociation Information about the required comments is stored here.
* @param graphSettings Provides settings that influence node formatting.
* @param modifier Calculates the address strings. This argument can be null.
*
* @return The maximum size in characters of all lines put into the lines list.
*/
private static int createLines(final INaviCodeNode node, final List<Pair<String, List<CStyleRunData>>> lines, final HashMap<Pair<String, List<CStyleRunData>>, ArrayList<CommentContainer>> commentsToLineAssociation, final ZyGraphViewSettings graphSettings, final INodeModifier modifier) {
int maxLineWidth = 0;
final Map<INaviInstruction, INaviFunction> instructionToFunctionReferences = CReferenceFinder.getCodeReferenceMap(node);
for (final INaviInstruction instruction : node.getInstructions()) {
final Pair<String, List<CStyleRunData>> zyLineContent = ZyInstructionBuilder.buildInstructionLine(instruction, graphSettings, modifier);
final ArrayList<CommentContainer> commentLineContainerList = new ArrayList<CommentContainer>();
final List<IComment> localComments = node.getComments().getLocalInstructionComment(instruction);
if (localComments != null) {
for (final IComment localComment : localComments) {
commentLineContainerList.add(new CommentContainer(localComment));
}
}
final List<IComment> globalComments = instruction.getGlobalComment();
if (globalComments != null) {
for (final IComment globalComment : globalComments) {
commentLineContainerList.add(new CommentContainer(globalComment));
}
}
final List<IComment> functionComments = instructionToFunctionReferences.get(instruction) == null ? null : instructionToFunctionReferences.get(instruction).getGlobalComment();
if (functionComments != null) {
for (final IComment functionComment : functionComments) {
commentLineContainerList.add(new CommentContainer(functionComment));
}
}
commentsToLineAssociation.put(zyLineContent, commentLineContainerList);
final int lineWidth = zyLineContent.first().length();
if (lineWidth > maxLineWidth) {
maxLineWidth = lineWidth;
}
lines.add(zyLineContent);
}
return maxLineWidth;
}
Aggregations