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));
}
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;
}
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;
}
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());
}
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) {
}
}
Aggregations