diff --git a/bin/m_carve.php b/bin/m_carve.php new file mode 100644 index 0000000..3e738e6 --- /dev/null +++ b/bin/m_carve.php @@ -0,0 +1,227 @@ + +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# ---------------------------------------------------------------------- +//Given a start and stop file, the location of the files and their pre-fix, +//this function puts file names that fit the start-stop parameter and stores +//the results in an array +function carve($start, $stop, $dir, $pre){ + + //tokenize start and end file name by (.) + $start_token = explode(".",$start); + $stop_token = explode(".",$stop); + //check to make sure file is in (prefix).(suffix) format (size 2) + if(count($start_token)!=2 or count($stop_token)!=2){ + print "Invalid file name format, must be two strings separated by a period (eg. cxt.12345)\n"; + } + else{ + //assign start and end timestamp + $start_tstamp = $start_token[1]; + $stop_tstamp = $stop_token[1]; + //store capture directory contents into variable + $dircontents = list_dir($dir,$pre); + //extract since it was passed from list_dir function + extract($dircontents); + //if first x digits match (in this case 6) then treat them as matches + //and add to the results array + $carve_results = array(); + $j=$i=0; + for($i; $i<(count($dircontents)); $i++){ + + if(substr_compare($start_tstamp,$dircontents[$i],0,5)==0){ + if($dircontents[$i]>=$start_tstamp and $dircontents[$i]<=$stop_tstamp){ + $carve_results[$j]=$dircontents[$i]; + $j++; + } + } + } + } + + //sort results and return array + //print "Searched ".count($dircontents)." files and found ".count($carve_results)." matching search criteria:\n"; + sort($carve_results); + return $carve_results; +} + +//takes directory and file prefix and adds all files in the directory +//with the given prefix to an array ($valid_files) +function list_dir($directory,$pre){ + + $directory = $directory; + $open_directory = opendir($directory); + while($filename = readdir($open_directory)){ + $filesplit = explode(".", $filename); + $check_prefix = $filesplit[0]; + if($check_prefix==$pre){ + $valid_files[] = $filesplit[1]; + } + } + closedir(); + return $valid_files; +} + +//Takes sorted list of files, the directory they are located in and the prefix of the +//file name as arguments and retrieves each file's size and stores it in an array +function get_sizes($files_array,$dir,$pre){ + + for($i=0;$i