use of com.google.security.zynamics.reil.algorithms.mono.OperandGraph in project binnavi by google.
the class CDataflowViewCreator method create.
/**
* Creates a new dataflow view.
*
* @param container The container in which the dataflow view is created.
* @param view The normal view that provides the control-flow information.
*
* @return The created dataflow view.
*
* @throws InternalTranslationException Thrown if the input view could not be translated to REIL.
*/
public static INaviView create(final IViewContainer container, final INaviView view) throws InternalTranslationException {
Preconditions.checkNotNull(container, "IE00411: Module argument can not be null");
Preconditions.checkNotNull(view, "IE00414: View argument can not be null");
final Map<IAddress, INaviInstruction> instructions = new HashMap<IAddress, INaviInstruction>();
for (final CCodeNode codeNode : view.getBasicBlocks()) {
for (final INaviInstruction instruction : codeNode.getInstructions()) {
instructions.put(instruction.getAddress(), instruction);
}
}
final ReilFunction function = view.getContent().getReilCode();
final OperandGraph operandGraph = OperandGraph.create(function.getGraph());
final INaviView dfView = container.createView(String.format("Data flow view of '%s'", view.getName()), "");
final Map<OperandGraphNode, INaviCodeNode> nodeMap = new HashMap<OperandGraphNode, INaviCodeNode>();
final Map<INaviInstruction, CCodeNode> instructionMap = new HashMap<INaviInstruction, CCodeNode>();
for (final OperandGraphNode operandGraphNode : operandGraph) {
final ReilInstruction reilInstruction = operandGraphNode.getInstruction();
final INaviInstruction instruction = instructions.get(ReilHelpers.toNativeAddress(reilInstruction.getAddress()));
if (instructionMap.containsKey(instruction)) {
nodeMap.put(operandGraphNode, instructionMap.get(instruction));
continue;
}
final CCodeNode codeNode = dfView.getContent().createCodeNode(null, Lists.newArrayList(instruction));
codeNode.setColor(ConfigManager.instance().getColorSettings().getBasicBlocksColor());
nodeMap.put(operandGraphNode, codeNode);
instructionMap.put(instruction, codeNode);
}
for (final OperandGraphEdge edge : operandGraph.getEdges()) {
final INaviCodeNode source = nodeMap.get(edge.getSource());
final INaviCodeNode target = nodeMap.get(edge.getTarget());
if (source.equals(target)) {
continue;
}
dfView.getContent().createEdge(source, target, EdgeType.JUMP_UNCONDITIONAL);
}
return dfView;
}
use of com.google.security.zynamics.reil.algorithms.mono.OperandGraph in project binnavi by google.
the class OperandGraphTest method testEmpty.
@Test
public void testEmpty() {
final ReilGraph rg = new ReilGraph(new ArrayList<ReilBlock>(), new ArrayList<ReilEdge>());
final OperandGraph g = OperandGraph.create(rg);
assertEquals(0, g.nodeCount());
assertEquals(0, g.edgeCount());
}
use of com.google.security.zynamics.reil.algorithms.mono.OperandGraph in project binnavi by google.
the class OperandGraphTest method testOneNode.
@Test
public void testOneNode() {
final Collection<ReilInstruction> instructions = new ArrayList<ReilInstruction>();
instructions.add(ReilHelpers.createAdd(0, OperandSize.DWORD, "eax", OperandSize.DWORD, "123", OperandSize.QWORD, "t0"));
instructions.add(ReilHelpers.createAnd(1, OperandSize.QWORD, "t0", OperandSize.DWORD, String.valueOf(0xFFFFFFFF), OperandSize.DWORD, "t1"));
final ReilBlock block1 = new ReilBlock(instructions);
final List<ReilBlock> blocks = Lists.<ReilBlock>newArrayList(block1);
final ReilGraph rg = new ReilGraph(blocks, new ArrayList<ReilEdge>());
final OperandGraph g = OperandGraph.create(rg);
assertEquals(6, g.nodeCount());
assertEquals(5, g.edgeCount());
}
use of com.google.security.zynamics.reil.algorithms.mono.OperandGraph in project binnavi by google.
the class OperandGraphTest method testTwoNodes.
@Test
public void testTwoNodes() {
final Collection<ReilInstruction> instructions1 = new ArrayList<ReilInstruction>();
instructions1.add(ReilHelpers.createAdd(0, OperandSize.DWORD, "eax", OperandSize.DWORD, "123", OperandSize.QWORD, "t0"));
final Collection<ReilInstruction> instructions2 = new ArrayList<ReilInstruction>();
instructions2.add(ReilHelpers.createAnd(1, OperandSize.QWORD, "t0", OperandSize.DWORD, String.valueOf(0xFFFFFFFF), OperandSize.DWORD, "t1"));
final ReilBlock block1 = new ReilBlock(instructions1);
final ReilBlock block2 = new ReilBlock(instructions2);
final ReilEdge edge1 = new ReilEdge(block1, block2, EdgeType.JUMP_CONDITIONAL_FALSE);
ReilBlock.link(block1, block2, edge1);
final List<ReilBlock> blocks = Lists.newArrayList(block1, block2);
final List<ReilEdge> edges = Lists.newArrayList(edge1);
final ReilGraph rg = new ReilGraph(blocks, edges);
final OperandGraph g = OperandGraph.create(rg);
assertEquals(6, g.nodeCount());
assertEquals(5, g.edgeCount());
}
Aggregations