9 #define SCAN_SPACE 8192
10 #define MAGIC 0x1BADB002
17 } __attribute__((packed)) tMBootImg;
20 void CheckMultiboot(char *file);
25 int main(int argc, char *argv[])
29 fprintf(stderr, "Usage: %s <file>\n", argv[0]);
30 fprintf(stderr, " <file> Path of file to validate\n");
31 fprintf(stderr, "\n");
34 CheckMultiboot(argv[1]);
41 void CheckMultiboot(char *file)
43 FILE *fp = fopen(file, "rb");
50 fprintf(stderr, "Unable to open '%s' for reading\n", file);
55 fseek(fp, 0, SEEK_END);
57 fseek(fp, 0, SEEK_SET);
60 if(len > SCAN_SPACE) len = SCAN_SPACE;
63 fread(buf, len, 1, fp);
66 for(ofs = 0; ofs < len-sizeof(tMBootImg); ofs += 4)
68 img = (void*)&buf[ofs];
70 if(img->Magic != MAGIC) continue;
72 if(img->Magic + img->Flags + img->Checksum != 0) {
73 printf("Checksum fail at 0x%x\n", ofs);
76 // Check undefined feature flags
77 if(img->Flags & 0xFFF8) {
78 printf("Header at 0x%x uses undefined features (0x%lx)\n", ofs, img->Flags);
82 printf("Found Multiboot header at 0x%x\n", ofs);
86 printf("No multiboot header found\n");