-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbarmaid_legacy.sh
executable file
·58 lines (48 loc) · 1.52 KB
/
barmaid_legacy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env bash
# Barmaid is a command line tool to manipulate BTW files.
#
# Written and placed into the public domain by
# Elias Oenal <barmaid@eliasoenal.com>
#
# GNU sed and grep required.
# Execute "./barmaid.sh -e file_in.btw" to extract container and separate prefix.
# Execute "./barmaid.sh -c file_out.btw" to construct file_out.btw from fragments.
set -e
OS_TYPE=$(uname)
case "$OS_TYPE" in
"Linux" )
GREP=grep
SED=sed
;;
"Darwin" )
GREP=grep
SED=gsed
;;
* )
echo "OS entry needed at line ${LINENO} of this script."
exit
esac
if [ "$1" == "-e" ] && [ -n "$2" ]; then
echo "Extracting $2 into prefix.bin and container.bin"
OFFSET=$(LANG=C $GREP -obUaP "\x49\x45\x4E\x44\xAE\x42\x60\x82\x00\x01" "$2" | LANG=C $SED -e "s/:.*//g")
let "OFFSET+=10"
echo "Found container at offset: $OFFSET"
dd if="$2" bs=1 count=$OFFSET > prefix.bin 2> /dev/null
dd if="$2" skip=$OFFSET bs=1 2> /dev/null | zlib-flate -uncompress > container.bin
echo "You may now edit container.bin and use -c to reconstruct the BTW file once you're done."
exit
fi
if [ "$1" == "-c" ] && [ -n "$2" ]; then
echo "Constructing $2 from prefix.bin and container.bin"
cp prefix.bin "$2"
zlib-flate -compress < container.bin >> "$2"
exit
fi
echo "Barmaid v0.1"
echo ""
echo "Usage: barmaid.sh [OPTIONS] [FILE]"
echo "Options:"
echo " -e [FILE] Extract prefix and container (fragments) from [FILE]"
echo " -c [FILE] Construct [FILE] from fragments"
echo ""
exit