diff --git a/windows_memory_extractor.cpp b/windows_memory_extractor.cpp index 9866f45..c8afca4 100644 --- a/windows_memory_extractor.cpp +++ b/windows_memory_extractor.cpp @@ -32,7 +32,7 @@ struct ArgumentManager { void validateArguments(int argc, char* argv[]) { namespace po = boost::program_options; - std::string version = "v1.0.6"; + std::string version = "v1.0.7"; po::options_description description("Windows memory extractor " + version + "\nUsage"); description.add_options() @@ -63,7 +63,8 @@ struct ArgumentManager { if (vm.count("module")) { std::string suppliedModule = vm["module"].as<std::string>(); - if (suppliedModule.length() > 37) { + if (suppliedModule.length() > 255) { + SetLastError(18); throw std::invalid_argument{ "The module name is too long" }; } else { @@ -167,6 +168,7 @@ struct ArgumentManager { BOOST_FOREACH(const std::string & protection, suppliedProtections) { bool isProtectionRepeated = std::find(protections.begin(), protections.end(), protection) != protections.end(); if (isProtectionRepeated) { + SetLastError(160); throw std::invalid_argument{ "The same memory protection cannot be supplied more than once" }; } @@ -175,6 +177,7 @@ struct ArgumentManager { protections.push_back(protection); } else { + SetLastError(160); throw std::invalid_argument{ "The memory protections supplied are invalid. " "Supply only supported ones, separate each one with a space, and enclose all of them in quotes" }; } @@ -258,8 +261,6 @@ struct MemoryExtractionManager { } } - directoryName = createDirectory(); - BYTE* memoryPointer = NULL; // Virtual address 0x0000000000000000 // Module option related variables @@ -286,15 +287,18 @@ struct MemoryExtractionManager { throw std::exception{ "An error has occurred trying to get the version information at function GetFileVersionInfoSizeA" }; } std::vector<unsigned char> fileVersionInfoBuffer(fileVersionInfoSize); - if (!GetFileVersionInfoA(modulePath.c_str(), dwHandle, fileVersionInfoSize, &fileVersionInfoBuffer[0])) - { + if (!GetFileVersionInfoA(modulePath.c_str(), dwHandle, fileVersionInfoSize, &fileVersionInfoBuffer[0])) { throw std::exception{ "An error has occurred trying to get the version information at function GetFileVersionInfoA" }; } - + directoryName = createDirectory(); retrieveFileVersionInformation(&fileVersionInfoBuffer[0]); } } + if (!isDirectoryCreated) { + directoryName = createDirectory(); + } + std::ofstream resultsFile(directoryName + "/results.txt", std::ofstream::out); resultsFile << "List of .dmp files generated:\n"; @@ -423,6 +427,7 @@ struct MemoryExtractionManager { } directoryNameStream << std::dec << argumentManager.getPid() << "_" << std::put_time(&buf, "%d-%m-%Y_%H-%M-%S_UTC"); CreateDirectoryA(directoryNameStream.str().c_str(), NULL); + isDirectoryCreated = true; return directoryNameStream.str(); } @@ -650,6 +655,7 @@ struct MemoryExtractionManager { ArgumentManager& argumentManager; std::string directoryName; // The directory where the memory data files will be placed + bool isDirectoryCreated; unsigned int dmpFilesGeneratedCount; };