@@ -32,7 +32,7 @@ struct ArgumentManager {
3232 void validateArguments (int argc, char * argv[]) {
3333
3434 namespace po = boost::program_options;
35- std::string version = " v1.0.6 " ;
35+ std::string version = " v1.0.7 " ;
3636 po::options_description description (" Windows memory extractor " + version + " \n Usage" );
3737
3838 description.add_options ()
@@ -63,7 +63,8 @@ struct ArgumentManager {
6363
6464 if (vm.count (" module" )) {
6565 std::string suppliedModule = vm[" module" ].as <std::string>();
66- if (suppliedModule.length () > 37 ) {
66+ if (suppliedModule.length () > 255 ) {
67+ SetLastError (18 );
6768 throw std::invalid_argument{ " The module name is too long" };
6869 }
6970 else {
@@ -167,6 +168,7 @@ struct ArgumentManager {
167168 BOOST_FOREACH (const std::string & protection, suppliedProtections) {
168169 bool isProtectionRepeated = std::find (protections.begin (), protections.end (), protection) != protections.end ();
169170 if (isProtectionRepeated) {
171+ SetLastError (160 );
170172 throw std::invalid_argument{ " The same memory protection cannot be supplied more than once" };
171173 }
172174
@@ -175,6 +177,7 @@ struct ArgumentManager {
175177 protections.push_back (protection);
176178 }
177179 else {
180+ SetLastError (160 );
178181 throw std::invalid_argument{ " The memory protections supplied are invalid. "
179182 " Supply only supported ones, separate each one with a space, and enclose all of them in quotes" };
180183 }
@@ -258,8 +261,6 @@ struct MemoryExtractionManager {
258261 }
259262 }
260263
261- directoryName = createDirectory ();
262-
263264 BYTE* memoryPointer = NULL ; // Virtual address 0x0000000000000000
264265
265266 // Module option related variables
@@ -286,15 +287,18 @@ struct MemoryExtractionManager {
286287 throw std::exception{ " An error has occurred trying to get the version information at function GetFileVersionInfoSizeA" };
287288 }
288289 std::vector<unsigned char > fileVersionInfoBuffer (fileVersionInfoSize);
289- if (!GetFileVersionInfoA (modulePath.c_str (), dwHandle, fileVersionInfoSize, &fileVersionInfoBuffer[0 ]))
290- {
290+ if (!GetFileVersionInfoA (modulePath.c_str (), dwHandle, fileVersionInfoSize, &fileVersionInfoBuffer[0 ])) {
291291 throw std::exception{ " An error has occurred trying to get the version information at function GetFileVersionInfoA" };
292292 }
293-
293+ directoryName = createDirectory ();
294294 retrieveFileVersionInformation (&fileVersionInfoBuffer[0 ]);
295295 }
296296 }
297297
298+ if (!isDirectoryCreated) {
299+ directoryName = createDirectory ();
300+ }
301+
298302 std::ofstream resultsFile (directoryName + " /results.txt" , std::ofstream::out);
299303 resultsFile << " List of .dmp files generated:\n " ;
300304
@@ -423,6 +427,7 @@ struct MemoryExtractionManager {
423427 }
424428 directoryNameStream << std::dec << argumentManager.getPid () << " _" << std::put_time (&buf, " %d-%m-%Y_%H-%M-%S_UTC" );
425429 CreateDirectoryA (directoryNameStream.str ().c_str (), NULL );
430+ isDirectoryCreated = true ;
426431 return directoryNameStream.str ();
427432 }
428433
@@ -650,6 +655,7 @@ struct MemoryExtractionManager {
650655
651656 ArgumentManager& argumentManager;
652657 std::string directoryName; // The directory where the memory data files will be placed
658+ bool isDirectoryCreated;
653659 unsigned int dmpFilesGeneratedCount;
654660
655661};
0 commit comments