public static void ExecuteOnFile(Pair <string, string> fileArg, Pair <string, string> hintArg) { var filePath = fileArg.Value; HashFile file = FileSystem.FindFileByPath(filePath); if (file == null) { var msg = string.Format("No file found at '{0}'.", filePath); msg = TextUtil.Error(msg); TerminalUtil.ShowText(msg); } else { var password = file.Password; LoopUtil.RunCoroutine(ExecuteOnPassword(password, hintArg.Value, (success) => { if (success) { var msg = string.Format("Password found!\nThe password of '{0}' is: {1}", filePath, file.Password); msg = TextUtil.Success(msg); TerminalUtil.ShowText(msg); } else { var msg = "Unable to find the password of '{0}' with the given arguments. Please try another set of hints."; msg = string.Format(msg, filePath); msg = TextUtil.Error(msg); TerminalUtil.ShowText(msg); } })); } }
public static void Execute(ProgramExecutionOptions options) { if (ProgramUtil.ShowHelpIfNeeded(options)) { return; } if (CommandLineUtil.ValidateArguments(options.ParsedArguments, Validations)) { Pair <string, string> pathArg = CommandLineUtil.FindArgumentByName(options.ParsedArguments, PathArgName); Pair <string, string> passwordArg = CommandLineUtil.FindArgumentByName(options.ParsedArguments, PasswordArgName); var path = pathArg.Value; var password = passwordArg.Value; HashFile file = FileSystem.FindFileByPath(path); if (file == null) { var msg = string.Format("The path '{0}' is not a valid file path.", path); ShowErrorMessage(msg); } else { if (file.Status != FileStatus.Encrypted) { var msg = string.Format("The file '{0}' is not encrypt. You can open it using 'open {0}'", path); msg = TextUtil.ApplyNGUIColor(msg, Constants.Colors.Success); TerminalUtil.ShowText(msg); } else { var filePassword = file.Password; if (string.Equals(password, filePassword)) { var msg = string.Format("File '{0}' decrypted successfully. Use 'open {0}' to open the file.", path); msg = TextUtil.ApplyNGUIColor(msg, Constants.Colors.Success); TerminalUtil.ShowText(msg); FileSystem.ChangeFileStatus(file, FileStatus.Normal); } else { var msg = "Invalid password."; ShowErrorMessage(msg); } } } } else { var pathResult = (int)PathValidation.ValidationResult; var passwordResult = (int)PasswordValidation.ValidationResult; if (MathUtil.ContainsFlag(pathResult, (int)ArgValidationResult.NotFound) || MathUtil.ContainsFlag(pathResult, (int)ArgValidationResult.EmptyValue)) { var msg = "You need to supply a path. Please use 'help cracker' for more info."; ShowErrorMessage(msg); } else if (MathUtil.ContainsFlag(passwordResult, (int)ArgValidationResult.NotFound) || MathUtil.ContainsFlag(passwordResult, (int)ArgValidationResult.EmptyValue)) { var msg = "You need to supply a password. Please use 'help cracker' for more info."; ShowErrorMessage(msg); } } }