use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment in project binnavi by google.
the class View2DTest method setUp.
@Before
public void setUp() throws CouldntLoadDataException, LoadCancelledException, FileReadException {
ConfigManager.instance().read();
final MockDatabase database = new MockDatabase();
final CModule module = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, new MockSqlProvider());
database.getContent().addModule(module);
manager.addDatabase(database);
module.load();
m_view = module.getContent().getViewContainer().createView("name", "description");
final ZyGraphViewSettings settings = new ZyGraphViewSettings(new CallGraphSettingsConfigItem());
settings.getLayoutSettings().setDefaultGraphLayout(LayoutStyle.CIRCULAR);
final ZyGraph2DView g2dView = new ZyGraph2DView();
final LinkedHashMap<Node, NaviNode> nodeMap = new LinkedHashMap<Node, NaviNode>();
final LinkedHashMap<Edge, NaviEdge> edgeMap = new LinkedHashMap<Edge, NaviEdge>();
final Node node1 = g2dView.getGraph2D().createNode();
final CTextNode rawNode1 = m_view.getContent().createTextNode(Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, " TEXT NODE ")));
nodeMap.put(node1, new NaviNode(node1, new ZyNormalNodeRealizer<NaviNode>(new ZyLabelContent(null)), rawNode1));
final Node node2 = g2dView.getGraph2D().createNode();
final CTextNode rawNode2 = m_view.getContent().createTextNode(Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, " TEXT COMMENT ")));
nodeMap.put(node2, new NaviNode(node2, new ZyNormalNodeRealizer<NaviNode>(new ZyLabelContent(null)), rawNode2));
final Edge edge = g2dView.getGraph2D().createEdge(node1, node2);
final INaviEdge rawEdge = m_view.getContent().createEdge(rawNode1, rawNode2, com.google.security.zynamics.zylib.gui.zygraph.edges.EdgeType.JUMP_CONDITIONAL_FALSE);
edgeMap.put(edge, new NaviEdge(nodeMap.get(node1), nodeMap.get(node2), edge, new ZyEdgeRealizer<NaviEdge>(new ZyLabelContent(null), null), rawEdge));
final ZyGraph graph = new ZyGraph(m_view, nodeMap, edgeMap, settings, g2dView);
m_view2d = new View2D(database, new CModuleContainer(database, module), graph, pluginInterface);
}
use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment in project binnavi by google.
the class ViewEdgeTest method setUp.
@Before
public void setUp() throws CouldntLoadDataException, LoadCancelledException {
final MockSqlProvider provider = new MockSqlProvider();
final Database database = new Database(new MockDatabase());
final CModule internalModule = new CModule(123, "Name", "Comment", new Date(), new Date(), "12345678123456781234567812345678", "1234567812345678123456781234567812345678", 55, 66, new CAddress(0x555), new CAddress(0x666), new DebuggerTemplate(1, "Mock Debugger", "localhaus", 88, provider), null, Integer.MAX_VALUE, false, provider);
internalModule.load();
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, internalModule, nodeTagManager, viewTagManager);
internalModule.getContent().getViewContainer().createView("", "");
// new View(module, mockView, nodeTagManager,
final View view = module.getViews().get(2);
// viewTagManager);
final ArrayList<IComment> comment = Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, " COMMENT "));
m_source = view.createTextNode(comment);
m_target = view.createTextNode(comment);
// m_internalEdge = new CNaviEdge(1, internalNode, internalNode,
// com.google.security.zynamics.zylib.gui.zygraph.edges.EdgeType.JUMP_UNCONDITIONAL, 0, 0, 0, 0,
// Color.MAGENTA,
// false, true, "", new FilledList<CBend>(), new MockSqlProvider());
// new
m_edge = view.createEdge(m_source, m_target, EdgeType.JumpUnconditional);
// ViewEdge(m_internalEdge,
// m_source,
// m_target);
}
use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment in project binnavi by google.
the class PostgreSQLInstructionFunctions method createInstructions.
/**
* Saves an instruction to the database.
*
* @param provider The provider used to access the database.
* @param instructions The instruction to save.
*
* @throws SQLException Thrown if the instruction could not be created.
*/
public static void createInstructions(final SQLProvider provider, final Iterable<INaviInstruction> instructions) throws SQLException {
Preconditions.checkNotNull(provider, "IE01550: Provider argument can not be null");
Preconditions.checkNotNull(instructions, "IE01554: Instruction argument can not be null");
final String query = "INSERT INTO " + CTableNames.INSTRUCTIONS_TABLE + "(module_id, address, mnemonic, data, native, architecture, comment_id) " + "VALUES(?, ?, ?, ?, ?, ?, ?)";
final PreparedStatement insertStatement = provider.getConnection().getConnection().prepareStatement(query);
final ArrayList<INaviInstruction> instructionsWithUnsavedComments = new ArrayList<INaviInstruction>();
final List<List<COperandTree>> operands = new ArrayList<List<COperandTree>>();
for (final INaviInstruction instruction : instructions) {
final String mnemonic = instruction.getMnemonic();
final byte[] data = instruction.getData();
operands.add(instruction.getOperands());
final INaviModule module = instruction.getModule();
final IAddress address = instruction.getAddress();
final int moduleID = module.getConfiguration().getId();
final List<IComment> comments = instruction.getGlobalComment();
final Integer commentId = comments == null ? null : comments.size() == 0 ? null : Iterables.getLast(comments).getId();
if ((comments != null) && (comments.size() != 0) && (commentId == null)) {
instructionsWithUnsavedComments.add(instruction);
}
try {
insertStatement.setInt(1, moduleID);
insertStatement.setObject(2, address.toBigInteger(), Types.BIGINT);
insertStatement.setString(3, mnemonic);
insertStatement.setBytes(4, data);
insertStatement.setBoolean(5, false);
insertStatement.setObject(6, instruction.getArchitecture(), Types.OTHER);
if (commentId == null) {
insertStatement.setNull(7, Types.INTEGER);
} else {
insertStatement.setInt(7, commentId);
}
insertStatement.execute();
} finally {
insertStatement.close();
}
}
// unsaved comments.
for (final INaviInstruction instruction : instructionsWithUnsavedComments) {
final ArrayList<IComment> instructionComments = new ArrayList<IComment>();
for (final IComment comment : instruction.getGlobalComment()) {
try {
final Integer commentId = PostgreSQLInstructionFunctions.appendGlobalInstructionComment(provider, instruction, comment.getComment(), comment.getUser().getUserId());
final IComment newComment = new CComment(commentId, comment.getUser(), comment.getParent(), comment.getComment());
instructionComments.add(newComment);
} catch (final CouldntSaveDataException exception) {
CUtilityFunctions.logException(exception);
}
}
instruction.initializeGlobalComment(instructionComments);
}
for (final List<COperandTree> operand : operands) {
int position = 0;
for (final COperandTree operandTree : operand) {
createOperandTree(provider, operandTree, position);
position++;
}
}
}
use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment 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.CComment in project binnavi by google.
the class PostgreSQLNodeSaver method saveFunctionNodes.
/**
* Saves the function 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 functionNodeIndices Index into the nodes list that identifies the function nodes.
*
* @throws SQLException Thrown if saving the function nodes failed.
*/
protected static void saveFunctionNodes(final SQLProvider provider, final List<INaviViewNode> nodes, final int firstNode, final List<Integer> functionNodeIndices) throws SQLException {
if (functionNodeIndices.isEmpty()) {
return;
}
final String query = "INSERT INTO " + CTableNames.FUNCTION_NODES_TABLE + "(module_id, node_id, function, comment_id) VALUES (?, ?, ?, ?)";
final ArrayList<INaviFunctionNode> functionNodesWithUnsavedComments = new ArrayList<INaviFunctionNode>();
final PreparedStatement preparedStatement = provider.getConnection().getConnection().prepareStatement(query);
try {
for (final int index : functionNodeIndices) {
final CFunctionNode node = (CFunctionNode) nodes.get(index);
final INaviFunction function = node.getFunction();
final List<IComment> comments = node.getLocalFunctionComment();
final Integer commentId = comments == null ? null : comments.size() == 0 ? null : Iterables.getLast(comments).getId();
if ((comments != null) && (comments.size() != 0) && (commentId == null)) {
functionNodesWithUnsavedComments.add(node);
}
preparedStatement.setInt(1, function.getModule().getConfiguration().getId());
preparedStatement.setInt(2, firstNode + index);
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();
}
for (final INaviFunctionNode functionNode : functionNodesWithUnsavedComments) {
final ArrayList<IComment> functionNodeComments = new ArrayList<IComment>();
for (final IComment comment : functionNode.getLocalFunctionComment()) {
try {
final Integer commentId = provider.appendFunctionNodeComment(functionNode, comment.getComment(), comment.getUser().getUserId());
final IComment newComment = new CComment(commentId, comment.getUser(), comment.getParent(), comment.getComment());
functionNodeComments.add(newComment);
} catch (final CouldntSaveDataException exception) {
CUtilityFunctions.logException(exception);
}
}
functionNode.initializeLocalFunctionComment(functionNodeComments);
}
}
Aggregations