20 bool parseBaseArguments( vector<string>& vArgs, ARGUMENTS& args ); |
20 bool parseBaseArguments( vector<string>& vArgs, ARGUMENTS& args ); |
21 bool parseHookArguments( vector<string>& vArgs, ARGUMENTS& args ); |
21 bool parseHookArguments( vector<string>& vArgs, ARGUMENTS& args ); |
22 bool parseAnalyzeArguments( vector<string>& vArgs, ARGUMENTS& args ); |
22 bool parseAnalyzeArguments( vector<string>& vArgs, ARGUMENTS& args ); |
23 bool parseParseArguments( vector<string>& vArgs, ARGUMENTS& args ); |
23 bool parseParseArguments( vector<string>& vArgs, ARGUMENTS& args ); |
24 bool checkDataFileName( string& sFileName ); |
24 bool checkDataFileName( string& sFileName ); |
25 bool checkDataFilePath( string& sFilePath ); |
|
26 bool parseSbsConfiguration( string& sConfiguration, ARGUMENTS& args ); |
25 bool parseSbsConfiguration( string& sConfiguration, ARGUMENTS& args ); |
27 |
26 |
28 // Constants for old "hooking" parameter parsing. |
27 // Constants for old "hooking" parameter parsing. |
29 #define INVALID_PARAMETER "AnalyzeTool : Error, invalid parameter: " |
28 #define INVALID_PARAMETER "AnalyzeTool : Error, invalid parameter: " |
30 const char DATAFILENAME_INVALID_CHARS[] = " &^+-@$*()|\\/[]{}<>?;:,\"'"; |
29 const char DATAFILENAME_INVALID_CHARS[] = " &^+-@$%*()|\\/[]{}<>?;:,\"'"; |
31 const char DATAFILEPATH_INVALID_CHARS[] = " &^+-@$%*()|/[]{}<>?;,\"'"; |
|
32 |
30 |
33 /** |
31 /** |
34 * Check datafile name for invalid characters. |
32 * Check datafile name for invalid characters. |
35 * @return true if file name ok. |
33 * @return true if file name ok. |
36 */ |
34 */ |
40 { |
38 { |
41 const char c = sFileName.at( i ); |
39 const char c = sFileName.at( i ); |
42 if( strchr( DATAFILENAME_INVALID_CHARS, c ) != 0 ) |
40 if( strchr( DATAFILENAME_INVALID_CHARS, c ) != 0 ) |
43 return false; |
41 return false; |
44 } |
42 } |
45 return true; |
|
46 } |
|
47 |
|
48 /** |
|
49 * Check datafile path for invalid characters and correct format. |
|
50 * @return true if file path ok. |
|
51 */ |
|
52 bool checkDataFilePath( string& sFilePath ) |
|
53 { |
|
54 for ( size_t i = 0; i < sFilePath.length(); i++ ) |
|
55 { |
|
56 char c = sFilePath.at( i ); |
|
57 if( strchr( DATAFILEPATH_INVALID_CHARS, c ) != 0 ) |
|
58 return false; |
|
59 // first char must be drive letter a-z |
|
60 if( i == 0 && ( c = tolower( c ) < 'a' || c > 'z' ) ) |
|
61 return false; |
|
62 // if last char is not '\', add it |
|
63 if( i == sFilePath.length()-1 && c != '\\' ) |
|
64 sFilePath.append( "\\" ); |
|
65 } |
|
66 |
|
67 // ':\' after drive letter |
|
68 if( sFilePath.find( ":\\" ) != 1 ) |
|
69 return false; |
|
70 |
|
71 // there can be only one ':' on pos 1 |
|
72 if( sFilePath.find( ":", 2 ) != string::npos ) |
|
73 return false; |
|
74 |
|
75 //check double slashes |
|
76 if( sFilePath.find( "\\\\" ) != string::npos ) |
|
77 return false; |
|
78 |
|
79 return true; |
43 return true; |
80 } |
44 } |
81 |
45 |
82 /** |
46 /** |
83 * Parse base arguments from given vector of strings. |
47 * Parse base arguments from given vector of strings. |
212 args.eMainSwitch = SWITCH_DBGHELP_VERSION; |
176 args.eMainSwitch = SWITCH_DBGHELP_VERSION; |
213 else if ( ! _stricmp( (*it).c_str(), "-help" ) ) |
177 else if ( ! _stricmp( (*it).c_str(), "-help" ) ) |
214 args.eMainSwitch = SWITCH_HELP; |
178 args.eMainSwitch = SWITCH_HELP; |
215 else if ( ! _stricmp( (*it).c_str(), "-me" ) ) |
179 else if ( ! _stricmp( (*it).c_str(), "-me" ) ) |
216 { |
180 { |
217 cout << AT_MSG << "This feature is no longer supported. You can use -tr parameter for output to trace. \n" << endl; |
181 args.eMainSwitch = SWITCH_HOOK; |
218 } |
182 args.eHookSwitch = HOOK_EXTERNAL; |
219 else if ( ! _stricmp( (*it).c_str(), "-e" ) || ! _stricmp( (*it).c_str(), "-tr" ) ) |
183 } |
|
184 else if ( ! _stricmp( (*it).c_str(), "-e" ) ) |
220 { |
185 { |
221 args.eMainSwitch = SWITCH_HOOK; |
186 args.eMainSwitch = SWITCH_HOOK; |
222 args.eHookSwitch = HOOK_EXTERNAL_FAST; |
187 args.eHookSwitch = HOOK_EXTERNAL_FAST; |
223 } |
188 } |
224 else if ( ! _stricmp( (*it).c_str(), "-mi" ) ) |
189 else if ( ! _stricmp( (*it).c_str(), "-mi" ) ) |
225 { |
|
226 cout << AT_MSG << "This feature is no longer supported. You can use -lf parameter for logging to file. \n" << endl; |
|
227 } |
|
228 else if ( ! _stricmp( (*it).c_str(), "-lf" ) ) |
|
229 { |
190 { |
230 args.eMainSwitch = SWITCH_HOOK; |
191 args.eMainSwitch = SWITCH_HOOK; |
231 args.eHookSwitch = HOOK_INTERNAL; |
192 args.eHookSwitch = HOOK_INTERNAL; |
232 } |
193 } |
233 else if ( ! _stricmp( (*it).c_str(), "-instrument_i" ) ) |
194 else if ( ! _stricmp( (*it).c_str(), "-instrument_i" ) ) |
392 cout << AT_MSG << "Error, missing call stack size parameter." << endl; |
353 cout << AT_MSG << "Error, missing call stack size parameter." << endl; |
393 break; |
354 break; |
394 } |
355 } |
395 else if ( ! _stricmp( it->c_str(), "sbs" ) |
356 else if ( ! _stricmp( it->c_str(), "sbs" ) |
396 || ! _stricmp( it->c_str(), "abld" ) |
357 || ! _stricmp( it->c_str(), "abld" ) |
397 || ! _stricmp( it->c_str(), "-f" ) |
358 || ! _stricmp( it->c_str(), "-f" ) ) |
398 || ! _stricmp( it->c_str(), "-fp" ) ) |
|
399 { |
359 { |
400 bRet = false; |
360 bRet = false; |
401 cout << AT_MSG << "Error, missing call stack size parameter." << endl; |
361 cout << AT_MSG << "Error, missing call stack size parameter." << endl; |
402 break; |
362 break; |
403 } |
363 } |
445 { |
405 { |
446 it++; |
406 it++; |
447 if ( it == vArgs.end() ) |
407 if ( it == vArgs.end() ) |
448 { |
408 { |
449 bRet = false; |
409 bRet = false; |
450 cout << AT_MSG << "Error, missing log file name." << endl; |
410 cout << AT_MSG << "Error, missing internal data gathering file name." << endl; |
451 break; |
411 break; |
452 } |
412 } |
453 else if ( ! _stricmp( it->c_str(), "sbs" ) || ! _stricmp( it->c_str(), "abld" ) ) |
413 else if ( ! _stricmp( it->c_str(), "sbs" ) || ! _stricmp( it->c_str(), "abld" ) ) |
454 { |
414 { |
455 bRet = false; |
415 bRet = false; |
456 cout << AT_MSG << "Error, missing log file name." << endl; |
416 cout << AT_MSG << "Error, missing internal data gathering file name." << endl; |
457 break; |
417 break; |
458 } |
418 } |
459 else |
419 else |
460 { |
420 { |
461 if ( checkDataFileName( string( *it ) ) ) |
421 if ( checkDataFileName( string( *it ) ) ) |
465 args.HOOK.sDataFileName = *it; |
425 args.HOOK.sDataFileName = *it; |
466 } |
426 } |
467 else |
427 else |
468 { |
428 { |
469 bRet = false; |
429 bRet = false; |
470 cout << AT_MSG << "Error, specified log file name contains invalid character(s)." << endl; |
430 cout << AT_MSG << "Error, specified internal data gathering file name contains invalid character(s)." << endl; |
471 break; |
|
472 } |
|
473 } |
|
474 } |
|
475 // Data file path. |
|
476 else if ( _stricmp( it->c_str(), "-fp" ) == 0 ) |
|
477 { |
|
478 it++; |
|
479 if ( it == vArgs.end() ) |
|
480 { |
|
481 bRet = false; |
|
482 cout << AT_MSG << "Error, missing path for log file." << endl; |
|
483 break; |
|
484 } |
|
485 else if ( ! _stricmp( it->c_str(), "sbs" ) || ! _stricmp( it->c_str(), "abld" ) ) |
|
486 { |
|
487 bRet = false; |
|
488 cout << AT_MSG << "Error, missing path for log file." << endl; |
|
489 break; |
|
490 } |
|
491 else |
|
492 { |
|
493 string sFormattedPath = string(*it); |
|
494 if ( checkDataFilePath( sFormattedPath ) ) |
|
495 { |
|
496 // Pickup filename. |
|
497 args.HOOK.bDataFilePath = true; |
|
498 args.HOOK.sDataFilePath = sFormattedPath; |
|
499 } |
|
500 else |
|
501 { |
|
502 bRet = false; |
|
503 cout << AT_MSG << "Error, specified log file path contains invalid character(s) " |
|
504 << "or is in wrong format. Please, check help for correct format," << endl; |
|
505 break; |
431 break; |
506 } |
432 } |
507 } |
433 } |
508 } |
434 } |
509 // Build command parsing. |
435 // Build command parsing. |