rev |
line source |
pascal@13691
|
1 #!/bin/sh
|
pascal@13691
|
2
|
pascal@13691
|
3 ddq()
|
pascal@13691
|
4 {
|
pascal@13691
|
5 dd $@ 2> /dev/null
|
pascal@13691
|
6 }
|
pascal@13691
|
7
|
pascal@13691
|
8 store()
|
pascal@13691
|
9 {
|
pascal@13691
|
10 n=$2; for i in $(seq 8 8 ${4:-16}); do
|
pascal@13691
|
11 printf '\\\\x%02X' $(($n & 255))
|
pascal@13691
|
12 n=$(($n >> 8))
|
pascal@13691
|
13 done | xargs echo -en | ddq bs=1 conv=notrunc of=$3 seek=$(($1))
|
pascal@13691
|
14 }
|
pascal@13691
|
15
|
pascal@13972
|
16 get()
|
pascal@13972
|
17 {
|
pascal@18824
|
18 echo $(od -j $(($1)) -N ${3:-2} -t u${3:-2} -An "$2")
|
pascal@13972
|
19 }
|
pascal@13972
|
20
|
pascal@17476
|
21 compress()
|
pascal@17476
|
22 {
|
pascal@17489
|
23 if [ "$1" ]; then
|
pascal@17489
|
24 gzip -9 > $1
|
pascal@17489
|
25 [ "$(which advdef 2> /dev/null)" ] &&
|
pascal@19425
|
26 advdef -z4 -i100 $1 > /dev/null
|
pascal@17489
|
27 elif [ "$(which xz 2> /dev/null)" ]; then
|
pascal@17476
|
28 xz -z -e --format=lzma --lzma1=mode=normal --stdout
|
pascal@17476
|
29 else
|
pascal@17476
|
30 lzma e -si -so
|
pascal@17476
|
31 fi 2> /dev/null
|
pascal@17476
|
32 }
|
pascal@17476
|
33
|
pascal@14150
|
34 add_rootfs()
|
pascal@13691
|
35 {
|
pascal@13691
|
36 TMP=/tmp/iso2exe$$
|
pascal@18815
|
37 mkdir -p $TMP/dev
|
pascal@18804
|
38 cp -a /dev/tty /dev/tty0 $TMP/dev
|
pascal@13691
|
39 $0 --get init > $TMP/init.exe
|
pascal@17489
|
40 # mount -o loop,ro $1 $TMP
|
pascal@17489
|
41 # oldslitaz="$(ls $TMP/boot/isolinux/splash.lss 2> /dev/null)"
|
pascal@17489
|
42 # umount -d $TMP
|
pascal@17489
|
43 # [ "$oldslitaz" ] && # for SliTaz <= 3.0 only...
|
pascal@18815
|
44 # grep -q mount.posixovl.iso2exe $TMP/init.exe && mkdir $TMP/bin &&
|
pascal@17489
|
45 # cp /usr/sbin/mount.posixovl $TMP/bin/mount.posixovl.iso2exe \
|
pascal@17489
|
46 # 2> /dev/null && echo "Store mount.posixovl ($(wc -c \
|
pascal@17489
|
47 # < /usr/sbin/mount.posixovl) bytes) ..."
|
pascal@17252
|
48 find $TMP -type f -print0 | xargs -0 chmod +x
|
pascal@19338
|
49 find $TMP -print0 | xargs -0 touch -t 197001010100.00
|
pascal@18909
|
50 ( cd $TMP ; find * | grep -v rootfs.gz | cpio -o -H newc ) | \
|
pascal@18909
|
51 compress $TMP/rootfs.gz
|
pascal@13691
|
52 SIZE=$(wc -c < $TMP/rootfs.gz)
|
pascal@13972
|
53 store 24 $SIZE $1
|
pascal@14261
|
54 OFS=$(( $OFS - $SIZE ))
|
pascal@17454
|
55 printf "Adding rootfs.gz file at %04X (%d bytes) ...\n" $OFS $SIZE
|
pascal@13691
|
56 cat $TMP/rootfs.gz | ddq of=$1 bs=1 seek=$OFS conv=notrunc
|
pascal@13691
|
57 rm -rf $TMP
|
pascal@14150
|
58 }
|
pascal@14150
|
59
|
pascal@14261
|
60 add_dosexe()
|
pascal@14261
|
61 {
|
pascal@17492
|
62 TMP=/tmp/bootiso$$
|
pascal@17492
|
63 $0 --get bootiso.bin > $TMP 2> /dev/null
|
pascal@17492
|
64 OFS=$(($(get 20 $TMP) - 0xC0))
|
pascal@17492
|
65 printf "Adding DOS/EXE stub at %04X (%d bytes) ...\n" $OFS $((0x8000 - $OFS))
|
pascal@17492
|
66 ddq if=$TMP bs=1 skip=$OFS of=$1 seek=$OFS conv=notrunc
|
pascal@17492
|
67 rm -f $TMP
|
pascal@14261
|
68 }
|
pascal@14261
|
69
|
pascal@14150
|
70 add_doscom()
|
pascal@14150
|
71 {
|
pascal@13972
|
72 SIZE=$($0 --get boot.com | wc -c)
|
pascal@13691
|
73 OFS=$(( $OFS - $SIZE ))
|
pascal@17454
|
74 printf "Adding DOS boot file at %04X (%d bytes) ...\n" $OFS $SIZE
|
pascal@13972
|
75 $0 --get boot.com | ddq of=$1 bs=1 seek=$OFS conv=notrunc
|
pascal@17810
|
76 store 64 $(($OFS+0xC0)) $1
|
pascal@14150
|
77 }
|
pascal@14150
|
78
|
pascal@18062
|
79 add_tazlito_info()
|
pascal@18062
|
80 {
|
pascal@18062
|
81 HOLE=$OFS
|
pascal@18062
|
82 [ $(get 0 $2) -eq 35615 ] || return
|
pascal@19008
|
83 zcat $2 | compress /tmp/rezipped$$.gz
|
pascal@18062
|
84 n=$(stat -c %s /tmp/rezipped$$.gz)
|
pascal@18062
|
85 printf "Moving tazlito data record at %04X ($n bytes) ...\n" $OFS
|
pascal@18062
|
86 ddq if=/tmp/rezipped$$.gz bs=1 of=$1 seek=$OFS conv=notrunc
|
pascal@18062
|
87 HOLE=$(($HOLE+$n))
|
pascal@18062
|
88 rm -f /tmp/rezipped$$.gz
|
pascal@19425
|
89 if [ -n "$gpt" ]; then
|
pascal@19425
|
90 store $((0x25E)) $n $1
|
pascal@19425
|
91 store $((0x25C)) $OFS $1
|
pascal@19425
|
92 fi
|
pascal@18062
|
93 }
|
pascal@18062
|
94
|
pascal@14150
|
95 add_win32exe()
|
pascal@14150
|
96 {
|
pascal@13974
|
97 SIZE=$($0 --get win32.exe 2> /dev/null | tee /tmp/exe$$ | wc -c)
|
pascal@19425
|
98 [ -n "$gpt" ] && SIZE=$(($SIZE+1024))
|
pascal@19425
|
99 [ -n "$mac" ] && SIZE=$(($SIZE+3072))
|
pascal@17454
|
100 printf "Adding WIN32 file at %04X (%d bytes) ...\n" 0 $SIZE
|
pascal@14261
|
101 ddq if=/tmp/exe$$ of=$1 conv=notrunc
|
pascal@19425
|
102 if [ -n "$gpt" ]; then
|
pascal@19425
|
103 printf "Adding GPT at %04X (1024 bytes) ...\n" 512
|
pascal@19425
|
104 ddq if=$2 bs=512 skip=1 of=$1 seek=1 conv=notrunc
|
pascal@19425
|
105 i=3; [ -n "$mac" ] && i=9
|
pascal@19425
|
106 ddq if=/tmp/exe$$ bs=512 skip=1 of=$1 seek=$i conv=notrunc
|
pascal@19425
|
107 for i in 12C 154 17C ; do # always 3 UPX sections
|
pascal@19425
|
108 store $((0x$i)) $((1024 + $(get 0x$i $1))) $1 2
|
pascal@19425
|
109 done
|
pascal@19425
|
110 fi
|
pascal@14261
|
111 printf "Adding bootiso head at %04X...\n" 0
|
pascal@14261
|
112 $0 --get bootiso.bin 2> /dev/null > /tmp/exe$$
|
pascal@14261
|
113 ddq if=/tmp/exe$$ of=$1 bs=128 count=1 conv=notrunc
|
pascal@14266
|
114 store $((0x94)) $((0xE0 - 12*8)) $1
|
pascal@14266
|
115 store $((0xF4)) $((16 - 12)) $1
|
pascal@14267
|
116 ddq if=$1 of=/tmp/coff$$ bs=1 skip=$((0x178)) count=$((0x88))
|
pascal@14267
|
117 ddq if=/tmp/coff$$ of=$1 conv=notrunc bs=1 seek=$((0x178 - 12*8))
|
pascal@17810
|
118 ddq if=/tmp/exe$$ of=$1 bs=1 count=24 seek=$((0x1A0)) skip=$((0x1A0)) conv=notrunc
|
pascal@17810
|
119 ddq if=$2 bs=1 skip=$((0x1B8)) seek=$((0x1B8)) count=72 of=$1 conv=notrunc
|
pascal@14261
|
120 store 510 $((0xAA55)) $1
|
pascal@14267
|
121 rm -f /tmp/exe$$ /tmp/coff$$
|
pascal@19425
|
122 i=$SIZE; OFS=$(($SIZE+512))
|
pascal@19425
|
123 [ -n "$mac" ] && OFS=$SIZE && i=1536
|
pascal@19425
|
124 store 417 $(($i/512)) $1 8
|
pascal@19425
|
125 printf "Moving syslinux hybrid boot record at %04X (512 bytes) ...\n" $i
|
pascal@19425
|
126 ddq if=$2 bs=1 count=512 of=$1 seek=$i conv=notrunc
|
pascal@14257
|
127 }
|
pascal@14257
|
128
|
pascal@14257
|
129 add_fdbootstrap()
|
pascal@14257
|
130 {
|
pascal@14268
|
131 SIZE=$($0 --get bootfd.bin 2> /dev/null | wc -c)
|
pascal@14257
|
132 if [ $SIZE -ne 0 ]; then
|
pascal@17454
|
133 SIZE=$(( $SIZE - 512 )) # sector 2 is data
|
pascal@17454
|
134 OFS=$(( $OFS - $SIZE ))
|
pascal@17454
|
135 printf "Adding floppy bootstrap file at %04X (%d bytes) ...\n" $OFS $SIZE
|
pascal@14268
|
136 $0 --get bootfd.bin | \
|
pascal@14268
|
137 ddq of=$1 bs=1 count=512 seek=$OFS conv=notrunc
|
pascal@14268
|
138 $0 --get bootfd.bin | \
|
pascal@14268
|
139 ddq of=$1 bs=1 skip=1024 seek=$((512 + $OFS)) conv=notrunc
|
pascal@17810
|
140 store 26 $(($SIZE/512)) $1 8
|
pascal@14257
|
141 fi
|
pascal@14150
|
142 }
|
pascal@18670
|
143
|
pascal@18824
|
144 gzsize()
|
pascal@18824
|
145 {
|
pascal@18824
|
146 echo $(($(hexdump -C | awk ' {
|
pascal@18824
|
147 for (i = 2; i < 18; i++) if ($i != "00") break;
|
pascal@18824
|
148 if (i == 18) {
|
pascal@18824
|
149 for (i = 17; i > 1; i--) if ($i != "00") break;
|
pascal@19033
|
150 print "0x" $1 " + 7 - " (16 - i)
|
pascal@18824
|
151 exit
|
pascal@18824
|
152 }
|
pascal@18824
|
153 }')))
|
pascal@18824
|
154 }
|
pascal@18824
|
155
|
pascal@18804
|
156 fileofs()
|
pascal@18804
|
157 {
|
pascal@19425
|
158 [ $(get 1024 "$ISO") -eq 35615 ] && x=1024 ||
|
pascal@19425
|
159 x=$((512*(1+$(get 417 "$ISO" 1))))
|
pascal@18824
|
160 stub=$(($(get 20 "$ISO") - 0xC0))
|
pascal@18848
|
161 c=$(custom_config_sector "$ISO")
|
pascal@18804
|
162 SIZE=0; OFFSET=0
|
pascal@18804
|
163 case "$1" in
|
pascal@19425
|
164 win32.exe) [ $x -eq 2048 ] && x=10752
|
pascal@19425
|
165 [ $x -eq 1024 ] || SIZE=$(($x - 512));;
|
pascal@19425
|
166 syslinux.mbr) [ $x -eq 1024 ] || OFFSET=$(($x - 512)); SIZE=512;;
|
pascal@19425
|
167 flavor.info) [ $(get 22528 "$ISO") -eq 35615 ] && OFFSET=22528
|
pascal@19425
|
168 [ $x -eq 2048 ] && x=$(get 0x25C "$ISO") &&
|
pascal@19425
|
169 SIZE=$(get 0x25E "$ISO")
|
pascal@19425
|
170 [ $(get $x "$ISO") -eq 35615 ] && OFFSET=$x
|
pascal@19425
|
171 [ $OFFSET -ne 0 ] && [ $SIZE -eq 0 ] &&
|
pascal@19425
|
172 SIZE=$(ddq bs=512 skip=$(($OFFSET/512)) if="$ISO" | gzsize);;
|
pascal@18824
|
173 floppy.boot) SIZE=$(($(get 26 "$ISO" 1)*512))
|
pascal@18824
|
174 OFFSET=$(($(get 64 "$ISO") - 0xC0 - $SIZE));;
|
pascal@18824
|
175 rootfs.gz) SIZE=$(get 24 "$ISO"); OFFSET=$(($stub - $SIZE));;
|
pascal@18824
|
176 tazboot.com) OFFSET=$(($(get 64 "$ISO") - 0xC0))
|
pascal@18824
|
177 SIZE=$(($stub - $(get 24 "$ISO") - $OFFSET));;
|
pascal@18804
|
178 dosstub) OFFSET=$stub; SIZE=$((0x8000 - $OFFSET));;
|
pascal@18848
|
179 boot.md5) OFFSET=$((0x7FF0)); SIZE=16;;
|
pascal@18848
|
180 fs.iso) OFFSET=$((0x8000))
|
pascal@18848
|
181 SIZE=$((2048*$c - $OFFSET));;
|
pascal@18848
|
182 custom.magic) ddq bs=2k skip=$c if="$ISO" | ddq bs=1 count=6 | \
|
pascal@18848
|
183 grep -q '#!boot' && OFFSET=$((2048*$c)) &&
|
pascal@18848
|
184 SIZE=39 ;;
|
pascal@18848
|
185 custom.append) OFFSET=$((2048*$c+47)) &&
|
pascal@18848
|
186 SIZE=$(ddq bs=2k skip=$c if="$ISO" count=1 | \
|
pascal@18848
|
187 sed '/^append=/!d;s/^[^=]*=.//' | wc -c);;
|
pascal@19450
|
188 custom.initrd) x=$(ddq bs=2k skip=$c if="$ISO" count=1 | \
|
pascal@18848
|
189 sed '/^append=\|^initrd:/!d' | wc -c)
|
pascal@19425
|
190 OFFSET=$((2048*$c+$x+40))
|
pascal@18848
|
191 SIZE=$(($(ddq bs=2k skip=$c if="$ISO" count=1 | \
|
pascal@18848
|
192 sed '/^initrd:/!d;s/.*://') + 0));;
|
pascal@18804
|
193 esac
|
pascal@18804
|
194 }
|
pascal@18804
|
195
|
pascal@18804
|
196 list()
|
pascal@18804
|
197 {
|
pascal@18824
|
198 HEAP=0
|
pascal@18848
|
199 for f in win32.exe syslinux.mbr flavor.info floppy.boot tazboot.com \
|
pascal@18848
|
200 rootfs.gz dosstub boot.md5 fs.iso custom.magic custom.append \
|
pascal@18848
|
201 custom.initrd; do
|
pascal@18804
|
202 fileofs $f
|
pascal@18848
|
203 [ $SIZE -le 0 ] && continue
|
pascal@18848
|
204 [ "${OFFSET:8}" ] && continue
|
pascal@18820
|
205 [ $OFFSET -lt 0 ] && continue
|
pascal@18824
|
206 [ $(get $OFFSET "$ISO") -eq 0 ] && continue
|
pascal@18848
|
207 [ $OFFSET -gt $HEAP ] && [ $(($OFFSET - $HEAP)) -gt 16 ] &&
|
pascal@18848
|
208 printf "%d free bytes in %04X..%04X\n" $(($OFFSET - $HEAP)) $HEAP $OFFSET
|
pascal@18848
|
209 [ $OFFSET -ge $HEAP ] && HEAP=$(($OFFSET+$SIZE))
|
pascal@18824
|
210 printf "$f at %04X ($SIZE bytes).\n" $OFFSET
|
pascal@18804
|
211 done
|
pascal@18848
|
212 OFFSET=$(stat -c %s "$ISO")
|
pascal@18848
|
213 [ $OFFSET -gt $HEAP ] &&
|
pascal@18848
|
214 printf "%d free bytes in %04X..%04X\n" $(($OFFSET - $HEAP)) $HEAP $OFFSET
|
pascal@19425
|
215 if [ $(get 510 "$ISO") -eq 43605 ]; then
|
pascal@19425
|
216 echo "MBR partitions :"
|
pascal@19425
|
217 for i in 0 1 2 3; do
|
pascal@19425
|
218 SIZE=$(get $((446+12+16*i)) "$ISO" 4)
|
pascal@19425
|
219 [ $SIZE -eq 0 ] && continue
|
pascal@19425
|
220 OFFSET=$(get $((446+8+16*i)) "$ISO" 4)
|
pascal@19425
|
221 printf " $i:%08X %08X %02X\n" $OFFSET $SIZE \
|
pascal@19425
|
222 $(get $((446+4+16*i)) "$ISO" 1)
|
pascal@19425
|
223 done
|
pascal@19425
|
224 if [ $(get 466 "$ISO") -eq 65263 ]; then
|
pascal@19425
|
225 echo "EFI partitions :"
|
pascal@19425
|
226 n=$(get 584 "$ISO" 1)
|
pascal@19425
|
227 s=$(get 596 "$ISO")
|
pascal@19425
|
228 o=$((($(get 552 "$ISO" 1)*512)-($(get 592 "$ISO")*$s)))
|
pascal@19425
|
229 i=0
|
pascal@19425
|
230 while [ $n -gt $i ]; do
|
pascal@19425
|
231 f=$(get $(($o+0x20)) "$ISO" 4)
|
pascal@19425
|
232 l=$(($(get $(($o+0x28)) "$ISO" 4)-$f))
|
pascal@19425
|
233 [ $l -eq 0 ] && break
|
pascal@19425
|
234 printf " $i:%08X %08X %s\n" $f $(($l+1)) \
|
pascal@19425
|
235 "$(od -An -N 36 -w -j $(($o+0x38)) -t a "$ISO" \
|
pascal@19425
|
236 | sed 's/\( nul\)*//g;s/ //g;s/ sp//')"
|
pascal@19425
|
237 o=$(($o+$s))
|
pascal@19425
|
238 i=$(($i+1))
|
pascal@19425
|
239 done
|
pascal@19425
|
240 fi
|
pascal@19425
|
241 fi
|
pascal@19425
|
242 o=2048
|
pascal@19425
|
243 if [ $(get $o "$ISO") -eq 19792 ]; then
|
pascal@19425
|
244 echo "Apple partitions :"
|
pascal@19425
|
245 i=0
|
pascal@19425
|
246 while [ $(get $o "$ISO") -eq 19792 ]; do
|
pascal@19425
|
247 f=$((0x$(od -An -N 4 -j $(($o+8)) -t x1 "$ISO" | sed 's/ //g')))
|
pascal@19425
|
248 l=$((0x$(od -An -N 4 -j $(($o+0x54)) -t x1 "$ISO" | sed 's/ //g')))
|
pascal@19425
|
249 printf " $i:%08X %08X %s\n" $f $l \
|
pascal@19425
|
250 "$(ddq bs=1 skip=$(($o+16)) count=32 if="$ISO")"
|
pascal@19425
|
251 o=$(($o+2048))
|
pascal@19425
|
252 i=$(($i+1))
|
pascal@19425
|
253 done
|
pascal@19425
|
254 fi
|
pascal@18804
|
255 }
|
pascal@18804
|
256
|
pascal@18804
|
257 extract()
|
pascal@18804
|
258 {
|
pascal@18804
|
259 for f in $@; do
|
pascal@18804
|
260 fileofs $f
|
pascal@18824
|
261 [ $SIZE -eq 0 ] ||
|
pascal@18824
|
262 ddq bs=1 count=$SIZE skip=$OFFSET if="$ISO" >$f
|
pascal@18804
|
263 done
|
pascal@18804
|
264 }
|
pascal@18804
|
265
|
pascal@18670
|
266 custom_config_sector()
|
pascal@18670
|
267 {
|
pascal@19324
|
268 get 32848 "$1" 4
|
pascal@18670
|
269 }
|
pascal@18670
|
270
|
pascal@18773
|
271 clear_custom_config()
|
pascal@18773
|
272 {
|
pascal@19425
|
273 start=$(custom_config_sector $1)
|
pascal@19425
|
274 cnt=$((512 - ($start % 512)))
|
pascal@19425
|
275 [ $cnt -ne 512 ] &&
|
pascal@19425
|
276 ddq if=/dev/zero of=$1 bs=2k seek=$start count=$cnt
|
pascal@18773
|
277 }
|
pascal@14150
|
278 case "$1" in
|
pascal@14150
|
279 --build)
|
pascal@14150
|
280 shift
|
pascal@14261
|
281 ls -l $@
|
pascal@14150
|
282 cat >> $0 <<EOM
|
pascal@17476
|
283 $(tar cf - $@ | compress | uuencode -m -)
|
pascal@14150
|
284 EOT
|
pascal@14150
|
285 EOM
|
pascal@14150
|
286 sed -i '/^case/,/^esac/d' $0
|
pascal@14150
|
287 exit ;;
|
pascal@14150
|
288 --get)
|
pascal@14150
|
289 cat $2
|
pascal@14150
|
290 exit ;;
|
pascal@14150
|
291 --array)
|
pascal@14150
|
292 DATA=/tmp/dataiso$$
|
pascal@14150
|
293 ddq if=/dev/zero bs=32k count=1 of=$DATA
|
pascal@14261
|
294 add_win32exe $DATA $2 > /dev/null
|
pascal@14261
|
295 HSZ=$OFS
|
pascal@14261
|
296 add_dosexe $DATA > /dev/null
|
pascal@14150
|
297 add_rootfs $DATA > /dev/null
|
pascal@14150
|
298 add_doscom $DATA > /dev/null
|
pascal@14257
|
299 add_fdbootstrap $DATA > /dev/null
|
pascal@14257
|
300 name=${3:-bootiso}
|
pascal@17451
|
301 BOOTISOSZ=$((0x8000 - $OFS + $HSZ))
|
pascal@14150
|
302 cat <<EOT
|
pascal@14150
|
303
|
pascal@17451
|
304 #define $(echo $name | tr '[a-z]' '[A-Z]')SZ $BOOTISOSZ
|
pascal@14150
|
305
|
pascal@18775
|
306 #ifndef __MSDOS__
|
pascal@14257
|
307 static char $name[] = {
|
pascal@17591
|
308 /* head */
|
pascal@18909
|
309 $(hexdump -v -n $HSZ -e '" " 16/1 "0x%02X, "' -e '" /* %04.4_ax */ \n"' $DATA | sed 's/ 0x ,/ /g')
|
pascal@17591
|
310 /* tail */
|
pascal@18909
|
311 $(hexdump -v -s $OFS -e '" " 16/1 "0x%02X, "' -e '" /* %04.4_ax */ \n"' $DATA | sed 's/ 0x ,/ /g')
|
pascal@17591
|
312
|
pascal@17591
|
313 /* These strange constants are defined in RFC 1321 as
|
pascal@17591
|
314 T[i] = (int)(4294967296.0 * fabs(sin(i))), i=1..64
|
pascal@17591
|
315 */
|
pascal@17591
|
316 /* static const uint32_t C_array[64] */
|
pascal@17591
|
317 EOT
|
pascal@17591
|
318 while read a b c d; do
|
pascal@17591
|
319 for i in $a $b $c $d; do
|
pascal@17591
|
320 echo $i | sed 's/0x\(..\)\(..\)\(..\)\(..\),/0x\4, 0x\3, 0x\2, 0x\1, /'
|
pascal@17591
|
321 done
|
pascal@17591
|
322 done <<EOT
|
pascal@17591
|
323 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
|
pascal@17591
|
324 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
|
pascal@17591
|
325 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
|
pascal@17591
|
326 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
|
pascal@17591
|
327 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa,
|
pascal@17591
|
328 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,
|
pascal@17591
|
329 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
|
pascal@17591
|
330 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
|
pascal@17591
|
331 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c,
|
pascal@17591
|
332 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
|
pascal@17591
|
333 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05,
|
pascal@17591
|
334 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
|
pascal@17591
|
335 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039,
|
pascal@17591
|
336 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
|
pascal@17591
|
337 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
|
pascal@17591
|
338 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391,
|
pascal@17591
|
339 EOT
|
pascal@17591
|
340 cat <<EOT
|
pascal@17591
|
341 /* static const char P_array[64] */
|
pascal@17591
|
342 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, /* 1 */
|
pascal@17591
|
343 1, 6, 11, 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, /* 2 */
|
pascal@17591
|
344 5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2, /* 3 */
|
pascal@17591
|
345 0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9, /* 4 */
|
pascal@17591
|
346 /* static const char S_array[16] */
|
pascal@17591
|
347 7, 12, 17, 22,
|
pascal@17591
|
348 5, 9, 14, 20,
|
pascal@17591
|
349 4, 11, 16, 23,
|
pascal@17591
|
350 6, 10, 15, 21,
|
pascal@17451
|
351 EOT
|
pascal@17451
|
352
|
pascal@17451
|
353 for mode in data offset ; do
|
pascal@17451
|
354 ofs=0
|
pascal@17451
|
355 while read tag str; do
|
pascal@17451
|
356 if [ "$mode" == "data" ]; then
|
pascal@17451
|
357 echo -en "$str\0" | hexdump -v -e '" " 16/1 "0x%02X, "' \
|
pascal@18909
|
358 -e '" /* %04.4_ax */ \n"' | \
|
pascal@17451
|
359 sed 's/ 0x ,/ /g'
|
pascal@17451
|
360 else
|
pascal@17451
|
361 if [ $ofs -eq 0 ]; then
|
pascal@17451
|
362 cat <<EOT
|
pascal@14150
|
363 };
|
pascal@14150
|
364 #endif
|
pascal@17591
|
365
|
pascal@17591
|
366 #define C_array (uint32_t *) ($name + $(($BOOTISOSZ)))
|
pascal@17591
|
367 #define P_array (char *) ($name + $(($BOOTISOSZ+(64*4))))
|
pascal@17591
|
368 #define S_array (char *) ($name + $(($BOOTISOSZ+(64*4)+64)))
|
pascal@17451
|
369 #define ELTORITOOFS 3
|
pascal@14150
|
370 EOT
|
pascal@17451
|
371 fi
|
pascal@17591
|
372 echo "#define $tag $(($BOOTISOSZ+(64*4)+64+16+$ofs))"
|
pascal@17451
|
373 ofs=$(($(echo -en "$str\0" | wc -c)+$ofs))
|
pascal@17451
|
374 fi
|
pascal@17451
|
375 done <<EOT
|
pascal@17451
|
376 READSECTORERR Read sector failure.
|
pascal@18897
|
377 USAGE Usage: isohybrid.exe [--list|--read] [--append cmdline] [--initrd file] file.iso [--forced|--undo|--quick|filename...]
|
pascal@18909
|
378 OPENERR Can't open the iso file.
|
pascal@17451
|
379 ELTORITOERR No EL TORITO SPECIFICATION signature.
|
pascal@17451
|
380 CATALOGERR Invalid boot catalog.
|
pascal@17451
|
381 HYBRIDERR No isolinux.bin hybrid signature.
|
paul@17671
|
382 SUCCESSMSG Now you can create a USB key with your .iso file.\\\\nSimply rename it to an .exe file and run it.
|
pascal@17451
|
383 FORCEMSG You can add --forced to proceed anyway.
|
pascal@17591
|
384 MD5MSG Computing md5sum...
|
pascal@17591
|
385 UNINSTALLMSG Uninstall done.
|
pascal@18775
|
386 OPENINITRDERR Can't open the initrd file.
|
pascal@18780
|
387 ALREADYEXEERR Already an EXE file.
|
pascal@18897
|
388 WIN32_EXE win32.exe
|
pascal@18897
|
389 SYSLINUX_MBR syslinux.mbr
|
pascal@18897
|
390 FLAVOR_INFO flavor.info
|
pascal@18897
|
391 FLOPPY_BOOT floppy.boot
|
pascal@18897
|
392 TAZBOOT_COM tazboot.com
|
pascal@18897
|
393 ROOTFS_GZ rootfs.gz
|
pascal@18897
|
394 DOSSTUB dosstub
|
pascal@18897
|
395 BOOT_MD5 boot.md5
|
pascal@18897
|
396 FS_ISO fs.iso
|
pascal@18897
|
397 CUSTOM_MAGIC custom.magic
|
pascal@18897
|
398 CUSTOM_APPEND custom.append
|
pascal@18897
|
399 CUSTOM_INITRD custom.initrd
|
pascal@18909
|
400 CUSTOM_HEADER #!boot 00000000000000000000000000000000\\\\n
|
pascal@18909
|
401 FREE_FORMAT %ld free bytes in %04lX..%04lX\\\\n
|
pascal@18909
|
402 USED_FORMAT %s at %04lX (%ld bytes).\\\\n
|
pascal@18909
|
403 CMDLINE_TAG append=
|
pascal@18909
|
404 INITRD_TAG initrd:
|
pascal@17451
|
405 EOT
|
pascal@17451
|
406 done
|
pascal@18909
|
407 cat <<EOT
|
pascal@18909
|
408 #ifdef __MSDOS__
|
pascal@18909
|
409 #define BOOTISOFULLSIZE $(($BOOTISOSZ+(64*4)+64+16+$ofs))
|
pascal@18909
|
410 static char bootiso[BOOTISOFULLSIZE];
|
pascal@18909
|
411 static data_fixup(void)
|
pascal@18909
|
412 {
|
pascal@18909
|
413 #asm
|
pascal@18909
|
414 push ds
|
pascal@18909
|
415 push ds
|
pascal@18909
|
416 pop es
|
pascal@18909
|
417 mov ax,ds
|
pascal@18909
|
418 sub ax,#0x1000
|
pascal@18909
|
419 mov ds,ax
|
pascal@18909
|
420 xor si,si
|
pascal@18909
|
421 scanlp:
|
pascal@18909
|
422 dec si
|
pascal@18909
|
423 jz copydone
|
pascal@18909
|
424 cmp byte ptr [si+2],#0xEB
|
pascal@18909
|
425 jne scanlp
|
pascal@18909
|
426 cmp word ptr [si],#0x5A4D
|
pascal@18909
|
427 jne scanlp
|
pascal@18909
|
428 mov cx,#BOOTISOFULLSIZE
|
pascal@18909
|
429 mov di,#_bootiso
|
pascal@18909
|
430 cld
|
pascal@18909
|
431 rep
|
pascal@18909
|
432 movsb
|
pascal@18909
|
433 copydone:
|
pascal@18909
|
434 pop ds
|
pascal@18909
|
435 #endasm
|
pascal@18909
|
436 if (!bootiso[0]) {
|
pascal@18909
|
437 puts("No bootiso data");
|
pascal@18909
|
438 exit(-1);
|
pascal@18909
|
439 }
|
pascal@18909
|
440 }
|
pascal@18909
|
441 #else
|
pascal@18909
|
442 #define data_fixup()
|
pascal@18909
|
443 #endif
|
pascal@18909
|
444 EOT
|
pascal@14150
|
445 rm -rf $DATA
|
pascal@14150
|
446 exit ;;
|
pascal@14150
|
447 --exe)
|
pascal@14150
|
448 # --exe mvcom.bin x.com y.exe > xy.exe
|
pascal@14150
|
449 cat $4 $3 > /tmp/exe$$
|
pascal@14150
|
450 S=$(stat -c %s /tmp/exe$$)
|
pascal@14150
|
451 store 2 $(($S%512)) /tmp/exe$$
|
pascal@14150
|
452 store 4 $((($S+511)/512)) /tmp/exe$$
|
pascal@14150
|
453 store 14 -16 /tmp/exe$$
|
pascal@14150
|
454 store 16 -2 /tmp/exe$$
|
pascal@14150
|
455 store 20 256 /tmp/exe$$
|
pascal@14150
|
456 store 22 -16 /tmp/exe$$
|
pascal@14150
|
457 ddq if=$2 bs=1 seek=64 of=/tmp/exe$$ conv=notrunc
|
pascal@14150
|
458 store 65 $(stat -c %s $3) /tmp/exe$$
|
pascal@14150
|
459 store 68 $((0x100-0x40+$(stat -c %s $4))) /tmp/exe$$
|
pascal@14150
|
460 cat /tmp/exe$$
|
pascal@14150
|
461 rm -f /tmp/exe$$
|
pascal@14150
|
462 exit ;;
|
pascal@14150
|
463 esac
|
pascal@14150
|
464
|
pascal@14150
|
465 main()
|
pascal@14150
|
466 {
|
pascal@18802
|
467 [ $(id -u) -ne 0 ] && cmd="$0 $@" && exec su -c "$cmd" < /dev/tty
|
pascal@18670
|
468 append=
|
pascal@18670
|
469 initrd=
|
pascal@19425
|
470
|
pascal@18670
|
471 while [ "$1" ]; do
|
pascal@18670
|
472 case "${1/--/-}" in
|
pascal@18670
|
473 -get) shift
|
pascal@18670
|
474 uudecode | unlzma | tar xOf - $@
|
pascal@18670
|
475 exit ;;
|
pascal@18670
|
476 -a*) append="$2" ; shift 2 ;;
|
pascal@18670
|
477 -i*) initrd="$2" ; shift 2 ;;
|
pascal@18848
|
478 -r*|-l*)
|
pascal@18848
|
479 ISO="$2" ; shift 2
|
pascal@18804
|
480 [ -z "$1" ] && list || extract $@
|
pascal@18804
|
481 exit ;;
|
pascal@18670
|
482 *) cat > /dev/null
|
pascal@18670
|
483 break
|
pascal@18670
|
484 esac
|
pascal@18670
|
485 done
|
pascal@14150
|
486
|
pascal@18670
|
487 [ ! -s "$1" ] && cat 1>&2 <<EOT && exit 1
|
pascal@18848
|
488 usage: $0 [--list|--read] [--append custom_cmdline ] [ --initrd custom_initrd ] image.iso [--force|--undo|"DOS help message"|filename...]
|
pascal@18670
|
489 EOT
|
pascal@17451
|
490 case "${2/--/-}" in
|
pascal@18820
|
491 -u*|-r*|-w*|-f*)
|
pascal@17451
|
492 case "$(get 0 $1)" in
|
pascal@17451
|
493 23117)
|
pascal@18063
|
494 b=$(get 417 $1 1)
|
pascal@18063
|
495 n=$(($(get 64 $1) + 0xC0 - ($(get 26 $1 1)*512) - ($b+1)*512))
|
pascal@18063
|
496 ddq if=$1 bs=512 count=1 skip=$b of=$1 conv=notrunc
|
pascal@19425
|
497 if [ $(get 512 $1) -eq 17989 ]; then
|
pascal@19425
|
498 n=$(($(get 0x25C $1)/512))
|
pascal@19425
|
499 ddq if=$1 bs=512 seek=44 count=20 skip=$n of=$1 conv=notrunc
|
pascal@19425
|
500 ddq if=/dev/zero bs=512 seek=9 count=35 of=$1 conv=notrunc
|
pascal@19425
|
501 ddq if=/dev/zero bs=512 seek=3 count=1 of=$1 conv=notrunc
|
pascal@19425
|
502 else
|
pascal@19425
|
503 ddq if=/dev/zero bs=512 seek=1 count=1 of=$1 conv=notrunc
|
pascal@19425
|
504 ddq if=$1 bs=512 seek=2 count=30 skip=$(($b+1)) of=$1 conv=notrunc
|
pascal@19425
|
505 ddq if=/dev/zero bs=1 seek=$n count=$((0x8000 - $n)) of=$1 conv=notrunc
|
pascal@19425
|
506 fi ;;
|
pascal@17451
|
507 *) ddq if=/dev/zero bs=1k count=32 of=$1 conv=notrunc ;;
|
pascal@17451
|
508 esac
|
pascal@18820
|
509 case "${2/--/-}" in
|
pascal@18820
|
510 -f*)
|
pascal@19077
|
511 [ "$append$initrd" ] && clear_custom_config $1
|
pascal@19077
|
512 set -- "$1" "$3" ;;
|
pascal@18820
|
513 *)
|
pascal@18820
|
514 clear_custom_config $1
|
pascal@18820
|
515 exit 0 ;;
|
pascal@18820
|
516 esac
|
pascal@17451
|
517 esac
|
pascal@14150
|
518 case "$(get 0 $1)" in
|
pascal@14150
|
519 23117) echo "The file $1 is already an EXE file." 1>&2 && exit 1;;
|
pascal@17812
|
520 0) [ -x /usr/bin/isohybrid ] && isohybrid $1;;
|
pascal@14150
|
521 esac
|
pascal@19425
|
522
|
pascal@19425
|
523 gpt= ; [ $(get 466 $1) -eq 65263 ] && gpt=1
|
pascal@19425
|
524 mac= ; [ $(get 2048 $1) -eq 19792 ] && mac=1
|
pascal@14261
|
525 echo "Read hybrid & tazlito data..."
|
pascal@19430
|
526 if [ -n "$gpt" ]; then
|
pascal@19425
|
527 echo "GUID Partition Table..."
|
pascal@19430
|
528 n=3; [ -n "$mac" ] && n=9 && echo "Apple Partition Table..."
|
pascal@19425
|
529 ddq if=$1 bs=512 count=$n of=/tmp/hybrid$$
|
pascal@19425
|
530 ddq if=$1 bs=512 skip=44 count=20 of=/tmp/tazlito$$
|
pascal@19425
|
531 else
|
pascal@19425
|
532 ddq if=$1 bs=512 count=1 of=/tmp/hybrid$$
|
pascal@19425
|
533 ddq if=$1 bs=512 skip=2 count=20 of=/tmp/tazlito$$
|
pascal@19425
|
534 fi
|
pascal@14261
|
535 add_win32exe $1 /tmp/hybrid$$
|
pascal@18062
|
536 add_tazlito_info $1 /tmp/tazlito$$
|
pascal@14261
|
537 rm -f /tmp/tazlito$$ /tmp/hybrid$$
|
pascal@14150
|
538
|
pascal@14150
|
539 # keep the largest room for the tazlito info file
|
pascal@14261
|
540 add_dosexe $1
|
pascal@14150
|
541 add_rootfs $1
|
pascal@14150
|
542 add_doscom $1
|
pascal@14257
|
543 add_fdbootstrap $1
|
pascal@17454
|
544 printf "%d free bytes in %04X..%04X\n" $(($OFS-$HOLE)) $HOLE $OFS
|
pascal@17810
|
545 store 440 $(date +%s) $1 32
|
pascal@17562
|
546 [ "$2" ] && echo "$2 " | \
|
pascal@17562
|
547 ddq bs=1 seek=$((0x7FDE)) count=15 conv=notrunc of=$1
|
pascal@17562
|
548 if [ $(stat -c %s $1) -gt 34816 ]; then
|
pascal@17562
|
549 echo "Adding ISO image md5 at 7FF0 (16 bytes) ..."
|
pascal@19323
|
550 echo -en "$(ddq if=$1 bs=2k skip=16 count=$(($(get 32848 "$1" 4)-16)) | \
|
pascal@17562
|
551 md5sum | cut -c-32 | sed 's/\(..\)/\\x\1/g')" | \
|
pascal@17562
|
552 ddq bs=16 seek=2047 conv=notrunc of=$1
|
pascal@17496
|
553 fi
|
pascal@18670
|
554 if [ "$append$initrd" ]; then
|
pascal@18670
|
555 echo -n "Adding custom config... "
|
pascal@18676
|
556 DATA=/tmp/$(basename $0)$$
|
pascal@18670
|
557 rm -f $DATA > /dev/null
|
pascal@18672
|
558 isosz=$(stat -c %s $1)
|
pascal@18670
|
559 [ "$append" ] && echo "append=$append" >> $DATA
|
pascal@18670
|
560 [ -s "$initrd" ] && echo "initrd:$(stat -c %s $initrd)" >> $DATA &&
|
pascal@18670
|
561 cat $initrd >> $DATA
|
pascal@18670
|
562 echo "#!boot $(md5sum $DATA | sed 's/ .*//')" | cat - $DATA | \
|
pascal@18672
|
563 ddq bs=2k seek=$(custom_config_sector $1) of=$1 conv=notrunc
|
pascal@19027
|
564 newsz=$(stat -c %s $1)
|
pascal@19258
|
565 for i in 0 1 2 3 ; do
|
pascal@19257
|
566 [ $(get $((0x1BE+16*i)) $1 4) == $((0x00010080)) ] || continue
|
pascal@19027
|
567 mb=$(((($newsz -1)/1024/1024)+1))
|
pascal@19027
|
568 h=$((512*$(get 417 "$1" 1)))
|
pascal@19358
|
569 store $((0x1C5+16*i)) $(($mb-1)) $1 8
|
pascal@19358
|
570 store $(($h+0x1C5+16*i)) $(($mb-1)) $1 8
|
pascal@19358
|
571 store $((0x1CA+16*i)) $(($mb*2048)) $1 32
|
pascal@19358
|
572 store $(($h+0x1CA+16*i)) $(($mb*2048)) $1 32
|
pascal@19027
|
573 done
|
pascal@19027
|
574 if [ $newsz -gt $isosz ]; then
|
pascal@19027
|
575 echo "$(($newsz - $isosz)) extra bytes."
|
pascal@18670
|
576 else
|
pascal@19324
|
577 echo "$(($isosz - 2048*$(get 32848 $1 4)
|
pascal@18670
|
578 - $(stat -c %s $DATA) - 24)) bytes free."
|
pascal@18670
|
579 fi
|
pascal@18670
|
580 rm -f $DATA > /dev/null
|
pascal@18670
|
581 fi
|
pascal@19027
|
582 echo -n "Adding boot checksum..."
|
pascal@19027
|
583 if [ $(stat -c %s $1) -gt 32768 ]; then
|
pascal@19027
|
584 n=$(($(get 2 $1) - 1 + ($(get 4 $1) - 1)*512))
|
pascal@19027
|
585 n=$(($(od -v -N $n -t u2 -w2 -An $1 | \
|
pascal@19027
|
586 awk '{ i+= $0 } END { print (i % 65536) }') \
|
pascal@19027
|
587 + $(get $(($n+1)) $1 1)))
|
pascal@19027
|
588 store 18 $(( (-$n -1) % 65536 )) $1
|
pascal@19027
|
589 fi
|
pascal@19027
|
590 echo " done."
|
pascal@13691
|
591 }
|
pascal@13691
|
592
|
pascal@18672
|
593 main "$@" <<EOT
|