Added x86Msr functions for the go bindings (#986)

Backports commit d6d413187324e8d9dc852f62016863a44b240a7e from unicorn.
This commit is contained in:
Jonas 2019-03-08 02:28:19 -05:00 committed by Lioncash
parent 7cad644235
commit d27ad4df1b
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7
2 changed files with 18 additions and 0 deletions

View file

@ -60,6 +60,8 @@ type Unicorn interface {
ContextSave(reuse Context) (Context, error) ContextSave(reuse Context) (Context, error)
ContextRestore(Context) error ContextRestore(Context) error
Handle() *C.uc_engine Handle() *C.uc_engine
RegWriteX86Msr(reg uint64, val uint64) error
RegReadX86Msr(reg uint64) (uint64, error)
} }
type uc struct { type uc struct {

View file

@ -36,3 +36,19 @@ func (u *uc) RegReadMmr(reg int) (*X86Mmr, error) {
} }
return ret, errReturn(ucerr) return ret, errReturn(ucerr)
} }
func (u *uc) RegWriteX86Msr(reg uint64, val uint64) error {
msr := C.uc_x86_msr{
rid: C.uint32_t(reg),
value: C.uint64_t(val),
}
return errReturn(C.uc_reg_write(u.handle, X86_REG_MSR, unsafe.Pointer(&msr)))
}
func (u *uc) RegReadX86Msr(reg uint64) (uint64, error) {
msr := C.uc_x86_msr{
rid: C.uint32_t(reg),
}
ucerr := C.uc_reg_read(u.handle, X86_REG_MSR, unsafe.Pointer(&msr))
return uint64(msr.value), errReturn(ucerr)
}