use of com.google.security.zynamics.binnavi.API.disassembly.Instruction in project binnavi by google.
the class PathFinder method connectFunctions.
/**
* Connects the functions in the view using inlining edges.
*
* @param view The view where the edges are created.
* @param startNode The start node of the path.
* @param targetNode The target node of the path.
* @param passedFunctions All functions that lie on the path.
* @param entryNodes Keeps track of the entry nodes of all functions.
* @param exitNodes Keeps track of the exit nodes of all functions.
* @param functionMap Keeps track to what function a node belongs to.
*
* @return Node pair that contains the updated start node and target node.
*/
private static NodePair connectFunctions(final View view, final ViewNode startNode, final ViewNode targetNode, final Collection<FunctionBlock> passedFunctions, final Map<Function, ViewNode> entryNodes, final ArrayListMultimap<Function, ViewNode> exitNodes, final Map<ViewNode, Function> functionMap) {
ViewNode realStartNode = startNode;
ViewNode realTargetNode = targetNode;
final Set<ViewNode> handled = new HashSet<ViewNode>();
while (true) {
boolean splitNode = false;
start: for (final ViewNode node : view.getGraph().getNodes()) {
if (handled.contains(node)) {
continue;
}
if (!(node instanceof CodeNode)) {
continue;
}
final CodeNode cnode = (CodeNode) node;
for (final Instruction instruction : cnode.getInstructions()) {
for (final FunctionBlock functionBlock : passedFunctions) {
final Function function = functionBlock.getFunction();
if (callsFunction(instruction, function)) {
// A function call to a function on the path was found.
// At this point we have to split the code node after
// the function call.
final NodePair result = splitBlock(view, functionMap.get(cnode), cnode, instruction);
if (realStartNode == cnode) {
// Of course it is possible that the start node was split,
// therefore we have to update the start node to the upper
// part of the new node.
realStartNode = result.getFirst();
}
if (realTargetNode == cnode) {
// Of course it is possible that the target node was split,
// therefore we have to update the target node to the upper
// part of the new node.
realTargetNode = result.getFirst();
}
// too.
for (final FunctionBlock functionBlock2 : passedFunctions) {
final Function function2 = functionBlock2.getFunction();
if (entryNodes.get(function2) == cnode) {
// Update the entry nodes
entryNodes.put(function2, result.getFirst());
}
if (exitNodes.get(function2).contains(cnode)) {
// Update the exit nodes
if (result.getSecond() != null) {
exitNodes.remove(function2, cnode);
exitNodes.put(function2, result.getSecond());
}
}
}
if (functionMap.containsKey(cnode)) {
final Function f = functionMap.get(cnode);
functionMap.remove(cnode);
functionMap.put(result.getFirst(), f);
}
handled.add(result.getFirst());
if (result.getSecond() == null) {
for (final ViewEdge edge : node.getOutgoingEdges()) {
for (final ViewNode currentExitNode : exitNodes.get(function)) {
final ViewEdge leaveEdge = view.createEdge(currentExitNode, edge.getTarget(), EdgeType.LeaveInlinedFunction);
leaveEdge.setColor(DEFAULT_INLINING_EDGE_COLOR);
}
view.deleteEdge(edge);
}
final ViewEdge enterEdge = view.createEdge(result.getFirst(), entryNodes.get(function), EdgeType.EnterInlinedFunction);
enterEdge.setColor(DEFAULT_INLINING_EDGE_COLOR);
handled.add(cnode);
} else {
// The node was split. We simply have to connect both split parts to the
// called function.
final ViewEdge enterEdge = view.createEdge(result.getFirst(), entryNodes.get(function), EdgeType.EnterInlinedFunction);
enterEdge.setColor(DEFAULT_INLINING_EDGE_COLOR);
for (final ViewNode currentExitNode : exitNodes.get(function)) {
final ViewEdge leaveEdge = view.createEdge(currentExitNode, result.getSecond(), EdgeType.LeaveInlinedFunction);
leaveEdge.setColor(DEFAULT_INLINING_EDGE_COLOR);
}
}
splitNode = true;
break start;
}
}
}
handled.add(cnode);
}
if (!splitNode) {
break;
}
}
return new NodePair(realStartNode, realTargetNode);
}
use of com.google.security.zynamics.binnavi.API.disassembly.Instruction in project binnavi by google.
the class BreakpointHelpersTest method setUp.
@Before
public void setUp() throws DebugExceptionWrapper, CouldntLoadDataException, LoadCancelledException, FileReadException {
ConfigManager.instance().read();
final CDatabase database = new CDatabase("", "", "", "", "", "", "", false, false);
final Database apiDatabase = new Database(database);
final SQLProvider mockProvider = new MockSqlProvider();
final ITreeNode<CTag> nodeRootNode = new TreeNode<CTag>(new CTag(0, "", "", TagType.NODE_TAG, mockProvider));
final Tree<CTag> nodeTagTree = new Tree<CTag>(nodeRootNode);
final TagManager nodeTagManager = new TagManager(new CTagManager(nodeTagTree, TagType.NODE_TAG, mockProvider));
final ITreeNode<CTag> viewRootNode = new TreeNode<CTag>(new CTag(0, "", "", TagType.VIEW_TAG, mockProvider));
final Tree<CTag> viewTagTree = new Tree<CTag>(viewRootNode);
final TagManager viewTagManager = new TagManager(new CTagManager(viewTagTree, TagType.VIEW_TAG, mockProvider));
m_module = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, mockProvider);
m_module.load();
m_mockDebugger = new MockDebugger(m_moduleDebugSettings);
m_mockDebugger.connect();
m_debugger = new Debugger(m_mockDebugger);
final INaviFunction parentFunction = m_module.getContent().getFunctionContainer().getFunctions().get(0);
m_mockDebugger.setAddressTranslator(m_module, new CAddress(0), new CAddress(0x1000));
final ViewContainer viewContainer = new Module(apiDatabase, m_module, nodeTagManager, viewTagManager);
final INaviView naviView = new MockView(mockProvider);
final Function apiFunction = new Function(ModuleFactory.get(), parentFunction);
final COperandTreeNode rootNode1 = new COperandTreeNode(1, IOperandTree.NODE_TYPE_REGISTER_ID, "eax", null, new ArrayList<IReference>(), mockProvider, m_module.getTypeManager(), m_module.getContent().getTypeInstanceContainer());
final COperandTreeNode rootNode2 = new COperandTreeNode(1, IOperandTree.NODE_TYPE_REGISTER_ID, "ebx", null, new ArrayList<IReference>(), mockProvider, m_module.getTypeManager(), m_module.getContent().getTypeInstanceContainer());
final COperandTree operand1 = new COperandTree(rootNode1, mockProvider, m_module.getTypeManager(), m_module.getContent().getTypeInstanceContainer());
final COperandTree operand2 = new COperandTree(rootNode2, mockProvider, m_module.getTypeManager(), m_module.getContent().getTypeInstanceContainer());
final List<COperandTree> operands = Lists.newArrayList(operand1, operand2);
final CInstruction internalInstruction = new CInstruction(true, m_module, new CAddress(0x1234), "mov", operands, new byte[] { 1, 2, 3 }, "x86-32", mockProvider);
m_view = new View(viewContainer, naviView, nodeTagManager, viewTagManager);
m_node = m_view.createCodeNode(apiFunction, Lists.newArrayList(new Instruction(internalInstruction)));
setM_functionNode(m_view.createFunctionNode(apiFunction));
}
use of com.google.security.zynamics.binnavi.API.disassembly.Instruction in project binnavi by google.
the class InstructionFinders method findInstruction.
/**
* Searches for an instruction in a code node.
*
* @param codeNode The code node to search through.
* @param searchInstruction The instruction to search for.
*
* @return The API instruction object that wraps the search instruction.
*/
public static Instruction findInstruction(final CodeNode codeNode, final IInstruction searchInstruction) {
Preconditions.checkNotNull(codeNode, "IE02027: Code node argument can not be null");
Preconditions.checkNotNull(searchInstruction, "IE02033: Instruction argument can not be null");
for (final Instruction instruction : codeNode.getInstructions()) {
if (instruction.getNative() == searchInstruction) {
return instruction;
}
}
throw new IllegalStateException("IE01273: Could not determine what instruction could not be translated");
}
use of com.google.security.zynamics.binnavi.API.disassembly.Instruction in project binnavi by google.
the class InstructionFinders method findInstruction.
/**
* Searches for an instruction in a function.
*
* @param function The function to search through.
* @param searchInstruction The instruction to search for.
*
* @return The API instruction object that wraps the search instruction.
*/
public static Instruction findInstruction(final Function function, final IInstruction searchInstruction) {
Preconditions.checkNotNull(function, "IE02034: Function argument can not be null");
Preconditions.checkNotNull(searchInstruction, "IE02052: Instruction argument can not be null");
for (final BasicBlock block : function.getGraph().getNodes()) {
for (final Instruction instruction : block.getInstructions()) {
if (instruction.getNative() == searchInstruction) {
return instruction;
}
}
}
throw new IllegalStateException("IE01274: Could not determine what instruction could not be translated");
}
use of com.google.security.zynamics.binnavi.API.disassembly.Instruction in project binnavi by google.
the class BreakpointHelpers method getBreakpoints.
/**
* Returns the addresses of a code node where breakpoints of a given type are set.
*
* @param debugger The debugger that set the breakpoints.
* @param node The code node to check.
* @param type The type of the breakpoints to search for.
*
* @return The addresses of the code node where breakpoints are set.
*/
private static List<Address> getBreakpoints(final Debugger debugger, final CodeNode node, final BreakpointType type) {
Preconditions.checkNotNull(debugger, "Error: Debugger argument can not be null");
Preconditions.checkNotNull(node, "Error: Node argument can not be null");
final BreakpointManager manager = debugger.getBreakpointManager();
final List<Address> breakpoints = new ArrayList<Address>();
for (final Instruction instruction : node.getInstructions()) {
final BreakpointAddress address = new BreakpointAddress(instruction.getNative().getModule(), new UnrelocatedAddress(new CAddress(instruction.getAddress().toLong())));
if (manager.getNative().hasBreakpoint(type, address)) {
breakpoints.add(new Address(address.getAddress().getAddress().toBigInteger()));
}
}
return breakpoints;
}
Aggregations