2024-02-27 23:53:53 -06:00
|
|
|
|
#!/bin/sh
|
|
|
|
|
# Name: shellfox.sh
|
|
|
|
|
# Desc: Shellfox’es native component: Executes lines of shell recieved on stdin.
|
|
|
|
|
# Date: 2024-02-27
|
|
|
|
|
# Author: Jaidyn Ann <jadedctrl@posteo.at>
|
|
|
|
|
# Dependencies: bc, xxd
|
|
|
|
|
# License: GNU GPLv3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Convert a number in hexadecimal format to decimal.
|
|
|
|
|
hex_to_dec() {
|
|
|
|
|
local hex="$1"
|
|
|
|
|
echo "ibase=16; $hex" \
|
|
|
|
|
| bc
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Read a native-messaging message from stdin, print it to stdout.
|
|
|
|
|
read_message() {
|
|
|
|
|
# Read the length from the four-byte number that leads each message…
|
|
|
|
|
local length_hex="$(head --bytes=4 | xxd -e -u | awk '{print $2}')"
|
|
|
|
|
local length="$(hex_to_dec "$length_hex")"
|
|
|
|
|
# … now read that many bytes.
|
|
|
|
|
head --bytes="$length"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-02-28 21:57:28 -06:00
|
|
|
|
# Deescape a JSON stream from input.
|
|
|
|
|
json_deescape() {
|
|
|
|
|
sed 's/^"//' \
|
|
|
|
|
| sed 's/"$//' \
|
|
|
|
|
| sed 's/\"/"/g'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-02-27 23:53:53 -06:00
|
|
|
|
while true; do
|
2024-02-28 21:57:28 -06:00
|
|
|
|
command="$(read_message | json_deescape)"
|
|
|
|
|
nohup "$SHELL" -c "$command" > /dev/null &
|
2024-02-27 23:53:53 -06:00
|
|
|
|
done
|