# HG changeset patch # User Pascal Bellard # Date 1418815520 -3600 # Node ID aca562aa836e59d0f9b78216719b8a5eb6e2e7ee # Parent 799c2ec31b047d6acd5a45b1cd32473ac199f7e1 syslinux/iso2exe: add --undo diff -r 799c2ec31b04 -r aca562aa836e syslinux/stuff/iso2exe/iso2exe.c --- a/syslinux/stuff/iso2exe/iso2exe.c Tue Dec 16 18:59:28 2014 +0100 +++ b/syslinux/stuff/iso2exe/iso2exe.c Wed Dec 17 12:25:20 2014 +0100 @@ -1,6 +1,11 @@ +#ifdef __TURBOC__ +#include +#endif #include #include #include +#include +#include #ifdef WIN32 #include #endif @@ -10,109 +15,111 @@ static char tazlitoinfo[10*1024]; #define buffer tazlitoinfo #define BUFFERSZ 2048 +#define WORD(n) * (unsigned short *) (n) +#define LONG(n) * (unsigned long *) (n) static void readsector(unsigned long sector) { if (lseek(fd, sector * BUFFERSZ, SEEK_SET) == -1 || read(fd, buffer, BUFFERSZ) != BUFFERSZ) { - puts("Read sector failure.\n"); + puts(bootiso+READSECTORERR); exit(1); } } -static char *install(char *filename) +static unsigned install(char *filename) { #define heads 64 #define sectors 32 #define partition 446 -#define trksz (512 * heads * sectors) +#define trksz (512UL * heads * sectors) unsigned long size, catalog, lba; int cylinders, i, j, isohybrid; unsigned n; #ifndef WIN32 - char *bootiso; for (bootiso = (char *) install; - bootiso[0] != 'M' || bootiso[1] != 'Z' || bootiso[2] != 0xEB; - bootiso++) if (bootiso < (char *) install) return "No bootiso data.\n"; + bootiso[0] != 'M' || bootiso[1] != 'Z' || bootiso[2] != '\xEB'; + bootiso++) if (bootiso < (char *) install) { + bootiso = "No bootiso data"; + return 0; + } #endif if (!filename) - return "Usage: isohybrid.exe file.iso [--forced]\n"; + return USAGE; fd = open(filename,O_RDWR|O_BINARY); if (fd == -1) - return "Can't open rw the iso file.\n"; + return OPENERR; if (forced == 0) { status = 2; - // Install hybridiso boot sector + /* Install hybridiso boot sector */ readsector(17UL); - if (strncmp(buffer+7, "EL TORITO SPECIFICATION", 23)) - return "No EL TORITO signature.\n"; - catalog = * (unsigned long *) (buffer + 71); + if (strncmp(buffer+7, bootiso+ELTORITOERR+ELTORITOOFS, 23)) + return ELTORITOERR; + catalog = LONG(buffer + 71); readsector(catalog); - if (* (unsigned long *) buffer != 1 || - * (unsigned long *) (buffer + 30) != 0x88AA55) - return "Invalid boot catalog.\n"; - lba = * (unsigned long *) (buffer + 40); + if (LONG(buffer) != 1 || LONG(buffer + 30) != 0x88AA55UL) + return CATALOGERR; + lba = LONG(buffer + 40); readsector(lba); - if (* (unsigned long *) (buffer + 64) != 1886961915) - return "No isolinux.bin hybrid signature.\n"; + if (LONG(buffer + 64) != 1886961915UL) + return HYBRIDERR; isohybrid = bootiso[69] * 512; - * (unsigned long *) &bootiso[isohybrid + 432] = lba * 4; - * (unsigned long *) &bootiso[isohybrid + 440] = rand(); - * (unsigned long *) &bootiso[isohybrid + partition] = 0x10080; - * (unsigned short *) &bootiso[isohybrid + 510] = 0xAA55; + LONG(bootiso + isohybrid + 432) = lba * 4; + LONG(bootiso + isohybrid + 440) = rand(); + LONG(bootiso + isohybrid + partition) = 0x10080UL; + WORD(bootiso + isohybrid + 510) = 0xAA55U; size = lseek(fd, 0UL, SEEK_END); cylinders = (size + trksz - 1) / trksz; - bootiso[isohybrid + partition + 4] = 23; // "Windows hidden IFS" + bootiso[isohybrid + partition + 4] = 23; /* "Windows hidden IFS" */ bootiso[isohybrid + partition + 5] = heads - 1; bootiso[isohybrid + partition + 6] = (((cylinders - 1) & 0x300) >> 2) + sectors; bootiso[isohybrid + partition + 7] = (cylinders - 1) & 0xFF; - * (unsigned long *) &bootiso[isohybrid + partition + 8] = 0; - * (unsigned long *) &bootiso[isohybrid + partition + 12] = cylinders * sectors * heads; + LONG(bootiso + isohybrid + partition + 8) = 0; + LONG(bootiso + isohybrid + partition + 12) = cylinders * sectors * heads; - // Copy the partition table + /* Copy the partition table */ memcpy(bootiso + 0x1BE, bootiso + isohybrid + 0x1BE, 66); } - // Install iso2exe boot sector - * (unsigned short *) (bootiso + 26) = rand(); + /* Install iso2exe boot sector */ + WORD(bootiso + 26) = rand(); - // read tazlito flavor data + /* read tazlito flavor data */ lseek(fd, 1024UL, SEEK_SET); read(fd, tazlitoinfo, sizeof(tazlitoinfo)); - // Update iso image + /* Update iso image */ n = (bootiso[69] + 1) * 512; lseek(fd, 0UL, SEEK_SET); - write(fd, bootiso, n); // EXE/PE + isohybrid mbr + write(fd, bootiso, n); /* EXE/PE + isohybrid mbr */ write(fd, tazlitoinfo, ((0x8000U - BOOTISOSZ) > sizeof(tazlitoinfo)) ? sizeof(tazlitoinfo) : (0x8000U - BOOTISOSZ)); - write(fd, bootiso + n, BOOTISOSZ - n); // COM + rootfs + EXE/DOS + write(fd, bootiso + n, BOOTISOSZ - n); /* COM + rootfs + EXE/DOS */ - // Compute the checksum + /* Compute the checksum */ lseek(fd, 0UL, SEEK_SET); for (i = 66, n = 0, j = 0; j < 16; j++, i = 0) { if (read(fd, buffer, BUFFERSZ) != BUFFERSZ) goto nochksum; for (; i < BUFFERSZ; i += 2) - n += * (unsigned short *) (buffer + i); + n += WORD(buffer + i); } - * (unsigned short *) (bootiso + 64) = -n; + WORD(bootiso + 64) = -n; lseek(fd, 0UL, SEEK_SET); write(fd, bootiso, 512); nochksum: close(fd); status = 0; - return "Now you can create a USB key with your .iso file.\n" - "Simply rename it to a .exe file and run it.\n"; + return SUCCESSMSG; } int main(int argc, char *argv[]) { forced = (argc > 2); - puts(install(argv[1])); + puts(bootiso + install(argv[1])); if (status > 1) - puts("You can add --forced to proceed anayway"); + puts(bootiso + FORCEMSG); #ifdef WIN32 Sleep(2000); #endif diff -r 799c2ec31b04 -r aca562aa836e syslinux/stuff/iso2exe/iso2exe.sh --- a/syslinux/stuff/iso2exe/iso2exe.sh Tue Dec 16 18:59:28 2014 +0100 +++ b/syslinux/stuff/iso2exe/iso2exe.sh Wed Dec 17 12:25:20 2014 +0100 @@ -114,17 +114,48 @@ add_doscom $DATA > /dev/null add_fdbootstrap $DATA > /dev/null name=${3:-bootiso} + BOOTISOSZ=$((0x8000 - $OFS + $HSZ)) cat < /dev/null esac - [ ! -s "$1" ] && echo "usage: $0 image.iso" 1>&2 && exit 1 + [ ! -s "$1" ] && echo "usage: $0 image.iso [--undo]" 1>&2 && exit 1 + case "${2/--/-}" in + -u*|-r*|-w*) + case "$(get 0 $1)" in + 23117) + ddq if=$1 bs=512 count=2 skip=$(get 69 $1 1) of=$1 conv=notrunc + ddq if=/dev/zero bs=1k seek=1 count=31 of=$1 conv=notrunc ;; + *) ddq if=/dev/zero bs=1k count=32 of=$1 conv=notrunc ;; + esac + exit 0 + esac case "$(get 0 $1)" in 23117) echo "The file $1 is already an EXE file." 1>&2 && exit 1;; 0) [ -x /usr/bin/isohybrid ] && isohybrid $1 && echo "Do isohybrid"