mirror of
https://github.com/yuzu-emu/unicorn
synced 2024-11-24 16:48:30 +00:00
add MemUnmap to Go bindings
This commit is contained in:
parent
e45d225d69
commit
716cbd78e9
2 changed files with 31 additions and 0 deletions
|
@ -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)))
|
||||
}
|
||||
|
|
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 a new issue