Fix ARMv7's ADD (#769)

* Fix armv7's ADD
This commit is contained in:
Yan Ivnitskiy 2018-02-23 18:07:49 -05:00 committed by GitHub
parent b9aa483745
commit 394401e3f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 2 deletions

View File

@ -85,7 +85,7 @@ class Armv7Operand(Operand):
# PC in this case has to be set to the instruction after next. PC at this point
# is already pointing to next instruction; we bump it one more.
if self.reg in ('PC', 'R15'):
value += cpu.instruction.size
value += self.cpu.instruction.size
if self.is_shifted():
shift = self.op.shift
value, carry = self.cpu._shift(value, shift.type, shift.value, carry)
@ -355,11 +355,11 @@ class Armv7Cpu(Cpu):
return state
def __setstate__(self, state):
super(Armv7Cpu, self).__setstate__(state)
self._last_flags = state['_last_flags']
self._at_symbolic_conditional = state['at_symbolic_conditional']
self._it_conditional = state['_it_conditional']
self._mode = state['_mode']
super(Armv7Cpu, self).__setstate__(state)
@property
def mode(self):

BIN
tests/binaries/basic_linux_armv7 Executable file

Binary file not shown.

View File

@ -1654,3 +1654,15 @@ class Armv7CpuInstructions(unittest.TestCase):
# the cpu lives in self.cpu
e.setstate(self, CS_MODE_THUMB)
self.assertEqual(self.cpu.mode, CS_MODE_THUMB)
@itest_setregs("R1=0x00000008") # pc/r15 is set to 0x1004 in _setupCpu()
@itest("add pc, pc, r1")
def test_add_to_pc(self):
self.assertEqual(self.rf.read('R15'), 0x1014)
# Make sure a cpu will survive a round trip through pickling/unpickling
def test_arm_save_restore_cpu(self):
import pickle
dumped_s = pickle.dumps(self.cpu)
self.cpu = pickle.loads(dumped_s)

View File

@ -141,6 +141,17 @@ class IntegrationTest(unittest.TestCase):
self._simple_cli_run('705.sol')
os.chdir(old_cwd)
def test_basic_arm(self):
dirname = os.path.dirname(__file__)
filename = os.path.abspath(os.path.join(dirname, 'binaries/basic_linux_armv7'))
workspace = '%s/workspace' % self.test_dir
output = subprocess.check_output(['python', '-m', 'manticore', '--workspace', workspace, filename])
with open(os.path.join(workspace, "test_00000000.stdout")) as f:
self.assertIn("Message", f.read())
with open(os.path.join(workspace, "test_00000001.stdout")) as f:
self.assertIn("Message", f.read())
if __name__ == '__main__':
unittest.main()