Initial import

This commit is contained in:
2025-10-10 10:05:13 +02:00
parent 3effc1597b
commit b96b6e7f8f
164 changed files with 5473 additions and 0 deletions

72
recorder/ttyrec.go Normal file
View File

@@ -0,0 +1,72 @@
package recorder
import (
"encoding/binary"
"io"
"sync"
"syscall"
"time"
)
type ttyRecordHeader struct {
Sec int32
USec int32
Len int32
}
func (h *ttyRecordHeader) Now() {
var (
now = time.Now()
tv = syscall.NsecToTimeval(now.UnixNano())
)
h.Sec = int32(tv.Sec)
h.USec = tv.Usec
}
func (h *ttyRecordHeader) WriteTo(w io.Writer) (int64, error) {
var b [6]byte
binary.LittleEndian.PutUint32(b[0:], uint32(h.Sec))
binary.LittleEndian.PutUint32(b[2:], uint32(h.USec))
binary.LittleEndian.PutUint32(b[4:], uint32(h.Len))
n, err := w.Write(b[:])
return int64(n), err
}
type ttyRecRecorder struct {
mu sync.Mutex
wc io.WriteCloser
header *ttyRecordHeader
}
func newTTYRecRecorder(wc io.WriteCloser) *ttyRecRecorder {
return &ttyRecRecorder{
wc: wc,
header: new(ttyRecordHeader),
}
}
func (r *ttyRecRecorder) Close() error {
return r.wc.Close()
}
func (w *ttyRecRecorder) Write(p []byte) (n int, err error) {
w.mu.Lock()
defer w.mu.Unlock()
w.header.Now()
if _, err = w.header.WriteTo(w.wc); err != nil {
return
}
if _, err = w.wc.Write(p); err != nil {
return
}
return len(p) + 9, nil
}
func (r *ttyRecRecorder) Reads() io.WriteCloser {
return r
}
func (r *ttyRecRecorder) Writes() io.WriteCloser {
return nopCloser{io.Discard}
}