Search in sources :

Example 46 with IOperandTree

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

the class SltiTranslator method translate.

@Override
public void translate(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) throws InternalTranslationException {
    TranslationHelpers.checkTranslationArguments(environment, instruction, instructions, "slti");
    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 subtractedValue = environment.getNextVariableString();
    final String maskedCarry = environment.getNextVariableString();
    // Subtract the input values
    instructions.add(ReilHelpers.createSub(offset++, dw, sourceRegister1, dw, sourceRegister2, qw, subtractedValue));
    // Isolate the carry flag
    instructions.add(ReilHelpers.createAnd(offset++, qw, subtractedValue, qw, String.valueOf(0x100000000L), qw, maskedCarry));
    // If the carry flag is set the first value was smaller => 0
    instructions.add(ReilHelpers.createBisz(offset++, qw, maskedCarry, dw, targetRegister));
    instructions.add(ReilHelpers.createBisz(offset++, dw, targetRegister, dw, targetRegister));
}
Also used : IOperandTree(com.google.security.zynamics.zylib.disassembly.IOperandTree) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 47 with IOperandTree

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

the class XorTranslator method translate.

@Override
public void translate(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) throws InternalTranslationException {
    TranslationHelpers.checkTranslationArguments(environment, instruction, instructions, "xor");
    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 long baseOffset = ReilHelpers.toReilAddress(instruction.getAddress()).toLong();
    final long offset = baseOffset;
    final OperandSize dw = OperandSize.DWORD;
    instructions.add(ReilHelpers.createXor(offset, dw, sourceRegister1, dw, sourceRegister2, dw, targetRegister));
}
Also used : IOperandTree(com.google.security.zynamics.zylib.disassembly.IOperandTree) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 48 with IOperandTree

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

the class OperandLoader method loadDuplicateFirst.

public static Triple<IOperandTree, IOperandTree, IOperandTree> loadDuplicateFirst(final IInstruction instruction) {
    final List<? extends IOperandTree> operands = instruction.getOperands();
    final IOperandTree operand1 = operands.get(0);
    final IOperandTree operand2 = operands.size() == 2 ? operands.get(0) : operands.get(1);
    final IOperandTree operand3 = operands.size() == 2 ? operands.get(1) : operands.get(2);
    return new Triple<IOperandTree, IOperandTree, IOperandTree>(operand1, operand2, operand3);
}
Also used : Triple(com.google.security.zynamics.zylib.general.Triple) IOperandTree(com.google.security.zynamics.zylib.disassembly.IOperandTree)

Example 49 with IOperandTree

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

the class OriTranslator method translate.

@Override
public void translate(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) throws InternalTranslationException {
    TranslationHelpers.checkTranslationArguments(environment, instruction, instructions, "ori");
    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 long baseOffset = ReilHelpers.toReilAddress(instruction.getAddress()).toLong();
    final long offset = baseOffset;
    instructions.add(ReilHelpers.createOr(offset, dw, sourceRegister, dw, sourceImmediate, dw, targetRegister));
}
Also used : IOperandTree(com.google.security.zynamics.zylib.disassembly.IOperandTree) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 50 with IOperandTree

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

the class BsfBsrTranslatorCommon method translateBsfOrBsr.

public static void translateBsfOrBsr(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions, boolean translateBsf) throws InternalTranslationException {
    if (instruction.getOperands().size() != 2) {
        throw new InternalTranslationException("Error: Argument instruction is not a bsr/bsf instruction (invalid number of operands)");
    }
    final long baseOffset = instruction.getAddress().toLong() * 0x100;
    long offset = baseOffset;
    final IOperandTree targetOperand = instruction.getOperands().get(0);
    final IOperandTree sourceOperand = instruction.getOperands().get(1);
    // Load the source operand.
    final TranslationResult sourceResult = Helpers.translateOperand(environment, offset, sourceOperand, true);
    instructions.addAll(sourceResult.getInstructions());
    offset = baseOffset + instructions.size();
    final OperandSize sourceSize = sourceResult.getSize();
    final String targetRegister = Helpers.getLeafValue(targetOperand.getRootNode());
    final String labelNotZero = String.format("%d.%d", instruction.getAddress().toLong(), instructions.size() + 4);
    final String labelLoopStart = String.format("%d.%d", instruction.getAddress().toLong(), instructions.size() + 7);
    final String labelLoopEnd = String.format("%d.%d", instruction.getAddress().toLong(), instructions.size() + 12);
    final String labelEnd = String.format("%d.%d", instruction.getAddress().toLong(), instructions.size() + 13);
    instructions.add(ReilHelpers.createJcc(offset++, sourceSize, sourceResult.getRegister(), OperandSize.ADDRESS, labelNotZero));
    // Input value is 0
    instructions.add(ReilHelpers.createStr(offset++, OperandSize.BYTE, "1", OperandSize.BYTE, Helpers.ZERO_FLAG));
    instructions.add(ReilHelpers.createUndef(offset++, environment.getArchitectureSize(), targetRegister));
    instructions.add(ReilHelpers.createJcc(offset++, OperandSize.BYTE, "1", OperandSize.ADDRESS, labelEnd));
    // Input value is not 0
    final String counter = environment.getNextVariableString();
    final String shiftedValue = environment.getNextVariableString();
    final String isolatedMsb = environment.getNextVariableString();
    instructions.add(ReilHelpers.createStr(offset++, OperandSize.BYTE, "0", OperandSize.BYTE, Helpers.ZERO_FLAG));
    instructions.add(ReilHelpers.createStr(offset++, sourceSize, sourceResult.getRegister(), sourceSize, shiftedValue));
    if (translateBsf) {
        instructions.add(ReilHelpers.createStr(offset++, OperandSize.BYTE, "0", OperandSize.BYTE, counter));
        instructions.add(ReilHelpers.createAnd(offset++, sourceSize, shiftedValue, sourceSize, "1", sourceSize, isolatedMsb));
    } else {
        instructions.add(ReilHelpers.createStr(offset++, OperandSize.BYTE, "31", OperandSize.BYTE, counter));
        // Generate the instruction for a BSR, e.g. bitmask is 0x80000000.
        instructions.add(ReilHelpers.createAnd(offset++, sourceSize, shiftedValue, sourceSize, String.valueOf(TranslationHelpers.getMsbMask(sourceSize)), sourceSize, isolatedMsb));
    }
    instructions.add(ReilHelpers.createJcc(offset++, sourceSize, isolatedMsb, OperandSize.ADDRESS, labelLoopEnd));
    if (translateBsf) {
        instructions.add(ReilHelpers.createAdd(offset++, OperandSize.BYTE, counter, OperandSize.BYTE, "1", OperandSize.BYTE, counter));
        instructions.add(ReilHelpers.createBsh(offset++, sourceSize, shiftedValue, sourceSize, "-1", sourceSize, shiftedValue));
    } else {
        instructions.add(ReilHelpers.createSub(offset++, OperandSize.BYTE, counter, OperandSize.BYTE, "1", OperandSize.BYTE, counter));
        instructions.add(ReilHelpers.createBsh(offset++, sourceSize, shiftedValue, sourceSize, "1", sourceSize, shiftedValue));
    }
    instructions.add(ReilHelpers.createJcc(offset++, OperandSize.BYTE, "1", OperandSize.ADDRESS, labelLoopStart));
    instructions.add(ReilHelpers.createStr(offset++, OperandSize.DWORD, counter, OperandSize.DWORD, targetRegister));
    instructions.add(ReilHelpers.createNop(offset++));
}
Also used : IOperandTree(com.google.security.zynamics.zylib.disassembly.IOperandTree) InternalTranslationException(com.google.security.zynamics.reil.translators.InternalTranslationException) TranslationResult(com.google.security.zynamics.reil.translators.TranslationResult) OperandSize(com.google.security.zynamics.reil.OperandSize)

Aggregations

IOperandTree (com.google.security.zynamics.zylib.disassembly.IOperandTree)60 OperandSize (com.google.security.zynamics.reil.OperandSize)53 TranslationResult (com.google.security.zynamics.reil.translators.TranslationResult)39 InternalTranslationException (com.google.security.zynamics.reil.translators.InternalTranslationException)35 ReilInstruction (com.google.security.zynamics.reil.ReilInstruction)2 TranslationResultType (com.google.security.zynamics.reil.translators.TranslationResultType)2 OperandType (com.google.security.zynamics.reil.OperandType)1 ReilOperand (com.google.security.zynamics.reil.ReilOperand)1 ReilOperandNode (com.google.security.zynamics.reil.ReilOperandNode)1 Triple (com.google.security.zynamics.zylib.general.Triple)1 ArrayList (java.util.ArrayList)1