Giter Site home page Giter Site logo

hexlog's Introduction

SYNOPSIS

hexlog [r]in|[r]out|[r]inout|none cmd ...

DESCRIPTION

hexlog: hexdump stdin and/or stdout to stderr

hexlog streams a hexdump (or optionally the raw bytes) of the standard I/O of a subprocess to standard error. Hexdumps can be enabled or disabled by sending a signal (see SIGNALS).

The hexdump code originates from:

https://gist.github.com/ccbrown/9722406

EXAMPLES

$ echo abc | hexlog inout cat -n
     1  abc
61 62 63 0A                                       |abc.| (0)
20 20 20 20 20 31 09 61  62 63 0A                 |     1.abc.| (1)

$ (echo test | HEXLOG_FD_STDIN=4 HEXLOG_FD_STDOUT=5 hexlog inout cat) 4>stdin 5>stdout

$ echo abc | hexlog rinout cat -n
     1  abc
abc
     1  abc

Build

make

# selecting process restrictions
RESTRICT_PROCESS=seccomp make

#### using musl
RESTRICT_PROCESS=rlimit ./musl-make

## linux seccomp sandbox: requires kernel headers

# clone the kernel headers somewhere
export MUSL_INCLUDE=/tmp
git clone https://github.com/sabotage-linux/kernel-headers.git $MUSL_INCLUDE/kernel-headers

# then compile
MUSL_INCLUDE=/tmp ./musl-make clean all

OPTIONS

None.

ARGUMENTS

none : do not dump stdio

in : dump stdin

out : dump stdout

inout : dump stdin/stdout

Prefacing a stream with 'r' will dump the raw bytes: rnone, rin, rout, rinout.

ENVIRONMENT VARIABLES

HEXLOG_LABEL_STDIN=" (0)" : Label attached to hexdump of the stdin stream.

HEXLOG_LABEL_STDOUT=" (1)" : Label attached to hexdump of the stdout stream.

HEXLOG_FD_STDIN="2" : File descriptor to write dump of the stdin stream.

HEXLOG_FD_STDOUT="2" : File descriptor to write dump of the stdout stream.

HEXLOG_TIMEOUT="0" : Dump any buffered data after HEXLOG_TIMEOUT seconds of inactivity (0 to disable)

SIGNALS

SIGUSR1 : stdin: activate or deactivate hexdump based on the initial settings

SIGUSR2 : stdout: activate or deactivate hexdump based on the initial settings

SIGHUP : reset hexdump stdio to initial value

SIGALRM : dump any buffered data

ALTERNATIVES

bash

The general problem is duplicating stdout to stderr which can be handled using tee(1) and bash's process substitution:

tee >(cat 1>&2) | command | tee >(cat 1>&2)

This pipeline forks 6 processes including bash. To hexdump:

tee >(stdbuf -oL hexdump -C 1>&2) | command | tee >(stdbuf -oL hexdump -C 1>&2)

A real version would use a format string and include the direction (stdin vs stdout).

And to wrap it in a script:

#!/bin/bash

set -o errexit
set -o nounset
set -o pipefail

tee >(stdbuf -oL hexdump -C 1>&2) | $@ | tee >(stdbuf -oL hexdump -C 1>&2)

For example:

./hexlog nc -l -k 9090

Note: hexdump doesn't exit and flush the buffer when stdin is closed. It will wait for the next full write.

socat

socat -xv - EXEC:"command arg1",pty

hexlog's People

Contributors

msantos avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.