Skip to content

Commit c8cadc4

Browse files
author
ThreePlanetsSoftware
committed
Added feature to save off the decompressed copies of compressed blobs if both --export and --decompress are chosen
1 parent cf00d4f commit c8cadc4

File tree

2 files changed

+56
-11
lines changed

2 files changed

+56
-11
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Version 1.1.0 (October 24 2017)
33
New Features
44
- Added a log file for each run to store the same output as is displayed on the screen
55
- Moved all output to log functions that copy anything displayed to aforementioned logs
6+
- Now exports both the compressed and decompressed versions of blobs if both the --export and --decompress options are chosen
67
Bug Fixes
78
- Typos in some of the output lines
89

sqlite_miner.pl

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
# Set verbose if very-verbose was chosen
6464
$verbose = $verbose || $very_verbose;
6565

66-
print_copyright();
66+
print_copyright(STDOUT);
6767

6868
# Set other files to read in
6969
my $fun_stuff_file = "fun_stuff.pl";
@@ -253,9 +253,18 @@ sub create_results_file {
253253
# Function returns a file handle
254254
sub open_log_file {
255255
my $run_folder = @_[0];
256+
257+
# Build log file path
256258
my $log_file = File::Spec->catfile($run_folder, "log.txt");
259+
260+
# Open the file
257261
open(LOG_OUTPUT, ">$log_file") or die "Can't open $log_file - $!\n";;
262+
263+
# Kick out the usual jargon and a creation note
264+
print_copyright(LOG_OUTPUT);
258265
log_line(LOG_OUTPUT, "Log file opened - ".File::Spec->abs2rel($log_file)."\n");
266+
267+
# Give back the file handle
259268
return LOG_OUTPUT;
260269
}
261270

@@ -449,8 +458,8 @@ sub check_column_for_fun {
449458
$tmp_export_file_name .= "-".$primary_key_column."-".$tmp_primary_key;
450459
}
451460
$tmp_export_file_name .= ".blob.".$fun_stuff{$file_type}{'extension'};
452-
$tmp_export_file_path = File::Spec->catfile($export_directory, $tmp_export_file_name);
453-
$tmp_export_file_counter = 1;
461+
my $tmp_export_file_path = File::Spec->catfile($export_directory, $tmp_export_file_name);
462+
my $tmp_export_file_counter = 1;
454463

455464
# Keep looping until we're sure we have a unique file path
456465
while(-e $tmp_export_file_path) {
@@ -461,10 +470,14 @@ sub check_column_for_fun {
461470
# Export the file
462471
(my $tmp_export_volume_for_output, my $tmp_export_directory_for_output, my $tmp_export_filename_for_output) = File::Spec->splitpath($tmp_export_file_path);
463472
print_log_line_if($log_file_handle, "\tExporting file as $tmp_export_filename_for_output\n", $very_verbose);
464-
open(OUTPUT, ">$tmp_export_file_path");
465-
binmode(OUTPUT);
466-
print OUTPUT $tmp_data_blob;
467-
close(OUTPUT);
473+
474+
# Save off the file
475+
open(EXPORT_OUTPUT, ">$tmp_export_file_path");
476+
binmode(EXPORT_OUTPUT);
477+
print EXPORT_OUTPUT $tmp_data_blob;
478+
close(EXPORT_OUTPUT);
479+
480+
# Record where we stored this
468481
print RESULT_OUTPUT ",\"$tmp_export_filename_for_output\"";
469482
}
470483

@@ -475,6 +488,36 @@ sub check_column_for_fun {
475488
# Decompress the blob
476489
anyuncompress(\$tmp_data_blob => \$tmp_new_blob);
477490

491+
# Save off the decompressed blob as well if we want to export
492+
if($export_files and length($tmp_new_blob) > 0) {
493+
494+
# At some point this should become its own function
495+
# Build the export filename (TABLE_COLUMN_[PRIMARYKEYCOLUMN_PRIMARYKEY].blob)
496+
my $tmp_export_file_name = $tmp_table_name."-".$column_name;
497+
if($tmp_primary_key) {
498+
$tmp_export_file_name .= "-".$primary_key_column."-".$tmp_primary_key;
499+
}
500+
$tmp_export_file_name .= ".blob.decompressed";
501+
my $tmp_export_file_path = File::Spec->catfile($export_directory, $tmp_export_file_name);
502+
my $tmp_export_file_counter = 1;
503+
504+
# Keep looping until we're sure we have a unique file path
505+
while(-e $tmp_export_file_path) {
506+
$tmp_export_file_counter += 1;
507+
$tmp_export_file_path = File::Spec->catfile($export_directory, $tmp_export_file_name."_".$tmp_export_file_counter);
508+
}
509+
510+
# Export the file
511+
(my $tmp_export_volume_for_output, my $tmp_export_directory_for_output, my $tmp_export_filename_for_output) = File::Spec->splitpath($tmp_export_file_path);
512+
print_log_line_if($log_file_handle, "\tExporting decompressed file as $tmp_export_filename_for_output\n", $very_verbose);
513+
514+
# Save off the file
515+
open(EXPORT_OUTPUT, ">$tmp_export_file_path");
516+
binmode(EXPORT_OUTPUT);
517+
print EXPORT_OUTPUT $tmp_new_blob;
518+
close(EXPORT_OUTPUT);
519+
}
520+
478521
# Build and execute our query to update the database
479522
if(length($tmp_new_blob) > 0 and $tmp_primary_key) {
480523
my $tmp_update_query = "UPDATE $table_name SET $column_name=? WHERE $primary_key_column=?";
@@ -641,10 +684,11 @@ sub print_final_results {
641684

642685
# Function to print run header
643686
sub print_copyright {
644-
print "SQLite Miner $version - Copyright (C) 2017 Jon Baumann, Ciofeca Forensics (https://www.ciofecaforensics.com)\n";
645-
print "\tThis program comes with ABSOLUTELY NO WARRANTY;\n";
646-
print "\tThis is free software, and you are welcome to redistribute it under certain conditions.\n";
647-
print "\tSee http://www.gnu.org/licenses/\n\n";
687+
my $file_handle = @_[0];
688+
print $file_handle "SQLite Miner $version - Copyright (C) 2017 Jon Baumann, Ciofeca Forensics (https://www.ciofecaforensics.com)\n";
689+
print $file_handle "\tThis program comes with ABSOLUTELY NO WARRANTY;\n";
690+
print $file_handle "\tThis is free software, and you are welcome to redistribute it under certain conditions.\n";
691+
print $file_handle "\tSee http://www.gnu.org/licenses/\n\n";
648692
}
649693

650694
# Function to print usage instructions

0 commit comments

Comments
 (0)