use of com.google.security.zynamics.binnavi.API.disassembly.Function in project binnavi by google.
the class OutputGraphGenerator method createCompleteView.
/**
* Creates a view that shows all nodes and edges from the original call graph in addition to the
* newly resolved functions.
*
* @param target The target whose indirect modules were resolved.
* @param indirectCallAddresses The addresses of the indirect call objects from the target.
* @param resolvedAddresses The resolved function addresses.
*
* @return The generated view.
*/
public static View createCompleteView(final ICallResolverTarget target, final List<IndirectCall> indirectCallAddresses, final Map<BigInteger, Set<ResolvedFunction>> resolvedAddresses) {
final View view = target.createView();
final Map<Function, FunctionNode> nodes = new HashMap<Function, FunctionNode>();
for (final Module module : target.getModules()) {
for (final Function function : module.getFunctions()) {
final FunctionNode node = view.createFunctionNode(function);
nodes.put(function, node);
}
final Callgraph callgraph = module.getCallgraph();
for (final FunctionEdge edge : callgraph.getEdges()) {
final FunctionNode sourceNode = nodes.get(edge.getSource().getFunction());
final FunctionNode targetNode = nodes.get(edge.getTarget().getFunction());
view.createEdge(sourceNode, targetNode, EdgeType.JumpUnconditional);
}
}
for (final Entry<BigInteger, Set<ResolvedFunction>> element : resolvedAddresses.entrySet()) {
final BigInteger start = element.getKey();
final Set<ResolvedFunction> targets = element.getValue();
final IndirectCall call = IndirectCallResolver.findIndirectCall(target.getDebugger(), indirectCallAddresses, start);
final FunctionNode sourceNode = nodes.get(call.getFunction());
if (sourceNode != null) {
for (final ResolvedFunction targetFunction : targets) {
final Function function = targetFunction.getFunction();
if (function != null) {
final FunctionNode targetNode = nodes.get(function);
final ViewEdge edge = view.createEdge(sourceNode, targetNode, EdgeType.JumpUnconditional);
edge.setColor(Color.RED);
}
}
}
}
return view;
}
use of com.google.security.zynamics.binnavi.API.disassembly.Function in project binnavi by google.
the class PathFinderTest method testRecursivePath.
@Test
public void testRecursivePath() throws CouldntLoadDataException, PartialLoadException {
// Tests pathfinding from a simple function to a simple function through
// a recursive path
// GetVolumePathNameA
final Function startFunction = findFunction(m_kernel32, 0x7C82E8B2);
final BasicBlock startBlock = findBlock(startFunction, 0x7C82E8B2);
final Function endFunction = findFunction(m_kernel32, 0x7C8092B0);
final BasicBlock endBlock = findBlock(endFunction, 0x7C8092B0);
final View view = PathFinder.createPath(m_kernel32, startBlock, endBlock, null, null);
assertEquals(1247, view.getGraph().nodeCount());
assertEquals(1988, view.getGraph().edgeCount());
}
use of com.google.security.zynamics.binnavi.API.disassembly.Function in project binnavi by google.
the class PathFinderTest method testRecursiveTarget.
@Test
public void testRecursiveTarget() throws CouldntLoadDataException, PartialLoadException {
// Tests pathfinding from a simple function to a self-recursive function
// SetCommConfig
final Function startFunction = findFunction(m_kernel32, 0x7C866E7B);
final BasicBlock startBlock = findBlock(startFunction, 0x7C866EF3);
// SetCommState
final Function endFunction = findFunction(m_kernel32, 0x7C865E16);
final BasicBlock endBlock = findBlock(endFunction, 0x7C866106);
final View view = PathFinder.createPath(m_kernel32, startBlock, endBlock, null, null);
assertEquals(2 + /** calling function **/
66 + /** called function **/
3, /** split blocks **/
view.getGraph().nodeCount());
assertEquals(99 + /** called function **/
1 + /** calling target function **/
3 + 3, /** recursive calls and returns **/
view.getGraph().edgeCount());
}
use of com.google.security.zynamics.binnavi.API.disassembly.Function in project binnavi by google.
the class PathFinderTest method testPassingFunctionReturn.
@Test
public void testPassingFunctionReturn() throws CouldntLoadDataException, PartialLoadException {
// Tests pathfinding from one function to another function while passing one function
// and having a target block that is a RETURN block.
//
// What should happen here is that the pathfinding algorithm stops when it reaches
// the RETURN node. That is consecutive calls to the target function should not
// be part of the pathfinding result.
// 0x1004565 -> 0x1003C92 -> 0x100398D
final Function startFunction = findFunction(m_notepad, 0x1004565);
final BasicBlock startBlock = findBlock(startFunction, 0x1004629);
final Function endFunction = findFunction(m_notepad, 0x100398D);
final BasicBlock endBlock = findBlock(endFunction, 0x10039D9);
final View view = PathFinder.createPath(m_notepad, startBlock, endBlock, null, null);
assertEquals(14, view.getGraph().nodeCount());
assertEquals(19, view.getGraph().edgeCount());
}
use of com.google.security.zynamics.binnavi.API.disassembly.Function in project binnavi by google.
the class PathFinderTest method testInsideFunction.
// @Test
// public void testFoo() throws CouldntLoadDataException, CouldntSaveDataException
// {
// // TODO: Bring this test back in msw3prt.idb
//
// final Function startFunction = findFunction(m_foo, 0x5FEF8426);
// final BasicBlock startBlock = findBlock(startFunction, 0x5FEF8426);
//
// final Function endFunction = findFunction(m_foo, 0x5FEFF06D);
// final BasicBlock endBlock = findBlock(endFunction, 0x5FEFF0DB);
//
// final View view = PathFinder.createPath(m_foo, startBlock, endBlock, null, null);
//
// assertEquals(46, view.getGraph().nodeCount());
// assertEquals(49, view.getGraph().edgeCount());
// }
@Test
public void testInsideFunction() throws CouldntLoadDataException, PartialLoadException {
// Tests path finding from the beginning to the end of a single function
final Function startFunction = findFunction(m_notepad, 0x01002B87);
final BasicBlock startBlock = findBlock(startFunction, 0x1002B87);
final BasicBlock endBlock = findBlock(startFunction, 0x100336A);
final View view = PathFinder.createPath(m_notepad, startBlock, endBlock, null, null);
assertEquals(96, view.getGraph().nodeCount());
assertEquals(150, view.getGraph().edgeCount());
}
Aggregations