wok-next rev 17496

syslinux/iso2exe: check ISO md5 (again)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Jan 05 12:38:18 2015 +0100 (2015-01-05)
parents d8c3590387b5
children c8d571ac0076
files syslinux/stuff/iso2exe/README syslinux/stuff/iso2exe/bootiso.S syslinux/stuff/iso2exe/init syslinux/stuff/iso2exe/iso2exe.sh
line diff
     1.1 --- a/syslinux/stuff/iso2exe/README	Sun Jan 04 11:37:00 2015 +0000
     1.2 +++ b/syslinux/stuff/iso2exe/README	Mon Jan 05 12:38:18 2015 +0100
     1.3 @@ -55,6 +55,8 @@
     1.4      +-----------------+
     1.5      |    untouched    | ISO9660 files including /boot/bzImage and /boot/rootfs*
     1.6  32K +-----------------+
     1.7 +    |       | iso md5 | ISO9660 image (except first 32K) md5 hash
     1.8 +    |       +---------+
     1.9      |  DOS .EXE stub  | Start DOS .COM loader
    1.10      +-----------------+
    1.11      |  ISO initramfs  | Live loader and UMSDOS like install script
     2.1 --- a/syslinux/stuff/iso2exe/bootiso.S	Sun Jan 04 11:37:00 2015 +0000
     2.2 +++ b/syslinux/stuff/iso2exe/bootiso.S	Mon Jan 05 12:38:18 2015 +0100
     2.3 @@ -26,24 +26,23 @@
     2.4  	.word	0			// File address of relocation table
     2.5  id:
     2.6  	.word	0			// Overlay number
     2.7 -fdcnt:
     2.8 +fdcnt:					// File address of relocation table
     2.9  	.byte	0			// Bootstrap floppy sector count
    2.10  
    2.11  /////////////////////// Master Boot Record code //////////////////////////////
    2.12  
    2.13 -start0:					// File address of relocation table
    2.14 -	pushw	%dx			// restore SP
    2.15 +start0:
    2.16 +	pushw	%dx			// restore %sp
    2.17  	incw	%bp			// restore %bp
    2.18 -	pushw	$0
    2.19 -	popw	%ds
    2.20 -	movw	$0x7C00, %bx
    2.21 -	pushfw
    2.22 -	pushw	%ds
    2.23 -	pushw	%bx
    2.24 +	xorw	%bx, %bx
    2.25 +	movw	%bx, %ds
    2.26 +	movb	$0x7C, %bh
    2.27 +	pushw	%bx			// return address
    2.28  	pushaw
    2.29  	movw	%sp, %bp
    2.30 -	pushw	%es
    2.31 +	pushw	%es			// save %es:%di
    2.32  	cld
    2.33 +	sti
    2.34  	pushw	%ds
    2.35  	popw	%es
    2.36  	call	setreg
    2.37 @@ -60,9 +59,11 @@
    2.38  comstart:
    2.39  	.word	0
    2.40  	
    2.41 -readsectorX:
    2.42 -	movb	$0, %cl
    2.43 +	.org	68
    2.44 +readsectorX:				// read isolinux boot sector
    2.45 +	movb	$0xA5, %cl		// patched by installer
    2.46  readsector1:
    2.47 +	andb	$0x83, %dl		// disk and floppy disk
    2.48  	movw	%cx, (%bx)
    2.49  	incw	%cx
    2.50  	movw	$0x201, %ax
    2.51 @@ -73,52 +74,52 @@
    2.52  	movw	$0x0100, %cx
    2.53  return:
    2.54  	ret
    2.55 +dxloop:
    2.56  start2:
    2.57 -dxloop:
    2.58 -	call	readsector1
    2.59 +	call	readsector1		// look for the boot device
    2.60  	repe
    2.61  	cmpsw
    2.62  	je	dxfound
    2.63 -next:
    2.64 -	xorw	%cx, %cx
    2.65 -	xchgw	%ax, %dx
    2.66 -	addb	$0x7D, %al		// try every hard disk
    2.67 -	andb	$0x83, %al		//   and floppy disk
    2.68 -	cmpb	$0x80, %al
    2.69 -	xchgw	%ax, %dx
    2.70 -	jnz	dxloop
    2.71 +	movb	$0, %cl			// ch = 0
    2.72 +	addb	$0x7D, %dl		// try every hard disk
    2.73 +	jno	dxloop
    2.74  dxfound:
    2.75 +	call	readsectorX		// read isolinux boot sector
    2.76  	movw	%dx, 10(%bp)
    2.77  	call	checkboot
    2.78 -	.ascii	"No isolinux mbr."
    2.79 +	.asciz	"No isolinux bs"
    2.80  
    2.81  	.org	0x0080
    2.82  ////////////////////////////// EXE/PE header //////////////////////////////////
    2.83  
    2.84  	.org	0x01A0
    2.85  checkboot:
    2.86 -	call	readsectorX
    2.87 -	lodsw
    2.88 +	cmpw	%cx, (%bx)
    2.89  	popw	%si
    2.90 -	shrw	$1, %ax
    2.91 -	jz	error			// read fail or not isohydrid
    2.92 +	jc	error			// read fail or no isohydrid boot sector
    2.93  	popw	%es
    2.94  	popa
    2.95 -	iret
    2.96 -
    2.97 -error:
    2.98 -	lodsb
    2.99 +putsret:
   2.100 +	ret
   2.101 +putstrlp:
   2.102  	movw	$7, %bx
   2.103  	movb	$0xE, %ah
   2.104  	int	$0x10
   2.105 -	cmp	$'.', %al
   2.106 -	jne	error
   2.107 +error:
   2.108 +	lodsb
   2.109 +	cmp	$1, %al
   2.110 +	jg	putstrlp
   2.111 +	jz	putsret
   2.112 +putstr:
   2.113 +	movb	$0x80, %ah
   2.114 +	xchgw	%ax, %si
   2.115 +	jnc	error
   2.116  halt:
   2.117  	hlt
   2.118  	jmp	halt
   2.119  	.org	0x01BE
   2.120  
   2.121 -	.org	0x7EE0
   2.122 +	.org	0x7F10
   2.123  ////////////////////////////// DOS EXE code ///////////////////////////////////
   2.124  
   2.125  exestart:
   2.126 @@ -137,10 +138,6 @@
   2.127  	cmpb	$3, %al
   2.128  	movb	$EXESTR(noDOS3), %al
   2.129  	jb	abort
   2.130 -#if 1
   2.131 -	cmpw	(%si), %dx	// checksum not set
   2.132 -	je	chked
   2.133 -#endif
   2.134  	movw	$(EXELOC(0x8000))/2, %cx
   2.135  chklp:
   2.136  	lodsw
   2.137 @@ -151,17 +148,8 @@
   2.138  	je	tst386		// dx == 0 ?
   2.139  abort:
   2.140  puts:
   2.141 -	movb	$0x80, %ah
   2.142 -	xchgw	%ax, %si
   2.143 -putslp:
   2.144 -	lodsb
   2.145 -	orb	%al, %al
   2.146 -	jz	moveret
   2.147 -	js	puts
   2.148 -	movw	$7, %bx
   2.149 -	movb	$0xE, %ah
   2.150 -	int	$0x10
   2.151 -	jmp	putslp
   2.152 +	clc
   2.153 +	jmp	putstr
   2.154  
   2.155  tst386:
   2.156  	pushfw			// save flags
   2.157 @@ -200,13 +188,12 @@
   2.158  	movb	$0x7C/2, %ch	// 31K-31.5K, > com length
   2.159  	rep
   2.160  	movsw
   2.161 -moveret:
   2.162  	ret
   2.163  
   2.164  VersionVCPI:
   2.165  	cmpb	$0x40, %dl		// >= 4.0 ?
   2.166  	jb	NoVCPI
   2.167 -	movb	$EXESTR(vm86modemsg), %al
   2.168 +	xchgw	%ax, %si		// movb	$EXESTR(vm86modemsg), %al
   2.169  	jmp	realmode
   2.170  tstvcpi:
   2.171  	pushw	%ds
   2.172 @@ -238,48 +225,42 @@
   2.173  	.byte	0x46			// version
   2.174  	.byte	0
   2.175  
   2.176 +vm86modemsg:
   2.177  // --------------- Must be in 7F40 7FFF range ------------------------
   2.178 -//noloader:
   2.179 -//	.ascii	"No isol"		// No isolinux boot loader
   2.180 -//	.byte	EXESTR(iloader)
   2.181 -no386:
   2.182 -	.ascii	"No 386"		// No 386+
   2.183 -	.byte	EXESTR(plus)
   2.184 +	.ascii	"vm"			// vm86
   2.185 +	.byte	EXESTR(_86)
   2.186  ERRvcpi:
   2.187 -	.ascii	"No EMM386/VCPI 4"	// No EMM386/VCPI 4.0+
   2.188 -	.byte	EXESTR(dot0)
   2.189 +	.ascii	"No VCPI-4.0/EMM"	// No VCPI-4.0/EMM386
   2.190 +	.byte	EXESTR(_386)
   2.191 +noDOS3:
   2.192 +	.ascii	"No DOS 3"		// No DOS 3
   2.193 +	.byte	EXESTR(eol)
   2.194  chkerr:
   2.195 -	.ascii	"Broken ISO9660 fil"	// Broken ISO9660 file.
   2.196 -	.byte	EXESTR(eeol)
   2.197 -vm86modemsg:
   2.198 -	.ascii	"vm86"			// vm86 mode.
   2.199 -	.byte	EXESTR(mode)
   2.200 +	.ascii	"Broken c"		// Broken code
   2.201 +	.byte	EXESTR(ode)
   2.202  rmPaging:
   2.203 -	.ascii	"Invalid: paging + "	// Invalid: paging + real mode.
   2.204 +	.ascii	"Un"			// Unreal mode
   2.205  realmodemsg:
   2.206 -	.ascii	"real"			// real mode.
   2.207 +	.ascii	"real m"		// real mode
   2.208  // --------------- Must be in 7FC0 7FFF range ------------------------
   2.209 -mode:
   2.210 -	.ascii	" mod"
   2.211 +ode:
   2.212 +	.ascii	"od"
   2.213  eeol:
   2.214  	.ascii  "e"
   2.215  	.byte	EXESTR(eol)
   2.216 -noDOS3:
   2.217 -	.ascii	"No DOS 3"		// No DOS 3.0+
   2.218 -dot0:
   2.219 -	.ascii	".0"
   2.220 -plus:
   2.221 -	.ascii	"+"
   2.222 -	.byte	EXESTR(eol2)
   2.223 +no386:
   2.224 +	.ascii	"No "			// No 386
   2.225 +_386:
   2.226 +	.ascii	"3"
   2.227 +_86:
   2.228 +	.ascii	"86"
   2.229 +	.byte	EXESTR(eol)
   2.230  help:
   2.231 -	.ascii	"SliTaz GNU/L"		// SliTaz GNU/Linux boot loader
   2.232 -iloader:
   2.233 -	.ascii	"inux boot loader"
   2.234 +	.ascii	"SliTaz boot loader"	// SliTaz boot loader
   2.235  eol:
   2.236 -	.ascii	"."
   2.237 -eol2:
   2.238 -	.asciz	"\r\n"
   2.239 +	.ascii	"\r\n"
   2.240 +	.byte	1
   2.241  
   2.242 +	.space	16,0			// ISO md5
   2.243  	.org	0x8000
   2.244  ////////////////////////// ISO9660 header /////////////////////////////////////
   2.245 -
     3.1 --- a/syslinux/stuff/iso2exe/init	Sun Jan 04 11:37:00 2015 +0000
     3.2 +++ b/syslinux/stuff/iso2exe/init	Mon Jan 05 12:38:18 2015 +0100
     3.3 @@ -1,7 +1,6 @@
     3.4  #!/bin/sh
     3.5  
     3.6  DIALOG=dialog
     3.7 -ISOMD5=
     3.8  
     3.9  ddq()
    3.10  {
    3.11 @@ -10,8 +9,8 @@
    3.12  
    3.13  get()
    3.14  {
    3.15 -	od -j $1 -N ${4:-${3:-2}} -t u${3:-2} -An $2 2> /dev/null ||
    3.16 -	hexdump -v -s $1 -n ${4:-${3:-2}} -e "\"\" 1/${3:-2} \" %d\"" $2
    3.17 +	od -v -j $1 -N ${4:-${3:-2}} -t u${3:-2} -w${3:-2} -An $2 2>/dev/null ||
    3.18 +	hexdump -v -s $1 -n ${4:-${3:-2}} -e "\"\" 1/${3:-2} \" %d\n\"" $2
    3.19  }
    3.20  
    3.21  getarg()
    3.22 @@ -638,17 +637,23 @@
    3.23  
    3.24  gotisomd5()
    3.25  {
    3.26 -	[ "$(which md5sum 2> /dev/null)" ] && [ "$ISOMD5" ] &&
    3.27 -	echo -en "\"$1\"	\"$2\""
    3.28 +	[ $(get 18 /dev/loop0) -ne 0 ] && echo -en "\"$1\"	\"$2\""
    3.29  }
    3.30  
    3.31  isomd5()
    3.32  {
    3.33  	dotwait "Checking iso image"
    3.34 -	[ "$(ddq if=/dev/loop0 bs=32k skip=1 | md5sum)" == "$ISOMD5  -" ] &&
    3.35 +	[ "$(ddq if=/dev/loop0 bs=32k skip=1 | md5sum)" == \
    3.36 +	  "$(ddq if=/dev/loop0 bs=16 count=1 skip=2047 | od -N 16 -t x1 -An | \
    3.37 +	     sed 's/ //g')  -" ] && echo "OK" || echo "ERROR"
    3.38 +	echo -n "Checking iso hybrid boot"
    3.39 +	n=$(($(get 2 /dev/loop0)-1+($(get 4 /dev/loop0)-1)*512))
    3.40 +	s=$(get 0 /dev/loop0 2 $n | awk '{ i+= $0 } END { print i }')
    3.41 +	[ $(((1+$s+$(get $(($n+1)) /dev/loop0 1)) % 65536)) -eq 0 ] &&
    3.42  	echo "OK" || echo "ERROR"
    3.43  	rm -f /tmp/wait
    3.44 -	sleep 5
    3.45 +	echo "Press RETURN to continue."
    3.46 +	read n
    3.47  }
    3.48  
    3.49  fdbootstrap()
    3.50 @@ -729,7 +734,7 @@
    3.51  	done ) > $device
    3.52  
    3.53  	# partition + fat32 format for the remining space
    3.54 -	get 446 $device 2 12 | { read dx cx ol oh ll lh 
    3.55 +	get 446 $device 2 12 | xargs echo | { read dx cx ol oh ll lh 
    3.56  	if [ $dx -eq $((0x3F17)) ]; then
    3.57  		cx=$(($cx & 0xFF00))
    3.58  		ofs=$(($ll+($lh<<16)))
     4.1 --- a/syslinux/stuff/iso2exe/iso2exe.sh	Sun Jan 04 11:37:00 2015 +0000
     4.2 +++ b/syslinux/stuff/iso2exe/iso2exe.sh	Mon Jan 05 12:38:18 2015 +0100
     4.3 @@ -37,11 +37,6 @@
     4.4  	mkdir -p $TMP/bin $TMP/dev
     4.5  	cp -a /dev/?d?* /dev/tty /dev/tty0 $TMP/dev
     4.6  	$0 --get init > $TMP/init.exe
     4.7 -	if [ $(stat -c %s $1) -gt 32768 ]; then
     4.8 -		echo "Compute ISO image md5 ..."
     4.9 -		sed -i "s/^ISOMD5.*/ISOMD5=$(ddq if=$1 bs=32k skip=1 | \
    4.10 -			md5sum | cut -c-32)/" $TMP/init.exe
    4.11 -	fi
    4.12  #	mount -o loop,ro $1 $TMP
    4.13  #	oldslitaz="$(ls $TMP/boot/isolinux/splash.lss 2> /dev/null)"
    4.14  #	umount -d $TMP
    4.15 @@ -242,9 +237,21 @@
    4.16  	add_fdbootstrap $1
    4.17  	printf "%d free bytes in %04X..%04X\n" $(($OFS-$HOLE)) $HOLE $OFS
    4.18  	store 26 ${RANDOM:-0} $1
    4.19 -	echo -n "Adding checksum..."
    4.20 +	if [ $(stat -c %s $1) -gt 32768 ]; then
    4.21 +		echo "Adding ISO image md5 ..."
    4.22 +		echo -en "$(ddq if=$1 bs=32k skip=1 | md5sum | cut -c-32 | sed \
    4.23 +		  's/\(..\)/\\x\1/g')" | ddq bs=16 seek=2047 conv=notrunc of=$1
    4.24 +	fi
    4.25 +	echo -n "Adding boot checksum..."
    4.26  	store 64 $(od -v -j 66 -N 32702 -t u2 -w2 -An $1 | \
    4.27  		   awk '{ i+= $0 } END { print -(i % 65536) }') $1
    4.28 +	if [ $(stat -c %s $1) -gt 32768 ]; then
    4.29 +		n=$(($(get 2 $1) - 1 + ($(get 4 $1) - 1)*512))
    4.30 +		n=$(($(od -v -N $n -t u2 -w2 -An $1 | \
    4.31 +		       awk '{ i+= $0 } END { print (i % 65536) }') \
    4.32 +		     + $(get $(($n+1)) $1 1)))
    4.33 +		store 18 $(( (-$n -1) % 65536 )) $1
    4.34 +	fi
    4.35  	echo " done."
    4.36  }
    4.37