#!/bin/sh # Listen in on serial port connections. # (Note that max packet size is hardcoded to be 512) # Written by jan2642 if [ "$#" -ne 1 ]; then echo "Usage: $0 " fi /usr/sbin/dtrace -n ' inline string PATHNAME = "'$1'"; #pragma D option quiet #pragma D option switchrate=10hz /* #pragma D option bufpolicy=ring */ dtrace:::BEGIN { } syscall::open:entry, syscall::open_nocancel:entry, syscall::open_extended:entry { self->path = arg0; self->file_open_in_progress = 1; } syscall::open:return, syscall::open_nocancel:return, syscall::open_extended:return /self->file_open_in_progress && (PATHNAME == copyinstr(self->path))/ { the_pid = pid; the_fd = arg1; self->path = 0; self->file_open_in_progress = 0; } syscall::*read:entry /pid == the_pid && arg0 == the_fd/ { self->read_in_progress = 1; self->read_ptr = arg1; } syscall::*read:return /self->read_in_progress/ { if (arg0 > 0) { printf("==+ %s IN %d : ", execname, (int)arg0); tracemem(copyin(self->read_ptr, arg0), 512); printf("==-\n"); } self->read_in_progress = 0; } syscall::*write:entry /pid == the_pid && arg0 == the_fd/ { if (arg2 > 0) { printf("==+ %s OUT %d : ", execname, (int)arg2); tracemem(copyin(arg1, arg2), 512); printf("==-\n"); } } ' 2> /dev/null | python -c ' import sys def parse_block(buf): lines = buf.split("\n"); meta = lines[0].split(" ") proc = meta[1] direction = meta[2] size = int(meta[3]) print("%s %-3s %5d :" % (proc, direction, size)), if size > 512: size = 512 for i in xrange(0, (size / 16) + 1): data = lines[2 + i].strip().split(" ") remain = 16 if i == size / 16: remain = size % 16 for j in xrange(0, remain): print("%s" % data[j + 1]), print("") for line in sys.stdin: if line.startswith("==+"): buf = ""; if line.startswith("==-"): parse_block(buf) buf += line ' # vim: expandtab:ts=4:sw=4