From d27ad4df1b0acae12acd4eb97da128d8cf2b9fac Mon Sep 17 00:00:00 2001 From: Jonas Date: Fri, 8 Mar 2019 02:28:19 -0500 Subject: [PATCH] Added x86Msr functions for the go bindings (#986) Backports commit d6d413187324e8d9dc852f62016863a44b240a7e from unicorn. --- bindings/go/unicorn/unicorn.go | 2 ++ bindings/go/unicorn/x86.go | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/bindings/go/unicorn/unicorn.go b/bindings/go/unicorn/unicorn.go index 28bd467f..5c20ab69 100644 --- a/bindings/go/unicorn/unicorn.go +++ b/bindings/go/unicorn/unicorn.go @@ -60,6 +60,8 @@ type Unicorn interface { ContextSave(reuse Context) (Context, error) ContextRestore(Context) error Handle() *C.uc_engine + RegWriteX86Msr(reg uint64, val uint64) error + RegReadX86Msr(reg uint64) (uint64, error) } type uc struct { diff --git a/bindings/go/unicorn/x86.go b/bindings/go/unicorn/x86.go index 9097de2a..7ffa25d2 100644 --- a/bindings/go/unicorn/x86.go +++ b/bindings/go/unicorn/x86.go @@ -36,3 +36,19 @@ func (u *uc) RegReadMmr(reg int) (*X86Mmr, error) { } 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) +}