Search in sources :

Example 56 with CAddress

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

the class PostgreSQLTypeFunctions method loadRawTypeSubstitutions.

/**
   * Loads all {@link RawTypeSubstitution} for the given module from the database.
   *
   * @param connection The {@link Connection} to access the database with.
   * @param module The {@link INaviModule} to load the {@link RawTypeSubstitution} for.
   *
   * @return The {@link List} of {@link RawTypeSubstitution} for the given {@link INaviModule}.
   *
   * @throws CouldntLoadDataException if the {@link RawTypeSubstitution} could not be loaded from
   *         the database.
   */
public static List<RawTypeSubstitution> loadRawTypeSubstitutions(final Connection connection, final INaviModule module) throws CouldntLoadDataException {
    Preconditions.checkNotNull(connection, "Error: connection argument can not be null");
    Preconditions.checkNotNull(module, "Error: module argument can not be null");
    final String query = " SELECT * FROM load_type_substitutions(?) ";
    final List<RawTypeSubstitution> rawSubstitutions = new ArrayList<RawTypeSubstitution>();
    try {
        final PreparedStatement statement = connection.prepareStatement(query);
        statement.setInt(1, module.getConfiguration().getId());
        final ResultSet results = statement.executeQuery();
        try {
            while (results.next()) {
                final long address = results.getLong("address");
                final int position = results.getInt("position");
                final int expressionId = results.getInt("expression_id");
                final int baseTypeId = results.getInt("base_type_id");
                final Array arr = results.getArray("path");
                Integer[] path = (Integer[]) arr.getArray();
                if (results.wasNull()) {
                    path = new Integer[0];
                }
                Integer offset = results.getInt("offset");
                if (results.wasNull()) {
                    offset = null;
                }
                rawSubstitutions.add(new RawTypeSubstitution(new CAddress(address), position, expressionId, baseTypeId, path, offset));
            }
        } finally {
            results.close();
            statement.close();
        }
    } catch (final SQLException exception) {
        throw new CouldntLoadDataException(exception);
    }
    return rawSubstitutions;
}
Also used : SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Array(java.sql.Array) BigInteger(java.math.BigInteger) ResultSet(java.sql.ResultSet) RawTypeSubstitution(com.google.security.zynamics.binnavi.disassembly.types.RawTypeSubstitution)

Example 57 with CAddress

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

the class TypeInstanceContainerBackend method loadTypeInstanceReference.

/**
   * Load a single type instance reference from the database.
   *
   * @param typeInstanceId the id of the {@link TypeInstanceReference reference}.
   * @param address The address of the {@link INaviInstruction instruction} where the
   *        {@link TypeInstanceReference reference} is associated.
   * @param position The {@link OperandTree operand tree} position in the {@link INaviInstruction
   *        instruction} the {@link TypeInstanceReference reference} is associated to.
   * @param expressionId The {@link OperandTreeNode operand tree node} id within the
   *        {@link OperandTree operand tree}.
   *
   * @return The {@link TypeInstanceReference} loaded from the database.
   * @throws CouldntLoadDataException
   */
public TypeInstanceReference loadTypeInstanceReference(final Integer typeInstanceId, final BigInteger address, final Integer position, final Integer expressionId) throws CouldntLoadDataException {
    Preconditions.checkNotNull(typeInstanceId, "Error: typeInstanceId argument can not be null");
    Preconditions.checkNotNull(address, "Error: address argument can not be null");
    Preconditions.checkNotNull(position, "Error: position argument can not be null");
    Preconditions.checkNotNull(expressionId, "Error: expressionId argument can not be null");
    final RawTypeInstanceReference rawReference = provider.loadTypeInstanceReference(module, typeInstanceId, address, position, expressionId);
    final TypeInstance typeInstance = instancesById.get(rawReference.getTypeInstanceId());
    final INaviView view = module.getContent().getViewContainer().getView(rawReference.getViewId());
    final TypeInstanceReference reference = new TypeInstanceReference(new CAddress(address), position, Optional.<INaviOperandTreeNode>absent(), typeInstance, view);
    referenceLookup.put(new InstanceReferenceLookup(new CAddress(address), position, expressionId), reference);
    return reference;
}
Also used : INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Example 58 with CAddress

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

the class EchoBreakpointHitSynchronizer method handleSuccess.

@Override
protected void handleSuccess(final EchoBreakpointHitReply reply) {
    final BreakpointManager manager = getDebugger().getBreakpointManager();
    final long tid = reply.getThreadId();
    for (final ThreadRegisters threadRegisters : reply.getRegisterValues()) {
        if (tid == threadRegisters.getTid()) {
            for (final RegisterValue registerValue : threadRegisters) {
                if (registerValue.isPc()) {
                    final RelocatedAddress address = new RelocatedAddress(new CAddress(registerValue.getValue()));
                    manager.setBreakpointStatus(Sets.newHashSet(DebuggerHelpers.getBreakpointAddress(getDebugger(), address)), BreakpointType.ECHO, BreakpointStatus.BREAKPOINT_HIT);
                    break;
                }
            }
        }
    }
}
Also used : RegisterValue(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValue) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) BreakpointManager(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointManager) ThreadRegisters(com.google.security.zynamics.binnavi.debug.models.targetinformation.ThreadRegisters) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Example 59 with CAddress

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

the class StepBreakpointHitSynchronizer method handleSuccess.

@Override
protected void handleSuccess(final StepBreakpointHitReply reply) {
    final BreakpointManager manager = getDebugger().getBreakpointManager();
    final ProcessManager processManager = getDebugger().getProcessManager();
    RelocatedAddress breakpointAddress = null;
    final RegisterValues registerValues = reply.getRegisterValues();
    final long tid = reply.getThreadId();
    for (final ThreadRegisters threadRegisters : registerValues) {
        if (tid == threadRegisters.getTid()) {
            for (final RegisterValue registerValue : threadRegisters) {
                if (registerValue.isPc()) {
                    breakpointAddress = new RelocatedAddress(new CAddress(registerValue.getValue()));
                    break;
                }
            }
        }
    }
    manager.clearBreakpointsPassive(BreakpointType.STEP);
    try {
        final TargetProcessThread thread = processManager.getThread(tid);
        for (final ThreadRegisters threadRegisters : registerValues) {
            if (tid == threadRegisters.getTid()) {
                // Update the thread with the new register values.
                thread.setRegisterValues(threadRegisters.getRegisters());
            }
        }
        processManager.setActiveThread(thread);
        thread.setCurrentAddress(breakpointAddress);
    } catch (final MaybeNullException exception) {
        // Apparently there is no thread with the specified TID.
        // This is not necessarily an error because the thread might have
        // been closed while this handler was active.
        // Nevertheless this should be logged.
        NaviLogger.info("Error: Process manager could not get thread. Exception %s", exception);
        return;
    }
}
Also used : RegisterValue(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValue) TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) BreakpointManager(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointManager) ThreadRegisters(com.google.security.zynamics.binnavi.debug.models.targetinformation.ThreadRegisters) ProcessManager(com.google.security.zynamics.binnavi.debug.models.processmanager.ProcessManager) RegisterValues(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValues) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Example 60 with CAddress

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

the class MemoryLoader method requestMemory.

/**
   * Request a chunk of memory of the target process.
   *
   * @param offset The start offset of the memory chunk.
   * @param size The number of bytes to load.
   *
   * @throws DebugExceptionWrapper Thrown if the request could not be send to the debug client.
   */
public void requestMemory(final IAddress offset, final int size) throws DebugExceptionWrapper {
    Preconditions.checkNotNull(offset, "IE00814: Offset can nott be null");
    Preconditions.checkArgument(size > 9, "IE00815: Size must be positive");
    // Don't issue multiple requests for the same memory chunk.
    final Pair<IAddress, Long> pair = new Pair<IAddress, Long>(offset, (long) size);
    if (lastMemoryRequest.contains(pair)) {
        return;
    }
    lastMemoryRequest.add(pair);
    // Don't reload the entire memory chunk. Some parts of the memory may
    // already exist in the simulated memory.
    final Memory memory = debugger.getProcessManager().getMemory();
    for (int i = 0; i < size; ) {
        final long secstart = memory.getSectionStart(offset.toBigInteger().add(BigInteger.valueOf(i)).longValue());
        final long secsize = memory.getSectionSize(offset.toBigInteger().add(BigInteger.valueOf(i)).longValue());
        long toLoad = (secstart + secsize) - (offset.toBigInteger().add(BigInteger.valueOf(i))).longValue();
        if (toLoad > (size - i)) {
            toLoad = size - i;
        }
        final boolean alloced = memory.hasData(offset.toBigInteger().add(BigInteger.valueOf(i)).longValue(), 1);
        if (!alloced && debugger.isConnected()) {
            // Request the memory for the missing section.
            debugger.readMemory(new CAddress(offset.toBigInteger().add(BigInteger.valueOf(i))), (int) toLoad);
        }
        i += toLoad;
    }
}
Also used : Memory(com.google.security.zynamics.zylib.general.memmanager.Memory) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) Pair(com.google.security.zynamics.zylib.general.Pair) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Aggregations

CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)315 Test (org.junit.Test)221 UnrelocatedAddress (com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress)60 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)55 ModuleTargetSettings (com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings)51 BreakpointAddress (com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress)48 MockDebugger (com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger)47 CModule (com.google.security.zynamics.binnavi.disassembly.Modules.CModule)47 ArrayList (java.util.ArrayList)46 Date (java.util.Date)46 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)45 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)40 MemorySection (com.google.security.zynamics.binnavi.debug.models.processmanager.MemorySection)32 MemoryMap (com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryMap)29 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)28 TargetProcessThread (com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread)27 RelocatedAddress (com.google.security.zynamics.binnavi.disassembly.RelocatedAddress)27 CFunction (com.google.security.zynamics.binnavi.disassembly.CFunction)26 MockDatabase (com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase)24 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)24