Search in sources :

Example 36 with Pair

use of com.google.security.zynamics.zylib.general.Pair in project binnavi by google.

the class StepBreakpointRemovedParser method parseSuccess.

@Override
public StepBreakpointsRemovedReply parseSuccess(final int packetId, final int argumentCount) throws IOException {
    final List<Pair<RelocatedAddress, Integer>> addresses = new ArrayList<>();
    for (int i = 0; i < parseInteger(); i++) {
        final RelocatedAddress address = new RelocatedAddress(parseAddress());
        addresses.add(new Pair<RelocatedAddress, Integer>(address, parseInteger()));
    }
    return new StepBreakpointsRemovedReply(packetId, 0, addresses);
}
Also used : StepBreakpointsRemovedReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.StepBreakpointsRemovedReply) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) ArrayList(java.util.ArrayList) Pair(com.google.security.zynamics.zylib.general.Pair)

Example 37 with Pair

use of com.google.security.zynamics.zylib.general.Pair in project binnavi by google.

the class RegisterTracker method track.

/**
 * Function to do register tracking.
 *
 * @param function The {@link ReilFunction} in which to do the register tracking.
 * @param startInstruction The {@link IInstruction} which is the start instruction.
 * @param trackedRegister The register to be tracked.
 * @param options The {@link RegisterTrackingOptions}.
 *
 * @return The {@link MonoReilSolverResult} of the tracking.
 */
public static MonoReilSolverResult<RegisterSetLatticeElement> track(final ReilFunction function, final IInstruction startInstruction, final String trackedRegister, final RegisterTrackingOptions options) {
    Preconditions.checkNotNull(function, "Error: function argument can not be null");
    Preconditions.checkNotNull(startInstruction, "Error: startInstruction argument can not be null");
    Preconditions.checkNotNull(trackedRegister, "Error: trackedRegister argument can not be null");
    Preconditions.checkNotNull(options, "Error: options argument can not be null");
    final CReilInstructionGraph instructionGraph = new CReilInstructionGraph(function.getGraph());
    final RegisterSetLatticeElement registerSetLatticeElement = new RegisterSetLatticeElement(trackedRegister);
    final MonoReilSolver<RegisterSetLatticeElement> monoReilSolver = new MonoReilSolver<RegisterSetLatticeElement>(instructionGraph, options.getAnalysisDirection(), new RegisterSetLattice());
    final Iterable<IInstructionGraphEdge> relevantEdges = options.trackIncoming() ? instructionGraph.getIncomingEdgesForAddress(startInstruction.getAddress()) : instructionGraph.getOutgoingEdgesForAddress(startInstruction.getAddress());
    final List<Pair<IInstructionGraphEdge, RegisterSetLatticeElement>> initialState = new ArrayList<Pair<IInstructionGraphEdge, RegisterSetLatticeElement>>();
    for (final IInstructionGraphEdge currentRelevantEdge : relevantEdges) {
        initialState.add(new Pair<IInstructionGraphEdge, RegisterSetLatticeElement>(currentRelevantEdge, registerSetLatticeElement));
    }
    final ITransformationProvider<RegisterSetLatticeElement> transformationProvider = new RegisterTrackingTransformationProvider(options);
    final MonoReilSolverResult<RegisterSetLatticeElement> solverResult = monoReilSolver.solve(transformationProvider, initialState, Integer.MAX_VALUE);
    return solverResult;
}
Also used : IInstructionGraphEdge(com.google.security.zynamics.reil.algorithms.mono2.common.instructiongraph.interfaces.IInstructionGraphEdge) ArrayList(java.util.ArrayList) CReilInstructionGraph(com.google.security.zynamics.reil.yfileswrap.algorithms.mono2.common.instructiongraph.CReilInstructionGraph) MonoReilSolver(com.google.security.zynamics.reil.algorithms.mono2.common.MonoReilSolver) Pair(com.google.security.zynamics.zylib.general.Pair)

Example 38 with Pair

use of com.google.security.zynamics.zylib.general.Pair in project binnavi by google.

the class RegisterTrackingTransformationProvider method transformStm.

@Override
protected Pair<RegisterSetLatticeElement, RegisterSetLatticeElement> transformStm(final ReilInstruction ins, final RegisterSetLatticeElement state) {
    final ReilOperand op1 = ins.getFirstOperand();
    if (op1.getType().equals(OperandType.REGISTER)) {
        if (state.isTainted(op1.getValue())) {
            final RegisterSetLatticeElement newState = state.copy();
            newState.addReadReg(op1.getValue());
            return new Pair<RegisterSetLatticeElement, RegisterSetLatticeElement>(newState, null);
        }
    }
    return new Pair<RegisterSetLatticeElement, RegisterSetLatticeElement>(state, null);
}
Also used : ReilOperand(com.google.security.zynamics.reil.ReilOperand) Pair(com.google.security.zynamics.zylib.general.Pair)

Example 39 with Pair

use of com.google.security.zynamics.zylib.general.Pair in project binnavi by google.

the class ReilInterpreter method interpretJcc.

/**
 * Interprets a JCC instruction.
 *
 * @param instruction The JCC instruction to interpret
 * @param programCounter The name of the program counter register
 */
private void interpretJcc(final ReilInstruction instruction, final String programCounter) {
    final Pair<Boolean, BigInteger> firstValue = loadLongValue(instruction.getFirstOperand());
    if (!firstValue.second().equals(BigInteger.ZERO) && (instruction.getThirdOperand().getType() == OperandType.SUB_ADDRESS)) {
        final String[] parts = instruction.getThirdOperand().getValue().split("\\.");
        assert parts.length == 2;
        setRegister(programCounter, new BigInteger(parts[0]), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
        setRegister(SUB_PC, new BigInteger(parts[1]), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
    } else if (!firstValue.second().equals(BigInteger.ZERO)) {
        final Pair<Boolean, BigInteger> secondValue = loadLongValue(instruction.getThirdOperand());
        setRegister(programCounter, secondValue.second(), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
    }
}
Also used : BigInteger(java.math.BigInteger) Pair(com.google.security.zynamics.zylib.general.Pair)

Example 40 with Pair

use of com.google.security.zynamics.zylib.general.Pair in project binnavi by google.

the class RegisterTrackingTransformationProvider method transformOr.

@Override
protected Pair<RegisterSetLatticeElement, RegisterSetLatticeElement> transformOr(final ReilInstruction ins, final RegisterSetLatticeElement state) {
    final OperandType operandOneType = ins.getFirstOperand().getType();
    final OperandType operandTwoType = ins.getSecondOperand().getType();
    final OperandSize operandOneSize = ins.getFirstOperand().getSize();
    final OperandSize operandTwoSize = ins.getSecondOperand().getSize();
    final OperandSize operandThreeSize = ins.getThirdOperand().getSize();
    final String operandOneValue = ins.getFirstOperand().getValue();
    final String operandTwoValue = ins.getSecondOperand().getValue();
    final String mask = getMask(operandThreeSize);
    if ((operandOneType == OperandType.INTEGER_LITERAL) && mask.equalsIgnoreCase(operandOneValue) && operandThreeSize.equals(operandTwoSize) && operandThreeSize.equals(operandOneSize)) {
        final RegisterSetLatticeElement newState = state.copy();
        newState.untaint(ins.getThirdOperand().getValue());
        return new Pair<RegisterSetLatticeElement, RegisterSetLatticeElement>(newState, null);
    } else if ((operandTwoType == OperandType.INTEGER_LITERAL) && mask.equalsIgnoreCase(operandTwoValue) && operandThreeSize.equals(operandTwoSize) && operandThreeSize.equals(operandOneSize)) {
        final RegisterSetLatticeElement newState = state.copy();
        newState.untaint(ins.getThirdOperand().getValue());
        return new Pair<RegisterSetLatticeElement, RegisterSetLatticeElement>(newState, null);
    }
    return transformNormalInstruction(ins, state);
}
Also used : OperandType(com.google.security.zynamics.reil.OperandType) OperandSize(com.google.security.zynamics.reil.OperandSize) Pair(com.google.security.zynamics.zylib.general.Pair)

Aggregations

Pair (com.google.security.zynamics.zylib.general.Pair)55 ArrayList (java.util.ArrayList)26 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)7 RelocatedAddress (com.google.security.zynamics.binnavi.disassembly.RelocatedAddress)7 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)6 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)6 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)6 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)6 IDebugger (com.google.security.zynamics.binnavi.debug.debugger.interfaces.IDebugger)4 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)4 Test (org.junit.Test)4 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)3 Breakpoint (com.google.security.zynamics.binnavi.debug.models.breakpoints.Breakpoint)3 BreakpointAddress (com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress)3 MemoryModule (com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryModule)3 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)3 ReilBlock (com.google.security.zynamics.reil.ReilBlock)3 ReilInstruction (com.google.security.zynamics.reil.ReilInstruction)3 BigInteger (java.math.BigInteger)3 HashSet (java.util.HashSet)3