use of com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge in project binnavi by google.
the class CViewContent method createEdge.
@Override
public CNaviViewEdge createEdge(final INaviViewNode source, final INaviViewNode target, final EdgeType edgeType) {
Preconditions.checkNotNull(source, "IE00290: Source argument can not be null");
Preconditions.checkNotNull(target, "IE00291: Target argument can not be null");
Preconditions.checkNotNull(edgeType, "IE00292: Edge type argument can not be null");
Preconditions.checkArgument(source.inSameDatabase(provider), "IE00187: Source node is not in the same database");
Preconditions.checkArgument(target.inSameDatabase(provider), "IE00189: Target node is not in the same database");
final CNaviViewEdge edge = new CNaviViewEdge(-1, source, target, edgeType, 0, 0, 0, 0, Color.BLACK, false, true, null, new ArrayList<CBend>(), provider);
source.addOutgoingEdge(edge);
target.addIncomingEdge(edge);
edge.addListener(m_internalEdgeListener);
graph.addEdge(edge);
for (final INaviViewListener listener : listeners) {
try {
listener.addedEdge(view, edge);
} catch (final Exception exception) {
CUtilityFunctions.logException(exception);
}
}
return edge;
}
use of com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge in project binnavi by google.
the class CViewInserter method createEdges.
/**
* Clones the edges of the source view and inserts them into the target view.
*
* @param target The target view where the cloned edges are inserted.
* @param edges The source edges that are cloned.
* @param nodeMap Maps between the source nodes and their cloned counterparts.
*/
private static void createEdges(final INaviView target, final List<INaviEdge> edges, final Map<INaviViewNode, INaviViewNode> nodeMap) {
for (final INaviEdge edge : edges) {
final INaviViewNode sourceNode = nodeMap.get(edge.getSource());
final INaviViewNode targetNode = nodeMap.get(edge.getTarget());
final CNaviViewEdge newEdge = target.getContent().createEdge(sourceNode, targetNode, edge.getType());
newEdge.setColor(edge.getColor());
newEdge.setX1(edge.getX1());
newEdge.setY1(edge.getY1());
newEdge.setX2(edge.getX2());
newEdge.setY2(edge.getY2());
for (final CBend bend : edge.getBends()) {
newEdge.addBend(bend.getX(), bend.getY());
}
}
}
use of com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge in project binnavi by google.
the class PostgreSQLProviderTest method testSave.
@Test
public void testSave() throws CouldntSaveDataException, CouldntLoadDataException, CouldntDeleteException, CPartialLoadException, InternalTranslationException, LoadCancelledException, MaybeNullException {
final CTagManager tagManager = getProvider().loadTagManager(TagType.NODE_TAG);
tagManager.addTag(tagManager.getRootTag(), "Node Tag I");
tagManager.addTag(tagManager.getRootTag(), "Node Tag II");
final ITreeNode<CTag> tag1 = tagManager.getRootTag().getChildren().get(0);
final ITreeNode<CTag> tag2 = tagManager.getRootTag().getChildren().get(1);
final INaviModule module = getProvider().loadModules().get(0);
module.load();
final CView view = module.getContent().getViewContainer().createView("Save View", "Save View Description");
final INaviFunction function = module.getContent().getFunctionContainer().getFunction("sub_1002B87");
function.load();
final List<COperandTree> operands = new ArrayList<COperandTree>();
final COperandTreeNode root1 = module.createOperandExpression("dword", ExpressionType.SIZE_PREFIX);
final COperandTreeNode child1 = module.createOperandExpression("eax", ExpressionType.REGISTER);
COperandTreeNode.link(root1, child1);
final COperandTreeNode root2 = module.createOperandExpression("dword", ExpressionType.SIZE_PREFIX);
final COperandTreeNode child2 = module.createOperandExpression("16", ExpressionType.IMMEDIATE_INTEGER);
COperandTreeNode.link(root2, child2);
final COperandTree operand1 = module.createOperand(root1);
final COperandTree operand2 = module.createOperand(root2);
operands.add(operand1);
operands.add(operand2);
final Iterable<INaviInstruction> instructions = function.getBasicBlocks().get(0).getInstructions();
final Iterable<INaviInstruction> instructions2 = function.getBasicBlocks().get(1).getInstructions();
final CCodeNode codeNode = view.getContent().createCodeNode(function, Lists.newArrayList(instructions));
codeNode.tagNode(tag1.getObject());
codeNode.getComments().appendLocalCodeNodeComment("XXX");
codeNode.getComments().appendLocalInstructionComment(Iterables.getLast(codeNode.getInstructions()), "YYY");
Iterables.getLast(codeNode.getInstructions()).appendGlobalComment(" GLOBAL INSTRUCTION COMMENT ");
@SuppressWarnings("unused") final CCodeNode codeNode2 = view.getContent().createCodeNode(null, Lists.newArrayList(instructions2));
final CFunctionNode functionNode = view.getContent().createFunctionNode(function);
functionNode.tagNode(tag2.getObject());
functionNode.appendLocalFunctionComment("ZZZ");
@SuppressWarnings("unused") final CNaviViewEdge edge = view.getContent().createEdge(codeNode, functionNode, EdgeType.JUMP_UNCONDITIONAL);
view.save();
view.close();
view.load();
assertEquals(3, view.getGraph().getNodes().size());
assertEquals(1, view.getGraph().getEdges().size());
assertTrue(view.getGraph().getNodes().get(0).isTagged(tag1.getObject()));
assertTrue(view.getGraph().getNodes().get(2).isTagged(tag2.getObject()));
final CCodeNode loadedCodeNode = (CCodeNode) view.getGraph().getNodes().get(0);
final CCodeNode loadedCodeNode2 = (CCodeNode) view.getGraph().getNodes().get(1);
assertEquals("XXX", loadedCodeNode.getComments().getLocalCodeNodeComment().get(0).getComment());
final INaviInstruction customInstruction = Iterables.getLast(loadedCodeNode.getInstructions());
assertEquals(" GLOBAL INSTRUCTION COMMENT ", customInstruction.getGlobalComment().get(0).getComment());
assertEquals("YYY", loadedCodeNode.getComments().getLocalInstructionComment(customInstruction).get(0).getComment());
final ReilTranslator<INaviInstruction> translator = new ReilTranslator<INaviInstruction>();
translator.translate(new StandardEnvironment(), loadedCodeNode);
translator.translate(new StandardEnvironment(), loadedCodeNode2);
final CFunctionNode loadedFunctionNode = (CFunctionNode) view.getGraph().getNodes().get(2);
assertEquals("ZZZ", loadedFunctionNode.getLocalFunctionComment().get(0).getComment());
tagManager.deleteTag(tag1);
tagManager.deleteTag(tag2);
}
use of com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge in project binnavi by google.
the class CReilViewCreator method create.
/**
* Creates a REIL view object from a REIL graph.
*
* @param container The container in which the new REIL view is created.
* @param graph The graph that contains the REIL code to be shown in the view.
*
* @return The created REIL code view.
*/
public static INaviView create(final INaviModule container, final ReilGraph graph) {
Preconditions.checkNotNull(container, "IE01809: Container argument can not be null");
Preconditions.checkNotNull(graph, "IE01815: Graph argument can not be null");
final INaviView view = container.getContent().getViewContainer().createView("REIL View", "");
final Map<ReilBlock, CCodeNode> nodeMap = new HashMap<ReilBlock, CCodeNode>();
for (final ReilBlock block : graph) {
final List<INaviInstruction> instructions = new ArrayList<INaviInstruction>();
for (final ReilInstruction reilInstruction : block) {
final List<COperandTree> operands = new ArrayList<COperandTree>();
if (reilInstruction.getFirstOperand().getType() == OperandType.EMPTY) {
operands.add(getEmptyOperand(container));
} else {
operands.add(convert(container, reilInstruction.getFirstOperand()));
}
if (reilInstruction.getSecondOperand().getType() == OperandType.EMPTY) {
operands.add(getEmptyOperand(container));
} else {
operands.add(convert(container, reilInstruction.getSecondOperand()));
}
if (reilInstruction.getThirdOperand().getType() == OperandType.EMPTY) {
operands.add(getEmptyOperand(container));
} else {
operands.add(convert(container, reilInstruction.getThirdOperand()));
}
final INaviInstruction convertedInstruction = container.createInstruction(reilInstruction.getAddress(), reilInstruction.getMnemonic(), operands, new byte[0], "REIL");
instructions.add(convertedInstruction);
}
final CCodeNode node = view.getContent().createCodeNode(null, instructions);
node.setColor(ConfigManager.instance().getColorSettings().getBasicBlocksColor());
nodeMap.put(block, node);
}
for (final ReilEdge edge : graph.getEdges()) {
final CNaviViewEdge reilEdge = view.getContent().createEdge(nodeMap.get(edge.getSource()), nodeMap.get(edge.getTarget()), edge.getType());
EdgeInitializer.adjustColor(reilEdge);
}
return view;
}
use of com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge in project binnavi by google.
the class CUnInlinerTest method testUninlineSingleBlock.
@Test
public void testUninlineSingleBlock() {
final List<INaviViewNode> nodes = new FilledList<INaviViewNode>();
final List<INaviEdge> edges = new FilledList<INaviEdge>();
final INaviFunction mockFunction = new MockFunction(m_provider);
final INaviFunction mockFunction2 = new MockFunction(m_provider);
final MockInstruction mi1 = new MockInstruction(0x123);
final MockInstruction mi2 = new MockInstruction(0x124);
final MockInstruction mi3 = new MockInstruction(0x125);
final CCodeNode upperNode = new CCodeNode(0, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
final CCodeNode inlinedNode = new CCodeNode(0, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction2, new HashSet<CTag>(), m_provider);
final CCodeNode lowerNode = new CCodeNode(0, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
final CTextNode textNode = new CTextNode(0, 0, 0, 0, 0, Color.RED, false, true, new HashSet<CTag>(), null, m_provider);
upperNode.addInstruction(mi1, null);
inlinedNode.addInstruction(mi2, null);
lowerNode.addInstruction(mi3, null);
nodes.add(upperNode);
nodes.add(inlinedNode);
nodes.add(textNode);
nodes.add(lowerNode);
final CNaviViewEdge enteringEdge = new CNaviViewEdge(0, upperNode, inlinedNode, EdgeType.ENTER_INLINED_FUNCTION, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
final CNaviViewEdge leavingEdge = new CNaviViewEdge(0, inlinedNode, lowerNode, EdgeType.LEAVE_INLINED_FUNCTION, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
final CNaviViewEdge textEdge = new CNaviViewEdge(0, textNode, inlinedNode, EdgeType.TEXTNODE_EDGE, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
edges.add(enteringEdge);
edges.add(leavingEdge);
edges.add(textEdge);
connect(upperNode, inlinedNode, enteringEdge);
connect(inlinedNode, lowerNode, leavingEdge);
connect(textNode, inlinedNode, textEdge);
final MockView view = new MockView(nodes, edges, m_provider);
CUnInliner.unInline(view, inlinedNode);
assertEquals(1, view.getNodeCount());
assertEquals(0, view.getEdgeCount());
final INaviCodeNode cnode = (INaviCodeNode) view.getGraph().getNodes().get(0);
assertEquals(2, Iterables.size(cnode.getInstructions()));
assertEquals(mi1.toString(), Iterables.get(cnode.getInstructions(), 0).toString());
assertEquals(mi3.toString(), Iterables.get(cnode.getInstructions(), 1).toString());
}
Aggregations