From 716cbd78e9d4e2c7d47b3096ed8429b2f5f14852 Mon Sep 17 00:00:00 2001 From: Ryan Hileman Date: Sun, 18 Oct 2015 12:21:43 -0700 Subject: [PATCH] add MemUnmap to Go bindings --- bindings/go/unicorn/unicorn.go | 5 +++++ bindings/go/unicorn/unicorn_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 bindings/go/unicorn/unicorn_test.go diff --git a/bindings/go/unicorn/unicorn.go b/bindings/go/unicorn/unicorn.go index 1de2c95f..fc52284e 100644 --- a/bindings/go/unicorn/unicorn.go +++ b/bindings/go/unicorn/unicorn.go @@ -26,6 +26,7 @@ func errReturn(err C.uc_err) error { type Unicorn interface { MemMap(addr, size uint64) error MemMapProt(addr, size uint64, prot int) error + MemUnmap(addr, size uint64) error MemRead(addr, size uint64) ([]byte, error) MemReadInto(dst []byte, addr uint64) error MemWrite(addr uint64, data []byte) error @@ -111,3 +112,7 @@ func (u *uc) MemMapProt(addr, size uint64, prot int) error { func (u *uc) MemMap(addr, size uint64) error { return u.MemMapProt(addr, size, PROT_ALL) } + +func (u *uc) MemUnmap(addr, size uint64) error { + return errReturn(C.uc_mem_unmap(u.handle, C.uint64_t(addr), C.size_t(size))) +} diff --git a/bindings/go/unicorn/unicorn_test.go b/bindings/go/unicorn/unicorn_test.go new file mode 100644 index 00000000..72c43c77 --- /dev/null +++ b/bindings/go/unicorn/unicorn_test.go @@ -0,0 +1,26 @@ +package unicorn + +import ( + "fmt" + "testing" +) + +func TestMemUnmap(t *testing.T) { + mu, err := NewUnicorn(ARCH_X86, MODE_32) + if err != nil { + t.Fatal(err) + } + if err := mu.MemMap(0x1000, 0x1000); err != nil { + t.Fatal(err) + } + tmp := make([]byte, 1024) + if err := mu.MemWrite(0x1000, tmp); err != nil { + t.Fatal(err) + } + if err := mu.MemUnmap(0x1000, 0x1000); err != nil { + t.Fatal(err) + } + if err := mu.MemWrite(0x1000, tmp); err.(UcError) != ERR_WRITE_UNMAPPED { + t.Fatal(fmt.Errorf("Expected ERR_WRITE_UNMAPPED, got: %v", err)) + } +}