[29] | 1 | // AiR-BOOT (c) Copyright 1998-2008 M. Kiewitz
|
---|
| 2 | //
|
---|
| 3 | // This file is part of AiR-BOOT
|
---|
| 4 | //
|
---|
| 5 | // AiR-BOOT is free software: you can redistribute it and/or modify it under
|
---|
| 6 | // the terms of the GNU General Public License as published by the Free
|
---|
| 7 | // Software Foundation, either version 3 of the License, or (at your option)
|
---|
| 8 | // any later version.
|
---|
| 9 | //
|
---|
| 10 | // AiR-BOOT is distributed in the hope that it will be useful, but WITHOUT ANY
|
---|
| 11 | // WARRANTY: without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
| 12 | // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
---|
| 13 | // details.
|
---|
| 14 | //
|
---|
| 15 | // You should have received a copy of the GNU General Public License along with
|
---|
| 16 | // AiR-BOOT. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 17 | //
|
---|
| 18 |
|
---|
| 19 | #define INCL_BASE
|
---|
| 20 | #define INCL_WINSHELLDATA
|
---|
| 21 | #define INCL_DOS
|
---|
| 22 | #define INCL_DOSDEVIOCTL
|
---|
| 23 | #include <os2.h>
|
---|
| 24 | #include <malloc.h>
|
---|
| 25 |
|
---|
| 26 | #include <stdlib.h>
|
---|
| 27 | #include <stdio.h>
|
---|
| 28 | #include <ctype.h>
|
---|
| 29 | #include <conio.h>
|
---|
| 30 | #include <string.h>
|
---|
| 31 |
|
---|
| 32 | int main (int argc, char **argv) {
|
---|
| 33 | PSZ FilenameBasicISO = NULL;
|
---|
| 34 | FILE *FileBasicISO = NULL;
|
---|
| 35 | ULONG FileBasicISOSize = 0;
|
---|
| 36 | PCHAR BasicISO = NULL;
|
---|
| 37 | PSZ FilenameBootcode = NULL;
|
---|
| 38 | FILE *FileBootcode = NULL;
|
---|
| 39 | ULONG FileBootcodeSize = 0;
|
---|
| 40 | PCHAR Bootcode = NULL;
|
---|
| 41 | PSZ FilenameOutput = NULL;
|
---|
| 42 | FILE *FileOutput = NULL;
|
---|
| 43 | PCHAR BasicISOBootcodePtr = NULL;
|
---|
| 44 | ULONG BytesLeft = 0;
|
---|
| 45 |
|
---|
| 46 | puts ("MAKEISO - AiR-BOOT Helper utility for making ISOs - (c) 2009 by M. Kiewitz");
|
---|
| 47 |
|
---|
| 48 | // This is a quick hackjob, it's only used during build, so i dont care.
|
---|
| 49 |
|
---|
| 50 | if (argc<4) {
|
---|
| 51 | printf("MAKEISO [basic-iso] [bootcode] [output-iso]\n");
|
---|
| 52 | return 1;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | FilenameBasicISO = argv[1];
|
---|
| 56 | FilenameBootcode = argv[2];
|
---|
| 57 | FilenameOutput = argv[3];
|
---|
| 58 |
|
---|
| 59 | FileBasicISO = fopen(FilenameBasicISO, "rb");
|
---|
| 60 | if (!FileBasicISO) {
|
---|
| 61 | printf("basic-iso not found\n");
|
---|
| 62 | return 1;
|
---|
| 63 | }
|
---|
| 64 | // Read whole basic-iso into memory...
|
---|
| 65 | fseek (FileBasicISO, 0, SEEK_END);
|
---|
| 66 | FileBasicISOSize = ftell(FileBasicISO);
|
---|
| 67 | BasicISO = malloc(FileBasicISOSize);
|
---|
| 68 | if (!BasicISO) {
|
---|
| 69 | printf("Out of memory\n");
|
---|
| 70 | fclose(FileBasicISO);
|
---|
| 71 | return 1;
|
---|
| 72 | }
|
---|
| 73 | fseek (FileBasicISO, 0, SEEK_SET);
|
---|
| 74 | fread (BasicISO, 1, FileBasicISOSize, FileBasicISO);
|
---|
| 75 | fclose (FileBasicISO);
|
---|
| 76 |
|
---|
| 77 | // Now search for AiRBOOT boot-record signature
|
---|
| 78 | BasicISOBootcodePtr = BasicISO;
|
---|
| 79 | BytesLeft = FileBasicISOSize - 9;
|
---|
| 80 | while (BytesLeft > 0) {
|
---|
| 81 | if (memcmp(BasicISOBootcodePtr, "\xFA\xEB\AiRBOOT", 9)==0) {
|
---|
| 82 | break;
|
---|
| 83 | }
|
---|
| 84 | BasicISOBootcodePtr++; BytesLeft--;
|
---|
| 85 | }
|
---|
| 86 | if (BytesLeft==0) {
|
---|
| 87 | free(BasicISO);
|
---|
| 88 | printf("AiR-BOOT signature not found in basic-iso\n");
|
---|
| 89 | return 1;
|
---|
| 90 | }
|
---|
| 91 | BytesLeft = BasicISOBootcodePtr - BasicISO;
|
---|
| 92 |
|
---|
| 93 | printf("AiR-BOOT signature found within basic-iso\n");
|
---|
| 94 |
|
---|
| 95 | FileBootcode = fopen(FilenameBootcode, "rb");
|
---|
| 96 | if (!FileBootcode) {
|
---|
| 97 | free(BasicISO);
|
---|
| 98 | printf("bootcode not found\n");
|
---|
| 99 | return 1;
|
---|
| 100 | }
|
---|
| 101 | // Read whole bootcode into memory...
|
---|
| 102 | fseek (FileBootcode, 0, SEEK_END);
|
---|
| 103 | FileBootcodeSize = ftell(FileBootcode);
|
---|
| 104 | Bootcode = malloc(FileBootcodeSize);
|
---|
| 105 | if (!Bootcode) {
|
---|
| 106 | printf("Out of memory\n");
|
---|
| 107 | fclose(FileBootcode);
|
---|
| 108 | free(BasicISO);
|
---|
| 109 | return 1;
|
---|
| 110 | }
|
---|
| 111 | fseek (FileBootcode, 0, SEEK_SET);
|
---|
| 112 | fread (Bootcode, 1, FileBootcodeSize, FileBootcode);
|
---|
| 113 | fclose (FileBootcode);
|
---|
| 114 |
|
---|
| 115 | // Now create output file
|
---|
| 116 | FileOutput = fopen(FilenameOutput, "wb");
|
---|
| 117 | if (!FileOutput) {
|
---|
| 118 | free(BasicISO); free(Bootcode);
|
---|
| 119 | printf("output could not be opened\n");
|
---|
| 120 | return 1;
|
---|
| 121 | }
|
---|
| 122 | // Put ISO till bootcode
|
---|
| 123 | fwrite (BasicISO, 1, BytesLeft, FileOutput);
|
---|
| 124 | // Then put requested bootcode
|
---|
| 125 | fwrite (Bootcode, 1, FileBootcodeSize, FileOutput);
|
---|
| 126 | // Finally write rest of ISO
|
---|
| 127 | BytesLeft = FileBasicISOSize - BytesLeft - FileBootcodeSize;
|
---|
| 128 | fwrite (BasicISOBootcodePtr + FileBootcodeSize, 1, BytesLeft, FileOutput);
|
---|
| 129 | fclose (FileOutput);
|
---|
| 130 | free(BasicISO); free(Bootcode);
|
---|
| 131 | printf("Output successfully written.\n");
|
---|
| 132 | return 0;
|
---|
| 133 | }
|
---|