-
Notifications
You must be signed in to change notification settings - Fork 25
/
binhexedit
executable file
·124 lines (110 loc) · 2.4 KB
/
binhexedit
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash
if [ $# == 0 ]
then
cat << EOF
binedit by Al Williams http://www.awce.com
Usage:
binedit [--o offset] [--unfill byte size] [--obs blksize] [--line-length length] [editor_options] -r filename.ext
This calls a binary editor (bless by default) after converting
known file types to .bin for writing or converting bin files after reading.
--o: Offset for file conversion (see srec_cat)
--unfill: Unfil blocks of at least size of byte (see srec_cat)
--obs: Output block size (see srec_cat)
--line-length: Output line length max (see srec_cat)
Assumes bless and srec_cat are on the path.
NOTE: Some versions of bless will report they are out of space
when saving a file if the temporary directory is not set
in the Edit | Preferences menu. Just set it to /tmp and
all will work! See https://bugs.launchpad.net/bless/+bug/876021
EOF
fi
BEDITOR=bless
# Options for bless
OPTS=
# The -r or -w
RWOPT=
# Real file name
FN=
# Extension provided
EXT=
# Options for srec_copy
SRECOPTS=
# Place to put stuff
TMPDIR=/tmp
# parse arguments and sort them out
while [ $# != 0 ]
do
# note --obs x becomes --obs=x
if [ "$1" == "--obs" ]
then
SRECOPTS="$SRECOPTS $1=$2"
shift
shift
continue
fi
# note --line-length x becomes --line-length=x
if [ "$1" == "--line-length" ]
then
SRECOPTS="$SRECOPTS $1=$2"
fi
if [ "$1" == "--unfill" ]
then
SRECOPTS="$SRECOPTS $1 $2 $3"
shift
shift
shift
continue
fi
if [ "$1" == "--offset" ]
then
SRECOPTS="$SRECOPTS $1 $2"
shift
shift
continue
fi
if [ "$1" == "-r" ]
then
RWOPT=-r
shift
FN=$1
else
OPTS="$OPTS $1"
fi
shift
done
# Pick apart file name
filename=$(basename "$FN")
extension="${filename##*.}"
fileprefix="${filename%.*}"
# for each case decide the real file name (RFILE)
# and what you have to do before or after
# to get the right answer
case "$extension" in
bin)
# no conversion needed
RFILE="$FN"
PRECVT=
POSTCVT=
;;
hex)
RFILE="$TMPDIR/$$.bin"
PRECVT="srec_cat $FN --intel -o $SRECOPT $RFILE --binary"
POSTCVT="srec_cat $RFILE --binary $SRECOPTS -o $FN --intel"
;;
srec)
RFILE=$TMPDIR/$$.bin
PRECVT="srec_cat $FN --motorola -o $SRECOPT $RFILE --binary"
POSTCVT="srec_cat $RFILE --binary $SRECOPTS -o $FN --motorola"
;;
txt) # special case
exec ${EDITOR:-nano} "$FN"
;;
*)
# Who knows?
RFILE="$FN"
PRECVT=
POSTCVT=
esac
$PRECVT
bless $OPTS $RFILE
$POSTCVT