Search in sources :

Example 76 with IAddress

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

the class PostgreSQLProjectFunctions method readAddressSpace.

/**
 * Loads an address space from the database.
 *
 * The address space ID must belong to an address space in the database connected to by the
 * provider argument.
 *
 * @param provider The connection to the database.
 * @param addressSpaceId The ID of the address space to load.
 * @param project The optional project for the address space.
 * @return The loaded address space.
 *
 * @throws SQLException Thrown if loading the address space failed.
 */
public static CAddressSpace readAddressSpace(final AbstractSQLProvider provider, final int addressSpaceId, final INaviProject project) throws SQLException {
    final String query = "SELECT name, description, creation_date, modification_date " + " FROM " + CTableNames.ADDRESS_SPACES_TABLE + " WHERE id = " + addressSpaceId;
    final ResultSet resultSet = provider.getConnection().executeQuery(query, true);
    try {
        while (resultSet.next()) {
            final String name = PostgreSQLHelpers.readString(resultSet, "name");
            final String description = PostgreSQLHelpers.readString(resultSet, "description");
            final Timestamp creationDate = resultSet.getTimestamp("creation_date");
            final Timestamp modificationDate = resultSet.getTimestamp("modification_date");
            return new CAddressSpace(addressSpaceId, name, description == null ? "" : description, creationDate, modificationDate, new HashMap<INaviModule, IAddress>(), null, provider, project);
        }
    } finally {
        resultSet.close();
    }
    return null;
}
Also used : INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) ResultSet(java.sql.ResultSet) Timestamp(java.sql.Timestamp) CAddressSpace(com.google.security.zynamics.binnavi.disassembly.AddressSpaces.CAddressSpace) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress)

Example 77 with IAddress

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

the class InstructionConverter method createInstruction.

/**
 * This line creates an instruction from the information of a raw instruction line.
 *
 * @param line The instruction line.
 * @param provider The connection to the database.
 *
 * @return The instruction object generated from the instruction line.
 */
public static CInstruction createInstruction(final InstructionLine line, final SQLProvider provider) {
    final ArrayList<COperandTree> operands = new ArrayList<COperandTree>();
    final INaviModule module = line.getModule();
    for (final OperandTree rawTree : line.getOperands()) {
        operands.add(generateTree(rawTree, provider, module));
    }
    final IAddress address = line.getAddress();
    final String mnemonic = line.getMnemonic();
    final String architecture = line.getArchitecture();
    final CInstruction instruction = new CInstruction(true, module, address, mnemonic, operands, line.getData(), architecture, provider);
    return instruction;
}
Also used : COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) ArrayList(java.util.ArrayList) CInstruction(com.google.security.zynamics.binnavi.disassembly.CInstruction) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress)

Example 78 with IAddress

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

the class CMemorySelectionFunctions method askMemoryRange.

/**
 * Asks the user for a memory range and displays it afterwards.
 *
 * @param dlg Dialog where the user can select a range.
 * @param debugPerspectiveModel Describes the debug GUI perspective where the refresh action takes
 *        place.
 */
public static void askMemoryRange(final CMemoryRangeDialog dlg, final CDebugPerspectiveModel debugPerspectiveModel) {
    final IDebugger debugger = debugPerspectiveModel.getCurrentSelectedDebugger();
    if (debugger == null) {
        return;
    }
    dlg.setVisible(true);
    final IAddress start = dlg.getStart();
    final IAddress numberOfBytes = dlg.getBytes();
    if (start != null && numberOfBytes != null) {
        debugPerspectiveModel.setActiveMemoryAddress(start, true);
        final ProcessManager pmanager = debugger.getProcessManager();
        pmanager.setMemoryMap(new MemoryMap(new FilledList<MemorySection>()));
        pmanager.getMemory().clear();
        final ArrayList<MemorySection> sections = new ArrayList<MemorySection>();
        sections.add(new MemorySection(start, new CAddress(start.toBigInteger().add(numberOfBytes.toBigInteger()).subtract(BigInteger.ONE))));
        final MemoryMap map = new MemoryMap(sections);
        pmanager.setMemoryMap(map);
    }
}
Also used : MemoryMap(com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryMap) MemorySection(com.google.security.zynamics.binnavi.debug.models.processmanager.MemorySection) FilledList(com.google.security.zynamics.zylib.types.lists.FilledList) ArrayList(java.util.ArrayList) IDebugger(com.google.security.zynamics.binnavi.debug.debugger.interfaces.IDebugger) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) ProcessManager(com.google.security.zynamics.binnavi.debug.models.processmanager.ProcessManager) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Example 79 with IAddress

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

the class CViewOpener method showForwardedFunction.

/**
 * Shows a forwarded function in a graph window.
 *
 * @param parent Parent window that is used as the parent of all dialogs.
 * @param container View container that provides the context in which a view is opened.
 * @param view The view to show.
 * @param function The imported function to show.
 * @param window Graph window where the graph is shown. If this value is null, the graph is shown
 *        in a new window.
 */
private static void showForwardedFunction(final Window parent, final IViewContainer container, final INaviView view, final INaviFunction function, final CGraphWindow window) {
    if (container instanceof CModuleContainer) {
        CMessageBox.showInformation(parent, "Please open forwarded views from inside a project.");
        return;
    }
    final IDatabase database = container.getDatabase();
    final int moduleId = function.getForwardedFunctionModuleId();
    final INaviModule forwardedModule = database.getContent().getModule(moduleId);
    if (forwardedModule == null) {
        final String message = "E00019: " + "Forwarded view can not be loaded (Unknown module)";
        final String description = CUtilityFunctions.createDescription("BinNavi could not open the forwarded view because the module of " + "the forwarding target is unknown.", new String[] { "Probably the result of a bug in BinNavi" }, new String[] { "The view can not be opened. Try to update the " + "forwarding target again. Restart BinNavi if the view " + "can still not be opened. Contact the BinNavi support if necessary." });
        NaviErrorDialog.show(parent, message, description);
    } else if (forwardedModule.isLoaded()) {
        final IAddress address = function.getForwardedFunctionAddress();
        final INaviFunction forwardedFunction = forwardedModule.getContent().getFunctionContainer().getFunction(address);
        if (forwardedFunction == null) {
            final String message = "E00020: " + "Forwarded view can not be loaded (Unknown function)";
            final String description = CUtilityFunctions.createDescription("BinNavi could not open the forwarded view because the target function is unknown.", new String[] { "Probably the result of a bug in BinNavi" }, new String[] { "The view can not be opened. Try to update the forwarding target " + "again. Restart BinNavi if the view can still not be opened. Contact the " + "BinNavi support if necessary." });
            NaviErrorDialog.show(parent, message, description);
        } else {
            final INaviView forwardedView = forwardedModule.getContent().getViewContainer().getView(forwardedFunction);
            if (forwardedView == null) {
                final String message = "E00107: " + "Forwarded view can not be loaded (Unknown view)";
                final String description = CUtilityFunctions.createDescription("BinNavi could not open the forwarded view because the target view is unknown.", new String[] { "Probably the result of a bug in BinNavi" }, new String[] { "The view can not be opened. Try to update the forwarding target " + "again. Restart BinNavi if the view can still not be opened. Contact the " + "BinNavi support if necessary." });
                NaviErrorDialog.show(parent, message, description);
            } else {
                CGraphOpener.showGraph(container, forwardedView, window, parent);
            }
        }
    } else {
        if (CMessageBox.showYesNoQuestion(parent, "The view can not be opened because it is forwarded to an unloaded module.\n\n" + "Do you want to load the forwarded module now?") == JOptionPane.YES_OPTION) {
            CModuleLoader.loadModule(parent, forwardedModule);
            if (forwardedModule.isLoaded()) {
                // Just call this function recursively now that the module is loaded.
                showForwardedFunction(parent, container, view, function, window);
            }
        }
    }
}
Also used : IDatabase(com.google.security.zynamics.binnavi.Database.Interfaces.IDatabase) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) CModuleContainer(com.google.security.zynamics.binnavi.disassembly.Modules.CModuleContainer) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress)

Example 80 with IAddress

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

the class CFunctionViewsModel method getForwarderColumnText.

/**
 * Calculates the content of the forwarder column for a given function.
 *
 * @param function The function to check.
 *
 * @return The text shown in the table for the forwarder column of the given function.
 */
private String getForwarderColumnText(final INaviFunction function) {
    final IAddress address = function.getForwardedFunctionAddress();
    if (address == null) {
        return "-";
    }
    final int moduleId = function.getForwardedFunctionModuleId();
    final INaviModule forwardedModule = m_database.getContent().getModule(moduleId);
    if (forwardedModule == null) {
        return "INVALID";
    } else if (!forwardedModule.isLoaded()) {
        return String.format("%s:%s", forwardedModule.getConfiguration().getName(), address.toHexString());
    }
    final INaviFunction forwardedFunction = forwardedModule.getContent().getFunctionContainer().getFunction(address);
    if (forwardedFunction == null) {
        return "INVALID";
    } else {
        return String.format("%s:%s", forwardedModule.getConfiguration().getName(), forwardedFunction.getName());
    }
}
Also used : INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) Breakpoint(com.google.security.zynamics.binnavi.debug.models.breakpoints.Breakpoint)

Aggregations

IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)82 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)28 ArrayList (java.util.ArrayList)23 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)19 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)16 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)15 Test (org.junit.Test)14 SQLException (java.sql.SQLException)12 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)11 ResultSet (java.sql.ResultSet)11 BigInteger (java.math.BigInteger)10 HashMap (java.util.HashMap)10 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)9 COperandTree (com.google.security.zynamics.binnavi.disassembly.COperandTree)7 INaviOperandTreeNode (com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode)7 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)7 CConnection (com.google.security.zynamics.binnavi.Database.CConnection)6 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)6 ReilFunction (com.google.security.zynamics.reil.ReilFunction)6 List (java.util.List)6