Merge pull request #203 from lunixbochs/master

add MemUnmap to Go bindings
This commit is contained in:
Nguyen Anh Quynh 2015-10-19 08:26:17 +08:00
commit 1ee7544d84
2 changed files with 31 additions and 0 deletions

View File

@ -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)))
}

View File

@ -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))
}
}