8 #define SCAN_SPACE 8192
9 #define MAGIC 0x1BADB002
15 unsigned long Checksum;
19 void CheckMultiboot(char *file);
24 int main(int argc, char *argv[])
28 fprintf(stderr, "Usage: %s <file>\n", argv[0]);
29 fprintf(stderr, " <file> Path of file to validate\n");
30 fprintf(stderr, "\n");
33 CheckMultiboot(argv[1]);
40 void CheckMultiboot(char *file)
42 FILE *fp = fopen(file, "rb");
49 fprintf(stderr, "Unable to open '%s' for reading\n", file);
54 fseek(fp, 0, SEEK_END);
56 fseek(fp, 0, SEEK_SET);
59 if(len > SCAN_SPACE) len = SCAN_SPACE;
62 fread(buf, len, 1, fp);
65 for(ofs = 0; ofs < len-sizeof(tMBootImg); ofs += 4)
67 img = (void*)&buf[ofs];
69 if(img->Magic != MAGIC) continue;
71 if(img->Magic + img->Flags + img->Checksum != 0) {
72 printf("Checksum fail at 0x%x\n", ofs);
75 // Check undefined feature flags
76 if(img->Flags & 0xFFF8) {
77 printf("Header at 0x%x uses undefined features (0x%lx)\n", ofs, img->Flags);
81 printf("Found Multiboot header at 0x%x\n", ofs);
85 printf("No multiboot header found\n");