Search in sources :

Example 11 with OperandSize

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));
}
Also used : OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 12 with OperandSize

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));
}
Also used : OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 13 with OperandSize

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));
}
Also used : OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 14 with OperandSize

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));
}
Also used : IOperandTree(com.google.security.zynamics.zylib.disassembly.IOperandTree) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 15 with OperandSize

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));
}
Also used : IOperandTree(com.google.security.zynamics.zylib.disassembly.IOperandTree) OperandSize(com.google.security.zynamics.reil.OperandSize)

Aggregations

OperandSize (com.google.security.zynamics.reil.OperandSize)442 IOperandTreeNode (com.google.security.zynamics.zylib.disassembly.IOperandTreeNode)257 IOperandTree (com.google.security.zynamics.zylib.disassembly.IOperandTree)53 InternalTranslationException (com.google.security.zynamics.reil.translators.InternalTranslationException)46 TranslationResult (com.google.security.zynamics.reil.translators.TranslationResult)45 ReilInstruction (com.google.security.zynamics.reil.ReilInstruction)16 ArrayList (java.util.ArrayList)15 BigInteger (java.math.BigInteger)12 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)5 OperandType (com.google.security.zynamics.reil.OperandType)2 ReilOperandNode (com.google.security.zynamics.reil.ReilOperandNode)2 TranslationResultType (com.google.security.zynamics.reil.translators.TranslationResultType)2 ReilBlock (com.google.security.zynamics.reil.ReilBlock)1 ReilEdge (com.google.security.zynamics.reil.ReilEdge)1 ReilGraph (com.google.security.zynamics.reil.ReilGraph)1 ReilOperand (com.google.security.zynamics.reil.ReilOperand)1 Pair (com.google.security.zynamics.zylib.general.Pair)1 EdgeType (com.google.security.zynamics.zylib.gui.zygraph.edges.EdgeType)1 HashMap (java.util.HashMap)1 StringTokenizer (java.util.StringTokenizer)1