Search in sources :

Example 1 with UnrelocatedAddress

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

the class PostgreSQLProjectFunctions method getViewsWithAddresses.

/**
   * Searches for the views of the project that contain a given address.
   *
   * The project must be stored in the database connected to by the provider argument.
   *
   * @param provider The connection to the database.
   * @param project The project to search through.
   * @param addresses The addresses to search for.
   * @param all True, to search for views that contain all addresses. False, for any addresses.
   *
   * @return The views that contain the search addresses.
   *
   * @throws CouldntLoadDataException Thrown if the views could not be loaded.
   */
public static List<INaviView> getViewsWithAddresses(final AbstractSQLProvider provider, final INaviProject project, final List<UnrelocatedAddress> addresses, final boolean all) throws CouldntLoadDataException {
    checkArguments(provider, project);
    Preconditions.checkNotNull(addresses, "IE00523: Addresses argument can not be null");
    final StringBuilder queryBuilder = new StringBuilder();
    if (addresses.size() == 0) {
        return new ArrayList<INaviView>();
    } else if (addresses.size() == 1) {
        queryBuilder.append("SELECT " + CTableNames.PROJECT_VIEWS_TABLE + ".project_id, " + CTableNames.PROJECT_VIEWS_TABLE + ".view_id " + " FROm " + CTableNames.PROJECT_VIEWS_TABLE + " JOIN " + CTableNames.NODES_TABLE + " ON " + CTableNames.PROJECT_VIEWS_TABLE + ".view_id = " + CTableNames.NODES_TABLE + ".view_id " + " JOIN " + CTableNames.CODENODE_INSTRUCTIONS_TABLE + " ON " + CTableNames.NODES_TABLE + ".id = " + CTableNames.CODENODE_INSTRUCTIONS_TABLE + ".node_id " + " WHERE project_id = " + project.getConfiguration().getId() + " AND " + CTableNames.CODENODE_INSTRUCTIONS_TABLE + ".address = " + addresses.get(0).getAddress().toBigInteger().toString());
    } else if (all) {
        boolean needsComma = false;
        int counter = 0;
        queryBuilder.append("select view_id from ");
        for (final UnrelocatedAddress address : addresses) {
            if (needsComma) {
                queryBuilder.append(" inner join ");
            }
            needsComma = true;
            queryBuilder.append("(select " + CTableNames.PROJECT_VIEWS_TABLE + ".project_id, " + CTableNames.PROJECT_VIEWS_TABLE + ".view_id " + " from " + CTableNames.PROJECT_VIEWS_TABLE + " " + " join " + CTableNames.NODES_TABLE + " on " + CTableNames.PROJECT_VIEWS_TABLE + ".view_id = " + CTableNames.NODES_TABLE + ".view_id " + " join " + CTableNames.CODENODE_INSTRUCTIONS_TABLE + " on " + CTableNames.NODES_TABLE + ".id = " + CTableNames.CODENODE_INSTRUCTIONS_TABLE + ".node_id " + " where " + CTableNames.PROJECT_VIEWS_TABLE + ".project_id = " + project.getConfiguration().getId() + " " + " and " + CTableNames.CODENODE_INSTRUCTIONS_TABLE + ".address = " + address.getAddress().toLong() + ") as t" + counter);
            counter++;
        }
        queryBuilder.append(" using (view_id)");
    } else {
        queryBuilder.append("select " + CTableNames.PROJECT_VIEWS_TABLE + ".project_id, " + CTableNames.PROJECT_VIEWS_TABLE + ".view_id from " + CTableNames.PROJECT_VIEWS_TABLE + " join " + CTableNames.NODES_TABLE + " on " + CTableNames.PROJECT_VIEWS_TABLE + ".view_id = " + CTableNames.NODES_TABLE + ".view_id join " + CTableNames.CODENODE_INSTRUCTIONS_TABLE + " on " + CTableNames.NODES_TABLE + ".id = " + CTableNames.CODENODE_INSTRUCTIONS_TABLE + ".node_id where " + CTableNames.PROJECT_VIEWS_TABLE + ".project_id = " + project.getConfiguration().getId() + " and " + CTableNames.CODENODE_INSTRUCTIONS_TABLE + ".address in (");
        boolean needsComma = false;
        for (final UnrelocatedAddress address : addresses) {
            if (needsComma) {
                queryBuilder.append(", ");
            }
            needsComma = true;
            queryBuilder.append(address.getAddress().toLong());
        }
        queryBuilder.append(") group by " + CTableNames.PROJECT_VIEWS_TABLE + ".view_id, " + CTableNames.PROJECT_VIEWS_TABLE + ".project_id");
    }
    return PostgreSQLHelpers.getViewsWithAddress(provider.getConnection(), queryBuilder.toString(), "project_id", new CProjectViewFinder(provider));
}
Also used : UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) ArrayList(java.util.ArrayList) CProjectViewFinder(com.google.security.zynamics.binnavi.Database.CProjectViewFinder)

Example 2 with UnrelocatedAddress

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

the class BreakpointableNodeCounter method next.

@Override
public IterationMode next(final NaviNode node) {
    final INaviViewNode viewNode = node.getRawNode();
    if (viewNode instanceof INaviCodeNode) {
        final INaviCodeNode codeNode = (INaviCodeNode) viewNode;
        final INaviInstruction instruction = Iterables.getFirst(codeNode.getInstructions(), null);
        final INaviModule module = instruction.getModule();
        final BreakpointAddress address = new BreakpointAddress(module, new UnrelocatedAddress(instruction.getAddress()));
        if (EchoBreakpointCollector.isBlocked(breakpointManager, address)) {
            return IterationMode.CONTINUE;
        }
        ++breakpointAbleNodeCount;
    } else if (viewNode instanceof INaviFunctionNode) {
        final INaviFunctionNode functionNode = (INaviFunctionNode) viewNode;
        final INaviModule module = functionNode.getFunction().getModule();
        final BreakpointAddress address = new BreakpointAddress(module, new UnrelocatedAddress(functionNode.getFunction().getAddress()));
        if (EchoBreakpointCollector.isBlocked(breakpointManager, address)) {
            return IterationMode.CONTINUE;
        }
        ++breakpointAbleNodeCount;
    }
    return IterationMode.CONTINUE;
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 3 with UnrelocatedAddress

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

the class EchoBreakpointCollector method next.

@Override
public IterationMode next(final NaviNode node) {
    final INaviViewNode viewNode = node.getRawNode();
    if (viewNode instanceof INaviCodeNode) {
        final INaviCodeNode codeNode = (INaviCodeNode) viewNode;
        final INaviInstruction instruction = Iterables.getFirst(codeNode.getInstructions(), null);
        final INaviModule module = instruction.getModule();
        final BreakpointAddress address = new BreakpointAddress(module, new UnrelocatedAddress(instruction.getAddress()));
        if (isBlocked(manager, address)) {
            return IterationMode.CONTINUE;
        }
        NaviLogger.info("Adding Echo breakpoint %s to the active list", address.getAddress().getAddress().toHexString());
        // Add the echo breakpoint to the list of active echo breakpoints
        echoBreakpointAbleAddresses.add(address);
    } else if (viewNode instanceof INaviFunctionNode) {
        final INaviFunctionNode functionNode = (INaviFunctionNode) viewNode;
        final INaviModule module = functionNode.getFunction().getModule();
        final BreakpointAddress address = new BreakpointAddress(module, new UnrelocatedAddress(functionNode.getFunction().getAddress()));
        if (isBlocked(manager, address)) {
            return IterationMode.CONTINUE;
        }
        NaviLogger.info("Adding Echo breakpoint %s to the active list", address.getAddress().getAddress().toHexString());
        // Add the echo breakpoint to the list of active echo breakpoints
        echoBreakpointAbleAddresses.add(address);
    }
    return IterationMode.CONTINUE;
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 4 with UnrelocatedAddress

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

the class BreakpointManagerTest method testPreinitialized.

@Test
public void testPreinitialized() {
    final com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointManager internalManager = new com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointManager();
    internalManager.addBreakpoints(BreakpointType.REGULAR, CommonTestObjects.BP_ADDRESS_0_SET);
    internalManager.addBreakpoints(BreakpointType.ECHO, Sets.newHashSet(new BreakpointAddress(CommonTestObjects.MODULE, new UnrelocatedAddress(new CAddress(1)))));
    final BreakpointManager apiManager = new BreakpointManager(internalManager);
    assertEquals(0, apiManager.getBreakpoints().get(0).getAddress().toLong());
    assertEquals(1, apiManager.getEchoBreakpoints().get(0).getAddress().toLong());
}
Also used : CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress) Test(org.junit.Test)

Example 5 with UnrelocatedAddress

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

the class BreakpointHelpersTest method testGetEchoBreakpointsNode.

@Test
public void testGetEchoBreakpointsNode() {
    assertTrue(BreakpointHelpers.getEchoBreakpoints(m_debugger, m_node).isEmpty());
    m_debugger.getBreakpointManager().getNative().addBreakpoints(BreakpointType.ECHO, Sets.newHashSet(new BreakpointAddress(m_module, new UnrelocatedAddress(new CAddress(0x1234)))));
    final List<Address> breakpoints = BreakpointHelpers.getEchoBreakpoints(m_debugger, m_node);
    assertEquals(1, breakpoints.size());
    assertEquals(0x1234, breakpoints.get(0).toLong());
    try {
        BreakpointHelpers.getEchoBreakpoints(null, m_node);
        fail();
    } catch (final NullPointerException exception) {
    }
    try {
        BreakpointHelpers.getEchoBreakpoints(m_debugger, (CodeNode) null);
        fail();
    } catch (final NullPointerException exception) {
    }
}
Also used : BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress) UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Address(com.google.security.zynamics.binnavi.API.disassembly.Address) UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Aggregations

UnrelocatedAddress (com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress)81 BreakpointAddress (com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress)60 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)60 Test (org.junit.Test)49 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)28 MockDebugger (com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger)15 ModuleTargetSettings (com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings)15 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)13 Address (com.google.security.zynamics.binnavi.API.disassembly.Address)12 ArrayList (java.util.ArrayList)11 TraceList (com.google.security.zynamics.binnavi.debug.models.trace.TraceList)10 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)9 HashSet (java.util.HashSet)9 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)8 DebugTargetSettings (com.google.security.zynamics.binnavi.debug.debugger.DebugTargetSettings)8 DebuggerProvider (com.google.security.zynamics.binnavi.debug.debugger.DebuggerProvider)8 Breakpoint (com.google.security.zynamics.binnavi.debug.models.breakpoints.Breakpoint)8 FilledList (com.google.security.zynamics.zylib.types.lists.FilledList)8 CBreakpointTableModel (com.google.security.zynamics.binnavi.Gui.Debug.BreakpointTable.CBreakpointTableModel)7 TraceLogger (com.google.security.zynamics.binnavi.debug.models.trace.TraceLogger)7