Search in sources :

Example 1 with MemoryModule

use of com.google.security.zynamics.binnavi.API.debug.MemoryModule in project binnavi by google.

the class CallResolver method resolveFunction.

private ResolvedFunction resolveFunction(final Address address) {
    for (final Module module : target.getModules()) {
        if (!resolvedFunctions.containsKey(module)) {
            resolveFunctions(module);
            if (!resolvedFunctions.containsKey(module)) {
                continue;
            }
        }
        final Map<Address, Function> functionMap = resolvedFunctions.get(module);
        final Function function = functionMap.get(address);
        if (function != null) {
            return new ResolvedFunction(function);
        }
    }
    for (final MemoryModule memoryModule : target.getDebugger().getProcess().getModules()) {
        if ((address.toLong() >= memoryModule.getBaseAddress().toLong()) && (address.toLong() < (memoryModule.getBaseAddress().toLong() + memoryModule.getSize()))) {
            return new ResolvedFunction(memoryModule, address);
        }
    }
    return new ResolvedFunction(address);
}
Also used : Function(com.google.security.zynamics.binnavi.API.disassembly.Function) Address(com.google.security.zynamics.binnavi.API.disassembly.Address) MemoryModule(com.google.security.zynamics.binnavi.API.debug.MemoryModule) Module(com.google.security.zynamics.binnavi.API.disassembly.Module) MemoryModule(com.google.security.zynamics.binnavi.API.debug.MemoryModule)

Example 2 with MemoryModule

use of com.google.security.zynamics.binnavi.API.debug.MemoryModule in project binnavi by google.

the class OutputGraphGenerator method createLoggedView.

/**
   * 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 createLoggedView(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 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);
        FunctionNode sourceNode = nodes.get(call.getFunction());
        if (sourceNode == null) {
            sourceNode = view.createFunctionNode(call.getFunction());
            nodes.put(call.getFunction(), sourceNode);
        }
        for (final ResolvedFunction targetFunction : targets) {
            final Function function = targetFunction.getFunction();
            final MemoryModule memoryModule = targetFunction.getMemoryModule();
            if (function != null) {
                FunctionNode targetNode = nodes.get(function);
                if (targetNode == null) {
                    targetNode = view.createFunctionNode(function);
                    nodes.put(function, targetNode);
                }
                try {
                    sourceNode.appendComment(start.toString(16).toUpperCase() + " -> " + function.getAddress().toHexString().toUpperCase());
                } catch (CouldntSaveDataException | CouldntLoadDataException e) {
                    e.printStackTrace();
                }
                view.createEdge(sourceNode, targetNode, EdgeType.JumpUnconditional);
            } else if (memoryModule != null) {
                final String targetString = String.format("%s!%s", targetFunction.getMemoryModule().getName(), targetFunction.getAddress().toHexString().toUpperCase());
                try {
                    sourceNode.appendComment(start.toString(16).toUpperCase() + " -> " + targetString);
                } catch (CouldntSaveDataException | CouldntLoadDataException e) {
                    e.printStackTrace();
                }
            } else {
                final String targetString = "???!" + targetFunction.getAddress().toHexString().toUpperCase();
                try {
                    sourceNode.appendComment(start.toString(16).toUpperCase() + " -> " + targetString);
                } catch (CouldntSaveDataException | CouldntLoadDataException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    for (final Module module : target.getModules()) {
        final Callgraph callgraph = module.getCallgraph();
        for (final FunctionEdge edge : callgraph.getEdges()) {
            final FunctionNode source = nodes.get(edge.getSource().getFunction());
            final FunctionNode targetNode = nodes.get(edge.getTarget().getFunction());
            if ((source != null) && (targetNode != null)) {
                view.createEdge(source, targetNode, EdgeType.JumpUnconditional);
            }
        }
    }
    return view;
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) CouldntSaveDataException(com.google.security.zynamics.binnavi.API.disassembly.CouldntSaveDataException) CouldntLoadDataException(com.google.security.zynamics.binnavi.API.disassembly.CouldntLoadDataException) FunctionNode(com.google.security.zynamics.binnavi.API.disassembly.FunctionNode) View(com.google.security.zynamics.binnavi.API.disassembly.View) MemoryModule(com.google.security.zynamics.binnavi.API.debug.MemoryModule) Function(com.google.security.zynamics.binnavi.API.disassembly.Function) Callgraph(com.google.security.zynamics.binnavi.API.disassembly.Callgraph) FunctionEdge(com.google.security.zynamics.binnavi.API.disassembly.FunctionEdge) BigInteger(java.math.BigInteger) Module(com.google.security.zynamics.binnavi.API.disassembly.Module) MemoryModule(com.google.security.zynamics.binnavi.API.debug.MemoryModule)

Example 3 with MemoryModule

use of com.google.security.zynamics.binnavi.API.debug.MemoryModule 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();
}
Also used : Function(com.google.security.zynamics.binnavi.API.disassembly.Function) Set(java.util.Set) Address(com.google.security.zynamics.binnavi.API.disassembly.Address) BigInteger(java.math.BigInteger) MemoryModule(com.google.security.zynamics.binnavi.API.debug.MemoryModule)

Aggregations

MemoryModule (com.google.security.zynamics.binnavi.API.debug.MemoryModule)3 Function (com.google.security.zynamics.binnavi.API.disassembly.Function)3 Address (com.google.security.zynamics.binnavi.API.disassembly.Address)2 Module (com.google.security.zynamics.binnavi.API.disassembly.Module)2 BigInteger (java.math.BigInteger)2 Set (java.util.Set)2 Callgraph (com.google.security.zynamics.binnavi.API.disassembly.Callgraph)1 CouldntLoadDataException (com.google.security.zynamics.binnavi.API.disassembly.CouldntLoadDataException)1 CouldntSaveDataException (com.google.security.zynamics.binnavi.API.disassembly.CouldntSaveDataException)1 FunctionEdge (com.google.security.zynamics.binnavi.API.disassembly.FunctionEdge)1 FunctionNode (com.google.security.zynamics.binnavi.API.disassembly.FunctionNode)1 View (com.google.security.zynamics.binnavi.API.disassembly.View)1 HashMap (java.util.HashMap)1