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);
}
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;
}
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);
}
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);
}
}
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);
}
Aggregations