use of com.google.security.zynamics.reil.ReilInstruction in project binnavi by google.
the class BsfTranslatorTest method testInputZero.
@Test
public void testInputZero() throws InternalTranslationException, InterpreterException {
interpreter.setRegister("eax", BigInteger.valueOf(0xFFFFFFFFL), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
interpreter.setRegister("ebx", BigInteger.valueOf(0x00000000L), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
final MockOperandTree operandTree1 = new MockOperandTree();
operandTree1.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
operandTree1.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "eax"));
final MockOperandTree operandTree2 = new MockOperandTree();
operandTree2.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
operandTree2.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "ebx"));
final List<MockOperandTree> operands = Lists.newArrayList(operandTree1, operandTree2);
final IInstruction instruction = new MockInstruction("bsf", operands);
translator.translate(environment, instruction, instructions);
for (final ReilInstruction mockOperandTree : instructions) {
System.out.println(mockOperandTree);
}
interpreter.interpret(TestHelpers.createMapping(instructions), BigInteger.valueOf(0x100));
assertEquals(3, TestHelpers.filterNativeRegisters(interpreter.getDefinedRegisters()).size());
assertEquals(BigInteger.valueOf(0x00000000L), interpreter.getVariableValue("ebx"));
assertEquals(BigInteger.valueOf(0x00000001L), interpreter.getVariableValue("ZF"));
assertEquals(BigInteger.ZERO, BigInteger.valueOf(interpreter.getMemorySize()));
}
use of com.google.security.zynamics.reil.ReilInstruction in project binnavi by google.
the class BsfTranslatorTest method testLast.
@Test
public void testLast() throws InternalTranslationException, InterpreterException {
interpreter.setRegister("eax", BigInteger.valueOf(0xFFFFFFFFL), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
interpreter.setRegister("ebx", BigInteger.valueOf(0x80000000L), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
final MockOperandTree operandTree1 = new MockOperandTree();
operandTree1.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
operandTree1.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "eax"));
final MockOperandTree operandTree2 = new MockOperandTree();
operandTree2.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
operandTree2.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "ebx"));
final List<MockOperandTree> operands = Lists.newArrayList(operandTree1, operandTree2);
final IInstruction instruction = new MockInstruction("bsf", operands);
translator.translate(environment, instruction, instructions);
for (final ReilInstruction mockOperandTree : instructions) {
System.out.println(mockOperandTree);
}
interpreter.interpret(TestHelpers.createMapping(instructions), BigInteger.valueOf(0x100));
assertEquals(4, TestHelpers.filterNativeRegisters(interpreter.getDefinedRegisters()).size());
assertEquals(BigInteger.valueOf(31), interpreter.getVariableValue("eax"));
assertEquals(BigInteger.valueOf(0x80000000L), interpreter.getVariableValue("ebx"));
assertEquals(BigInteger.ZERO, BigInteger.valueOf(interpreter.getMemorySize()));
}
use of com.google.security.zynamics.reil.ReilInstruction in project binnavi by google.
the class BsrTranslatorTest method testFirst.
@Test
public void testFirst() throws InternalTranslationException, InterpreterException {
interpreter.setRegister("eax", BigInteger.valueOf(0xFFFFFFFFL), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
interpreter.setRegister("ebx", BigInteger.valueOf(0x80000000L), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
final MockOperandTree operandTree1 = new MockOperandTree();
operandTree1.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
operandTree1.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "eax"));
final MockOperandTree operandTree2 = new MockOperandTree();
operandTree2.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
operandTree2.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "ebx"));
final List<MockOperandTree> operands = Lists.newArrayList(operandTree1, operandTree2);
final IInstruction instruction = new MockInstruction("bsr", operands);
translator.translate(environment, instruction, instructions);
for (final ReilInstruction mockOperandTree : instructions) {
System.out.println(mockOperandTree);
}
interpreter.interpret(TestHelpers.createMapping(instructions), BigInteger.valueOf(0x100));
assertEquals(4, TestHelpers.filterNativeRegisters(interpreter.getDefinedRegisters()).size());
assertEquals(BigInteger.valueOf(31), interpreter.getVariableValue("eax"));
assertEquals(BigInteger.valueOf(0x80000000L), interpreter.getVariableValue("ebx"));
assertEquals(BigInteger.ZERO, BigInteger.valueOf(interpreter.getMemorySize()));
}
use of com.google.security.zynamics.reil.ReilInstruction in project binnavi by google.
the class LoopeTranslatorTest method testSimple.
@Test
public void testSimple() throws InternalTranslationException, InterpreterException {
interpreter.setRegister("eax", BigInteger.valueOf(3), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
interpreter.setRegister("ecx", BigInteger.valueOf(5), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
final MockOperandTree operandTree1 = new MockOperandTree();
operandTree1.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
operandTree1.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "eax"));
final List<MockOperandTree> operands = Lists.newArrayList(operandTree1);
final IInstruction instruction = new MockInstruction("dec", operands);
final ArrayList<ReilInstruction> instructionsDec = new ArrayList<ReilInstruction>();
decTranslator.translate(environment, instruction, instructionsDec);
final MockOperandTree operandTree2 = new MockOperandTree();
operandTree2.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
operandTree2.root.m_children.add(new MockOperandTreeNode(ExpressionType.IMMEDIATE_INTEGER, "256"));
final MockInstruction instruction2 = new MockInstruction("loope", Lists.newArrayList(operandTree2));
instruction2.address = new CAddress(0x101);
translator.translate(environment, instruction2, instructions);
final HashMap<BigInteger, List<ReilInstruction>> mapping = new HashMap<BigInteger, List<ReilInstruction>>();
mapping.put(BigInteger.valueOf(instructions.get(0).getAddress().toLong()), instructions);
mapping.put(BigInteger.valueOf(instructionsDec.get(0).getAddress().toLong()), instructionsDec);
interpreter.interpret(mapping, BigInteger.valueOf(0x100));
assertEquals(6, TestHelpers.filterNativeRegisters(interpreter.getDefinedRegisters()).size());
assertEquals(BigInteger.valueOf(2), interpreter.getVariableValue("eax"));
assertEquals(BigInteger.valueOf(4), interpreter.getVariableValue("ecx"));
assertEquals(BigInteger.ZERO, interpreter.getVariableValue("ZF"));
assertEquals(BigInteger.ZERO, interpreter.getVariableValue("SF"));
assertEquals(BigInteger.ZERO, interpreter.getVariableValue("OF"));
assertEquals(BigInteger.ZERO, BigInteger.valueOf(interpreter.getMemorySize()));
}
use of com.google.security.zynamics.reil.ReilInstruction in project binnavi by google.
the class ShldTranslatorTest method testOne.
@Test
public void testOne() throws InternalTranslationException, InterpreterException {
interpreter.setRegister("eax", BigInteger.valueOf(0x80000000L), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
interpreter.setRegister("ebx", BigInteger.valueOf(0x80000000L), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
final MockOperandTree operandTree1 = new MockOperandTree();
operandTree1.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
operandTree1.root.m_children.add(new MockOperandTreeNode(ExpressionType.IMMEDIATE_INTEGER, "eax"));
final MockOperandTree operandTree2 = new MockOperandTree();
operandTree2.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
operandTree2.root.m_children.add(new MockOperandTreeNode(ExpressionType.IMMEDIATE_INTEGER, "ebx"));
final MockOperandTree operandTree3 = new MockOperandTree();
operandTree3.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
operandTree3.root.m_children.add(new MockOperandTreeNode(ExpressionType.IMMEDIATE_INTEGER, "1"));
final List<MockOperandTree> operands = Lists.newArrayList(operandTree1, operandTree2, operandTree3);
final IInstruction instruction = new MockInstruction("shld", operands);
translator.translate(environment, instruction, instructions);
interpreter.interpret(TestHelpers.createMapping(instructions), BigInteger.valueOf(0x100));
long counter = 0x10000;
for (final ReilInstruction inst : instructions) {
assertEquals(counter, inst.getAddress().toLong());
counter++;
}
assertEquals(7, TestHelpers.filterNativeRegisters(interpreter.getDefinedRegisters()).size());
assertEquals(BigInteger.valueOf(1L), interpreter.getVariableValue("eax"));
assertEquals(BigInteger.valueOf(0x80000000L), interpreter.getVariableValue("ebx"));
assertEquals(BigInteger.valueOf(0L), interpreter.getVariableValue(Helpers.ZERO_FLAG));
assertEquals(BigInteger.valueOf(1L), interpreter.getVariableValue(Helpers.OVERFLOW_FLAG));
assertEquals(BigInteger.valueOf(1L), interpreter.getVariableValue(Helpers.CARRY_FLAG));
assertEquals(BigInteger.valueOf(0L), interpreter.getVariableValue(Helpers.SIGN_FLAG));
assertEquals(BigInteger.ZERO, BigInteger.valueOf(interpreter.getMemorySize()));
}
Aggregations