Merge pull request #203 from lunixbochs/master
add MemUnmap to Go bindings
This commit is contained in:
commit
1ee7544d84
@ -26,6 +26,7 @@ func errReturn(err C.uc_err) error {
|
|||||||
type Unicorn interface {
|
type Unicorn interface {
|
||||||
MemMap(addr, size uint64) error
|
MemMap(addr, size uint64) error
|
||||||
MemMapProt(addr, size uint64, prot int) error
|
MemMapProt(addr, size uint64, prot int) error
|
||||||
|
MemUnmap(addr, size uint64) error
|
||||||
MemRead(addr, size uint64) ([]byte, error)
|
MemRead(addr, size uint64) ([]byte, error)
|
||||||
MemReadInto(dst []byte, addr uint64) error
|
MemReadInto(dst []byte, addr uint64) error
|
||||||
MemWrite(addr uint64, data []byte) 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 {
|
func (u *uc) MemMap(addr, size uint64) error {
|
||||||
return u.MemMapProt(addr, size, PROT_ALL)
|
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)))
|
||||||
|
}
|
||||||
|
26
bindings/go/unicorn/unicorn_test.go
Normal file
26
bindings/go/unicorn/unicorn_test.go
Normal 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))
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user