use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment in project binnavi by google.
the class GroupNodeTest method testSetCollapsed.
@Test
public void testSetCollapsed() {
final Database database = new Database(new MockDatabase());
final MockModule mockModule = new MockModule();
final TagManager nodeTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.NODE_TAG));
final TagManager viewTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.VIEW_TAG));
final Module module = new Module(database, mockModule, nodeTagManager, viewTagManager);
final MockView mockView = new MockView();
final View view = new View(module, mockView, nodeTagManager, viewTagManager);
final INaviGroupNode internalGroupNode = new CGroupNode(0, 0, 0, 0, 0, Color.RED, false, false, new HashSet<CTag>(), new ArrayList<IComment>(), false, new MockSqlProvider());
final GroupNode node = new GroupNode(view, internalGroupNode, viewTagManager);
final MockGroupNodeListener listener = new MockGroupNodeListener();
node.addListener(listener);
node.setCollapsed(true);
assertEquals("changedState;", listener.events);
assertTrue(node.isCollapsed());
node.removeListener(listener);
}
use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment in project binnavi by google.
the class CGraphDebuggerTest method testToggleBreakpoint3.
@Test
public void testToggleBreakpoint3() {
final MockModule module = new MockModule();
module.getConfiguration().setDebugger(m_debugger);
m_debugger.setAddressTranslator(module, m_fileBase, m_imageBase);
final DebugTargetSettings target = new ModuleTargetSettings(module);
final DebuggerProvider debuggerProvider = new DebuggerProvider(target);
debuggerProvider.addDebugger(m_debugger);
final CFunction function = new CFunction(module, new MockView(), new CAddress(0x123), "Mock Function", "Mock Function", "Mock Description", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, m_provider);
final ArrayList<IComment> comments = Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "Mock Comment"));
final INaviCodeNode codeNode = new CCodeNode(0, 0, 0, 0, 0, Color.RED, Color.RED, false, false, comments, function, new HashSet<CTag>(), new MockSqlProvider());
codeNode.addInstruction(new CInstruction(true, module, new CAddress(0x123), "nop", new ArrayList<COperandTree>(), new byte[] { (byte) 0x90 }, "x86-32", m_provider), null);
codeNode.addInstruction(new CInstruction(true, module, new CAddress(0x124), "nop", new ArrayList<COperandTree>(), new byte[] { (byte) 0x90 }, "x86-32", m_provider), null);
CGraphDebugger.toggleBreakpoint(debuggerProvider, codeNode, 2);
assertEquals(1, m_debugger.getBreakpointManager().getNumberOfBreakpoints(BreakpointType.REGULAR));
assertEquals(0x124, m_debugger.getBreakpointManager().getBreakpoint(BreakpointType.REGULAR, 0).getAddress().getAddress().getAddress().toLong());
assertEquals(BreakpointStatus.BREAKPOINT_INACTIVE, m_debugger.getBreakpointManager().getBreakpointStatus(BreakpointType.REGULAR, 0));
CGraphDebugger.toggleBreakpoint(debuggerProvider, codeNode, 2);
assertEquals(0, m_debugger.getBreakpointManager().getNumberOfBreakpoints(BreakpointType.REGULAR));
}
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 PostgreSQLNodeSaver method saveCodeNodes.
/**
* Saves the code 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 codeNodeIndices Index into the nodes list that identifies the code nodes.
*
* @throws SQLException Thrown if saving the code node instructions failed.
*/
protected static void saveCodeNodes(final SQLProvider provider, final List<INaviViewNode> nodes, final int firstNode, final List<Integer> codeNodeIndices) throws SQLException {
if (!codeNodeIndices.isEmpty()) {
final List<Pair<INaviCodeNode, INaviInstruction>> instructionsWithUnsavedLocalComments = PostgreSQLNodeSaver.saveCodeNodeInstructions(provider, nodes, firstNode, codeNodeIndices);
final String query = "INSERT INTO " + CTableNames.CODE_NODES_TABLE + "(module_id, node_id, parent_function, comment_id) VALUES (?, ?, ?, ?)";
final ArrayList<INaviCodeNode> codeNodesWithUnsavedComments = new ArrayList<INaviCodeNode>();
final PreparedStatement preparedStatement = provider.getConnection().getConnection().prepareStatement(query);
try {
for (final int index : codeNodeIndices) {
final INaviCodeNode codeNode = (INaviCodeNode) nodes.get(index);
codeNode.setId(firstNode + index);
INaviFunction function = null;
try {
function = codeNode.getParentFunction();
} catch (final MaybeNullException e) {
}
final int moduleId = Iterables.getLast(codeNode.getInstructions()).getModule().getConfiguration().getId();
final List<IComment> comment = codeNode.getComments().getLocalCodeNodeComment();
final Integer commentId = comment == null ? null : comment.size() == 0 ? null : Iterables.getLast(comment).getId();
if ((comment != null) && (comment.size() != 0) && (commentId == null)) {
codeNodesWithUnsavedComments.add(codeNode);
}
preparedStatement.setInt(1, moduleId);
preparedStatement.setInt(2, firstNode + index);
if (function == null) {
preparedStatement.setNull(3, Types.BIGINT);
} else {
preparedStatement.setObject(3, function.getAddress().toBigInteger(), Types.BIGINT);
}
if (commentId == null) {
preparedStatement.setNull(4, Types.INTEGER);
} else {
preparedStatement.setInt(4, commentId);
}
preparedStatement.addBatch();
}
preparedStatement.executeBatch();
} finally {
preparedStatement.close();
}
// implementation.
for (final INaviCodeNode codeNode : codeNodesWithUnsavedComments) {
final ArrayList<IComment> codeNodecomments = new ArrayList<IComment>();
for (final IComment comment : codeNode.getComments().getLocalCodeNodeComment()) {
try {
final Integer commentId = PostgreSQLNodeFunctions.appendLocalCodeNodeComment(provider, codeNode, comment.getComment(), comment.getUser().getUserId());
final IComment newComment = new CComment(commentId, comment.getUser(), comment.getParent(), comment.getComment());
codeNodecomments.add(newComment);
} catch (final CouldntSaveDataException exception) {
CUtilityFunctions.logException(exception);
}
}
codeNode.getComments().initializeLocalCodeNodeComment(codeNodecomments);
}
// implementation.
for (final Pair<INaviCodeNode, INaviInstruction> pair : instructionsWithUnsavedLocalComments) {
final ArrayList<IComment> localInstructionComments = new ArrayList<IComment>();
for (final IComment comment : pair.first().getComments().getLocalInstructionComment(pair.second())) {
try {
final int commentId = PostgreSQLInstructionFunctions.appendLocalInstructionComment(provider, pair.first(), pair.second(), comment.getComment(), comment.getUser().getUserId());
final IComment newComment = new CComment(commentId, comment.getUser(), comment.getParent(), comment.getComment());
localInstructionComments.add(newComment);
} catch (final CouldntSaveDataException exception) {
CUtilityFunctions.logException(exception);
}
}
pair.first().getComments().initializeLocalInstructionComment(pair.second(), localInstructionComments);
}
}
}
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;
}
Aggregations