use of com.google.security.zynamics.reil.OperandSize in project binnavi by google.
the class Helpers method signedSub.
/**
* Signed subtraction
*
* @param offset
* @param environment
* @param instruction
* @param instructions
* @param firstOperand
* @param secondOperand
* @param resultOperand
* @param trueResult
*/
public static void signedSub(final long offset, final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions, final String firstOperand, final String secondOperand, final String resultOperand, final String trueResult) {
final String tmpResult = environment.getNextVariableString();
final String twoComplementfirstOperand = environment.getNextVariableString();
final OperandSize dw = OperandSize.DWORD;
final OperandSize qw = OperandSize.QWORD;
final OperandSize bt = OperandSize.BYTE;
long baseOffset = offset;
// perform actual subtraction in the 2's complement !rA + rB + 1
instructions.add(ReilHelpers.createXor(baseOffset++, dw, firstOperand, dw, String.valueOf(0xFFFFFFFFL), dw, twoComplementfirstOperand));
instructions.add(ReilHelpers.createAdd(baseOffset++, dw, twoComplementfirstOperand, dw, secondOperand, qw, tmpResult));
instructions.add(ReilHelpers.createAdd(baseOffset++, qw, tmpResult, bt, String.valueOf(1L), qw, trueResult));
instructions.add(ReilHelpers.createAnd(baseOffset++, qw, trueResult, dw, String.valueOf(0xFFFFFFFFL), dw, resultOperand));
}
use of com.google.security.zynamics.reil.OperandSize in project binnavi by google.
the class AddTranslator method translate.
@Override
public void translate(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) throws InternalTranslationException {
TranslationHelpers.checkTranslationArguments(environment, instruction, instructions, "add");
final String targetRegister = instruction.getOperands().get(0).getRootNode().getChildren().get(0).getValue();
final String sourceRegister1 = instruction.getOperands().get(1).getRootNode().getChildren().get(0).getValue();
final String sourceRegister2 = instruction.getOperands().get(2).getRootNode().getChildren().get(0).getValue();
final OperandSize bt = OperandSize.BYTE;
final OperandSize dw = OperandSize.DWORD;
final OperandSize qw = OperandSize.QWORD;
final long baseOffset = ReilHelpers.toReilAddress(instruction.getAddress()).toLong();
long offset = baseOffset;
final String temporaryResult = environment.getNextVariableString();
final String bit31 = environment.getNextVariableString();
final String bit32 = environment.getNextVariableString();
final String jumpCondition = environment.getNextVariableString();
final String xoredBits = environment.getNextVariableString();
final String sourceImmediateSignExtended = SignExtendGenerator.extend16BitTo32(offset, environment, sourceRegister2, instructions);
instructions.add(ReilHelpers.createAdd(offset++, dw, sourceRegister1, dw, sourceImmediateSignExtended, qw, temporaryResult));
// is bit 32 != bit 31
instructions.add(ReilHelpers.createBsh(offset++, qw, temporaryResult, dw, String.valueOf(-31L), bt, bit31));
instructions.add(ReilHelpers.createBsh(offset++, qw, temporaryResult, dw, String.valueOf(-32L), bt, bit32));
instructions.add(ReilHelpers.createXor(offset++, bt, bit31, bt, bit32, bt, xoredBits));
instructions.add(ReilHelpers.createBisz(offset++, bt, xoredBits, bt, jumpCondition));
final String jmpGoal = String.format("%d.%d", instruction.getAddress().toLong(), instructions.size() + 2);
instructions.add(ReilHelpers.createJcc(offset++, bt, jumpCondition, dw, jmpGoal));
instructions.add(ReilHelpers.createAnd(offset++, qw, temporaryResult, dw, String.valueOf(0xFFFFFFFFL), dw, targetRegister));
instructions.add(ReilHelpers.createNop(offset));
}
use of com.google.security.zynamics.reil.OperandSize in project binnavi by google.
the class AddiTranslator method translate.
@Override
public void translate(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) throws InternalTranslationException {
TranslationHelpers.checkTranslationArguments(environment, instruction, instructions, "addi");
final String targetRegister = instruction.getOperands().get(0).getRootNode().getChildren().get(0).getValue();
final String sourceRegister = instruction.getOperands().get(1).getRootNode().getChildren().get(0).getValue();
final String sourceImmediate = instruction.getOperands().get(2).getRootNode().getChildren().get(0).getValue();
final OperandSize bt = OperandSize.BYTE;
final OperandSize dw = OperandSize.DWORD;
final OperandSize qw = OperandSize.QWORD;
final long baseOffset = ReilHelpers.toReilAddress(instruction.getAddress()).toLong();
long offset = baseOffset;
final String temporaryResult = environment.getNextVariableString();
final String bit31 = environment.getNextVariableString();
final String bit32 = environment.getNextVariableString();
final String jumpCondition = environment.getNextVariableString();
final String xoredBits = environment.getNextVariableString();
final String sourceImmediateSignExtended = SignExtendGenerator.extend16BitTo32(offset, environment, sourceImmediate, instructions);
instructions.add(ReilHelpers.createAdd(offset++, dw, sourceRegister, dw, sourceImmediateSignExtended, qw, temporaryResult));
// is bit 32 != bit 31
instructions.add(ReilHelpers.createBsh(offset++, qw, temporaryResult, dw, String.valueOf(-31L), bt, bit31));
instructions.add(ReilHelpers.createBsh(offset++, qw, temporaryResult, dw, String.valueOf(-32L), bt, bit32));
instructions.add(ReilHelpers.createXor(offset++, bt, bit31, bt, bit32, bt, xoredBits));
instructions.add(ReilHelpers.createBisz(offset++, bt, xoredBits, bt, jumpCondition));
final String jmpGoal = String.format("%d.%d", instruction.getAddress().toLong(), instructions.size() + 2);
instructions.add(ReilHelpers.createJcc(offset++, bt, jumpCondition, dw, jmpGoal));
instructions.add(ReilHelpers.createAnd(offset++, qw, temporaryResult, dw, String.valueOf(0xFFFFFFFFL), dw, targetRegister));
instructions.add(ReilHelpers.createNop(offset));
}
use of com.google.security.zynamics.reil.OperandSize in project binnavi by google.
the class AddiuTranslator method translate.
@Override
public void translate(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) throws InternalTranslationException {
TranslationHelpers.checkTranslationArguments(environment, instruction, instructions, "addiu");
final Triple<IOperandTree, IOperandTree, IOperandTree> operands = OperandLoader.loadDuplicateFirst(instruction);
final String targetRegister = operands.first().getRootNode().getChildren().get(0).getValue();
final String sourceRegister = operands.second().getRootNode().getChildren().get(0).getValue();
final String sourceImmediate = operands.third().getRootNode().getChildren().get(0).getValue();
final OperandSize dw = OperandSize.DWORD;
final OperandSize qw = OperandSize.QWORD;
final long baseOffset = ReilHelpers.toReilAddress(instruction.getAddress()).toLong();
long offset = baseOffset;
final String temporaryResult = environment.getNextVariableString();
final String sourceImmediateSignExtended = SignExtendGenerator.extend16BitTo32(offset, environment, sourceImmediate, instructions);
offset = baseOffset + instructions.size();
instructions.add(ReilHelpers.createAdd(offset++, dw, sourceRegister, dw, sourceImmediateSignExtended, qw, temporaryResult));
instructions.add(ReilHelpers.createAnd(offset, qw, temporaryResult, dw, String.valueOf(0xFFFFFFFFL), dw, targetRegister));
}
use of com.google.security.zynamics.reil.OperandSize in project binnavi by google.
the class AdduTranslator method translate.
@Override
public void translate(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) throws InternalTranslationException {
TranslationHelpers.checkTranslationArguments(environment, instruction, instructions, "addu");
final Triple<IOperandTree, IOperandTree, IOperandTree> operands = OperandLoader.loadDuplicateFirst(instruction);
final String targetRegister = operands.first().getRootNode().getChildren().get(0).getValue();
final String sourceRegister1 = operands.second().getRootNode().getChildren().get(0).getValue();
final String sourceRegister2 = operands.third().getRootNode().getChildren().get(0).getValue();
final OperandSize dw = OperandSize.DWORD;
final OperandSize qw = OperandSize.QWORD;
final long baseOffset = ReilHelpers.toReilAddress(instruction.getAddress()).toLong();
long offset = baseOffset;
final String temporaryResult = environment.getNextVariableString();
instructions.add(ReilHelpers.createAdd(offset++, dw, sourceRegister1, dw, sourceRegister2, qw, temporaryResult));
instructions.add(ReilHelpers.createAnd(offset, qw, temporaryResult, dw, String.valueOf(0xFFFFFFFFL), dw, targetRegister));
}
Aggregations