void detect_cdimage(SECTION *section, int level) { int mode, off; unsigned char *buf; SOURCE *s; if (get_buffer(section, 0, 2352, (void **)&buf) < 2352) return; /* check sync bytes as signature */ if (memcmp(buf, syncbytes, 12) != 0) return; /* get mode of the track -- this determines sector layout */ mode = buf[15]; if (mode == 1) { /* standard data track */ print_line(level, "Raw CD image, Mode 1"); off = 16; } else if (mode == 2) { /* free-form track, assume XA form 1 */ print_line(level, "Raw CD image, Mode 2, assuming Form 1"); off = 24; } else return; /* create and analyze wrapped source */ s = init_cdimage_source(section->source, section->pos + off); analyze_source(s, level); close_source(s); /* don't run other analyzers */ stop_detect(); }
static void analyze_file(const char *filename) { int fd, filekind; u8 filesize; struct stat sb; char *reason; SOURCE *s; print_line(0, "--- %s", filename); /* stat check */ if (stat(filename, &sb) < 0) { errore("Can't stat %.300s", filename); return; } filekind = 0; filesize = 0; reason = NULL; if (S_ISREG(sb.st_mode)) { filesize = sb.st_size; print_kind(filekind, filesize, 1); } else if (S_ISBLK(sb.st_mode)) filekind = 1; else if (S_ISCHR(sb.st_mode)) filekind = 2; else if (S_ISDIR(sb.st_mode)) reason = "Is a directory"; else if (S_ISFIFO(sb.st_mode)) reason = "Is a FIFO"; #ifdef S_ISSOCK else if (S_ISSOCK(sb.st_mode)) reason = "Is a socket"; #endif else reason = "Is an unknown kind of special file"; if (reason != NULL) { error("%.300s: %s", filename, reason); return; } /* Mac OS type & creator code (if running on Mac OS X) */ #ifdef USE_MACOS_TYPE if (filekind == 0) show_macos_type(filename); #endif /* empty regular files need no further analysis */ if (filekind == 0 && filesize == 0) return; /* open for reading */ fd = open(filename, O_RDONLY); if (fd < 0) { errore("Can't open %.300s", filename); return; } /* (try to) guard against TTY character devices */ if (filekind == 2) { if (isatty(fd)) { error("%.300s: Is a TTY device", filename); return; } } /* create a source */ s = init_file_source(fd, filekind); /* tell the user what it is */ if (filekind != 0) print_kind(filekind, s->size, s->size_known); /* now analyze it */ analyze_source(s, 0); /* finish it up */ close_source(s); }