?? sorter.base
字號:
print EXCLUDEMIS "${TAB}MD5: $md5${NL}" if ($DO_MD5 == 1); print EXCLUDEMIS "${TAB}$exclude${NL}${NL}"; } } # Now we will return if we are supposed to ignore this file return if ($exclude ne ""); ############################################################### # File Type Category my $save_name = ""; my $cat = ""; if ($DO_INDEX) { # is this a category we want to save data about? for (my $cat_i = $#cat_order; $cat_i >= 0; $cat_i--) { my $cat_kw = $cat_order[$cat_i]; if ($file =~ /$cat_kw/i) { $cat = $file_to_cat{$cat_kw}; last if ($cat eq $IGNORE_NAME); $output_used{$cat}++; # Are we going to save this to a directory? if ($SAVE == 1) { my $save_dir = "${DIR}/${cat}"; mkdir($save_dir, 0775) unless (-d $save_dir); if ($ext eq "") { $save_name = "${img_shrt}-${inode}"; } else { $save_name = "${img_shrt}-${inode}.${ext}"; } rename("${TEMP_FILE}$inode", "${save_dir}/${save_name}"); # Add to the thumbnail file if (($cat eq "images") && ($HTML == 1)) { print_thumb($save_name, $path_encode); } } last; } } } # make sure it is gone if we did not move it to a category unlink("${TEMP_FILE}$inode") if (($SAVE == 1) && (-e "${TEMP_FILE}$inode")); if ($cat eq $IGNORE_NAME) { $ignore_cnt++; goto PRINT_ALERT; } # Print the category results # If we are listing, then print anything to STDOUT if ($LIST == 1) { if ($cat eq "") { print "Category: Unknown\n"; $output_used{'unknown'}++; } else { print "Category: $cat\n"; } print "${MNT}$path_encode\n" . "$file\n"; print "--- Found in Alert Hash Database ---\n" if ($alert == 1); print "--- Extension Mismatch! ---\n" if ($mismatch == 1); print "Image: $first_img Inode: $inode\n"; print "SHA-1: $sha1\n" if ($DO_SHA1 == 1); print "MD5: $md5\n" if ($DO_MD5 == 1); print "\n"; } # print to a specific category file elsif ($DO_INDEX == 1) { if ($cat ne "") { my $tmphandle = $cat_handle{$cat}; print $tmphandle "<A NAME=\"${save_name}\">\n" if ($HTML == 1); print $tmphandle "${MNT}$path_encode${NL}"; print $tmphandle "${TAB}$file${NL}"; print $tmphandle "${TAB}--- Found in Alert Database ---${NL}" if ($alert == 1); print $tmphandle "${TAB}--- Extension Mismatch! ---${NL}" if ($mismatch == 1); print $tmphandle "${TAB}Image: $first_img Inode: $inode${NL}"; print $tmphandle "${TAB}SHA-1: $sha1${NL}" if ($DO_SHA1 == 1); print $tmphandle "${TAB}MD5: $md5${NL}" if ($DO_MD5 == 1); if ($SAVE == 1) { if ($HTML == 0) { print $tmphandle "${TAB}Saved to: ${cat}/${save_name}${NL}"; } else { print $tmphandle "${TAB}Saved to: <A HREF=\"./${cat}/${save_name}\">" . "${cat}/${save_name}</A>${NL}"; } } print $tmphandle "${NL}"; } # the $cat is "" and we are making index files and it has some # uniqe file output, so save it to the unknown file # # Ignore the 'data' type and the 'empty' type has already been removed # data should be saved by the default config file and if not then the # user obviously does not want it elsif ($file ne 'data') { if ($DO_UNKNOWN == 1) { print UNKNOWN "${MNT}$path_encode${NL}"; print UNKNOWN "${TAB}--- Found in Alert Database ---${NL}" if ($alert == 1); print UNKNOWN "${TAB}$file${NL}"; print UNKNOWN "${TAB}Image: $first_img Inode: $inode${NL}${NL}"; } $output_used{'unknown'}++; } } # Print the mismatch info if (($DO_EXT == 1) && ($mismatch == 1)) { $mis_cnt++; if ($LIST == 0) { print MISMATCH "${MNT}$path_encode${NL}"; print MISMATCH "${TAB}$file (Ext: $ext)${NL}"; print MISMATCH "${TAB}Image: $first_img Inode: $inode${NL}"; print MISMATCH "${TAB}SHA-1: $sha1${NL}" if ($DO_SHA1 == 1); print MISMATCH "${TAB}MD5: $md5${NL}" if ($DO_MD5 == 1); if ($SAVE == 1) { if ($HTML == 0) { print MISMATCH "${TAB}Saved to: ${cat}/${save_name}${NL}"; } else { print MISMATCH "${TAB}Saved to: <A HREF=\"./${cat}/${save_name}\">" . "${cat}/${save_name}</A>${NL}"; } } print MISMATCH "${NL}"; } } PRINT_ALERT: # If we are alerting because of a hash value, do it now. It is all # the way down here so that we know the path that it was saved to if ($alert == 1) { $alert_cnt++; if ($LIST == 0) { print ALERT "${MNT}$path_encode${NL}"; print ALERT "${TAB}Image: $first_img Inode: $inode${NL}"; print ALERT "${TAB}SHA-1: $sha1${NL}" if ($DO_SHA1 == 1); print ALERT "${TAB}MD5: $md5${NL}" if ($DO_MD5 == 1); if ($SAVE == 1) { if ($HTML == 0) { print ALERT "${TAB}Saved to: ${cat}/${save_name}${NL}"; } else { print ALERT "${TAB}Saved to: <A HREF=\"./${cat}/${save_name}\">" . "${cat}/${save_name}</A>${NL}"; } } print ALERT "${NL}"; } } return;}# Read the config filessub read_config { my $config = shift; open(CONFIG, "$config") or die "Can't open $config"; print "Reading $config\n" if ($VERBOSE); while (<CONFIG>) { next if ((/^\#/) || (/^\s+$/)); # category definition # category name key_words if (/^\s*category\s+([\w\d]+)\s+(.*?)\s*$/) { my $kw = $2; my $cat = $1; # Make lowercase $cat =~ tr/[A-Z]/[a-z]/; # we have some reservered categories already if ( ($cat eq $MIS_NAME) || ($cat eq $UNK_NAME) || ($cat eq $ALERT_NAME) || ($cat eq $EXCLUDE_NAME) || ($cat eq $EXCLUDEMIS_NAME)) { print "Invalid Category Name: $cat (Reserved)\n"; exit(1); } # do a sanity check to see if we are overriding a # category that already existed for this file type if ( (exists $file_to_cat{$kw}) && ($file_to_cat{$kw} ne $cat)) { print"Warning: overriding category $file_to_cat{$kw} with $cat for key words: $kw\n"; } else { push @cat_order, $kw; } $file_to_cat{$kw} = $cat; print "Adding Category: $cat File Keywords: $kw\n" if ($VERBOSE); } # extention defn # ext ext1,ext2, key_words elsif (/^\s*ext\s+([\w\d\,]+)\s+(.*?)\s*$/) { my $ext = $1; my $kw = $2; # Make lowercase $ext =~ tr/[A-Z]/[a-z]/; # If there are already some extensions, then we will just # extend them if (exists $file_to_ext{$kw}) { # We could just do a push, but then we risk having # duplicate entries, which will waste time later foreach my $e1 (split(/,/, $ext)) { my $exists = 0; foreach my $e2 (@{$file_to_ext{$kw}}) { if ($e1 eq $e2) { $exists = 1; last; } } push @{$file_to_ext{$kw}}, $e1 if ($exists == 0); } print "Adding Extensions: $ext File Keywords: $kw\n" if ($VERBOSE); } else { $file_to_ext{$kw} = [split(/,/, $ext)]; push @ext_order, $kw; print "New Extensions: $ext File Keywords: $kw\n" if ($VERBOSE); } } else { print "Invalid line in $config:$.\n"; exit(1); } } close(CONFIG);}# This is needed to assign the handle to a local variablesub myopen { my $path = shift; local *FH; open(FH, $path) or die("Can not open $path"); return *FH;}# Open the summary files into an array of handlessub open_files { return if ($LIST == 1); if ($DO_EXT == 1) { open(MISMATCH, ">${DIR}/${MIS_NAME}${EXT}") or die "Can't open ${DIR}/${MIS_NAME}${EXT}"; $mis_cnt = 0; print MISMATCH "<HTML><HEAD>\n" . "<TITLE>Extension Mismatches</TITLE>" . "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></HEAD>\n" . "<BODY>\n" . "<CENTER><H2>Extension Mismatch</H2></CENTER>\n" if ($HTML == 1); } if ("$ALERT_DB" ne "") { open(ALERT, ">${DIR}/${ALERT_NAME}${EXT}") or die "Can't open ${DIR}/${ALERT_NAME}${EXT}"; $alert_cnt = 0; print ALERT "<HTML><HEAD>\n" . "<TITLE>Hash Database Alerts</TITLE>" . "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></HEAD>\n" . "<BODY>\n" . "<CENTER><H2>Hash Database Alerts</H2></CENTER>\n" if ($HTML == 1); } if (("$EXCLUDE_DB" ne "") || ("$NSRL" ne "")) { open(EXCLUDE, ">${DIR}/${EXCLUDE_NAME}${EXT}") or die "Can't open ${DIR}/${EXCLUDE_NAME}${EXT}"; $excl_cnt = 0; print EXCLUDE "<HTML><HEAD>\n" . "<TITLE>Hash Database Excludes</TITLE>" . "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></HEAD>\n" . "<BODY>\n" . "<CENTER><H2>Hash Database Excludes</H2></CENTER>\n" if ($HTML == 1); if ($DO_EXT == 1) { open(EXCLUDEMIS, ">${DIR}/${EXCLUDEMIS_NAME}${EXT}") or die "Can't open ${DIR}/${EXCLUDEMIS_NAME}${EXT}"; $exclmis_cnt = 0; print EXCLUDEMIS "<HTML><HEAD>\n" . "<TITLE>Hash Database Excludes with Mismatches</TITLE>" . "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></HEAD>\n" . "<BODY>\n" . "<CENTER><H2>Hash Database Excludes with Mismatches</H2></CENTER>\n" if ($HTML == 1); } } if ($DO_INDEX == 1) { $output_used{'unknown'} = 0; if ($DO_UNKNOWN == 1) { open(UNKNOWN, ">${DIR}/${UNK_NAME}${EXT}") or die "Can't open ${DIR}/${UNK_NAME}${EXT}"; print UNKNOWN "<HTML><HEAD>\n" . "<TITLE>Unknown Category</TITLE>" . "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></HEAD>\n" . "<BODY>\n" . "<CENTER><H2>Unknown Category</H2></CENTER>\n" if ($HTML == 1); } foreach my $cat (values %file_to_cat) { next if (exists $cat_handle{$cat}); next if ($cat eq $IGNORE_NAME); $cat_handle{$cat} = myopen(">${DIR}/${cat}${EXT}"); my $tmphandle = $cat_handle{$cat}; $output_used{$cat} = 0; print $tmphandle "<HTML><HEAD>\n" . "<TITLE>$cat Category</TITLE>" . "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></HEAD>\n" . "<BODY>\n" . "<CENTER><H2>$cat Category</H2></CENTER>\n" if ($HTML == 1); # make a directory for the thumbnail images if (($cat eq "images") && ($SAVE == 1) && ($HTML == 1)) { mkdir("${DIR}/images", 0775) unless (-d "${DIR}/images"); open(IMG_INDEX, ">${DIR}/images/index.html") or die "Can't open ${DIR}/images/index.html"; print IMG_INDEX "<HTML><HEAD>\n" . "<TITLE>Image Thumbnails Index</TITLE>" . "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></HEAD>\n" . "<BODY>\n" . "<CENTER><H2>Image Thumbnails Index</H2></CENTER>\n<UL>\n"; } } } return;}# Close the output summary files and remove them if they have# a size of 0#sub close_files { return if ($LIST == 1); # Extension Mismatch if ($DO_EXT == 1) { close(MISMATCH); unlink "${DIR}/${MIS_NAME}${EXT}" if ($mis_cnt == 0); } # Alert Hash database if ("$ALERT_DB" ne "") { close(ALERT); unlink "${DIR}/${ALERT_NAME}${EXT}" if ($alert_cnt == 0); } # Exclude hash databases (-x and NSRL) if (("$EXCLUDE_DB" ne "") || ("$NSRL" ne "")) { close(EXCLUDE); unlink "${DIR}/${EXCLUDE_NAME}${EXT}" if ($excl_cnt == 0); if ($DO_EXT == 1) { close(EXCLUDEMIS); unlink "${DIR}/${EXCLUDEMIS_NAME}${EXT}" if ($exclmis_cnt == 0); } } # Categories if ($DO_INDEX == 1) { if ($DO_UNKNOWN == 1) { close(UNKNOWN); unlink "${DIR}/${UNK_NAME}${EXT}" if ($output_used{'unknown'} == 0);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -