Go: add RegReadMmr and test
This commit is contained in:
parent
5ede98abec
commit
4f1c88e70c
|
@ -42,6 +42,7 @@ type Unicorn interface {
|
|||
MemWrite(addr uint64, data []byte) error
|
||||
RegRead(reg int) (uint64, error)
|
||||
RegWrite(reg int, value uint64) error
|
||||
RegReadMmr(reg int) (*X86Mmr, error)
|
||||
RegWriteMmr(reg int, value *X86Mmr) error
|
||||
Start(begin, until uint64) error
|
||||
StartWithOptions(begin, until uint64, options *UcOptions) error
|
||||
|
|
|
@ -24,3 +24,15 @@ func (u *uc) RegWriteMmr(reg int, value *X86Mmr) error {
|
|||
ucerr := C.uc_reg_write(u.handle, C.int(reg), unsafe.Pointer(&val))
|
||||
return errReturn(ucerr)
|
||||
}
|
||||
|
||||
func (u *uc) RegReadMmr(reg int) (*X86Mmr, error) {
|
||||
var val C.uc_x86_mmr
|
||||
ucerr := C.uc_reg_read(u.handle, C.int(reg), unsafe.Pointer(&val))
|
||||
ret := &X86Mmr{
|
||||
Selector: uint16(val.selector),
|
||||
Base: uint64(val.base),
|
||||
Limit: uint32(val.limit),
|
||||
Flags: uint32(val.flags),
|
||||
}
|
||||
return ret, errReturn(ucerr)
|
||||
}
|
||||
|
|
|
@ -143,3 +143,18 @@ func TestX86Syscall(t *testing.T) {
|
|||
t.Fatal("Incorrect syscall return value.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestX86Mmr(t *testing.T) {
|
||||
mu, err := MakeUc(MODE_64, "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = mu.RegWriteMmr(X86_REG_GDTR, &X86Mmr{Selector: 0, Base: 0x1000, Limit: 0x1fff, Flags: 0})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mmr, err := mu.RegReadMmr(X86_REG_GDTR)
|
||||
if mmr.Selector != 0 || mmr.Base != 0x1000 || mmr.Limit != 0x1fff || mmr.Flags != 0 {
|
||||
t.Fatalf("mmr read failed: %#v", mmr)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue