verify hardware mode for ARM. this fixes issue #16

This commit is contained in:
Nguyen Anh Quynh 2015-08-24 09:50:55 +08:00
parent cd072b4e20
commit bb34eebd24
2 changed files with 25 additions and 4 deletions

21
regress/wrong_sp_arm.py Normal file → Executable file
View file

@ -3,7 +3,20 @@
from unicorn import *
from unicorn.arm_const import *
uc = Uc(UC_ARCH_ARM, UC_MODE_32)
uc.reg_write(ARM_REG_SP, 4)
print 'Writing 4 to SP'
print 'SP =', uc.reg_read(ARM_REG_SP)
try:
uc = Uc(UC_ARCH_ARM, UC_MODE_32)
uc.reg_write(ARM_REG_SP, 4)
print 'Writing 4 to SP'
print 'SP =', uc.reg_read(ARM_REG_SP)
except UcError as e:
print("ERROR: %s" % e)
try:
print "==========="
uc = Uc(UC_ARCH_ARM, UC_MODE_ARM)
uc.reg_write(ARM_REG_SP, 4)
print 'Writing 4 to SP'
print 'SP =', uc.reg_read(ARM_REG_SP)
except UcError as e:
print("ERROR: %s" % e)

8
uc.c
View file

@ -177,6 +177,14 @@ uc_err uc_open(uc_arch arch, uc_mode mode, uch *handle)
#ifdef UNICORN_HAS_ARM
case UC_ARCH_ARM:
uc->init_arch = arm_uc_init;
// verify mode
if (mode != UC_MODE_ARM && mode != UC_MODE_THUMB) {
*handle = 0;
free(uc);
return UC_ERR_MODE;
}
if (mode == UC_MODE_THUMB)
uc->thumb = 1;
break;