Search in sources :

Example 11 with Module

use of com.google.security.zynamics.binnavi.API.disassembly.Module in project binnavi by google.

the class IndirectCallResolver method findIndirectCall.

/**
   * Searches for an indirect call given the relocated call address.
   * 
   * @param debugger The debugger that provides the relocation information.
   * @param indirectCallAddresses The list of indirect call addresses to search through.
   * @param callAddress The relocated call address to find.
   * 
   * @return The found indirect call object.
   */
public static IndirectCall findIndirectCall(final Debugger debugger, final List<IndirectCall> indirectCallAddresses, final BigInteger callAddress) {
    for (final IndirectCall indirectCall : indirectCallAddresses) {
        final Module module = indirectCall.getModule();
        final Address address = indirectCall.getAddress();
        final Address rebasedAddress = debugger.toImagebase(module, address);
        if (rebasedAddress.equals(new Address(callAddress))) {
            return indirectCall;
        }
    }
    return null;
}
Also used : Address(com.google.security.zynamics.binnavi.API.disassembly.Address) Module(com.google.security.zynamics.binnavi.API.disassembly.Module)

Example 12 with Module

use of com.google.security.zynamics.binnavi.API.disassembly.Module 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 13 with Module

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

Example 14 with Module

use of com.google.security.zynamics.binnavi.API.disassembly.Module in project binnavi by google.

the class TraceTest method testEvent.

@Test
public void testEvent() {
    final Trace trace = new Trace(new TraceList(1, "Name", "Description", new MockSqlProvider()));
    final MockTraceListener listener = new MockTraceListener();
    trace.addListener(listener);
    final MockModule module = new MockModule();
    final Module m = ModuleFactory.get(module);
    trace.addEvent(0, m, new Address(123), TraceEventType.Breakpoint);
    trace.addEvent(0, m, new Address(124), TraceEventType.EchoBreakpoint);
    assertEquals(2, trace.getEvents().size());
    assertEquals(123, trace.getEvents().get(0).getAddress().toLong());
    assertEquals(TraceEventType.Breakpoint, trace.getEvents().get(0).getType());
    assertEquals(124, trace.getEvents().get(1).getAddress().toLong());
    assertEquals(TraceEventType.EchoBreakpoint, trace.getEvents().get(1).getType());
    assertEquals("addedEvent;addedEvent;", listener.events);
    trace.removeListener(listener);
}
Also used : Trace(com.google.security.zynamics.binnavi.API.disassembly.Trace) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) Address(com.google.security.zynamics.binnavi.API.disassembly.Address) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) TraceList(com.google.security.zynamics.binnavi.debug.models.trace.TraceList) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) Module(com.google.security.zynamics.binnavi.API.disassembly.Module) Test(org.junit.Test)

Example 15 with Module

use of com.google.security.zynamics.binnavi.API.disassembly.Module in project binnavi by google.

the class ModuleFactory method get.

public static Module get(final INaviModule module) {
    final MockSqlProvider provider = new MockSqlProvider();
    final TagManager nodeTagManager = new TagManager(new CTagManager(new Tree<CTag>(new TreeNode<CTag>(new CTag(0, "", "", TagType.NODE_TAG, provider))), TagType.NODE_TAG, provider));
    final TagManager viewTagManager = new TagManager(new CTagManager(new Tree<CTag>(new TreeNode<CTag>(new CTag(0, "", "", TagType.VIEW_TAG, provider))), TagType.VIEW_TAG, provider));
    final Database db = new Database(new MockDatabase());
    return new Module(db, module, nodeTagManager, viewTagManager);
}
Also used : TagManager(com.google.security.zynamics.binnavi.API.disassembly.TagManager) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) Database(com.google.security.zynamics.binnavi.API.disassembly.Database) Tree(com.google.security.zynamics.zylib.types.trees.Tree) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) Module(com.google.security.zynamics.binnavi.API.disassembly.Module) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule)

Aggregations

Module (com.google.security.zynamics.binnavi.API.disassembly.Module)25 Database (com.google.security.zynamics.binnavi.API.disassembly.Database)8 Address (com.google.security.zynamics.binnavi.API.disassembly.Address)7 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)7 MemoryModule (com.google.security.zynamics.binnavi.API.debug.MemoryModule)6 TagManager (com.google.security.zynamics.binnavi.API.disassembly.TagManager)6 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)6 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)6 CTagManager (com.google.security.zynamics.binnavi.Tagging.CTagManager)6 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)6 Tree (com.google.security.zynamics.zylib.types.trees.Tree)6 Test (org.junit.Test)6 Project (com.google.security.zynamics.binnavi.API.disassembly.Project)5 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)5 Function (com.google.security.zynamics.binnavi.API.disassembly.Function)4 View (com.google.security.zynamics.binnavi.API.disassembly.View)4 ViewContainer (com.google.security.zynamics.binnavi.API.disassembly.ViewContainer)4 MockDatabase (com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase)4 CModule (com.google.security.zynamics.binnavi.disassembly.Modules.CModule)4 IDatabase (com.google.security.zynamics.binnavi.Database.Interfaces.IDatabase)3