Go: add uc_query api

This commit is contained in:
Ryan Hileman 2016-02-27 11:15:06 -08:00
parent 9f1603c157
commit 43eb9ec351
2 changed files with 21 additions and 0 deletions

View file

@ -48,6 +48,7 @@ type Unicorn interface {
Stop() error Stop() error
HookAdd(htype int, cb interface{}, begin, end uint64, extra ...int) (Hook, error) HookAdd(htype int, cb interface{}, begin, end uint64, extra ...int) (Hook, error)
HookDel(hook Hook) error HookDel(hook Hook) error
Query(queryType int) (uint64, error)
Close() error Close() error
} }
@ -167,3 +168,9 @@ func (u *uc) MemProtect(addr, size uint64, prot int) error {
func (u *uc) MemUnmap(addr, size uint64) error { func (u *uc) MemUnmap(addr, size uint64) error {
return errReturn(C.uc_mem_unmap(u.handle, C.uint64_t(addr), C.size_t(size))) return errReturn(C.uc_mem_unmap(u.handle, C.uint64_t(addr), C.size_t(size)))
} }
func (u *uc) Query(queryType int) (uint64, error) {
var ret C.size_t
ucerr := C.uc_query(u.handle, C.uc_query_type(queryType), &ret)
return uint64(ret), errReturn(ucerr)
}

View file

@ -59,3 +59,17 @@ func TestMemRegions(t *testing.T) {
t.Fatalf("incorrect region: %#v", r) t.Fatalf("incorrect region: %#v", r)
} }
} }
func TestQuery(t *testing.T) {
mu, err := NewUnicorn(ARCH_ARM, MODE_THUMB)
if err != nil {
t.Fatal(err)
}
mode, err := mu.Query(QUERY_MODE)
if err != nil {
t.Fatal(err)
}
if mode != MODE_THUMB {
t.Fatal("query returned invalid mode: %d != %d", mode, MODE_THUMB)
}
}