sub fileformat_scanner {
  my($start_ffs_time, $stop_ffs_time, $ffs_time, @allfiles, $index, $DATA, $f);
  my(@FORMATS, $formats);
  $start_ffs_time=[gettimeofday];
  &debug("ffs: starting scan of directory \"$scandir/$file_id\"...");

  # This could probably be replaced by a database somewheres...
  @FORMATS = ({ Name => "UPX Compressed Binary", Offset => 0x3e0, Data => "UPX", Length => 3 },
			  { Name => "W32/Bagle-H", Offset => 0x00,
					Data => pack("H*", "504b03040a0001000000"), Length => 10}); 

  $formats = (@FORMATS);

  &debug("ffs: scanning for $formats item\(s\)");
  opendir(SCANDIR, "$scandir/$file_id") || &error_condition("ffs: cannot open \"$scandir/$file_id\"");
  @allfiles = grep(!/^\.+$/, readdir(SCANDIR));
  closedir(SCANDIR);
  
  foreach $f (@allfiles) {
    &debug("ffs: scanning \"$scandir/$file_id/$f\"");

    open(SCANFILE, "$scandir/$file_id/$f")||&error_condition("ffs: cannot open \"$scandir/$file_id/$f\"");

    $index = 0;
    while($index < (@FORMATS)) {
      seek(SCANFILE, $FORMATS[$index]{Offset}, 0);
      read(SCANFILE, $DATA, $FORMATS[$index]{Length});

        # Probably needs to be a bit more complex than this
      if($DATA eq $FORMATS[$index]{Data}) {
        &debug("ffs: File is \"$FORMATS[$index]{Name}\"");
        $quarantine_description = $FORMATS[$index]{Name};

        ($quarantine_event=$quarantine_description)=~s/\s/_/g;
        $quarantine_event="ffs:".substr($quarantine_event,0,$QE_LEN);
        $description .= "\n--- file format scanner ---\n";
        $description .= "FILE/DIR  : $scandir/$file_id\n";
        $description .= "FORMAT    : $quarantine_description\n";
      }
      $index++;
    }
    close(SCANFILE);
  }

  $stop_ffs_time=[gettimeofday];
  $ffs_time = tv_interval($start_ffs_time, $stop_ffs_time);
  &debug("ffs: finished scan of dir \"$scandir/$file_id\" in $ffs_time secs"); 
}
