use of com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent in project binnavi by google.
the class TooltipGenerator method createTooltip.
/**
* Creates the tooltip for an edge in the graph.
*
* @param <NodeType> Type of the nodes in the graph.
*
* @param graph The graph the edge belongs to.
* @param edge The edge the tooltip is created for.
*
* @return The generated tooltip text for the edge.
*/
public static <NodeType extends ZyGraphNode<?>> String createTooltip(final AbstractZyGraph<NodeType, ?> graph, final Edge edge) {
Preconditions.checkNotNull(graph, "Error: Graph argument can not be null");
Preconditions.checkNotNull(edge, "Error: Edge argument can not be null");
// The generated tooltip has the following form:
//
// 1. Content of the source node
// 2. Content of the edge label
// 3. Content of the target node
String text = createTooltip(graph, edge.source()).replace("</html>", "");
final ZyEdgeRealizer<?> realizer = (ZyEdgeRealizer<?>) graph.getGraph().getRealizer(edge);
if (realizer.labelCount() > 0) {
final ZyEdgeLabel edgeLabel = (ZyEdgeLabel) realizer.getLabel();
final ZyLabelContent content = edgeLabel.getLabelContent();
text += "<hr>" + HtmlGenerator.getHtml(content, GuiHelper.getMonospaceFont(), false).replace("<html>", "").replace("</html>", "");
}
text += "<hr>" + createTooltip(graph, edge.target()).replace("<html>", "");
return text;
}
use of com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent in project binnavi by google.
the class ZyTextNodeBuilder method buildContent.
/**
* Builds the content of the text node.
*
* @param node The node for which the context is built.
*
* @return The created node content.
*/
public static ZyLabelContent buildContent(final INaviTextNode node) {
Preconditions.checkNotNull(node, "IE01700: Node argument can not be null");
final ZyLabelContent content = new ZyLabelContent(null);
buildContent(content, node);
return content;
}
use of com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent in project binnavi by google.
the class ZyCodeNodeBuilder method buildContent.
/**
* Builds the visible content of a code node.
*
* @param node The code node that provides the raw data.
* @param graphSettings Provides settings that influence node formatting.
* @param modifier Calculates the address strings. This argument can be null.
*
* @return The content that was built from the information from the raw node.
*/
public static ZyLabelContent buildContent(final INaviCodeNode node, final ZyGraphViewSettings graphSettings, final INodeModifier modifier) {
Preconditions.checkNotNull(node, "IE00897: Node argument can not be null");
final ZyLabelContent content = new ZyLabelContent(new IZyEditableObject() {
@Override
public int getEnd() {
throw new IllegalStateException();
}
@Override
public int getLength() {
throw new IllegalStateException();
}
@Override
public Object getPersistentModel() {
throw new IllegalStateException();
}
@Override
public int getStart() {
throw new IllegalStateException();
}
@Override
public boolean isCommentDelimiter() {
throw new IllegalStateException();
}
@Override
public boolean isPlaceholder() {
throw new IllegalStateException();
}
@Override
public boolean update(final String newContent) {
throw new IllegalStateException();
}
@Override
public boolean updateComment(final String newContent, final ECommentPlacement placement) {
throw new IllegalStateException();
}
}, true, false);
buildContent(content, node, graphSettings, modifier);
return content;
}
use of com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent in project binnavi by google.
the class ZyGraphFactory method generateTestGraph.
public static ZyGraph generateTestGraph() throws FileReadException, CouldntLoadDataException, LoadCancelledException, CouldntSaveDataException {
ConfigManager.instance().read();
final MockDatabase database = new MockDatabase();
final SQLProvider provider = new MockSqlProvider();
final CModule module = new CModule(1, "", "", new Date(), new Date(), CommonTestObjects.MD5, CommonTestObjects.SHA1, 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, provider);
final ZyGraphViewSettings settings = new ZyGraphViewSettings(new CallGraphSettingsConfigItem());
settings.getLayoutSettings().setDefaultGraphLayout(LayoutStyle.CIRCULAR);
database.getContent().addModule(module);
final MockDatabaseManager manager = new MockDatabaseManager();
manager.addDatabase(database);
module.load();
final CView m_view = module.getContent().getViewContainer().createView("name", "description");
final LinkedHashMap<Node, NaviNode> nodeMap = new LinkedHashMap<Node, NaviNode>();
final ZyGraph2DView g2dView = new ZyGraph2DView();
final LinkedHashMap<Edge, NaviEdge> edgeMap = new LinkedHashMap<Edge, NaviEdge>();
final Node node1 = g2dView.getGraph2D().createNode();
final COperandTreeNode rootNode1 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
final COperandTreeNode childNode1 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_REGISTER_ID, "eax", null, new ArrayList<IReference>(), provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
COperandTreeNode.link(rootNode1, childNode1);
final COperandTreeNode rootNode2 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
final COperandTreeNode childNode2 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_REGISTER_ID, "ebx", null, new ArrayList<IReference>(), provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
COperandTreeNode.link(rootNode2, childNode2);
final COperandTree operand1 = new COperandTree(rootNode1, provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
final COperandTree operand2 = new COperandTree(rootNode2, provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
final ArrayList<COperandTree> operands1 = Lists.newArrayList(operand1, operand2);
final List<INaviInstruction> instructions1 = Lists.newArrayList((INaviInstruction) new MockInstruction(new CAddress(0x123456), "mov", operands1, null, module));
final INaviCodeNode rawNode1 = m_view.getContent().createCodeNode(null, instructions1);
final ZyLabelContent content = ZyCodeNodeBuilder.buildContent(rawNode1, settings, null);
nodeMap.put(node1, new NaviNode(node1, new ZyNormalNodeRealizer<NaviNode>(content), rawNode1));
final Node node2 = g2dView.getGraph2D().createNode();
final List<INaviInstruction> instructions2 = Lists.newArrayList((INaviInstruction) new MockInstruction());
final INaviCodeNode rawNode2 = m_view.getContent().createCodeNode(null, instructions2);
final ZyLabelContent content2 = ZyCodeNodeBuilder.buildContent(rawNode2, settings, null);
nodeMap.put(node2, new NaviNode(node2, new ZyNormalNodeRealizer<NaviNode>(content2), rawNode2));
rawNode2.setColor(Color.RED);
rawNode2.setVisible(false);
final CTag tag = new CTag(0, "Tag", "Description", TagType.NODE_TAG, new MockSqlProvider());
rawNode2.tagNode(tag);
final Node node3 = g2dView.getGraph2D().createNode();
final String mnemonicName = "call";
final List<COperandTree> operandTrees = new ArrayList<COperandTree>();
final int type = ExpressionType.REGISTER.ordinal();
final CReference reference = new CReference(new CAddress(0x123), ReferenceType.CALL_DIRECT);
final List<IReference> referencea = new ArrayList<IReference>();
referencea.add(reference);
final COperandTreeNode root = new COperandTreeNode(0, type, "eax", null, referencea, provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
final COperandTree operandTree = new COperandTree(root, provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
operandTrees.add(0, operandTree);
final List<INaviInstruction> instructions3 = Lists.newArrayList((INaviInstruction) new MockInstruction(mnemonicName, operandTrees, m_globalComment));
final INaviCodeNode rawNode3 = m_view.getContent().createCodeNode(null, instructions3);
final ZyLabelContent content3 = ZyCodeNodeBuilder.buildContent(rawNode3, settings, null);
nodeMap.put(node3, new NaviNode(node3, new ZyNormalNodeRealizer<NaviNode>(content3), rawNode3));
final Edge edge = g2dView.getGraph2D().createEdge(node1, node2);
final INaviEdge rawEdge = m_view.getContent().createEdge(rawNode1, rawNode2, EdgeType.JUMP_UNCONDITIONAL);
edgeMap.put(edge, new NaviEdge(nodeMap.get(node1), nodeMap.get(node2), edge, new ZyEdgeRealizer<NaviEdge>(new ZyLabelContent(null), null), rawEdge));
final Edge edge2 = g2dView.getGraph2D().createEdge(node2, node3);
final INaviEdge rawEdge2 = m_view.getContent().createEdge(rawNode2, rawNode3, EdgeType.JUMP_UNCONDITIONAL);
edgeMap.put(edge2, new NaviEdge(nodeMap.get(node2), nodeMap.get(node3), edge, new ZyEdgeRealizer<NaviEdge>(new ZyLabelContent(null), null), rawEdge2));
return new ZyGraph(m_view, nodeMap, edgeMap, settings, g2dView);
}
use of com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent in project binnavi by google.
the class GraphSearcherTest method setUp.
@Before
public void setUp() throws CouldntLoadDataException, CPartialLoadException, LoadCancelledException {
final Graph2D g = new Graph2D();
m_ynode = g.createNode();
final MockSqlProvider sql = new MockSqlProvider();
final CModule module = MockCreator.createModule(sql);
module.load();
final CFunction function = MockCreator.createFunction(module, sql);
final CView m_view = MockCreator.createView(sql, module);
final CInstruction instruction1 = MockCreator.createInstruction(module, sql);
final CInstruction instruction2 = MockCreator.createInstruction(module, sql);
final CInstruction instruction3 = MockCreator.createInstruction(module, sql);
m_view.load();
m_codeNode1 = m_view.getContent().createCodeNode(function, Lists.newArrayList(instruction1, instruction2, instruction3));
m_content = new ZyLabelContent(null);
}
Aggregations