use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.
the class BasicBlockTest method testConstructor.
@Test
public void testConstructor() throws InternalTranslationException {
final MockSqlProvider provider = new MockSqlProvider();
final CModule internalModule = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, provider);
final CFunction internalFunction = new CFunction(internalModule, new MockView(), new CAddress(0x123), "Mock Function", "Mock Function", "Mock Description", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, provider);
final List<INaviInstruction> instructions = new ArrayList<INaviInstruction>();
instructions.add(new MockInstruction(0x123));
final INaviBasicBlock bblock = new CBasicBlock(1, "Hannes", instructions);
final IBlockNode node = new CBlockNode(bblock);
final Function pFunction = new Function(ModuleFactory.get(), internalFunction);
final BasicBlock block = new BasicBlock(node, pFunction);
assertEquals(0x123, block.getAddress().toLong());
assertEquals(pFunction, block.getParentFunction());
assertEquals("Hannes", block.getComment());
assertEquals(0x123, block.getInstructions().get(0).getAddress().toLong());
assertNotNull(block.getReilCode());
assertTrue(block.getChildren().isEmpty());
assertTrue(block.getParents().isEmpty());
assertEquals("123 nop \n", block.toString());
}
use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.
the class BlockEdgeTest method testConstructor.
@Test
public void testConstructor() {
final MockSqlProvider provider = new MockSqlProvider();
final CModule internalModule = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, provider);
final CFunction parentFunction = new CFunction(internalModule, new MockView(), new CAddress(0x123), "Mock Function", "Mock Function", "Mock Description", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, provider);
final List<INaviInstruction> instructions = new ArrayList<INaviInstruction>();
instructions.add(new MockInstruction(0x123));
final INaviBasicBlock bblock = new CBasicBlock(1, "Hannes", instructions);
final IBlockNode node = new CBlockNode(bblock);
final Function pFunction = new Function(ModuleFactory.get(), parentFunction);
final BasicBlock block1 = new BasicBlock(node, pFunction);
final BasicBlock block2 = new BasicBlock(node, pFunction);
final IBlockEdge mockEdge = new CFunctionEdge(node, node, com.google.security.zynamics.zylib.gui.zygraph.edges.EdgeType.JUMP_UNCONDITIONAL);
final BlockEdge edge = new BlockEdge(mockEdge, block1, block2);
assertEquals(block1, edge.getSource());
assertEquals(block2, edge.getTarget());
assertEquals(block1, block2.getParents().get(0));
assertEquals(block2, block1.getChildren().get(0));
assertEquals(EdgeType.JumpUnconditional, edge.getType());
assertEquals("Block Edge [123 -> 123]", edge.toString());
}
use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.
the class CGraphInliner method inlineAll.
/**
* Inlines all function calls of a given graph.
*
* @param parent Parent window used for dialogs.
* @param container Contains the functions to be inlined.
* @param graph Graph where the inline operation takes place.
*/
public static void inlineAll(final JFrame parent, final IViewContainer container, final ZyGraph graph) {
Preconditions.checkNotNull(parent, "IE02285: Parent argument can not be null");
Preconditions.checkNotNull(container, "IE02286: Container argument can not be null");
Preconditions.checkNotNull(graph, "IE02287: Graph Argument can not be null");
final MutableDirectedGraph<INaviViewNode, INaviEdge> mutableGraph = (MutableDirectedGraph<INaviViewNode, INaviEdge>) graph.getRawView().getGraph();
final List<INaviViewNode> nodes = mutableGraph.getNodes();
final HashMap<INaviInstruction, INaviFunction> instructionToFunctionMap = new HashMap<INaviInstruction, INaviFunction>();
for (final INaviViewNode iNaviViewNode : nodes) {
if (iNaviViewNode instanceof INaviCodeNode) {
instructionToFunctionMap.putAll(CReferenceFinder.getCodeReferenceMap((INaviCodeNode) iNaviViewNode));
}
}
for (final INaviInstruction iNaviInstruction : instructionToFunctionMap.keySet()) {
INaviCodeNode updatedNode = null;
for (final INaviViewNode iNaviViewNode2 : graph.getRawView().getGraph().getNodes()) {
final INaviCodeNode codeNode = (INaviCodeNode) iNaviViewNode2;
if (codeNode.hasInstruction(iNaviInstruction)) {
updatedNode = codeNode;
}
}
if (updatedNode != null) {
inlineFunctionSilently(parent, container, graph, updatedNode, iNaviInstruction, instructionToFunctionMap.get(iNaviInstruction));
} else {
throw new IllegalStateException("IE01174: Graph final has been rendered final to an final inconsitant state");
}
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.
the class CLineGrayer method grayLine.
/**
* Grays or ungrays a line in a code node.
*
* @param model The model of the graph the node belongs to.
* @param node The node where the user clicked.
* @param codeNode The node that provides the raw data for the node.
* @param y The y location where the user clicked.
*/
private void grayLine(final CGraphModel model, final NaviNode node, final INaviCodeNode codeNode, final double y) {
final double yPos = y - node.getY();
final int row = node.positionToRow(yPos);
final INaviInstruction instruction = CCodeNodeHelpers.lineToInstruction(codeNode, row);
if (instruction == null) {
return;
}
if (m_grayedInstructions.contains(instruction)) {
final Pair<String, List<CStyleRunData>> content = ZyInstructionBuilder.buildInstructionLine(instruction, model.getGraph().getSettings(), new CDefaultModifier(model.getGraph().getSettings(), model.getDebuggerProvider()));
for (final CStyleRunData style : content.second()) {
node.setColor(row, style.getStart(), style.getLength(), style.getColor());
}
m_grayedInstructions.remove(instruction);
} else {
node.setColor(row, Color.LIGHT_GRAY);
m_grayedInstructions.add(instruction);
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.
the class PostgreSQLTypesNotificationParser method findOperandTreeNode.
/**
* Only used internally to find the necessary {@link INaviOperandTreeNode operand node} where a
* {@link TypeSubstitution type substitution} is associated to.
*
* @param provider The {@link SQLProvider} used to differentiate between the different caches used
* for getting {@link INaviInstruction instructions}.
* @param moduleId The id of the {@link INaviModule module} this {@link TypeSubstitution type
* substitution} is associated to.
* @param address The {@link CAddress} of the {@link INaviInstruction instruction} where the
* {@link TypeSubstitution type substitution} is associated to.
* @param position The {@link INaviOperandTree operand tree} position where the
* {@link TypeSubstitution type substitution} is associated to.
* @param operandNodeId the id of the {@link INaviOperandTreeNode operand node} to which the
* {@link TypeSubstitution type substitution} is associated.
* @return A {@link INaviOperandTreeNode} if it is in the cache otherwise null;
*/
private INaviOperandTreeNode findOperandTreeNode(final SQLProvider provider, final int moduleId, final CAddress address, final int position, final int operandNodeId) {
final INaviInstruction instruction = InstructionCache.get(provider).getInstructionByAddress(address, moduleId);
if (instruction != null) {
final INaviOperandTree operandTree = instruction.getOperands().get(position);
final INaviOperandTreeNode root = operandTree.getRootNode();
final OperandOrderIterator iterator = new OperandOrderIterator(root);
while (iterator.next()) {
final INaviOperandTreeNode currentNode = (INaviOperandTreeNode) iterator.current();
if (currentNode.getId() == operandNodeId) {
return currentNode;
}
}
}
return null;
}
Aggregations