kernctl

package module
v0.0.0-...-0a10173 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2014 License: MIT Imports: 5 Imported by: 0

README

kernctl

Version 0.0.1

kernctl is a library for interacting with OSX kernel extensions via the KEXT Control API

Installing

go get github.com/aschepis/kernctl

Example

package main

import(
    "fmt"
    "github.com/aschepis/kernctl"
)

type KextMessage struct {
    Version uint32
    Command uint32
}

func (msg *KextMessage) Bytes() []byte {
    buf := new(bytes.Buffer)
    binary.Write(buf, binary.LittleEndian, msg)
    return buf.Bytes()
}

func main() {
    msg := &KextMessage{
        Version: 1,
        Command: 17,
    }

  conn := kernctl.NewConnByName("my.kext.name")
    conn.Connect()
    conn.SendCommand(msg)
    conn.Close()
}

Sending Messages

Sending messages via the SendCommand function requires only that your argument implements the kernctl.Message interface

TODO

  • bi-directional communication functionality so that a kext can send information back to a connected client.
  • ability to use the KEXT Notification API to receive notifications from a KEXT
  • some tests? This stuff is unfortunately difficult to test but it may be possible to refactor things enough that there are some testable components that can verify that the interaction with the kext is called properly.

Contributing

By all means, please do! Pull requests and issues are welcome. No offical workflow yet.

Versioning

kernctl uses semantic versioning. This is a bit pointless at the moment since the library is yet to reach 1.0

Documentation

Overview

package kernctl provides access to the OSX Kext Control API for sending and receiving messages from kernel extensions.

Index

Constants

View Source
const (
	SYSPROTO_CONTROL = 2
	AF_SYSTEM        = 32
	PF_SYSTEM        = AF_SYSTEM
	AF_SYS_CONTROL   = 2
	CTLIOCGINFO      = 3227799043
)

Variables

This section is empty.

Functions

func FD_ISSET

func FD_ISSET(p *syscall.FdSet, i int) bool

func FD_SET

func FD_SET(p *syscall.FdSet, i int)

stolen from https://github.com/pebbe/zmq2

func FD_ZERO

func FD_ZERO(p *syscall.FdSet)

func GetCtlId

func GetCtlId(fd int, CtlName string) (uint32, error)

GetCtlId retrieves the kext control id for the kext named in CtlName using the socket file descriptor fd.

Types

type Conn

type Conn struct {
	CtlId  uint32
	UnitId uint32
	Fd     int
}

func NewConnByCtlId

func NewConnByCtlId(CtlId uint32, UnitId uint32) *Conn

func NewConnByName

func NewConnByName(CtlName string) *Conn

Create a new connection to a named kext's kernel control socket

func (*Conn) Close

func (conn *Conn) Close()

Close closes a connection to a kernel extension

func (*Conn) Connect

func (conn *Conn) Connect() error

Connect will create a connection to the control socket for the kernel extension named in CtlName

func (*Conn) Select

func (conn *Conn) Select(bufSize int) (error, []byte)

func (*Conn) SendCommand

func (conn *Conn) SendCommand(msg Message)

type Message

type Message interface {
	Bytes() []byte
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL