use of com.google.security.zynamics.binnavi.API.disassembly.BasicBlock 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.BasicBlock in project binnavi by google.
the class PathFinderTest method testFirstBlock.
@Test
public void testFirstBlock() throws CouldntLoadDataException, PartialLoadException {
// Tests 100337E -> 1005179 -> 1007568 where all calls are in the first block
// of the respective functions.
// Tests path finding from the beginning to the end of a single function
final Function startFunction = findFunction(m_notepad, 0x100337E);
final BasicBlock startBlock = findBlock(startFunction, 0x10033C2);
final Function endFunction = findFunction(m_notepad, 0x1007568);
final BasicBlock endBlock = findBlock(endFunction, 0x1007568);
final View view = PathFinder.createPath(m_notepad, startBlock, endBlock, null, null);
assertEquals(3, view.getGraph().nodeCount());
assertEquals(2, view.getGraph().edgeCount());
}
use of com.google.security.zynamics.binnavi.API.disassembly.BasicBlock in project binnavi by google.
the class PathFinder method findEntryExitNodes.
/**
* Finds the entry nodes and exit nodes of all functions that lie on the path. This is necessary
* for function inlining.
*
* @param passedFunctions All functions that lie on the path.
* @param nodeMap Maps between the basic blocks of the functions and their corresponding code
* nodes.
* @param functionMap Keeps track to what function a view node belongs to.
* @param entryNodes Keeps track of the entry nodes of all functions.
* @param exitNodes Keeps track of the exit nodes of all functions.
*/
private static void findEntryExitNodes(final Collection<FunctionBlock> passedFunctions, final Map<BasicBlock, ViewNode> nodeMap, final Map<ViewNode, Function> functionMap, final Map<Function, ViewNode> entryNodes, final ArrayListMultimap<Function, ViewNode> exitNodes) {
// actually do have basic blocks.
for (final FunctionBlock functionBlock : passedFunctions) {
final Function function = functionBlock.getFunction();
if (function.getType() != FunctionType.Import) {
entryNodes.put(function, nodeMap.get(findEntryNode(function)));
for (final BasicBlock block : findExitNode(function.getGraph())) {
exitNodes.put(function, nodeMap.get(block));
}
}
}
// Afterwards we find the entry and exit nodes of the imported functions.
for (final Map.Entry<ViewNode, Function> p : functionMap.entrySet()) {
final Function function = p.getValue();
if (function.getType() == FunctionType.Import) {
final ViewNode node = p.getKey();
entryNodes.put(function, node);
exitNodes.put(function, node);
}
}
}
use of com.google.security.zynamics.binnavi.API.disassembly.BasicBlock in project binnavi by google.
the class PathFinder method createInitialBlocks.
/**
* Creates the initial nodes for all basic blocks in the passed functions.
*
* @param view The view where the nodes are created.
*
* @param passedFunctions All functions that lie on the path.
* @param nodeMap Maps basic blocks of the functions on the path to their corresponding view
* nodes.
* @param functionMap Keeps track to what function a node belongs to.
*
* @throws CouldntLoadDataException Thrown if a function could not be loaded.
*/
private static void createInitialBlocks(final View view, final Collection<FunctionBlock> passedFunctions, final Map<BasicBlock, ViewNode> nodeMap, final Map<ViewNode, Function> functionMap) throws CouldntLoadDataException {
for (final FunctionBlock functionBlock : passedFunctions) {
final Function function = functionBlock.getFunction();
if (function.getType() == FunctionType.Import) {
// Imported functions to not have any basic blocks, for those functions
// we simply create a function node.
final FunctionNode newNode = view.createFunctionNode(function);
functionMap.put(newNode, function);
// TODO (timkornau): Assign a proper color to the node.
// TODO (timkornau): Properly treat forwarded functions.
} else {
function.load();
for (final BasicBlock block : function.getGraph().getNodes()) {
final CodeNode newNode = view.createCodeNode(function, block.getInstructions());
newNode.setColor(DEFAULT_BLOCK_COLOR);
nodeMap.put(block, newNode);
functionMap.put(newNode, function);
}
}
}
}
Aggregations