use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment in project binnavi by google.
the class PostgreSQLNodeSaver method saveCodeNodeInstructions.
/**
* Saves the mapping between code nodes and their instructions to the database.
*
* @param provider The provider used to access the database.
* @param nodes The nodes to save.
* @param firstNode The database index of the first node.
* @param codeNodeIndices Index into the nodes list that identifies the code nodes.
*
* @throws SQLException Thrown if saving the code node instructions failed.
*/
protected static ArrayList<Pair<INaviCodeNode, INaviInstruction>> saveCodeNodeInstructions(final SQLProvider provider, final List<INaviViewNode> nodes, final int firstNode, final List<Integer> codeNodeIndices) throws SQLException {
if (!nodes.isEmpty()) {
final Set<INaviInstruction> unsavedInstructions = new HashSet<INaviInstruction>();
for (final int index : codeNodeIndices) {
final CCodeNode node = (CCodeNode) nodes.get(index);
final Iterable<INaviInstruction> instructions = node.getInstructions();
for (final INaviInstruction instruction : instructions) {
if (!(instruction.isStored())) {
unsavedInstructions.add(instruction);
}
}
}
PostgreSQLInstructionFunctions.createInstructions(provider, unsavedInstructions);
final String query = "INSERT INTO " + CTableNames.CODENODE_INSTRUCTIONS_TABLE + " (module_id, node_id, position, address, comment_id) VALUES (?, ?, ?, ?, ?)";
final PreparedStatement preparedStatement = provider.getConnection().getConnection().prepareStatement(query);
final ArrayList<Pair<INaviCodeNode, INaviInstruction>> instructionsWithUnsavedLocalComments = new ArrayList<Pair<INaviCodeNode, INaviInstruction>>();
try {
for (final Integer index : codeNodeIndices) {
final INaviCodeNode codeNode = (INaviCodeNode) nodes.get(index);
int position = 0;
for (final INaviInstruction instruction : codeNode.getInstructions()) {
final List<IComment> comments = codeNode.getComments().getLocalInstructionComment(instruction);
final Integer commentId = comments == null ? null : comments.size() == 0 ? null : Iterables.getLast(comments).getId();
if ((comments != null) && (comments.size() != 0) && (commentId == null)) {
instructionsWithUnsavedLocalComments.add(new Pair<INaviCodeNode, INaviInstruction>(codeNode, instruction));
}
final int moduleId = instruction.getModule().getConfiguration().getId();
preparedStatement.setInt(1, moduleId);
preparedStatement.setInt(2, firstNode + index);
preparedStatement.setInt(3, position);
preparedStatement.setObject(4, instruction.getAddress().toBigInteger(), Types.BIGINT);
if (commentId == null) {
preparedStatement.setNull(5, Types.INTEGER);
} else {
preparedStatement.setInt(5, commentId);
}
position++;
preparedStatement.addBatch();
}
}
preparedStatement.executeBatch();
} finally {
preparedStatement.close();
}
return instructionsWithUnsavedLocalComments;
}
return null;
}
use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment in project binnavi by google.
the class PostgreSQLNodeSaver method saveGroupNodes.
/**
* Saves the group nodes to the database.
*
* @param provider The connection to the database.
* @param nodes The nodes to save.
* @param firstNode The database index of the first node.
* @param groupNodeIndices Index into the nodes list that identifies the group nodes.
*
* @throws SQLException Thrown if saving the group nodes failed.
*/
protected static void saveGroupNodes(final SQLProvider provider, final List<INaviViewNode> nodes, final int firstNode, final List<Integer> groupNodeIndices) throws SQLException {
Preconditions.checkNotNull(provider, "IE02525: connection argument can not be null");
Preconditions.checkNotNull(nodes, "IE02526: nodes argument can not be null");
Preconditions.checkNotNull(groupNodeIndices, "Error: groupNodeIndices argument can not be null");
if (!groupNodeIndices.isEmpty()) {
final String query = "INSERT INTO " + CTableNames.GROUP_NODES_TABLE + "(node_id, collapsed, comment_id) VALUES (?, ?, ?)";
final PreparedStatement preparedStatement = provider.getConnection().getConnection().prepareStatement(query);
final List<INaviGroupNode> groupNodesWithUnsavedComments = new ArrayList<INaviGroupNode>();
try {
for (final Integer index : groupNodeIndices) {
final INaviGroupNode node = (INaviGroupNode) nodes.get(index);
preparedStatement.setInt(1, firstNode + index);
preparedStatement.setBoolean(2, node.isCollapsed());
final List<IComment> comment = node.getComments();
final Integer commentId = comment == null ? null : comment.size() == 0 ? null : Iterables.getLast(comment).getId();
if ((comment != null) && (comment.size() != 0) && (commentId == null)) {
groupNodesWithUnsavedComments.add(node);
}
if (commentId == null) {
preparedStatement.setNull(3, Types.INTEGER);
} else {
preparedStatement.setInt(3, commentId);
}
preparedStatement.addBatch();
}
preparedStatement.executeBatch();
} finally {
preparedStatement.close();
}
// TODO (timkornau): this can work better.
for (final INaviGroupNode groupNode : groupNodesWithUnsavedComments) {
final ArrayList<IComment> groupNodeComments = new ArrayList<IComment>();
for (final IComment comment : groupNode.getComments()) {
try {
final Integer commentId = provider.appendGroupNodeComment(groupNode, comment.getComment(), comment.getUser().getUserId());
final IComment newComment = new CComment(commentId, comment.getUser(), comment.getParent(), comment.getComment());
groupNodeComments.add(newComment);
} catch (final CouldntSaveDataException exception) {
CUtilityFunctions.logException(exception);
}
}
groupNode.initializeComment(groupNodeComments);
}
}
}
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;
}
use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment in project binnavi by google.
the class PostgreSQLNotificationProviderTest method testAppendLocalEdgeCommentSync.
@Test
public void testAppendLocalEdgeCommentSync() throws CouldntSaveDataException, CouldntLoadDataException, InterruptedException {
final INaviEdge databaseOneEdge = databaseOneView.getContent().getGraph().getEdges().get(3);
final INaviEdge databaseTwoEdge = databaseTwoView.getContent().getGraph().getEdges().get(3);
final List<IComment> oneBefore = databaseOneEdge.getLocalComment() == null ? new ArrayList<IComment>() : databaseOneEdge.getLocalComment();
final List<IComment> twoBefore = databaseTwoEdge.getLocalComment() == null ? new ArrayList<IComment>() : databaseTwoEdge.getLocalComment();
assertEquals(oneBefore, twoBefore);
databaseOneEdge.appendLocalComment(" TEST NOTIFICATION PROVIDER TESTS (LOCAL CODE NODE COMMENT) ");
// database one to two over the PostgreSQL back end.
synchronized (lock) {
lock.await(1000, TimeUnit.MILLISECONDS);
}
final List<IComment> oneAfter = databaseOneEdge.getLocalComment();
final List<IComment> twoAfter = databaseTwoEdge.getLocalComment();
assertNotNull(oneAfter);
assertNotNull(twoAfter);
assertEquals(oneBefore.size() + 1, oneAfter.size());
assertEquals(twoBefore.size() + 1, twoAfter.size());
assertEquals(oneAfter, twoAfter);
}
use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment in project binnavi by google.
the class PostgreSQLNotificationProviderTest method testAppendLocalInstructionCommentSync.
@Test
public void testAppendLocalInstructionCommentSync() throws CouldntSaveDataException, CouldntLoadDataException, InterruptedException {
final INaviCodeNode databaseOnecodeNode = databaseOneView.getContent().getBasicBlocks().get(3);
final INaviCodeNode databaseTwocodeNode = databaseTwoView.getContent().getBasicBlocks().get(3);
final List<IComment> oneBefore = databaseOnecodeNode.getComments().getLocalInstructionComment(databaseOnecodeNode.getLastInstruction()) == null ? new ArrayList<IComment>() : databaseOnecodeNode.getComments().getLocalInstructionComment(databaseOnecodeNode.getLastInstruction());
final List<IComment> twoBefore = databaseTwocodeNode.getComments().getLocalInstructionComment(databaseTwocodeNode.getLastInstruction()) == null ? new ArrayList<IComment>() : databaseTwocodeNode.getComments().getLocalInstructionComment(databaseTwocodeNode.getLastInstruction());
assertEquals(oneBefore, twoBefore);
databaseOnecodeNode.getComments().appendLocalInstructionComment(databaseOnecodeNode.getLastInstruction(), " TEST NOTIFICATION PROVIDER TESTS (GLOBAL INSTRUCTION COMMENT)");
// database one to two over the PostgreSQL back end.
synchronized (lock) {
lock.await(1000, TimeUnit.MILLISECONDS);
}
final List<IComment> oneAfter = databaseOnecodeNode.getComments().getLocalInstructionComment(databaseOnecodeNode.getLastInstruction());
final List<IComment> twoAfter = databaseTwocodeNode.getComments().getLocalInstructionComment(databaseTwocodeNode.getLastInstruction());
assertNotNull(oneAfter);
assertNotNull(twoAfter);
assertEquals(oneBefore.size() + 1, oneAfter.size());
assertEquals(twoBefore.size() + 1, twoAfter.size());
assertEquals(oneAfter, twoAfter);
}
Aggregations