Encode arbitrary data as a printf-compatible string.
$ head -c 10 /dev/random > file_A
$ cargo run --example pfencode < file_A
j%%\247C\207R\314\16I}
$ printf 'j%%\247C\207R\314\16I}' > file_B
$ diff -s file_A file_B
Files file_A and file_B are identicalIn a rare situation when you only have basic shell access to a machine, and no FTP/wget/netcat/etc, it can be a huge pain if you need to upload some data to it (e.g. an executable).
Typically you can use something like base64(1), but it's not guaranteed to be available everywhere. However, printf(1) is always available, and it supports (among other things) octal escape sequences, which can be used to print any data1.
This library/program encodes anything into a string that can be passed to printf(1), which will produce identical data. Splitting into chunks of a certain size is also supported.
An example binary is provided in the examples/ folder.
Usage: pfencode [OPTIONS] [PATH]
Arguments:
[PATH]
Options:
-c, --chunk-size <CHUNK_SIZE> Split into chunks at most SIZE in length
-p, --prefix <PREFIX> String to add before encoded data
-s, --suffix <SUFFIX> String to add after encoded data
-h, --help Print help
Run fuzz/fuzz.sh and provide a path where AFL will store it's findings. See Rust Fuzz Book for more info.
Footnotes
-
Strictly speaking, printf will happily print bytes outside ASCII as-is, but it's not very practical to copy & paste these. ↩