wok annotate syslinux/stuff/iso2exe/iso2exe.c @ rev 17492

syslinux/iso2exe: check ISO md5
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Jan 03 21:41:48 2015 +0100 (2015-01-03)
parents aca562aa836e
children 52c9cc2da3c6
rev   line source
pascal@17451 1 #ifdef __TURBOC__
pascal@17451 2 #include <io.h>
pascal@17451 3 #endif
pascal@14150 4 #include <sys/types.h>
pascal@14150 5 #include <fcntl.h>
pascal@14150 6 #include <stdio.h>
pascal@17451 7 #include <stdlib.h>
pascal@17451 8 #include <string.h>
pascal@14268 9 #ifdef WIN32
pascal@14268 10 #include <windows.h>
pascal@14268 11 #endif
pascal@14150 12 #include "iso2exe.h"
pascal@14150 13
pascal@16055 14 static int fd, forced, status = 1;
pascal@17489 15 static char tazlitoinfo[0x8000U - BOOTISOSZ];
pascal@14264 16 #define buffer tazlitoinfo
pascal@14264 17 #define BUFFERSZ 2048
pascal@17451 18 #define WORD(n) * (unsigned short *) (n)
pascal@17451 19 #define LONG(n) * (unsigned long *) (n)
pascal@14150 20
pascal@14150 21 static void readsector(unsigned long sector)
pascal@14150 22 {
pascal@14264 23 if (lseek(fd, sector * BUFFERSZ, SEEK_SET) == -1 ||
pascal@14268 24 read(fd, buffer, BUFFERSZ) != BUFFERSZ) {
pascal@17451 25 puts(bootiso+READSECTORERR);
pascal@14268 26 exit(1);
pascal@14268 27 }
pascal@14150 28 }
pascal@14150 29
pascal@17451 30 static unsigned install(char *filename)
pascal@14150 31 {
pascal@14150 32 #define heads 64
pascal@14150 33 #define sectors 32
pascal@17489 34 #define partition (446+16)
pascal@17451 35 #define trksz (512UL * heads * sectors)
pascal@14150 36 unsigned long size, catalog, lba;
pascal@14261 37 int cylinders, i, j, isohybrid;
pascal@14150 38 unsigned n;
pascal@14150 39 #ifndef WIN32
pascal@14268 40 for (bootiso = (char *) install;
pascal@17451 41 bootiso[0] != 'M' || bootiso[1] != 'Z' || bootiso[2] != '\xEB';
pascal@17451 42 bootiso++) if (bootiso < (char *) install) {
pascal@17451 43 bootiso = "No bootiso data";
pascal@17451 44 return 0;
pascal@17451 45 }
pascal@14150 46 #endif
pascal@14268 47 if (!filename)
pascal@17451 48 return USAGE;
pascal@14268 49 fd = open(filename,O_RDWR|O_BINARY);
pascal@14150 50 if (fd == -1)
pascal@17451 51 return OPENERR;
pascal@14150 52
pascal@16055 53 if (forced == 0) {
pascal@16055 54 status = 2;
pascal@17451 55 /* Install hybridiso boot sector */
pascal@16055 56 readsector(17UL);
pascal@17451 57 if (strncmp(buffer+7, bootiso+ELTORITOERR+ELTORITOOFS, 23))
pascal@17451 58 return ELTORITOERR;
pascal@17451 59 catalog = LONG(buffer + 71);
pascal@16055 60 readsector(catalog);
pascal@17451 61 if (LONG(buffer) != 1 || LONG(buffer + 30) != 0x88AA55UL)
pascal@17451 62 return CATALOGERR;
pascal@17451 63 lba = LONG(buffer + 40);
pascal@16055 64 readsector(lba);
pascal@17451 65 if (LONG(buffer + 64) != 1886961915UL)
pascal@17451 66 return HYBRIDERR;
pascal@16055 67 isohybrid = bootiso[69] * 512;
pascal@17451 68 LONG(bootiso + isohybrid + 432) = lba * 4;
pascal@17451 69 LONG(bootiso + isohybrid + 440) = rand();
pascal@17451 70 LONG(bootiso + isohybrid + partition) = 0x10080UL;
pascal@17451 71 WORD(bootiso + isohybrid + 510) = 0xAA55U;
pascal@17489 72 #if 0
pascal@16055 73 size = lseek(fd, 0UL, SEEK_END);
pascal@17489 74 size += 0x000FFFFFUL;
pascal@17489 75 size &= 0xFFF00000UL;
pascal@17489 76 #else
pascal@17489 77 for (size = 0x000FFFFFUL; /* 1M - 1 */
pascal@17489 78 read(fd, tazlitoinfo, 1024) == 1024;
pascal@17489 79 size += 1024);
pascal@17489 80 size &= 0xFFF00000UL; /* round */
pascal@17489 81 #endif
pascal@17489 82 cylinders = (size >> 20) - 1;
pascal@17451 83 bootiso[isohybrid + partition + 4] = 23; /* "Windows hidden IFS" */
pascal@16055 84 bootiso[isohybrid + partition + 5] = heads - 1;
pascal@17489 85 bootiso[isohybrid + partition + 6] = ((cylinders & 0x300) >> 2) + sectors;
pascal@17489 86 bootiso[isohybrid + partition + 7] = cylinders & 0xFF;
pascal@17451 87 LONG(bootiso + isohybrid + partition + 8) = 0;
pascal@17489 88 LONG(bootiso + isohybrid + partition + 12) = (size >> 9);
pascal@14150 89
pascal@17451 90 /* Copy the partition table */
pascal@16055 91 memcpy(bootiso + 0x1BE, bootiso + isohybrid + 0x1BE, 66);
pascal@16055 92 }
pascal@14266 93
pascal@17451 94 /* Install iso2exe boot sector */
pascal@17451 95 WORD(bootiso + 26) = rand();
pascal@14150 96
pascal@17451 97 /* read tazlito flavor data */
pascal@14261 98 lseek(fd, 1024UL, SEEK_SET);
pascal@14261