diff options
author | David Timber <mieabby@gmail.com> | 2020-08-20 12:23:35 +0930 |
---|---|---|
committer | David Timber <mieabby@gmail.com> | 2020-08-20 15:15:57 +0930 |
commit | 76d4d6b2bafada7b790e817b7324d53f3d3a0c7f (patch) | |
tree | d8b3669fa7b167fc3bf764e971fc6e70bd8d9b49 /src/build-utils.sh | |
parent | 7bd3eb3b1ad4209ac4cf4b46f849213d46bc33aa (diff) |
Progress ...
* Move DVault out of executable. Dynamically load it on startup
* Improved testing scheme
* Tidy up prne_*assert* macro series
* Protocol: store host credentials in base64 string. No mask
* Use the lock shm as a shared_global so the stats can persist
* mmap() the executable read-only for later use
Diffstat (limited to 'src/build-utils.sh')
-rwxr-xr-x | src/build-utils.sh | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/build-utils.sh b/src/build-utils.sh new file mode 100755 index 0000000..77ca1e0 --- /dev/null +++ b/src/build-utils.sh @@ -0,0 +1,69 @@ +#!/bin/bash +cmd_align-size () { + local aligned + + if [ $# -lt 2 ]; then + echo "Usage: $0 <alignment> <size>" >&2 + return 2 + fi + + let "aligned = $2 % $1" + if [ $aligned -eq 0 ]; then + aligned=$2 + else + let "aligned = ($2 / $1 + 1) * $1" + fi + + echo $aligned + + return 0 +} + +cmd_align-file () { + if [ $# -lt 2 ]; then + echo "Usage: $0 <alignment> <file>" >&2 + return 2 + fi + + truncate -s $("$SELF" align-size "$1" $(stat -c "%s" $2)) "$2" +} + +cmd_append-uint32 () { + local a b c d + + if [ $# -lt 2 ]; then + echo "Usage: $0 <value> <file>" >&2 + return 2 + fi + + let "a = ($1 & 0xFF000000) >> 24" + let "b = ($1 & 0x00FF0000) >> 16" + let "c = ($1 & 0x0000FF00) >> 8" + let "d = ($1 & 0x000000FF) >> 0" + a=$(printf "%X" $a) + b=$(printf "%X" $b) + c=$(printf "%X" $c) + d=$(printf "%X" $d) + printf "\\x$a\\x$b\\x$c\\x$d" >> "$2" +} + +cmd_append-uint16 () { + local a b + + if [ $# -lt 2 ]; then + echo "Usage: $0 <value> <file>" >&2 + return 2 + fi + + let "a = ($1 & 0xFF00) >> 8" + let "b = ($1 & 0x00FF) >> 0" + a=$(printf "%X" $a) + b=$(printf "%X" $b) + printf "\\x$a\\x$b" >> "$2" +} + +SELF="$0" +cmd="$1" +shift 1 + +"cmd_$cmd" $@ |