本文整理汇总了Golang中github.com/lunixbochs/usercorn/go/models.Usercorn.Mmap方法的典型用法代码示例。如果您正苦于以下问题:Golang Usercorn.Mmap方法的具体用法?Golang Usercorn.Mmap怎么用?Golang Usercorn.Mmap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/lunixbochs/usercorn/go/models.Usercorn
的用法示例。
在下文中一共展示了Usercorn.Mmap方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: CgcSyscall
func CgcSyscall(u models.Usercorn) {
// TODO: handle errors or something
args, _ := u.ReadRegs(LinuxRegs)
eax, _ := u.RegRead(uc.X86_REG_EAX)
var ret uint64
switch eax {
case 1: // _terminate
syscall.Exit(int(args[0]))
case 2: // transmit
mem, _ := u.MemRead(args[1], args[2])
n, _ := syscall.Write(int(args[0]), mem)
writeAddr(u, args[3], uint64(n))
case 3: // receive
tmp := make([]byte, args[2])
n, _ := syscall.Read(int(args[0]), tmp)
u.MemWrite(args[1], tmp[:n])
writeAddr(u, args[3], uint64(n))
case 5: // allocate
addr, _ := u.Mmap(0, args[0])
// args[1] == is executable
writeAddr(u, args[2], addr)
case 6: // fdwait
nfds := int(args[0])
var readSet, writeSet *fdset32
var timeout posix.Timespec
u.StrucAt(args[1]).Unpack(&readSet)
u.StrucAt(args[2]).Unpack(&writeSet)
u.StrucAt(args[3]).Unpack(&timeout)
readyFds := args[4]
readNative := readSet.Native()
writeNative := writeSet.Native()
n, err := cgcNativeSelect(nfds, readNative, writeNative, &timeout)
if err != nil {
ret = UINT32_MAX // FIXME?
} else {
numReady := int32(n)
if readyFds != 0 {
u.StrucAt(readyFds).Pack(numReady)
}
}
case 7: // random
tmp := make([]byte, args[1])
rand.Read(tmp)
u.MemWrite(args[0], tmp)
writeAddr(u, args[2], args[1])
}
u.RegWrite(uc.X86_REG_EAX, ret)
}
示例2: enterUsermode
func enterUsermode(u models.Usercorn) error {
// move CPU from System to User mode
modeSwitch := []byte{
0x00, 0x00, 0x0f, 0xe1, // mrs r0, cpsr
0x1f, 0x00, 0xc0, 0xe3, // bic r0, r0, $0x1f
0x10, 0x00, 0x80, 0xe3, // orr r0, r0, $0x10
0x00, 0xf0, 0x21, 0xe1, // msr cpsr_c, r0
}
mmap, err := u.Mmap(0, uint64(len(modeSwitch)))
if err != nil {
return err
}
defer u.MemUnmap(mmap.Addr, mmap.Size)
end := mmap.Addr + uint64(len(modeSwitch))
err = u.RunShellcodeMapped(mmap, modeSwitch,
map[int]uint64{uc.ARM_REG_LR: end},
[]int{uc.ARM_REG_R0, uc.ARM_REG_LR, uc.ARM_REG_SP},
)
return err
}