Exemple #1
0
func (u *Usercorn) Syscall(num int, name string, getArgs func(n int) ([]uint64, error)) (uint64, error) {
	if name == "" {
		panic(fmt.Sprintf("Syscall missing: %d", num))
	}
	indent := ""
	if u.config.TraceSys && u.stacktrace.Len() > 0 {
		indent = strings.Repeat("  ", u.stacktrace.Len()-1)
		u.Printf("%s", u.memlog.Flush(indent, u.arch.Bits))
	}
	for _, k := range u.kernels {
		if sys := co.Lookup(u, k, name); sys != nil {
			args, err := getArgs(len(sys.In))
			if err != nil {
				return 0, err
			}
			if u.config.TraceSys {
				u.Printf(indent + "s ")
				u.Printf("%s", sys.Trace(args))
				// don't memlog our strace
				u.memlog.Reset()
			}
			ret := sys.Call(args)
			if u.config.TraceSys {
				// don't memlog ret either
				u.memlog.Freeze()
				// TODO: print this manually?
				u.Printf("%s", sys.TraceRet(args, ret))
			}
			u.Printf("%s", u.memlog.Flush(indent, u.arch.Bits))
			return ret, nil
		}
	}
	panic(fmt.Errorf("Kernel not found for syscall '%s'", name))
}
Exemple #2
0
func (k *LinuxKernel) Socketcall(index int, params co.Buf) uint64 {
	if name, ok := socketCallMap[index]; ok {
		if sys := co.Lookup(k.U, k, name); sys != nil {
			rawArgs := make([]uint32, len(sys.In))
			if err := params.Unpack(rawArgs); err != nil {
				return posix.UINT64_MAX
			}
			args := make([]uint64, len(rawArgs))
			for i, v := range rawArgs {
				args[i] = uint64(v)
			}
			return sys.Call(args)
		}
	}
	return posix.UINT64_MAX // FIXME
}