wok rev 14150

syslinux: add isohybrid.exe
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Mar 04 09:52:12 2013 +0100 (2013-03-04)
parents 8819aef2cbc9
children ab3f0098073a
files syslinux-tools/receipt syslinux/stuff/iso2exe/Makefile syslinux/stuff/iso2exe/bootiso.S syslinux/stuff/iso2exe/iso2exe.c syslinux/stuff/iso2exe/iso2exe.sh syslinux/stuff/iso2exe/mvcom.S
line diff
     1.1 --- a/syslinux-tools/receipt	Mon Mar 04 09:49:43 2013 +0000
     1.2 +++ b/syslinux-tools/receipt	Mon Mar 04 09:52:12 2013 +0100
     1.3 @@ -12,9 +12,10 @@
     1.4  # Rules to gen a SliTaz package suitable for Tazpkg.
     1.5  genpkg_rules()
     1.6  {
     1.7 -	mkdir -p $fs/usr/bin
     1.8 +	mkdir -p $fs/usr/bin $fs/usr/share/boot
     1.9  	for i in keytab-lilo lss16toppm ppmtolss16 mkdiskimage \
    1.10  		 syslinux2ansi isohybrid ; do
    1.11  		cp -a $src/utils/$i $fs/usr/bin
    1.12  	done
    1.13 +	cp -a $src/iso2exe/isohybrid.exe $fs/usr/share/boot
    1.14  }
     2.1 --- a/syslinux/stuff/iso2exe/Makefile	Mon Mar 04 09:49:43 2013 +0000
     2.2 +++ b/syslinux/stuff/iso2exe/Makefile	Mon Mar 04 09:52:12 2013 +0100
     2.3 @@ -2,11 +2,27 @@
     2.4  BCC=bcc -ansi -O -0 -C-t
     2.5  BCCFLAGS=-D__MSDOS__ -Md
     2.6  
     2.7 +all: isohybrid.exe iso2exe
     2.8 +
     2.9  iso2exe: iso2exe.sh boot.com bootiso.bin init win32.exe
    2.10  	cp iso2exe.sh $@
    2.11  	chmod +x $@
    2.12  	./$@ --build boot.com bootiso.bin init win32.exe
    2.13  
    2.14 +iso2exe.h: iso2exe ../mbr/isohdpfx.bin
    2.15 +	chmod +x iso2exe.sh
    2.16 +	./iso2exe.sh --array ../mbr/isohdpfx.bin > $@
    2.17 +
    2.18 +iso2exe.com: iso2exe.c iso2exe.h
    2.19 +	$(BCC) $(BCCFLAGS) -o $@ iso2exe.c
    2.20 +
    2.21 +iso2exe.exe: iso2exe.c iso2exe.h
    2.22 +	i586-pc-mingw32-gcc -s -o $@ iso2exe.c -lws2_32
    2.23 +
    2.24 +isohybrid.exe: iso2exe.sh mvcom.bin iso2exe.com iso2exe.exe
    2.25 +	./iso2exe.sh --exe mvcom.bin iso2exe.com iso2exe.exe > $@
    2.26 +	chmod +x $@
    2.27 +
    2.28  OBJS = boot.o iso9660.o libdos.o bootlinux.o
    2.29  boot.com: $(OBJS)
    2.30  	$(BCC) $(BCCFLAGS) -o $@ $(OBJS) &&  upx --ultra-brute $@
    2.31 @@ -21,7 +37,7 @@
    2.32  
    2.33  win32.exe: win32.c
    2.34  	i586-pc-mingw32-gcc -s -o $@ $< -lws2_32 && upx --ultra-brute $@
    2.35 -	
    2.36 +
    2.37  %.o: %.c
    2.38  	$(BCC) $(BCCFLAGS) -A-l -A$*.lst -c -o $@ $<
    2.39  
     3.1 --- a/syslinux/stuff/iso2exe/bootiso.S	Mon Mar 04 09:49:43 2013 +0000
     3.2 +++ b/syslinux/stuff/iso2exe/bootiso.S	Mon Mar 04 09:52:12 2013 +0100
     3.3 @@ -196,9 +196,9 @@
     3.4  	movl	%cr0, %eax
     3.5  	andb	$1, %al
     3.6  	jne	tstvcpi
     3.7 -	shll	$1, %eax
     3.8 +	incl	%eax
     3.9  	movb	$EXESTR(rmPaging), %al
    3.10 -	jc	abort
    3.11 +	js	abort
    3.12  	movb	$EXESTR(realmodemsg), %al
    3.13  realmode:
    3.14  	call	puts
    3.15 @@ -207,16 +207,15 @@
    3.16  	cmpb	$3, %al
    3.17  	movb	$EXESTR(noDOS3), %al
    3.18  	jb	abort
    3.19 -	movw	EXEADRS(comstart), %ax			// .com address
    3.20  	movw	$moveend-move, %cx
    3.21 -	movw	$EXEADRS(move), %si
    3.22  	movw	$0xC000, %di
    3.23 -	jmp	move2
    3.24 +	call	move2
    3.25  move:
    3.26  	movb	$0x80, %ch
    3.27 -	xchgw	%ax, %si
    3.28  	movw	$0x0100, %di
    3.29 +	pushw	comstart-end_header(%di)		// .com address
    3.30  move2:
    3.31 +	popw	%si
    3.32  	pushw	%di
    3.33  	rep
    3.34  	movsb
    3.35 @@ -234,21 +233,15 @@
    3.36  	movw	%cx, %ds		// %cx = 0
    3.37  	movw	0x67*4+2, %ds
    3.38  	movw	$10, %si
    3.39 -	lodsw
    3.40 +	lodsl
    3.41  	xorw	$0x4D45, %ax		// EM(MX) or EM(MQ)
    3.42 -	xchgw	%ax, %dx
    3.43 -	lodsw				// si += 2
    3.44 -	lodsw
    3.45 -	xorw	$0x5858, %ax		// XX
    3.46 -	orw	%ax, %dx
    3.47 -	lodsw
    3.48 +	lodsl
    3.49  	popw	%ds
    3.50 -	xorw	$0x3058, %ax		// X0
    3.51 -	orw	%ax, %dx
    3.52 +	jne	NoVCPI
    3.53 +	xorl	$0x30585858, %eax	// XXX0
    3.54  	movw	$EXEADRS(CmdVCPI), %si
    3.55  ChkVCPI:
    3.56  NoVCPI:
    3.57 -	xchgw	%ax, %dx
    3.58  	movb	$EXESTR(ERRvcpi), %al
    3.59  	jne	abort
    3.60  	lodsb
    3.61 @@ -256,6 +249,7 @@
    3.62  	je	VersionVCPI
    3.63  	int	$0x67
    3.64  	testb	%ah, %ah
    3.65 +	xchgw	%ax, %dx
    3.66  	jmp	ChkVCPI
    3.67  CmdVCPI:
    3.68  	.byte	0x40			// status
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/syslinux/stuff/iso2exe/iso2exe.c	Mon Mar 04 09:52:12 2013 +0100
     4.3 @@ -0,0 +1,92 @@
     4.4 +#include <sys/types.h>
     4.5 +#include <fcntl.h>
     4.6 +#include <stdio.h>
     4.7 +#include "iso2exe.h"
     4.8 +
     4.9 +static int fd;
    4.10 +static char buffer[2048];
    4.11 +
    4.12 +static void quit(char *msg)
    4.13 +{
    4.14 +	fprintf(stderr,"%s.\n", msg);
    4.15 +	exit(1);
    4.16 +}
    4.17 +
    4.18 +static void readsector(unsigned long sector)
    4.19 +{
    4.20 +	if (lseek(fd, sector * sizeof(buffer), SEEK_SET) == -1 ||
    4.21 +	    read(fd, buffer, sizeof(buffer)) != sizeof(buffer))
    4.22 +		quit("read sector failure");
    4.23 +}
    4.24 +
    4.25 +int main(int argc, char *argv[])
    4.26 +{
    4.27 +#define heads 64
    4.28 +#define sectors 32
    4.29 +#define partition 446
    4.30 +#define trksz (512 * heads * sectors)
    4.31 +	unsigned long size, catalog, lba;
    4.32 +	int cylinders, i, j;
    4.33 +	unsigned n;
    4.34 +#ifndef WIN32
    4.35 +	char *bootiso;
    4.36 +	for (bootiso = (char *) main;
    4.37 +	     bootiso[0] != 'M' || bootiso[1] != 'Z' || bootiso[2] != 0xEB;
    4.38 +	     bootiso++) if (bootiso < (char *) main) quit("bootiso not found");
    4.39 +#endif
    4.40 +	if (argc < 2)
    4.41 +		quit("Usage : isohybrid.exe file.iso");
    4.42 +	fd = open(argv[1],O_RDWR|O_BINARY);
    4.43 +	if (fd == -1)
    4.44 +		quit("Can't open rw");
    4.45 +
    4.46 +	// Install hybridiso boot sector
    4.47 +	readsector(17UL);
    4.48 +	if (strncmp(buffer+7, "EL TORITO SPECIFICATION", 23))
    4.49 +		quit("No EL TORITO boot record found");
    4.50 +	catalog = * (unsigned long *) (buffer + 71);
    4.51 +	readsector(catalog);
    4.52 +	if (* (unsigned long *) buffer != 1 || 
    4.53 +	    * (unsigned long *) (buffer + 30) != 0x88AA55)
    4.54 +	    	quit("invalid boot catalog.");
    4.55 +	lba = * (unsigned long *) (buffer + 40);
    4.56 +	readsector(lba);
    4.57 +	if (* (unsigned long *) (buffer + 64) != 1886961915)
    4.58 +		quit("no isolinux.bin hybrid signature in bootloader");
    4.59 +	* (unsigned long *)  &bootiso[512 + 432] = lba * 4;
    4.60 +	* (unsigned long *)  &bootiso[512 + 440] = rand();
    4.61 +	* (unsigned long *)  &bootiso[512 + partition] = 0x10080;
    4.62 +	* (unsigned short *) &bootiso[512 + 510] = 0xAA55;
    4.63 +	size = lseek(fd, 0, SEEK_END);
    4.64 +	cylinders = (size + trksz - 1) / trksz;
    4.65 +	bootiso[512 + partition + 4] = 23; // "Windows hidden IFS"
    4.66 +	bootiso[512 + partition + 5] = heads - 1;
    4.67 +	bootiso[512 + partition + 6] = (((cylinders - 1) & 0x300) >> 2) + sectors;
    4.68 +	bootiso[512 + partition + 7] = (cylinders - 1) & 0xFF;
    4.69 +	* (unsigned long *) &bootiso[512 + partition + 8] = 0;
    4.70 +	* (unsigned long *) &bootiso[512 + partition + 12] = cylinders * sectors * heads;
    4.71 +
    4.72 +	// Install iso2exe boot sector
    4.73 +	memcpy(bootiso + 512 - 66, bootiso + 1024 - 66, 66); 
    4.74 +	* (unsigned short *) (bootiso + 26) = rand();
    4.75 +
    4.76 +	// Update iso image
    4.77 +	lseek(fd, 0, SEEK_SET);
    4.78 +	write(fd, bootiso, 1024);
    4.79 +	lseek(fd, 0x8400 - BOOTISOSZ, SEEK_SET);
    4.80 +	write(fd, bootiso + 1024, BOOTISOSZ - 1024);
    4.81 +
    4.82 +	// Compute the checksum
    4.83 +	lseek(fd, 0, SEEK_SET);
    4.84 +	for (i = 66, n = 0, j = 0; j < 16; j++, i = 0) {
    4.85 +		if (read(fd, buffer, sizeof(buffer)) != sizeof(buffer))
    4.86 +			goto nochksum;
    4.87 +		for (; i < sizeof(buffer); i += 2)
    4.88 +			n += * (unsigned short *) (buffer + i);
    4.89 +	}
    4.90 +	* (unsigned short *) (bootiso + 64) = -n;
    4.91 +	lseek(fd, 0, SEEK_SET);
    4.92 +	write(fd, bootiso, 512);
    4.93 +nochksum:
    4.94 +	close(fd);
    4.95 +}
     5.1 --- a/syslinux/stuff/iso2exe/iso2exe.sh	Mon Mar 04 09:49:43 2013 +0000
     5.2 +++ b/syslinux/stuff/iso2exe/iso2exe.sh	Mon Mar 04 09:52:12 2013 +0100
     5.3 @@ -1,16 +1,4 @@
     5.4  #!/bin/sh
     5.5 -if [ "$1" == "--build" ]; then
     5.6 -	shift
     5.7 -	[ $(tar cf - $@ | wc -c) -gt $((32 * 1024)) ] &&
     5.8 -		echo "The file set $@ is too large (31K max) :" &&
     5.9 -		ls -l $@ && exit 1
    5.10 -	cat >> $0 <<EOM
    5.11 -$(tar cf - $@ | lzma e -si -so | uuencode -m -)
    5.12 -EOT
    5.13 -EOM
    5.14 -	sed -i '/--build/,/^fi/d' $0
    5.15 -	exit
    5.16 -fi
    5.17  
    5.18  ddq()
    5.19  {
    5.20 @@ -30,28 +18,8 @@
    5.21  	echo $(od -j $(($1)) -N ${3:-2} -t u${3:-2} -An $2)
    5.22  }
    5.23  
    5.24 -main()
    5.25 +add_rootfs()
    5.26  {
    5.27 -	case "$1" in
    5.28 -	--get)	shift
    5.29 -		uudecode | unlzma | tar xOf - $@
    5.30 -		exit ;;
    5.31 -	*)	cat > /dev/null
    5.32 -	esac
    5.33 -	
    5.34 -	[ ! -s "$1" ] && echo "usage: $0 image.iso" 1>&2 && exit 1
    5.35 -	case "$(od -N 2 -t x2 -An $1)" in
    5.36 -	*5a4d)	echo "The file $1 is already an EXE file." 1>&2 && exit 1;;
    5.37 -	*0000)	[ -x /usr/bin/isohybrid ] && isohybrid $1
    5.38 -	esac
    5.39 -		
    5.40 -	echo "Moving syslinux hybrid boot record..."
    5.41 -	ddq if=$1 bs=512 count=1 | ddq of=$1 bs=512 count=1 seek=1 conv=notrunc 
    5.42 -	
    5.43 -	echo "Inserting EXE boot record..."
    5.44 -	$0 --get bootiso.bin | ddq of=$1 conv=notrunc
    5.45 -
    5.46 -	# keep the largest room for the tazlito info file
    5.47  	TMP=/tmp/iso2exe$$
    5.48  	mkdir -p $TMP/bin $TMP/dev
    5.49  	cp -a /dev/?d?* $TMP/dev
    5.50 @@ -67,24 +35,113 @@
    5.51  	printf "Adding rootfs.gz file at %04X...\n" $OFS
    5.52  	cat $TMP/rootfs.gz | ddq of=$1 bs=1 seek=$OFS conv=notrunc
    5.53  	rm -rf $TMP
    5.54 +}
    5.55 +
    5.56 +add_doscom()
    5.57 +{
    5.58  	SIZE=$($0 --get boot.com | wc -c)
    5.59  	OFS=$(( $OFS - $SIZE ))
    5.60  	printf "Adding DOS boot file at %04X...\n" $OFS
    5.61  	$0 --get boot.com | ddq of=$1 bs=1 seek=$OFS conv=notrunc
    5.62  	store 66 $(($OFS+0xC0)) $1
    5.63 +}
    5.64 +
    5.65 +add_win32exe()
    5.66 +{
    5.67  	SIZE=$($0 --get win32.exe 2> /dev/null | tee /tmp/exe$$ | wc -c)
    5.68  	if [ $SIZE -ne 0 ]; then
    5.69  		OFS=$(( 128 + ( ($OFS - $SIZE + 128) & 0xFE00 ) ))
    5.70  		printf "Adding WIN32 file at %04X...\n" $OFS
    5.71  		LOC=$((0xAC+$(get 0x94 /tmp/exe$$)))
    5.72  		for i in $(seq 1 $(get 0x86 /tmp/exe$$)); do
    5.73 -			store $LOC $(($(get $LOC /tmp/exe$$)+$OFS-128)) /tmp/exe$$
    5.74 +			CUR=$(get $LOC /tmp/exe$$)
    5.75 +			[ $CUR -eq 0 ] || store $LOC $(($CUR+$OFS-128)) /tmp/exe$$
    5.76  			LOC=$(($LOC+40))
    5.77  		done
    5.78  		ddq if=/tmp/exe$$ of=$1 bs=1 skip=128 seek=$OFS conv=notrunc
    5.79  	fi
    5.80  	rm -f /tmp/exe$$ 
    5.81  	store 60 $OFS $1
    5.82 +}
    5.83 +case "$1" in
    5.84 +--build)
    5.85 +	shift
    5.86 +	[ $(tar cf - $@ | wc -c) -gt $((32 * 1024)) ] &&
    5.87 +		echo "The file set $@ is too large (31K max) :" &&
    5.88 +		ls -l $@ && exit 1
    5.89 +	cat >> $0 <<EOM
    5.90 +$(tar cf - $@ | lzma e -si -so | uuencode -m -)
    5.91 +EOT
    5.92 +EOM
    5.93 +	sed -i '/^case/,/^esac/d' $0
    5.94 +	exit ;;
    5.95 +--get)
    5.96 +	cat $2
    5.97 +	exit ;;
    5.98 +--array)
    5.99 +	DATA=/tmp/dataiso$$
   5.100 +	ddq if=/dev/zero bs=32k count=1 of=$DATA
   5.101 +	ddq if=bootiso.bin of=$DATA conv=notrunc
   5.102 +	ddq if=$2 of=$DATA bs=512 seek=1 conv=notrunc
   5.103 +	add_rootfs $DATA > /dev/null
   5.104 +	add_doscom $DATA > /dev/null
   5.105 +	add_win32exe $DATA > /dev/null
   5.106 +	cat <<EOT
   5.107 +
   5.108 +#define BOOTISOSZ $((0x8400 - $OFS))
   5.109 +
   5.110 +#ifdef WIN32
   5.111 +static char bootiso[] = {
   5.112 +$(hexdump -v -n 1024 -e '"    " 16/1 "0x%02X, "' -e '"  // %04.4_ax |" 16/1 "%_p" "| \n"' $DATA | sed 's/ 0x  ,/      /g')
   5.113 +$(hexdump -v -s $OFS -e '"    " 16/1 "0x%02X, "' -e '"  // %04.4_ax |" 16/1 "%_p" "| \n"' $DATA | sed 's/ 0x  ,/      /g')
   5.114 +};
   5.115 +#endif
   5.116 +EOT
   5.117 +	rm -rf $DATA
   5.118 +	exit ;;
   5.119 +--exe)
   5.120 +	# --exe mvcom.bin x.com y.exe > xy.exe
   5.121 +	cat $4 $3 > /tmp/exe$$
   5.122 +	S=$(stat -c %s /tmp/exe$$)
   5.123 +	store 2 $(($S%512)) /tmp/exe$$
   5.124 +	store 4 $((($S+511)/512)) /tmp/exe$$
   5.125 +	store 14 -16 /tmp/exe$$
   5.126 +	store 16 -2 /tmp/exe$$
   5.127 +	store 20 256 /tmp/exe$$
   5.128 +	store 22 -16 /tmp/exe$$
   5.129 +	ddq if=$2 bs=1 seek=64 of=/tmp/exe$$ conv=notrunc
   5.130 +	store 65 $(stat -c %s $3) /tmp/exe$$
   5.131 +	store 68 $((0x100-0x40+$(stat -c %s $4))) /tmp/exe$$
   5.132 +	cat /tmp/exe$$
   5.133 +	rm -f /tmp/exe$$
   5.134 +	exit ;;
   5.135 +esac
   5.136 +
   5.137 +main()
   5.138 +{
   5.139 +	case "$1" in
   5.140 +	--get)	shift
   5.141 +		uudecode | unlzma | tar xOf - $@
   5.142 +		exit ;;
   5.143 +	*)	cat > /dev/null
   5.144 +	esac
   5.145 +	
   5.146 +	[ ! -s "$1" ] && echo "usage: $0 image.iso" 1>&2 && exit 1
   5.147 +	case "$(get 0 $1)" in
   5.148 +	23117)	echo "The file $1 is already an EXE file." 1>&2 && exit 1;;
   5.149 +	0)	[ -x /usr/bin/isohybrid ] && isohybrid $1
   5.150 +	esac
   5.151 +		
   5.152 +	echo "Moving syslinux hybrid boot record..."
   5.153 +	ddq if=$1 bs=512 count=1 | ddq of=$1 bs=512 count=1 seek=1 conv=notrunc 
   5.154 +	
   5.155 +	echo "Inserting EXE boot record..."
   5.156 +	$0 --get bootiso.bin | ddq of=$1 conv=notrunc
   5.157 +
   5.158 +	# keep the largest room for the tazlito info file
   5.159 +	add_rootfs $1
   5.160 +	add_doscom $1
   5.161 +	add_win32exe $1
   5.162  	store 26 ${RANDOM:-0} $1
   5.163  	i=66
   5.164  	n=0
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/syslinux/stuff/iso2exe/mvcom.S	Mon Mar 04 09:52:12 2013 +0100
     6.3 @@ -0,0 +1,43 @@
     6.4 +	.text
     6.5 +	.code16
     6.6 +	
     6.7 +ORGCOM	=	0x100
     6.8 +
     6.9 +	.org	0
    6.10 +
    6.11 +	.globl	_start
    6.12 +_start:
    6.13 +	movw	$0, %si		// .com size
    6.14 +	movw	$0, %bx		// .com loc
    6.15 +#if 1
    6.16 +	pushw	%si
    6.17 +	leaw	1-64-256(%bx,%si), %cx
    6.18 +	leaw	(%bx,%si), %si
    6.19 +	movw	$0xF000, %di
    6.20 +	cmpw	%si, %di
    6.21 +	jc	skip
    6.22 +	std
    6.23 +	rep
    6.24 +	  movsb
    6.25 +	subw	%si, %di
    6.26 +	addw	%di, %bx
    6.27 +skip:
    6.28 +	popw	%si
    6.29 +#endif
    6.30 +	movw	$done-install, %cx
    6.31 +	leaw	(%bx,%si), %di
    6.32 +	pushw	%si
    6.33 +	call	move
    6.34 +install:
    6.35 +	popw	%cx
    6.36 +	movw	$ORGCOM, %di
    6.37 +	pushw	%bx
    6.38 +move:
    6.39 +	popw	%si
    6.40 +	pushw	%di
    6.41 +	cld
    6.42 +	rep
    6.43 +	  movsb
    6.44 +	ret
    6.45 +done:
    6.46 +//	.org	64