use of com.google.security.zynamics.binnavi.disassembly.CTextNode in project binnavi by google.
the class View method createNode.
// ! Clones an existing node.
/**
* Creates a new view node by cloning an existing view node.
*
* @param node The node to clone.
*
* @return The cloned node.
*/
public ViewNode createNode(final ViewNode node) {
Preconditions.checkNotNull(node, "Error: Node argument can not be null");
if (node instanceof CodeNode) {
final List<INaviInstruction> instructionsList = new ArrayList<INaviInstruction>();
for (final Instruction instruction : ((CodeNode) node).getInstructions()) {
Preconditions.checkNotNull(instruction, "Error: Instruction list contains a null-element");
instructionsList.add(instruction.getNative());
}
CCodeNode newNode;
try {
newNode = naviView.getContent().createCodeNode(((INaviCodeNode) node.getNative()).getParentFunction(), instructionsList);
} catch (final MaybeNullException e) {
newNode = naviView.getContent().createCodeNode(null, instructionsList);
}
adjustAttributes(node, newNode);
return cachedNodes.get(newNode);
} else if (node instanceof FunctionNode) {
final CFunctionNode newNode = naviView.getContent().createFunctionNode(((INaviFunctionNode) node.getNative()).getFunction());
adjustAttributes(node, newNode);
return cachedNodes.get(newNode);
} else if (node instanceof TextNode) {
final CTextNode newNode = naviView.getContent().createTextNode(((TextNode) node).getComments());
adjustAttributes(node, newNode);
return cachedNodes.get(newNode);
} else if (node instanceof GroupNode) {
throw new IllegalStateException("Group nodes can not be cloned");
} else {
throw new IllegalStateException("Error: Unknown node type");
}
}
use of com.google.security.zynamics.binnavi.disassembly.CTextNode in project binnavi by google.
the class View method createTextNode.
// ! Creates a new text node.
/**
* creates a new text node.
*
* @param comments The list of comments to fill the text node with.
*
* @return The newly generated text node.
*/
public TextNode createTextNode(final ArrayList<IComment> comments) {
Preconditions.checkNotNull(comments, "Error: Text argument can not be null");
final CTextNode newTextNode = naviView.getContent().createTextNode(comments);
return (TextNode) cachedNodes.get(newTextNode);
}
use of com.google.security.zynamics.binnavi.disassembly.CTextNode in project binnavi by google.
the class CNodeFunctions method createCommentNode.
/**
* Attaches a comment node to a given view node.
*
* @param parent Parent used for dialogs.
* @param view The view where the new comment node is created.
* @param node The node the new comment node is attached to.
*/
public static void createCommentNode(final JFrame parent, final INaviView view, final INaviViewNode node) {
Preconditions.checkNotNull(parent, "IE02128: Parent argument can not be null");
Preconditions.checkNotNull(view, "IE02129: View argument can not be null");
Preconditions.checkNotNull(node, "IE01726: Node argument can not be null");
// TODO (timkornau): this is just transposed from the old code
// needs to be checked to if we still want this to be like this.
final CTextNode source = view.getContent().createTextNode(null);
final CNaviViewEdge edge = view.getContent().createEdge(source, node, EdgeType.TEXTNODE_EDGE);
final DialogTextNodeComment dlg = new DialogTextNodeComment(parent, source);
GuiHelper.centerChildToParent(parent, dlg, true);
dlg.setVisible(true);
final List<IComment> newComment = dlg.getComment();
if (newComment == null) {
view.getContent().deleteEdge(edge);
view.getContent().deleteNode(source);
}
}
use of com.google.security.zynamics.binnavi.disassembly.CTextNode in project binnavi by google.
the class ViewTest method testGraph.
@Test
public void testGraph() {
final List<INaviViewNode> nodes = new ArrayList<INaviViewNode>();
final List<INaviEdge> edges = new ArrayList<INaviEdge>();
final MutableDirectedGraph<INaviViewNode, INaviEdge> graph = new MutableDirectedGraph<INaviViewNode, INaviEdge>(nodes, edges);
final int viewId = new BigInteger(31, new SecureRandom()).intValue();
final INaviView internalView = new CView(viewId, internalModule, "My View", "My View Description", com.google.security.zynamics.zylib.disassembly.ViewType.NonNative, m_creationDate, m_modificationDate, graph, new HashSet<CTag>(), false, m_provider);
final INaviFunction internalFunction = internalModule.getContent().getFunctionContainer().getFunctions().get(0);
final CCodeNode codeNode = internalView.getContent().createCodeNode(internalFunction, Lists.newArrayList(new MockInstruction()));
final CFunctionNode functionNode = internalView.getContent().createFunctionNode(internalFunction);
@SuppressWarnings("unused") final CTextNode textNode = internalView.getContent().createTextNode(Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "Foo")));
@SuppressWarnings("unused") final CGroupNode groupNode = internalView.getContent().createGroupNode(internalView.getGraph().getNodes());
internalView.getContent().createEdge(codeNode, functionNode, com.google.security.zynamics.zylib.gui.zygraph.edges.EdgeType.JUMP_UNCONDITIONAL);
final TagManager tagManager = new TagManager(new MockTagManager(TagType.NODE_TAG));
final MockViewListener listener = new MockViewListener();
final View view = new View(module, internalView, tagManager, m_viewTagManager);
view.addListener(listener);
assertEquals(4, view.getGraph().getNodes().size());
assertEquals(1, view.getGraph().getEdges().size());
internalView.getContent().deleteNodes(internalView.getContent().getGraph().getNodes());
assertEquals("deletedEdge;deletedNode;deletedNode;deletedNode;", listener.events);
}
use of com.google.security.zynamics.binnavi.disassembly.CTextNode in project binnavi by google.
the class PostgreSQLNodeSaver method saveNodes.
/**
* Saves the nodes to the nodes table. As a side effect, this function also fills index lists that
* store the indices into the nodes list for all node types. TODO: This method should probably be
* split into two methods.
*
* @param provider Provides the connection to the database.
* @param newViewId ID of the new view that is being saved.
* @param nodes The nodes to save.
* @param functionNodeIndices Index into the nodes list that identifies the function nodes.
* @param codeNodeIndices Index into the nodes list that identifies the code nodes.
* @param textNodeIndices Index into the nodes list that identifies the text nodes.
* @param groupNodeIndices Index into the nodes list that identifies the group nodes.
* @param groupNodeMap Maps between node IDs and group node objects.
* @return The ID of the first node saved to the database.
* @throws SQLException Thrown if saving the nodes failed.
*/
private static int saveNodes(final AbstractSQLProvider provider, final int newViewId, final List<INaviViewNode> nodes, final List<Integer> functionNodeIndices, final List<Integer> codeNodeIndices, final List<Integer> textNodeIndices, final List<Integer> groupNodeIndices, final BiMap<Integer, INaviGroupNode> groupNodeMap) throws SQLException {
final String query = "INSERT INTO " + CTableNames.NODES_TABLE + "( view_id, parent_id, type, x, y, width, height, color, bordercolor, " + " selected, visible) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
final PreparedStatement preparedStatement = provider.getConnection().getConnection().prepareStatement(query, java.sql.Statement.RETURN_GENERATED_KEYS);
int counter = 0;
for (final INaviViewNode node : nodes) {
String nodeType = null;
if (node instanceof CCodeNode) {
nodeType = CODE;
codeNodeIndices.add(counter);
} else if (node instanceof CFunctionNode) {
nodeType = FUNCTION;
functionNodeIndices.add(counter);
} else if (node instanceof INaviGroupNode) {
nodeType = GROUP;
groupNodeIndices.add(counter);
groupNodeMap.put(counter, (INaviGroupNode) node);
} else if (node instanceof CTextNode) {
nodeType = TEXT;
textNodeIndices.add(counter);
}
counter++;
preparedStatement.setInt(1, newViewId);
preparedStatement.setNull(2, Types.INTEGER);
preparedStatement.setObject(3, nodeType, Types.OTHER);
preparedStatement.setDouble(4, node.getX());
preparedStatement.setDouble(5, node.getY());
preparedStatement.setDouble(6, node.getWidth());
preparedStatement.setDouble(7, node.getHeight());
preparedStatement.setInt(8, node.getColor().getRGB());
preparedStatement.setInt(9, node.getBorderColor().getRGB());
preparedStatement.setBoolean(10, node.isSelected());
preparedStatement.setBoolean(11, node.isVisible());
preparedStatement.addBatch();
}
preparedStatement.executeBatch();
final ResultSet resultSet = preparedStatement.getGeneratedKeys();
int lastId = 0;
try {
while (resultSet.next()) {
if (resultSet.isFirst()) {
lastId = resultSet.getInt(1);
break;
}
}
} finally {
preparedStatement.close();
resultSet.close();
}
return lastId;
}
Aggregations