Rename save/restore functions to match the style of the rest of the API

This commit is contained in:
Andrew Dutcher 2016-09-26 14:38:32 -07:00
parent 20ce432dbc
commit e3b0e52013
5 changed files with 19 additions and 19 deletions

View file

@ -329,7 +329,7 @@ def test_i386_reg_save():
mu.emu_start(address, address+1)
print(">>> save the register state")
saved_regs = mu.save_regs()
saved_regs = mu.regstate_save()
print(">>> execute 'inc eax'")
mu.emu_start(address, address+1)
@ -338,7 +338,7 @@ def test_i386_reg_save():
assert mu.reg_read(UC_X86_REG_EAX) == 3
print(">>> restore the register state")
mu.restore_regs(saved_regs)
mu.regstate_restore(saved_regs)
print(">>> assert eax == 2")
assert mu.reg_read(UC_X86_REG_EAX) == 2
@ -350,7 +350,7 @@ def test_i386_reg_save():
assert mu.reg_read(UC_X86_REG_EAX) == 3
print(">>> restore the register state")
mu.restore_regs(saved_regs)
mu.regstate_restore(saved_regs)
print(">>> assert eax == 2")
assert mu.reg_read(UC_X86_REG_EAX) == 2

View file

@ -127,8 +127,8 @@ _setup_prototype(_uc, "uc_mem_map_ptr", ucerr, uc_engine, ctypes.c_uint64, ctype
_setup_prototype(_uc, "uc_mem_unmap", ucerr, uc_engine, ctypes.c_uint64, ctypes.c_size_t)
_setup_prototype(_uc, "uc_mem_protect", ucerr, uc_engine, ctypes.c_uint64, ctypes.c_size_t, ctypes.c_uint32)
_setup_prototype(_uc, "uc_query", ucerr, uc_engine, ctypes.c_uint32, ctypes.POINTER(ctypes.c_size_t))
_setup_prototype(_uc, "uc_save_regstate", ctypes.c_voidp, uc_engine, ctypes.c_voidp)
_setup_prototype(_uc, "uc_restore_regstate", None, uc_engine, ctypes.c_voidp)
_setup_prototype(_uc, "uc_regstate_save", ctypes.c_voidp, uc_engine, ctypes.c_voidp)
_setup_prototype(_uc, "uc_regstate_restore", None, uc_engine, ctypes.c_voidp)
_setup_prototype(_uc, "free", None, ctypes.c_voidp)
# uc_hook_add is special due to variable number of arguments
@ -452,20 +452,20 @@ class Uc(object):
raise UcError(status)
h = 0
def save_regs(self, store=None):
def regstate_save(self, store=None):
if store is None:
ptr = ctypes.cast(0, ctypes.c_voidp)
return _ActivePointer(_uc.uc_save_regstate(self._uch, ptr))
return _ActivePointer(_uc.uc_regstate_save(self._uch, ptr))
elif type(store) is _ActivePointer:
_uc.uc_save_regstate(self._uch, store.pointer)
_uc.uc_regstate_save(self._uch, store.pointer)
return store
else:
raise TypeError("Bad register store %s" % repr(store))
def restore_regs(self, store):
def regstate_restore(self, store):
if type(store) is not _ActivePointer:
raise TYpeError("Bad register store %s" % repr(store))
_uc.uc_restore_regstate(self._uch, store.pointer)
_uc.uc_regstate_restore(self._uch, store.pointer)
class _ActivePointer(object):
def __init__(self, pointer):

View file

@ -640,18 +640,18 @@ uc_err uc_mem_regions(uc_engine *uc, uc_mem_region **regions, uint32_t *count);
Any allocation performed by this function must be freed by the user.
*/
UNICORN_EXPORT
void *uc_save_regstate(uc_engine *uc, void *buffer);
void *uc_regstate_save(uc_engine *uc, void *buffer);
/*
Restore the current state's registers from a saved copy
This API should be used to roll the CPU register state back to a previous
state saved by uc_save_regstate().
state saved by uc_regstate_save().
@uc: handle returned by uc_open()
@buffer: pointer returned by uc_save_regstate()
@buffer: pointer returned by uc_regstate_save()
*/
UNICORN_EXPORT
void uc_restore_regstate(uc_engine *uc, void *buffer);
void uc_regstate_restore(uc_engine *uc, void *buffer);
#ifdef __cplusplus
}

View file

@ -755,7 +755,7 @@ static void test_i386_reg_save(void **state)
uc_assert_success(uc_emu_start(uc, address, address+1, 0, 0));
// save the state
void *saved_regs = uc_save_regstate(uc, NULL);
void *saved_regs = uc_regstate_save(uc, NULL);
// step one instruction
uc_assert_success(uc_emu_start(uc, address, address+1, 0, 0));
@ -765,7 +765,7 @@ static void test_i386_reg_save(void **state)
assert_int_equal(eax, 3);
// restore the state
uc_restore_regstate(uc, saved_regs);
uc_regstate_restore(uc, saved_regs);
// check that eax == 2
uc_assert_success(uc_reg_read(uc, UC_X86_REG_EAX, &eax));
@ -779,7 +779,7 @@ static void test_i386_reg_save(void **state)
assert_int_equal(eax, 3);
// restore the state
uc_restore_regstate(uc, saved_regs);
uc_regstate_restore(uc, saved_regs);
// check that eax == 2
uc_assert_success(uc_reg_read(uc, UC_X86_REG_EAX, &eax));

4
uc.c
View file

@ -1179,7 +1179,7 @@ size_t cpu_regs_size(uc_arch arch, uc_mode mode)
}
UNICORN_EXPORT
void *uc_save_regstate(uc_engine *uc, void *buffer)
void *uc_regstate_save(uc_engine *uc, void *buffer)
{
size_t sz = cpu_regs_size(uc->arch, uc->mode);
if (!buffer) {
@ -1191,7 +1191,7 @@ void *uc_save_regstate(uc_engine *uc, void *buffer)
}
UNICORN_EXPORT
void uc_restore_regstate(uc_engine *uc, void *buffer)
void uc_regstate_restore(uc_engine *uc, void *buffer)
{
size_t sz = cpu_regs_size(uc->arch, uc->mode);
memcpy(first_cpu->env_ptr, buffer, sz);