use of com.google.security.zynamics.binnavi.disassembly.CCodeNode in project binnavi by google.
the class CCodeNodeParserTest method testSameOperandTwice.
@Test
public void testSameOperandTwice() throws ParserException, CPartialLoadException, IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
// 00000000: jz eax
// 00000001: jg eax
final MockCodeNodeProvider cnProvider = new MockCodeNodeProvider();
final MockCodeNodeData instruction1 = new MockCodeNodeData();
instruction1.nodeId = 0;
instruction1.expressionId = 0;
instruction1.expressionType = 5;
instruction1.operandPosition = 0;
instruction1.symbol = "eax";
final MockCodeNodeData instruction2 = new MockCodeNodeData();
instruction2.address = new CAddress(BigInteger.ONE);
instruction2.nodeId = 1;
instruction2.expressionId = 0;
instruction2.expressionType = 5;
instruction2.operandPosition = 0;
instruction2.symbol = "eax";
cnProvider.data.add(instruction1);
cnProvider.data.add(instruction2);
final MockSqlProvider provider = new MockSqlProvider();
final MockModule module = new MockModule();
CFunctionContainerHelper.addFunction(module.getContent().getFunctionContainer(), new MockFunction(0));
final CCodeNodeParser p = new CCodeNodeParser(cnProvider, Lists.newArrayList(module), provider);
final List<CCodeNode> result = p.parse();
assertEquals(2, result.size());
assertEquals(1, Iterables.size(result.get(0).getInstructions()));
assertEquals(1, Iterables.size(result.get(1).getInstructions()));
}
use of com.google.security.zynamics.binnavi.disassembly.CCodeNode in project binnavi by google.
the class CCodeNodeParserTest method testSingleInstruction.
@Test
public void testSingleInstruction() throws ParserException, CPartialLoadException, IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
// nop
final MockCodeNodeProvider cnProvider = new MockCodeNodeProvider();
cnProvider.data.add(new MockCodeNodeData());
final MockSqlProvider provider = new MockSqlProvider();
final MockModule module = new MockModule();
CFunctionContainerHelper.addFunction(module.getContent().getFunctionContainer(), new MockFunction(0));
final CCodeNodeParser p = new CCodeNodeParser(cnProvider, Lists.newArrayList(module), provider);
final List<CCodeNode> result = p.parse();
assertEquals(1, result.size());
}
use of com.google.security.zynamics.binnavi.disassembly.CCodeNode in project binnavi by google.
the class CCodeNodeParserTest method testMultipleOperands.
@Test
public void testMultipleOperands() throws ParserException, CPartialLoadException, IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
// 00000000: mov eax, ebx
final MockCodeNodeProvider cnProvider = new MockCodeNodeProvider();
final MockCodeNodeData instruction1a = new MockCodeNodeData();
instruction1a.mnemonic = "mov";
instruction1a.nodeId = 0;
instruction1a.expressionId = 0;
instruction1a.expressionType = 5;
instruction1a.operandPosition = 0;
instruction1a.symbol = "eax";
final MockCodeNodeData instruction1b = new MockCodeNodeData();
instruction1b.mnemonic = "mov";
instruction1b.nodeId = 0;
instruction1b.expressionId = 1;
instruction1b.expressionType = 5;
instruction1b.operandPosition = 1;
instruction1b.symbol = "ebx";
cnProvider.data.add(instruction1a);
cnProvider.data.add(instruction1b);
final MockSqlProvider provider = new MockSqlProvider();
final MockModule module = new MockModule();
CFunctionContainerHelper.addFunction(module.getContent().getFunctionContainer(), new MockFunction(0));
final CCodeNodeParser p = new CCodeNodeParser(cnProvider, Lists.newArrayList(module), provider);
final List<CCodeNode> result = p.parse();
assertEquals(1, result.size());
assertEquals(1, Iterables.size(result.get(0).getInstructions()));
final INaviInstruction instruction = Iterables.getFirst(result.get(0).getInstructions(), null);
assertEquals("mov", instruction.getMnemonic());
assertEquals("dword", instruction.getOperands().get(0).getRootNode().getValue());
assertEquals("eax", instruction.getOperands().get(0).getRootNode().getChildren().get(0).getValue());
assertEquals("dword", instruction.getOperands().get(1).getRootNode().getValue());
assertEquals("ebx", instruction.getOperands().get(1).getRootNode().getChildren().get(0).getValue());
}
use of com.google.security.zynamics.binnavi.disassembly.CCodeNode in project binnavi by google.
the class CCodeNodeParserTest method testReference.
@Test
public void testReference() throws ParserException, CPartialLoadException, IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
// 00000000: jz 123
final MockCodeNodeProvider cnProvider = new MockCodeNodeProvider();
final MockCodeNodeData instruction1 = new MockCodeNodeData();
instruction1.reference = new CReference(new CAddress(BigInteger.valueOf(123)), ReferenceType.CONDITIONAL_TRUE);
instruction1.nodeId = 0;
instruction1.expressionId = 0;
instruction1.expressionType = 2;
instruction1.operandPosition = 0;
instruction1.immediate = "123";
cnProvider.data.add(instruction1);
final MockSqlProvider provider = new MockSqlProvider();
final MockModule module = new MockModule();
CFunctionContainerHelper.addFunction(module.getContent().getFunctionContainer(), new MockFunction(0));
final CCodeNodeParser p = new CCodeNodeParser(cnProvider, Lists.newArrayList(module), provider);
final List<CCodeNode> result = p.parse();
assertEquals(1, result.size());
assertEquals(1, Iterables.size(result.get(0).getInstructions()));
}
use of com.google.security.zynamics.binnavi.disassembly.CCodeNode 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;
}
Aggregations