use of com.google.security.zynamics.zylib.disassembly.IAddress in project binnavi by google.
the class CMemoryMenu method createMenu.
/**
* Creates the context menu of a memory viewer component.
*
* @param offset The memory offset where the context menu will be shown.
*
* @return The context menu for the specified address.
*/
@Override
public JPopupMenu createMenu(final long offset) {
final JPopupMenu menu = new JPopupMenu();
final IDebugger debugger = m_debugger.getCurrentSelectedDebugger();
if (debugger == null) {
return null;
}
menu.add(CActionProxy.proxy(new CSearchAction(m_parent, m_debugger, m_memoryView)));
menu.add(CActionProxy.proxy(new CGotoAction(m_parent, m_memoryView, m_debugger)));
if (canReadDword(debugger.getProcessManager().getMemoryMap(), offset)) {
final byte[] data = debugger.getProcessManager().getMemory().getData(offset, 4);
final IAddress dword = new CAddress(ByteHelpers.readDwordLittleEndian(data, 0));
if (canReadDword(debugger.getProcessManager().getMemoryMap(), dword.toLong())) {
menu.add(CActionProxy.proxy(new CFollowDumpAction(m_debugger, dword)));
}
}
menu.addSeparator();
final long firstOffset = m_memoryView.getHexView().getBaseAddress();
final int size = m_memoryView.getHexView().getData().getDataLength();
menu.add(new CLoadAllAction(m_parent, debugger, new CAddress(firstOffset), size));
// Offer the option to dump memory
final JMenu dumpMenu = new JMenu("Dump to file");
dumpMenu.add(CActionProxy.proxy(new CDumpMemoryRangeAction(m_parent, debugger, m_memoryView.getHexView().getData(), new CAddress(firstOffset), size)));
menu.add(dumpMenu);
menu.addSeparator();
final BookmarkManager manager = debugger.getBookmarkManager();
// At first offer the option to add or remove a bookmark
// at the specified position.
final CBookmark bookmark = manager.getBookmark(new CAddress(offset));
if (bookmark == null) {
menu.add(new JMenuItem(CActionProxy.proxy(new CCreateBookmarkAction(manager, new CAddress(offset)))));
} else {
menu.add(new JMenuItem(CActionProxy.proxy(new CDeleteBookmarkAction(manager, bookmark))));
}
if (manager.getNumberOfBookmarks() != 0) {
// Afterwards list all currently active bookmarks.
menu.addSeparator();
final JMenu bookmarksItem = new JMenu("Bookmarks");
for (int i = 0; i < manager.getNumberOfBookmarks(); i++) {
bookmarksItem.add(CActionProxy.proxy(new CGotoBookmarkAction(m_debugger, manager.getBookmark(i))));
}
menu.add(bookmarksItem);
}
menu.addSeparator();
menu.add(HexViewOptionsMenu.createHexViewOptionsMenu(m_memoryView.getHexView()));
return menu;
}
use of com.google.security.zynamics.zylib.disassembly.IAddress in project binnavi by google.
the class CMemoryFunctions method searchMemory.
/**
* Shows a Search dialog and searches through the memory of target process afterwards.
*
* @param parent Parent window used for dialogs.
* @param debugger Debugger that requests the target memory.
* @param memoryView Memory view where the search result is shown.
*/
public static void searchMemory(final Window parent, final IDebugger debugger, final CMemoryViewer memoryView) {
checkArguments(parent, debugger);
Preconditions.checkNotNull(memoryView, "IE01431: Memory view argument can not be null");
// Show the search dialog
final CSearchDialog dlg = new CSearchDialog(parent);
final byte[] data = dlg.getSearchData();
// Make sure that the user entered data and clicked the OK button
if (data != null && data.length != 0) {
final JHexView hexView = memoryView.getHexView();
final long start = hexView.getCurrentOffset();
final int size = (int) (hexView.getLastOffset() - hexView.getCurrentOffset());
final CSearchWaiter waiter = new CSearchWaiter(debugger, new CAddress(start), size, data);
CProgressDialog.showEndless(parent, "Loading memory" + " ...", waiter);
hexView.uncolorizeAll();
if (waiter.getException() == null) {
final SearchReply reply = waiter.getReply();
if (reply != null) {
final IAddress offset = reply.getAddress();
if (reply.success()) {
// Make sure that the memory data is actually available
if (hexView.isEnabled() && hexView.getDefinitionStatus() == DefinitionStatus.DEFINED) {
// It is not necessary to make sure that the offset is
// actually part of the currently visible memory range.
// If it is not, the new memory range is loaded automatically.
hexView.colorize(5, offset.toLong(), data.length, Color.BLACK, Color.YELLOW);
hexView.gotoOffset(offset.toLong());
hexView.requestFocusInWindow();
}
} else {
// Tell the user that the search string was not found
CMessageBox.showInformation(parent, "The specified search string was not found.");
}
}
} else {
CUtilityFunctions.logException(waiter.getException());
final String innerMessage = "E00079: " + "Could not search through memory";
final String innerDescription = CUtilityFunctions.createDescription("It was not possible to send the search request to the debug client.", new String[] { "There was a problem with the connection to the debug client." }, new String[] { "The search operation could not be started." });
NaviErrorDialog.show(parent, innerMessage, innerDescription, waiter.getException());
}
}
}
use of com.google.security.zynamics.zylib.disassembly.IAddress in project binnavi by google.
the class CMemoryFunctions method gotoOffset.
/**
* Shows the Goto Offset dialog and sets the caret of a hex control to the entered offset.
*
* @param parent Parent window used for dialogs.
* @param view Hex view to focus after the Goto operation.
* @param model Model that contains the memory viewer where the offset is changed.
*/
public static void gotoOffset(final JFrame parent, final CMemoryViewer view, final CDebugPerspectiveModel model) {
final IDebugger debugger = model.getCurrentSelectedDebugger();
if (debugger == null) {
return;
}
final TargetProcessThread activeThread = debugger.getProcessManager().getActiveThread();
final Memory memory = debugger.getProcessManager().getMemory();
final CDefaultMemoryExpressionBinding binding = new CDefaultMemoryExpressionBinding(activeThread, memory);
final CGotoDialog dlg = new CGotoDialog(parent, model.getCurrentSelectedDebugger().getProcessManager().getMemoryMap(), binding, model.getGotoAddress());
dlg.setVisible(true);
final IAddress value = dlg.getValue();
if (value != null) {
model.setGotoAddress(value);
model.setActiveMemoryAddress(value, true);
view.requestFocusInWindow();
}
}
use of com.google.security.zynamics.zylib.disassembly.IAddress in project binnavi by google.
the class TypeSubstitutionDialog method createOrUpdateSubstitution.
private void createOrUpdateSubstitution(final TypeSelectionPath path) throws CouldntSaveDataException {
final int offset = path.determineTotalMemberOffset();
final BaseType baseType = path.getRootType();
final int position = selectedNode.getOperandPosition();
final IAddress address = selectedNode.getInstructionAddress();
final TypeSubstitution substitution = selectedNode.getTypeSubstitution();
final List<TypeMember> memberPath = path.getMembers();
if (substitution == null) {
typeManager.createTypeSubstitution(selectedNode, baseType, memberPath, position, offset, address);
} else {
typeManager.updateTypeSubstitution(selectedNode, substitution, baseType, path.getMembers(), offset);
}
}
use of com.google.security.zynamics.zylib.disassembly.IAddress in project binnavi by google.
the class CDataflowViewCreator method create.
/**
* Creates a new dataflow view.
*
* @param container The container in which the dataflow view is created.
* @param view The normal view that provides the control-flow information.
*
* @return The created dataflow view.
*
* @throws InternalTranslationException Thrown if the input view could not be translated to REIL.
*/
public static INaviView create(final IViewContainer container, final INaviView view) throws InternalTranslationException {
Preconditions.checkNotNull(container, "IE00411: Module argument can not be null");
Preconditions.checkNotNull(view, "IE00414: View argument can not be null");
final Map<IAddress, INaviInstruction> instructions = new HashMap<IAddress, INaviInstruction>();
for (final CCodeNode codeNode : view.getBasicBlocks()) {
for (final INaviInstruction instruction : codeNode.getInstructions()) {
instructions.put(instruction.getAddress(), instruction);
}
}
final ReilFunction function = view.getContent().getReilCode();
final OperandGraph operandGraph = OperandGraph.create(function.getGraph());
final INaviView dfView = container.createView(String.format("Data flow view of '%s'", view.getName()), "");
final Map<OperandGraphNode, INaviCodeNode> nodeMap = new HashMap<OperandGraphNode, INaviCodeNode>();
final Map<INaviInstruction, CCodeNode> instructionMap = new HashMap<INaviInstruction, CCodeNode>();
for (final OperandGraphNode operandGraphNode : operandGraph) {
final ReilInstruction reilInstruction = operandGraphNode.getInstruction();
final INaviInstruction instruction = instructions.get(ReilHelpers.toNativeAddress(reilInstruction.getAddress()));
if (instructionMap.containsKey(instruction)) {
nodeMap.put(operandGraphNode, instructionMap.get(instruction));
continue;
}
final CCodeNode codeNode = dfView.getContent().createCodeNode(null, Lists.newArrayList(instruction));
codeNode.setColor(ConfigManager.instance().getColorSettings().getBasicBlocksColor());
nodeMap.put(operandGraphNode, codeNode);
instructionMap.put(instruction, codeNode);
}
for (final OperandGraphEdge edge : operandGraph.getEdges()) {
final INaviCodeNode source = nodeMap.get(edge.getSource());
final INaviCodeNode target = nodeMap.get(edge.getTarget());
if (source.equals(target)) {
continue;
}
dfView.getContent().createEdge(source, target, EdgeType.JUMP_UNCONDITIONAL);
}
return dfView;
}
Aggregations