use of com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress in project binnavi by google.
the class CCodeNodeUpdater method generateContent.
@Override
public void generateContent(final IZyNodeRealizer realizer, final ZyLabelContent content) {
ZyCodeNodeBuilder.buildContent(content, codeNode, graph.getSettings(), nodeModifier);
for (final INaviInstruction instruction : codeNode.getInstructions()) {
final INaviModule module = instruction.getModule();
if ((provider != null) && (provider.getDebugger(module) != null) && graph.getSettings().getDisplaySettings().getShowMemoryAddresses(provider.getDebugger(module))) {
final int line = CCodeNodeHelpers.instructionToLine(codeNode, instruction);
if (line != -1) {
final ZyLineContent lineContent = this.realizer.getNodeContent().getLineContent(line);
// TODO(timkornau) x64
lineContent.setTextColor(0, 8, Color.RED);
}
}
}
// Set highlighting for breakpoints and the instruction pointer.
final INaviInstruction instruction = codeNode.getInstructions().iterator().next();
if (instruction != null) {
final INaviModule module = instruction.getModule();
final IDebugger debugger = provider.getDebugger(module);
if (debugger == null) {
return;
}
final BreakpointManager manager = debugger.getBreakpointManager();
CBreakpointPainter.paintBreakpoints(manager, node, codeNode);
if (debugger.getProcessManager().getActiveThread() != null) {
final RelocatedAddress instructionPointer = debugger.getProcessManager().getActiveThread().getCurrentAddress();
final MemoryModule memoryModule = debugger.getProcessManager().getModule(instructionPointer);
final UnrelocatedAddress unrelocatedIP = new DefaultAddressConverter(memoryModule.getBaseAddress().getAddress(), module.getConfiguration().getFileBase()).memoryToFile(instructionPointer);
CDebuggerPainter.updateSingleNodeDebuggerHighlighting(graph, unrelocatedIP, node);
}
}
}
use of com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress in project binnavi by google.
the class TraceEventTest method testConstructor.
@Test
public void testConstructor() {
final MockModule module = new MockModule();
final TraceEvent event = new TraceEvent(new com.google.security.zynamics.binnavi.debug.models.trace.TraceEvent(0, new BreakpointAddress(module, new UnrelocatedAddress(new CAddress(0x123))), TraceEventType.ECHO_BREAKPOINT, new ArrayList<com.google.security.zynamics.binnavi.debug.models.trace.TraceRegister>()));
assertEquals(0x123, event.getAddress().toLong());
assertEquals(com.google.security.zynamics.binnavi.API.disassembly.TraceEventType.EchoBreakpoint, event.getType());
assertEquals("Trace Event [EchoBreakpoint : 123]", event.toString());
}
use of com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress in project binnavi by google.
the class PostgreSQLModuleFunctions method getViewsWithAddresses.
/**
* Finds the views inside the module that contain instructions of a given address.
*
* The module must be stored in the database connected to by the provider argument.
*
* @param provider The SQL provider that provides the connection.
* @param module The module 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 A list of views where instructions with the given address can be found.
*
* @throws CouldntLoadDataException Thrown if searching through the module failed.
*/
public static List<INaviView> getViewsWithAddresses(final AbstractSQLProvider provider, final INaviModule module, final List<UnrelocatedAddress> addresses, final boolean all) throws CouldntLoadDataException {
checkArguments(provider, module);
Preconditions.checkNotNull(addresses, "IE00492: Addresses argument can not be null");
final StringBuilder queryBuilder = new StringBuilder();
final int moduleID = module.getConfiguration().getId();
if (addresses.size() == 0) {
return new ArrayList<INaviView>();
} else if (addresses.size() == 1) {
queryBuilder.append("SELECT mvt.module_id, mvt.view_id FROM " + CTableNames.MODULE_VIEWS_TABLE + " AS mvt JOIN " + CTableNames.NODES_TABLE + " AS nt ON mvt.view_id = nt.view_id AND mvt.module_id = " + moduleID + " JOIN " + CTableNames.CODENODE_INSTRUCTIONS_TABLE + " AS cit ON nt.id = cit.node_id AND cit.module_id = " + moduleID + " JOIN " + CTableNames.INSTRUCTIONS_TABLE + " AS it ON it.address = cit.address AND it.module_id = " + moduleID + " WHERE it.address = " + addresses.get(0).getAddress().toLong());
} 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 mvt.module_id, mvt.view_id FROM " + CTableNames.MODULE_VIEWS_TABLE + " AS mvt JOIN " + CTableNames.NODES_TABLE + " AS nt ON mvt.view_id = nt.view_id AND mvt.module_id = " + moduleID + " JOIN " + CTableNames.CODENODE_INSTRUCTIONS_TABLE + " AS cit ON nt.id = cit.node_id AND cit.module_id = " + moduleID + " JOIN " + CTableNames.INSTRUCTIONS_TABLE + " AS it ON it.address = cit.address AND it.module_id = " + moduleID + " WHERE it.address = " + address.getAddress().toLong() + ") AS t" + counter);
counter++;
}
queryBuilder.append(" USING (view_id)");
} else {
queryBuilder.append("SELECT mvt.module_id, mvt.view_id FROM " + CTableNames.MODULE_VIEWS_TABLE + " AS mvt JOIN " + CTableNames.NODES_TABLE + " AS nt ON mvt.view_id = nt.view_id AND mvt.module_id = " + moduleID + " JOIN " + CTableNames.CODENODE_INSTRUCTIONS_TABLE + " AS cit ON nt.id = cit.node_id AND cit.module_id = " + moduleID + " JOIN " + CTableNames.INSTRUCTIONS_TABLE + " AS it ON it.address = cit.address AND it.module_id = " + moduleID + " WHERE it.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 mvt.view_id, mvt.module_id");
}
return PostgreSQLHelpers.getViewsWithAddress(provider.getConnection(), queryBuilder.toString(), "module_id", new CModuleViewFinder(provider));
}
use of com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress in project binnavi by google.
the class CDebuggerFunctions method stepBlock.
/**
* Lets the debugger step to the next block.
*
* @param parent Parent window used for dialogs.
* @param debugger The debugger that steps to the next block.
* @param graph The graph where the step operation happens.
*/
public static void stepBlock(final JFrame parent, final IDebugger debugger, final ZyGraph graph) {
checkArguments(parent, debugger, graph);
if (!debugger.isConnected()) {
return;
}
final TargetProcessThread activeThread = debugger.getProcessManager().getActiveThread();
if (activeThread == null) {
return;
}
final RelocatedAddress currentAddress = activeThread.getCurrentAddress();
if (currentAddress == null) {
CMessageBox.showError(parent, "Could not step because the selected thread is not suspended");
return;
}
final UnrelocatedAddress oldAddress = debugger.memoryToFile(currentAddress);
final Set<BreakpointAddress> relocatedBlockAddresses = CStepBlockHelper.getNextBlocks(graph, oldAddress);
if (relocatedBlockAddresses.isEmpty()) {
CMessageBox.showError(parent, "Couldn't step to the next block");
return;
} else {
debugger.getProcessManager().setActiveThread(null);
final Set<BreakpointAddress> setBreakpoints = new HashSet<BreakpointAddress>();
debugger.getBreakpointManager().addBreakpoints(BreakpointType.STEP, relocatedBlockAddresses);
setBreakpoints.addAll(relocatedBlockAddresses);
try {
debugger.resume();
} catch (final DebugExceptionWrapper e) {
// TODO: Step breakpoints should be removed at this point
debugger.getProcessManager().setActiveThread(activeThread);
CUtilityFunctions.logException(e);
final String innerMessage = "E00045: " + "Could not send step block command to the debug client";
final String innerDescription = CUtilityFunctions.createDescription("BinNavi could not send the step block command to the debug client.", new String[] { "There was a problem with the connection to the debug client." }, new String[] { "The state of the debugged process remains unchanged." });
NaviErrorDialog.show(parent, innerMessage, innerDescription, e);
}
}
}
use of com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress in project binnavi by google.
the class CDebuggerFunctions method stepOver.
/**
* Lets the debugger step over the next instruction.
*
* @param parent Parent window used for dialogs.
* @param debugger The debugger that steps over the next instruction.
* @param graph The graph where the step operation happens.
*/
public static void stepOver(final JFrame parent, final IDebugger debugger, final ZyGraph graph) {
checkArguments(parent, debugger, graph);
if (!debugger.isConnected()) {
return;
}
final TargetProcessThread activeThread = debugger.getProcessManager().getActiveThread();
if (activeThread == null) {
return;
}
final RelocatedAddress currentAddress = activeThread.getCurrentAddress();
if (currentAddress == null) {
CMessageBox.showError(parent, "Could not step because the selected thread is not suspended");
return;
}
final UnrelocatedAddress oldAddress = debugger.memoryToFile(currentAddress);
final Set<BreakpointAddress> relocatedAddresses = CStepOverHelper.getNextInstructions(graph, oldAddress);
if (relocatedAddresses.isEmpty()) {
CMessageBox.showError(parent, "Couldn't step over the current instruction");
return;
} else {
debugger.getProcessManager().setActiveThread(null);
debugger.getBreakpointManager().addBreakpoints(BreakpointType.STEP, relocatedAddresses);
try {
debugger.resume();
} catch (final DebugExceptionWrapper e) {
// TODO: Step breakpoints should be removed at this point
debugger.getProcessManager().setActiveThread(activeThread);
CUtilityFunctions.logException(e);
final String innerMessage = "E00087: " + "Could not send step over command to the debug client";
final String innerDescription = CUtilityFunctions.createDescription("BinNavi could not send the step over command to the debug client.", new String[] { "There was a problem with the connection to the debug client." }, new String[] { "The state of the debugged process remains unchanged." });
NaviErrorDialog.show(parent, innerMessage, innerDescription, e);
}
}
}
Aggregations