use of com.google.security.zynamics.reil.translators.TranslationResultType in project binnavi by google.
the class SetccTranslator method translate.
/**
* Translates a SETcc instruction to REIL code.
*
* @param environment A valid translation environment.
* @param instruction The SETcc instruction to translate.
* @param instructions The generated REIL code will be added to this list
*
* @throws InternalTranslationException if any of the arguments are null the passed instruction is
* not a conditional set instruction
*/
@Override
public void translate(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) throws InternalTranslationException {
Preconditions.checkNotNull(environment, "Error: Argument environment can't be null");
Preconditions.checkNotNull(instruction, "Error: Argument instruction can't be null");
Preconditions.checkNotNull(instructions, "Error: Argument instructions can't be null");
if (instruction.getOperands().size() != 1) {
throw new InternalTranslationException("Error: Argument instruction is not a conditional setcc instruction (invalid number of operands)");
}
final long reilOffsetBase = instruction.getAddress().toLong() * 0x100;
long reilOffset = reilOffsetBase;
// SETCC instructions have exactly one operand.
final IOperandTree operand = instruction.getOperands().get(0);
// Load the operand.
final TranslationResult result = Helpers.translateOperand(environment, reilOffset, operand, false);
final OperandSize size = result.getSize();
final TranslationResultType type = result.getType();
final String address = result.getAddress();
instructions.addAll(result.getInstructions());
// Adjust the offset of the next REIL instruction.
reilOffset = reilOffsetBase + instructions.size();
final Pair<OperandSize, String> condition = conditionGenerator.generate(environment, reilOffset, instructions);
reilOffset = reilOffsetBase + instructions.size();
final String conditionRegister = condition.second();
Helpers.writeBack(environment, reilOffset, operand, conditionRegister, size, address, type, instructions);
}
use of com.google.security.zynamics.reil.translators.TranslationResultType in project binnavi by google.
the class Helpers method processLeafNode.
private static TranslationResult processLeafNode(final ITranslationEnvironment environment, final long baseOffset, final IOperandTreeNode expression, OperandSize size, boolean loadOperand) throws InternalTranslationException {
// All leaves are either registers or integer literals. They are translated
// into "STR leaf, , nextVariable" instructions. Optimizations are handled
// during the translation of their parent nodes.
// Get the type of the leaf.
final String value = expression.getValue();
final OperandType operandType = OperandType.getOperandType(value);
TranslationResultType nodeType = null;
switch(operandType) {
case REGISTER:
nodeType = TranslationResultType.REGISTER;
break;
case INTEGER_LITERAL:
nodeType = TranslationResultType.LITERAL;
break;
default:
throw new InternalTranslationException("Error: Leaf has invalid type");
}
final List<ReilInstruction> instructions = new ArrayList<>();
final String nextVariableString = environment.getNextVariableString();
if ((operandType == OperandType.INTEGER_LITERAL) || !needsExtraction(environment, value)) {
if (loadOperand) {
instructions.add(ReilHelpers.createStr(baseOffset, size, value, size, nextVariableString));
return new TranslationResult(nextVariableString, size, nodeType, null, instructions, baseOffset);
} else {
// str t3, --, ebx
return new TranslationResult(value, size, nodeType, null, instructions, baseOffset);
}
} else {
// Mask smaller operands
return extractRegister(environment, baseOffset, value);
}
}
use of com.google.security.zynamics.reil.translators.TranslationResultType in project binnavi by google.
the class PopTranslator method translate.
/**
* Translates a POP instruction to REIL code.
*
* @param environment A valid translation environment.
* @param instruction The PUSH instruction to translate.
* @param instructions The generated REIL code will be added to this list
*
* @throws InternalTranslationException if any of the arguments are null the passed instruction is
* not an POP instruction
*/
@Override
public void translate(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) throws InternalTranslationException {
if (instruction.getOperands().size() != 1) {
throw new InternalTranslationException("Error: Argument instruction is not a pop instruction (invalid number of operands)");
}
final long baseOffset = instruction.getAddress().toLong() * 0x100;
long offset = baseOffset;
// POP instructions have exactly one operand
final IOperandTree operand = instruction.getOperands().get(0);
// Load the operand
final TranslationResult result = Helpers.translateOperand(environment, offset, operand, false);
final TranslationResultType resultType = result.getType();
final OperandSize resultSize = result.getSize();
instructions.addAll(result.getInstructions());
// Adjust the offset of the next REIL instruction
offset = baseOffset + instructions.size();
// Load the value from the stack
final String popResult = Helpers.generatePop(environment, offset, resultSize, null, instructions);
// Adjust the offset of the next REIL instruction
offset = baseOffset + instructions.size();
// Write the loaded value into the target register
Helpers.writeBack(environment, offset, operand, popResult, resultSize, result.getAddress(), resultType, instructions);
}
Aggregations