use of com.google.security.zynamics.binnavi.API.disassembly.Function 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.Function in project binnavi by google.
the class PathFinderTest method testToImportedFunction.
@Test
public void testToImportedFunction() throws CouldntLoadDataException, PartialLoadException {
// Tests from the beginning of a function to an imported function
final Function startFunction = findFunction(m_notepad, 0x0100398D);
final BasicBlock startBlock = findBlock(startFunction, 0x100398D);
final Function endFunction = findFunction(m_notepad, 0x1001000);
endFunction.load();
final View view = PathFinder.createPath(m_notepad, startBlock, null, null, endFunction);
assertEquals(3, view.getGraph().nodeCount());
assertEquals(2, view.getGraph().edgeCount());
}
use of com.google.security.zynamics.binnavi.API.disassembly.Function in project binnavi by google.
the class OutputListGenerator method generate.
/**
* Generates a string that shows the resolved functions.
*
* @param resolvedAddresses The function resolver result.
*
* @return The string that shows the resolved functions.
*/
public static String generate(final Map<BigInteger, Set<ResolvedFunction>> resolvedAddresses) {
assert resolvedAddresses != null;
final StringBuffer buffer = new StringBuffer();
buffer.append("Resolved the following indirect calls:\n");
for (final Entry<BigInteger, Set<ResolvedFunction>> element : sort(resolvedAddresses.entrySet())) {
final BigInteger start = element.getKey();
final Set<ResolvedFunction> targets = element.getValue();
buffer.append(String.format("%08X ->\n", start.longValue()));
for (final ResolvedFunction target : targets) {
if (target.getFunction() != null) {
final Function function = target.getFunction();
final Address functionAddress = function.getAddress();
final String functionName = function.getModule().getName() + "!" + function.getName();
buffer.append(String.format(" %08X (%s)\n", functionAddress.toLong(), functionName));
} else if (target.getMemoryModule() != null) {
final MemoryModule module = target.getMemoryModule();
final Address functionAddress = target.getAddress();
final String functionName = module.getName() + "!???";
buffer.append(String.format(" %08X (%s)\n", functionAddress.toLong(), functionName));
} else {
final Address address = target.getAddress();
buffer.append(String.format(" %s (%s)\n", address.toHexString().toUpperCase(), "???!???"));
}
}
}
return buffer.toString();
}
use of com.google.security.zynamics.binnavi.API.disassembly.Function 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.Function 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