Updated ruby bindings (#744)
* added methods for uc_context_save, uc_context_restore * added test for context_save * changed version of the lib
This commit is contained in:
committed by
Nguyen Anh Quynh
parent
89d536df5a
commit
eb4dc61c66
@@ -26,12 +26,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
VALUE UnicornModule = Qnil;
|
||||
VALUE UcClass = Qnil;
|
||||
VALUE UcError = Qnil;
|
||||
VALUE SavedContext = Qnil;
|
||||
|
||||
|
||||
void Init_unicorn() {
|
||||
rb_require("unicorn/unicorn_const");
|
||||
UnicornModule = rb_define_module("Unicorn");
|
||||
UcError = rb_define_class_under(UnicornModule, "UcError", rb_eStandardError);
|
||||
SavedContext = rb_define_class_under(UnicornModule, "SavedContext", rb_cObject);
|
||||
|
||||
UcClass = rb_define_class_under(UnicornModule, "Uc", rb_cObject);
|
||||
rb_define_method(UcClass, "initialize", m_uc_initialize, 2);
|
||||
@@ -47,6 +49,9 @@ void Init_unicorn() {
|
||||
rb_define_method(UcClass, "hook_add", m_uc_hook_add, -1);
|
||||
rb_define_method(UcClass, "hook_del", m_uc_hook_del, 1);
|
||||
rb_define_method(UcClass, "query", m_uc_hook_del, 1);
|
||||
rb_define_method(UcClass, "context_save", m_uc_context_save, 0);
|
||||
rb_define_method(UcClass, "context_update", m_uc_context_update, 1);
|
||||
rb_define_method(UcClass, "contest_restore", m_uc_context_restore, 1);
|
||||
}
|
||||
|
||||
VALUE m_uc_initialize(VALUE self, VALUE arch, VALUE mode) {
|
||||
@@ -422,3 +427,53 @@ VALUE m_uc_query(VALUE self, VALUE query_mode){
|
||||
}
|
||||
return INT2NUM(result);
|
||||
}
|
||||
|
||||
VALUE m_uc_context_save(VALUE self){
|
||||
uc_err err;
|
||||
uc_engine *_uc;
|
||||
Data_Get_Struct(rb_iv_get(self,"@uch"), uc_engine, _uc);
|
||||
|
||||
uc_context *_context;
|
||||
err = uc_context_alloc(_uc, &_context);
|
||||
if (err != UC_ERR_OK) {
|
||||
rb_raise(UcError, "%s", uc_strerror(err));
|
||||
}
|
||||
|
||||
err = uc_context_save(_uc, _context);
|
||||
if (err != UC_ERR_OK) {
|
||||
rb_raise(UcError, "%s", uc_strerror(err));
|
||||
}
|
||||
|
||||
VALUE sc = Data_Wrap_Struct(SavedContext, 0, uc_free, _context);
|
||||
return sc;
|
||||
}
|
||||
|
||||
VALUE m_uc_context_update(VALUE self, VALUE context){
|
||||
uc_err err;
|
||||
uc_engine *_uc;
|
||||
Data_Get_Struct(rb_iv_get(self,"@uch"), uc_engine, _uc);
|
||||
|
||||
uc_context *_context;
|
||||
Data_Get_Struct(context, uc_context, _context);
|
||||
|
||||
err = uc_context_save(_uc, _context);
|
||||
if (err != UC_ERR_OK) {
|
||||
rb_raise(UcError, "%s", uc_strerror(err));
|
||||
}
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
VALUE m_uc_context_restore(VALUE self, VALUE context){
|
||||
uc_err err;
|
||||
uc_engine *_uc;
|
||||
Data_Get_Struct(rb_iv_get(self,"@uch"), uc_engine, _uc);
|
||||
|
||||
uc_context *_context;
|
||||
Data_Get_Struct(context, uc_context, _context);
|
||||
|
||||
err = uc_context_restore(_uc, _context);
|
||||
if (err != UC_ERR_OK) {
|
||||
rb_raise(UcError, "%s", uc_strerror(err));
|
||||
}
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
@@ -30,4 +30,7 @@ VALUE m_uc_mem_unmap(VALUE self, VALUE address, VALUE size);
|
||||
VALUE m_uc_mem_protect(VALUE self, VALUE address, VALUE size, VALUE perms);
|
||||
VALUE m_uc_hook_add(int argc, VALUE* argv, VALUE self);
|
||||
VALUE m_uc_hook_del(VALUE self, VALUE hook);
|
||||
VALUE m_uc_query(VALUE self, VALUE query_mode);
|
||||
VALUE m_uc_query(VALUE self, VALUE query_mode);
|
||||
VALUE m_uc_context_save(VALUE self);
|
||||
VALUE m_uc_context_update(VALUE self, VALUE context);
|
||||
VALUE m_uc_context_restore(VALUE self, VALUE context);
|
||||
|
||||
Reference in New Issue
Block a user