wok diff syslinux/stuff/iso2exe/iso2exe.c @ rev 17451
syslinux/iso2exe: add --undo
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Wed Dec 17 12:25:20 2014 +0100 (2014-12-17) |
parents | 9c889f88b9fd |
children | 054f70cb9bec |
line diff
1.1 --- a/syslinux/stuff/iso2exe/iso2exe.c Tue Mar 11 15:44:47 2014 +0000 1.2 +++ b/syslinux/stuff/iso2exe/iso2exe.c Wed Dec 17 12:25:20 2014 +0100 1.3 @@ -1,6 +1,11 @@ 1.4 +#ifdef __TURBOC__ 1.5 +#include <io.h> 1.6 +#endif 1.7 #include <sys/types.h> 1.8 #include <fcntl.h> 1.9 #include <stdio.h> 1.10 +#include <stdlib.h> 1.11 +#include <string.h> 1.12 #ifdef WIN32 1.13 #include <windows.h> 1.14 #endif 1.15 @@ -10,109 +15,111 @@ 1.16 static char tazlitoinfo[10*1024]; 1.17 #define buffer tazlitoinfo 1.18 #define BUFFERSZ 2048 1.19 +#define WORD(n) * (unsigned short *) (n) 1.20 +#define LONG(n) * (unsigned long *) (n) 1.21 1.22 static void readsector(unsigned long sector) 1.23 { 1.24 if (lseek(fd, sector * BUFFERSZ, SEEK_SET) == -1 || 1.25 read(fd, buffer, BUFFERSZ) != BUFFERSZ) { 1.26 - puts("Read sector failure.\n"); 1.27 + puts(bootiso+READSECTORERR); 1.28 exit(1); 1.29 } 1.30 } 1.31 1.32 -static char *install(char *filename) 1.33 +static unsigned install(char *filename) 1.34 { 1.35 #define heads 64 1.36 #define sectors 32 1.37 #define partition 446 1.38 -#define trksz (512 * heads * sectors) 1.39 +#define trksz (512UL * heads * sectors) 1.40 unsigned long size, catalog, lba; 1.41 int cylinders, i, j, isohybrid; 1.42 unsigned n; 1.43 #ifndef WIN32 1.44 - char *bootiso; 1.45 for (bootiso = (char *) install; 1.46 - bootiso[0] != 'M' || bootiso[1] != 'Z' || bootiso[2] != 0xEB; 1.47 - bootiso++) if (bootiso < (char *) install) return "No bootiso data.\n"; 1.48 + bootiso[0] != 'M' || bootiso[1] != 'Z' || bootiso[2] != '\xEB'; 1.49 + bootiso++) if (bootiso < (char *) install) { 1.50 + bootiso = "No bootiso data"; 1.51 + return 0; 1.52 + } 1.53 #endif 1.54 if (!filename) 1.55 - return "Usage: isohybrid.exe file.iso [--forced]\n"; 1.56 + return USAGE; 1.57 fd = open(filename,O_RDWR|O_BINARY); 1.58 if (fd == -1) 1.59 - return "Can't open rw the iso file.\n"; 1.60 + return OPENERR; 1.61 1.62 if (forced == 0) { 1.63 status = 2; 1.64 - // Install hybridiso boot sector 1.65 + /* Install hybridiso boot sector */ 1.66 readsector(17UL); 1.67 - if (strncmp(buffer+7, "EL TORITO SPECIFICATION", 23)) 1.68 - return "No EL TORITO signature.\n"; 1.69 - catalog = * (unsigned long *) (buffer + 71); 1.70 + if (strncmp(buffer+7, bootiso+ELTORITOERR+ELTORITOOFS, 23)) 1.71 + return ELTORITOERR; 1.72 + catalog = LONG(buffer + 71); 1.73 readsector(catalog); 1.74 - if (* (unsigned long *) buffer != 1 || 1.75 - * (unsigned long *) (buffer + 30) != 0x88AA55) 1.76 - return "Invalid boot catalog.\n"; 1.77 - lba = * (unsigned long *) (buffer + 40); 1.78 + if (LONG(buffer) != 1 || LONG(buffer + 30) != 0x88AA55UL) 1.79 + return CATALOGERR; 1.80 + lba = LONG(buffer + 40); 1.81 readsector(lba); 1.82 - if (* (unsigned long *) (buffer + 64) != 1886961915) 1.83 - return "No isolinux.bin hybrid signature.\n"; 1.84 + if (LONG(buffer + 64) != 1886961915UL) 1.85 + return HYBRIDERR; 1.86 isohybrid = bootiso[69] * 512; 1.87 - * (unsigned long *) &bootiso[isohybrid + 432] = lba * 4; 1.88 - * (unsigned long *) &bootiso[isohybrid + 440] = rand(); 1.89 - * (unsigned long *) &bootiso[isohybrid + partition] = 0x10080; 1.90 - * (unsigned short *) &bootiso[isohybrid + 510] = 0xAA55; 1.91 + LONG(bootiso + isohybrid + 432) = lba * 4; 1.92 + LONG(bootiso + isohybrid + 440) = rand(); 1.93 + LONG(bootiso + isohybrid + partition) = 0x10080UL; 1.94 + WORD(bootiso + isohybrid + 510) = 0xAA55U; 1.95 size = lseek(fd, 0UL, SEEK_END); 1.96 cylinders = (size + trksz - 1) / trksz; 1.97 - bootiso[isohybrid + partition + 4] = 23; // "Windows hidden IFS" 1.98 + bootiso[isohybrid + partition + 4] = 23; /* "Windows hidden IFS" */ 1.99 bootiso[isohybrid + partition + 5] = heads - 1; 1.100 bootiso[isohybrid + partition + 6] = (((cylinders - 1) & 0x300) >> 2) + sectors; 1.101 bootiso[isohybrid + partition + 7] = (cylinders - 1) & 0xFF; 1.102 - * (unsigned long *) &bootiso[isohybrid + partition + 8] = 0; 1.103 - * (unsigned long *) &bootiso[isohybrid + partition + 12] = cylinders * sectors * heads; 1.104 + LONG(bootiso + isohybrid + partition + 8) = 0; 1.105 + LONG(bootiso + isohybrid + partition + 12) = cylinders * sectors * heads; 1.106 1.107 - // Copy the partition table 1.108 + /* Copy the partition table */ 1.109 memcpy(bootiso + 0x1BE, bootiso + isohybrid + 0x1BE, 66); 1.110 } 1.111 1.112 - // Install iso2exe boot sector 1.113 - * (unsigned short *) (bootiso + 26) = rand(); 1.114 + /* Install iso2exe boot sector */ 1.115 + WORD(bootiso + 26) = rand(); 1.116 1.117 - // read tazlito flavor data 1.118 + /* read tazlito flavor data */ 1.119 lseek(fd, 1024UL, SEEK_SET); 1.120 read(fd, tazlitoinfo, sizeof(tazlitoinfo)); 1.121 1.122 - // Update iso image 1.123 + /* Update iso image */ 1.124 n = (bootiso[69] + 1) * 512; 1.125 lseek(fd, 0UL, SEEK_SET); 1.126 - write(fd, bootiso, n); // EXE/PE + isohybrid mbr 1.127 + write(fd, bootiso, n); /* EXE/PE + isohybrid mbr */ 1.128 write(fd, tazlitoinfo, ((0x8000U - BOOTISOSZ) > sizeof(tazlitoinfo)) 1.129 ? sizeof(tazlitoinfo) : (0x8000U - BOOTISOSZ)); 1.130 - write(fd, bootiso + n, BOOTISOSZ - n); // COM + rootfs + EXE/DOS 1.131 + write(fd, bootiso + n, BOOTISOSZ - n); /* COM + rootfs + EXE/DOS */ 1.132 1.133 - // Compute the checksum 1.134 + /* Compute the checksum */ 1.135 lseek(fd, 0UL, SEEK_SET); 1.136 for (i = 66, n = 0, j = 0; j < 16; j++, i = 0) { 1.137 if (read(fd, buffer, BUFFERSZ) != BUFFERSZ) 1.138 goto nochksum; 1.139 for (; i < BUFFERSZ; i += 2) 1.140 - n += * (unsigned short *) (buffer + i); 1.141 + n += WORD(buffer + i); 1.142 } 1.143 - * (unsigned short *) (bootiso + 64) = -n; 1.144 + WORD(bootiso + 64) = -n; 1.145 lseek(fd, 0UL, SEEK_SET); 1.146 write(fd, bootiso, 512); 1.147 nochksum: 1.148 close(fd); 1.149 status = 0; 1.150 - return "Now you can create a USB key with your .iso file.\n" 1.151 - "Simply rename it to a .exe file and run it.\n"; 1.152 + return SUCCESSMSG; 1.153 } 1.154 1.155 int main(int argc, char *argv[]) 1.156 { 1.157 forced = (argc > 2); 1.158 - puts(install(argv[1])); 1.159 + puts(bootiso + install(argv[1])); 1.160 if (status > 1) 1.161 - puts("You can add --forced to proceed anayway"); 1.162 + puts(bootiso + FORCEMSG); 1.163 #ifdef WIN32 1.164 Sleep(2000); 1.165 #endif