當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Usercorn.Bits方法代碼示例

本文整理匯總了Golang中github.com/lunixbochs/usercorn/go/models.Usercorn.Bits方法的典型用法代碼示例。如果您正苦於以下問題:Golang Usercorn.Bits方法的具體用法?Golang Usercorn.Bits怎麽用?Golang Usercorn.Bits使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/lunixbochs/usercorn/go/models.Usercorn的用法示例。


在下文中一共展示了Usercorn.Bits方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: StackArgs

func StackArgs(u models.Usercorn) func(n int) ([]uint64, error) {
	return func(n int) ([]uint64, error) {
		sp, _ := u.RegRead(u.Arch().SP)
		// starts with an empty slot
		s := u.StrucAt(sp + uint64(u.Bits()/8))

		ret := make([]uint64, n)
		for i := 0; i < n; i++ {
			var arg uint64
			var err error
			// TODO: simplify this when struc issue #47 is fixed
			if u.Bits() == 64 {
				err = s.Unpack(&arg)
			} else {
				var arg32 uint32
				err = s.Unpack(&arg32)
				arg = uint64(arg32)
			}
			if err != nil {
				return nil, err
			}
			ret[i] = arg
		}
		return ret, nil
	}
}
開發者ID:lunixbochs,項目名稱:usercorn,代碼行數:26,代碼來源:args.go

示例2: setupElfAuxv

func setupElfAuxv(u models.Usercorn) ([]Elf64Auxv, error) {
	// set up AT_RANDOM
	var tmp [16]byte
	if _, err := rand.Read(tmp[:]); err != nil {
		return nil, err
	}
	randAddr, err := u.PushBytes(tmp[:])
	if err != nil {
		return nil, err
	}
	// insert platform string
	platformAddr, err := u.PushBytes([]byte(u.Loader().Arch() + "\x00"))
	if err != nil {
		return nil, err
	}
	// main auxv table
	auxv := []Elf64Auxv{
		// TODO: set/track a page size somewhere - on Arch.OS?
		{ELF_AT_PAGESZ, 4096},
		{ELF_AT_BASE, u.InterpBase()},
		{ELF_AT_FLAGS, 0},
		{ELF_AT_ENTRY, uint64(u.BinEntry())},
		{ELF_AT_UID, uint64(os.Getuid())},
		{ELF_AT_EUID, uint64(os.Geteuid())},
		{ELF_AT_GID, uint64(os.Getgid())},
		{ELF_AT_EGID, uint64(os.Getegid())},
		{ELF_AT_PLATFORM, platformAddr},
		{ELF_AT_CLKTCK, 100}, // 100hz, totally fake
		{ELF_AT_RANDOM, randAddr},
		{ELF_AT_NULL, 0},
	}
	// add phdr information if present in binary
	phdrOff, _, phdrCount := u.Loader().Header()
	segments, _ := u.Loader().Segments()
	for _, s := range segments {
		if s.ContainsPhys(phdrOff) {
			phdrOff += s.Addr
			break
		}
	}
	phdrEnt := 56
	if u.Bits() == 32 {
		phdrEnt = 56 // FIXME
	}
	if phdrOff > 0 {
		auxv = append(auxv, []Elf64Auxv{
			{ELF_AT_PHDR, phdrOff},
			{ELF_AT_PHENT, uint64(phdrEnt)},
			{ELF_AT_PHNUM, uint64(phdrCount)},
		}...)
	}
	return auxv, nil
}
開發者ID:x56,項目名稱:usercorn,代碼行數:53,代碼來源:elf_auxv.go

示例3: packAddrs

func packAddrs(u models.Usercorn, addrs []uint64) ([]byte, error) {
	buf := make([]byte, int(u.Bits())/8*(len(addrs)+1))
	pos := buf
	for _, v := range addrs {
		x, err := u.PackAddr(pos, v)
		if err != nil {
			return nil, err
		}
		pos = pos[len(x):]
	}
	return buf, nil
}
開發者ID:lunixbochs,項目名稱:usercorn,代碼行數:12,代碼來源:kernel.go

示例4: SetupElfAuxv

func SetupElfAuxv(u models.Usercorn) ([]byte, error) {
	var buf bytes.Buffer
	auxv, err := setupElfAuxv(u)
	if err != nil {
		return nil, err
	}
	options := &struc.Options{
		PtrSize: int(u.Bits()),
		Order:   u.ByteOrder(),
	}
	for _, a := range auxv {
		if err := struc.PackWithOptions(&buf, &a, options); err != nil {
			return nil, err
		}
	}
	return buf.Bytes(), err
}
開發者ID:lunixbochs,項目名稱:usercorn,代碼行數:17,代碼來源:elf_auxv.go

示例5: SetupElfAuxv

func SetupElfAuxv(u models.Usercorn) ([]byte, error) {
	var buf bytes.Buffer
	auxv, err := setupElfAuxv(u)
	if err != nil {
		return nil, err
	}
	if u.Bits() == 32 {
		var auxv32 Elf32Auxv
		for _, a := range auxv {
			auxv32.Type = uint32(a.Type)
			auxv32.Val = uint32(a.Val)
			if err := struc.PackWithOrder(&buf, &auxv32, u.ByteOrder()); err != nil {
				return nil, err
			}
		}
	} else {
		for _, a := range auxv {
			if err := struc.PackWithOrder(&buf, &a, u.ByteOrder()); err != nil {
				return nil, err
			}
		}
	}
	return buf.Bytes(), err
}
開發者ID:x56,項目名稱:usercorn,代碼行數:24,代碼來源:elf_auxv.go


注:本文中的github.com/lunixbochs/usercorn/go/models.Usercorn.Bits方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。