| Uutiset | Koodikirjasto | Wiki | Keskustelut | FAQ | Info |
isoimagechkraspi 20.11.04 11:54 Tarkistaa onko ISO-image boottaava.
/* raspi 2003 ISO-image boot chexxor Tarkistaa onko ISO-image boottaava. Käyttö: isoimagechk foo.iso auttaja(t): e2prom slasher */ #include <stdlib.h> #include <stdio.h> #include <string.h> #define SECTOR_SIZE 0x800 #define CHECK_ONE_OFFSET (SECTOR_SIZE * 0x10) + 1 #define CHECK_ONE_VALUE "CD001" #define CHECK_TWO_OFFSET (SECTOR_SIZE * 0x11) + 1 #define CHECK_TWO_VALUE CHECK_ONE_VALUE #define CHECK_THREE_VALUE 0x1 #define CHECK_FOUR_VALUE "EL TORITO SPECIFICATION" const char *trueorfalse (unsigned char n) { // bool2str static const char *when_true = "Löytyi"; static const char *when_false = "Ei löytynyt"; return n ? when_true : when_false; } int main (int argc, const char **argv) { FILE *tiedosto; // mistä luetaan char tiednimi[255]; char tmpbuffer[1024]; unsigned long koko, startsector; unsigned char cd001_1 = 0; unsigned char cd001_2 = 0; unsigned char mustbe1 = 0; unsigned char eltorito = 0; int mustbenull = 0; int i = 0; // index, for() if(argc != 2) { fprintf(stdout, "ISO-9660 BOOT CHECKER by raspi 2003\n"); fprintf(stdout, "Usage: %s <file.iso>\n", argv[0]); return 1; } strncpy(tiednimi, argv[1], sizeof(tiednimi) - 1); // ensimmäinen arg -> tiedoston nimeksi tiedosto = fopen(tiednimi, "rb"); // avataan tiedosto if (tiedosto == NULL) { fprintf(stderr, "Tiedoston \"%s\" avaaminen epäonnistui\n", tiednimi); return 2; } fseek(tiedosto, 0, SEEK_END); // mennään tiedoston loppuun koko = ftell(tiedosto); // otetaan selville tiedoston koko // first check, cd001 (0x8001) fseek(tiedosto, CHECK_ONE_OFFSET, SEEK_SET); fread(tmpbuffer, 1, strlen(CHECK_ONE_VALUE), tiedosto); if (!strncmp(CHECK_ONE_VALUE, tmpbuffer, strlen(CHECK_ONE_VALUE))) cd001_1 = 1; // second check, cd001 (0x8801) fseek(tiedosto, CHECK_TWO_OFFSET, SEEK_SET); fread(tmpbuffer, 1, strlen(CHECK_TWO_VALUE), tiedosto); if (!strncmp(CHECK_TWO_VALUE, tmpbuffer, strlen(CHECK_TWO_VALUE))) cd001_2 = 1; // third check, 1 fread(tmpbuffer, 1, 1, tiedosto); if (tmpbuffer[0] == CHECK_THREE_VALUE) mustbe1 = 1; // fourth check, el torito fread(tmpbuffer, 1, strlen(CHECK_FOUR_VALUE), tiedosto); //tmpbuffer[strlen(CHECK_FOUR_VALUE)] = '\0'; if (!strcmp(CHECK_FOUR_VALUE, tmpbuffer)) eltorito = 1; fprintf(stdout, "1 OFFSET=%x\n", ftell(tiedosto)); // fifth check, NULL * 0x1F for(i=0; i<0x1f; i++) { if(fread(tmpbuffer, 1, 1, tiedosto) == NULL) mustbenull++; } fprintf(stdout, "2 OFFSET=%x\n", ftell(tiedosto)); fread(tmpbuffer, 1, 0x3, tiedosto); fprintf(stdout, "3 OFFSET=%x\n", ftell(tiedosto)); startsector = atol(tmpbuffer); fclose(tiedosto); // suljetaan tiedosto fprintf(stdout, "start: %x\n", startsector); fprintf(stdout, "Filename: %s\n", tiednimi); fprintf(stdout, "Filesize: %d bytes\n", koko); fprintf(stdout, "Sectors: %d\n", (koko / SECTOR_SIZE)); fprintf(stdout, "CD001 #1: %s\n", trueorfalse(cd001_1)); fprintf(stdout, "CD001 #2: %s\n", trueorfalse(cd001_2)); fprintf(stdout, "1: %s\n", trueorfalse(mustbe1)); fprintf(stdout, "\"el torito\": %s\n", trueorfalse(eltorito)); if(cd001_1 && cd001_2 && mustbe1 && eltorito) fprintf(stdout, "Tämä on boottaava CD!\n"); else fprintf(stdout, "Tämä EI OLE boottaava CD\n"); // All ok return 0; } editoitu: 17:15 20.11.04 Ztane 17:09 20.11.04 const char *trueorfalse (unsigned char n) { // bool2str static const char *when_true = "Löytyi"; static const char *when_false = "Ei löytynyt"; return n ? when_true : when_false; } Ei saa naurattaa... miten olis const char *trueorfalse(int v) { oodia...return v ? "Löytyi" : "Ei löytynyt"; } Mikä paha sillä tiedostonnimellä on olla siellä argv:ssä? Ja strncmp:n kanssa ei oo hyvä käyttää nottia, se vaan sotkee... selkeämpää olisi strncmp() == 0. fprintf(stdout... tunnetaan yleisemmin nimellä printf... Ja niinku mitä *vettiä tää tekee? for(i=0; i<0x1f; i++) { if(fread(tmpbuffer, 1, 1, tiedosto) == NULL) mustbenull++; } stWasm1.0 14:49 24.11.04 Kääntäjäni varoittaa: warning: comparison between pointer and integer |
![]() Haku
|