Skip to content
Snippets Groups Projects
Unverified Commit ce3b6704 authored by Richard Cordovano's avatar Richard Cordovano Committed by GitHub
Browse files

Merge pull request #1533 from jkho/5189-Add-debug-statements-to-tsk_logical_imager

Add -v option to print debug info
parents 85bc960c 0ecf37aa
No related branches found
No related tags found
No related merge requests found
......@@ -42,14 +42,18 @@ static TSK_TCHAR *progname;
static std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
static BOOL debug = FALSE;
void printDebug(char *msg, const char *fmt...) {
if (debug) {
fprintf(stderr, msg, fmt);
if (tsk_verbose) {
string prefix("tsk_logical_imager: ");
string message = prefix + msg + "\n";
tsk_fprintf(stderr, message.c_str(), fmt);
}
}
void printDebug(char *msg) {
printDebug(msg, "");
}
/**
* GetErrorStdStr - returns readable error message for the given error code
*
......@@ -544,7 +548,7 @@ BOOL getPhysicalDrives(std::vector<std::wstring> &phyiscalDrives) {
std::wstring str(TskHelper::toWide(pos));
if (str.rfind(_TSK_T("PhysicalDrive")) == 0) {
phyiscalDrives.push_back(str);
printDebug("Found %s\n", pos);
printDebug("Found %s", pos);
}
}
} else {
......@@ -834,7 +838,6 @@ static void usage() {
tsk_fprintf(stderr, "\t-i imgPath: The image file\n");
tsk_fprintf(stderr, "\t-c configPath: The configuration file. Default is logical-imager-config.json\n");
tsk_fprintf(stderr, "\t-v: verbose output to stderr\n");
tsk_fprintf(stderr, "\t-d: debug output to stderr\n");
tsk_fprintf(stderr, "\t-V: Print version\n");
exit(1);
}
......@@ -897,9 +900,6 @@ main(int argc, char **argv1)
iFlagUsed = TRUE;
break;
case _TSK_T('d'):
debug = TRUE;
break;
}
}
......@@ -907,6 +907,7 @@ main(int argc, char **argv1)
configFilename = _TSK_T("logical-imager-config.json");
fprintf(stdout, "Using default configuration file logical-imager-config.json\n");
}
printDebug("Using config file %s", TskHelper::toNarrow(configFilename).c_str());
// create a directory with hostname_timestamp
std::string directoryPath;
......@@ -922,6 +923,7 @@ main(int argc, char **argv1)
imgPaths.push_back(imgPath);
} else {
if (getDrivesToProcess(drivesToProcess)) {
printDebug("Process is running in elevated mode");
for (auto it = std::begin(drivesToProcess); it != std::end(drivesToProcess); ++it) {
imgPaths.push_back(std::wstring(_TSK_T("\\\\.\\")) + *it);
}
......@@ -949,12 +951,13 @@ main(int argc, char **argv1)
for (int i = 0; i < imgPaths.size(); ++i) {
const TSK_TCHAR *image = (TSK_TCHAR *)imgPaths[i].c_str();
driveToProcess = iFlagUsed ? TskHelper::toNarrow(imgPaths[i]) : TskHelper::toNarrow(drivesToProcess[i]);
printDebug("Processing drive %s", driveToProcess.c_str());
std::string outputFileName = directoryPath + "/" + (iFlagUsed ? "sparse_image" : driveToProcess) + ".vhd";
std::wstring outputFileNameW = TskHelper::toWide(outputFileName);
if (hasTskLogicalImager(image)) {
printDebug("Skipping drive %s\n", driveToProcess.c_str());
printDebug("Skipping drive %s because tsk_logical_imager.exe exists at the root directory.", driveToProcess.c_str());
continue; // Don't process a drive with /tsk_logicial_image.exe at the root
}
......@@ -1056,6 +1059,7 @@ main(int argc, char **argv1)
TSK_IMG_INFO *img = *it;
if (img->itype == TSK_IMG_TYPE_RAW) {
if (config->getFinalizeImagerWriter()) {
printDebug("finalize image writer for %s", driveToProcess.c_str());
if (tsk_img_writer_finish(img) == TSK_ERR) {
fprintf(stderr, "tsk_img_writer_finish returns TSK_ERR\n");
}
......@@ -1067,5 +1071,6 @@ main(int argc, char **argv1)
if (config) {
delete config;
}
printDebug("Exiting");
exit(0);
}
\ No newline at end of file
......@@ -497,7 +497,7 @@ static TSK_RETVAL_ENUM tsk_img_writer_close(TSK_IMG_WRITER* img_writer) {
if (tsk_verbose) {
tsk_fprintf(stderr,
"tsk_img_writer_close: Closing image writer");
"tsk_img_writer_close: Closing image writer\n");
}
if (img_writer->outputFileHandle != 0) {
......@@ -537,7 +537,7 @@ static TSK_RETVAL_ENUM tsk_img_writer_close(TSK_IMG_WRITER* img_writer) {
static TSK_RETVAL_ENUM tsk_img_writer_finish_image(TSK_IMG_WRITER* img_writer) {
if (tsk_verbose) {
tsk_fprintf(stderr,
"tsk_img_writer_finish_image: Finishing image");
"tsk_img_writer_finish_image: Finishing image\n");
}
if (img_writer->is_finished == 1) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment