Example #1
0
        public static void ShowEncryptedFileMessage()
        {
            var msg = "This file is encrypted, its encrypted content will be shown. You'll need to decrypted the file to see its real content.\nType 'help cracker' for more info.";

            msg = TextUtil.Warning(msg);
            TerminalUtil.ShowText(msg);
        }
Example #2
0
        public static void OpenTextFile(HashFile file, TextFile textFile, bool openOnTerminal)
        {
            string textContent;

            if (file.Status == FileStatus.Encrypted)
            {
                ShowEncryptedFileMessage();

                textContent = textFile.EncryptedTextContent;
            }
            else
            {
                textContent = FileSystem.GetTextFileContent(textFile);
            }

            if (openOnTerminal)
            {
                TerminalUtil.ShowText(textContent);
            }
            else
            {
                string title = FileSystem.GetWindowTitleForFile(file);
                WindowUtil.CreateTextWindow(textContent, title);
            }
        }
Example #3
0
        /// <summary>
        /// Initialized the game.
        /// </summary>
        public void InitializeGame()
        {
#if DEB
            if (GUIReferences.InputListener == null)
            {
                DebugUtil.Error("INPUT LISTENER IS NULL. PLEASE BAKE THE GAME HOLDER!");
            }
            if (GUIReferences.TerminalComponent == null)
            {
                DebugUtil.Error("TERMINAL COMPONENT IS NULL. PLEASE BAKE THE GAME HOLDER!");
            }
#endif

            Constants.Colors           = Colors;
            DataHolder.DebugCondition  = DebugCondition;
            DataHolder.GUIReferences   = GUIReferences;
            DataHolder.DreamReferences = DreamReferences;

            DataHolder.GUIReferences.TerminalComponent.Initialize();
            StoryUtil.Init();
            LoopUtil.Init();
            WindowUtil.Initialize();
            DataUtil.LoadData();
            ProgramUtil.SetupPrograms();
            GUIUtil.SetCursorToDefault();

            TerminalUtil.HideTerminal();
            AnnouncementUtil.HideAnnouncement();

            DreamUtil.ExecuteDreamOne();
        }
Example #4
0
        public static void ShowProgramsUsage()
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendLine("Program usage:");

            var usage = "    <program_comand> [<program_option> <program_option> <program_option>]";

            builder.AppendLine(usage);

            builder.AppendLine();
            builder.AppendLine("    Examples:");

            var example = "        help open";

            builder.AppendLine(example);

            example = "        open path/to/file -t";
            builder.AppendLine(example);

            example = "        cracker path/to/file -p password";
            builder.AppendLine(example);

            TerminalUtil.ShowText(builder.ToString());
        }
Example #5
0
        public static void OpenImageFile(HashFile file, ImageFile imageFile, bool openOnTerminal)
        {
            var imageContent = imageFile.ImageContent;

            if (file.Status == FileStatus.Encrypted)
            {
                ShowEncryptedFileMessage();
            }

            if (openOnTerminal)
            {
                TerminalUtil.ShowImage(imageContent);
            }
            else
            {
                string title = FileSystem.GetWindowTitleForFile(file);
                ImageWindowComponent imageWindow = WindowUtil.CreateImageWindow(imageContent, title);

                if (file.Status == FileStatus.Encrypted)
                {
                    var materialPrefab = DataHolder.GUIReferences.EncryptedImageMaterial;

                    var material = new Material(materialPrefab);
                    material.CopyPropertiesFromMaterial(materialPrefab);

                    imageWindow.ImageHolder.material      = material;
                    imageWindow.UpdateImageBlendFactor    = true;
                    imageWindow.EncryptedImageBlendFactor = 1f;
                }
            }
        }
Example #6
0
        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);
                    }
                }));
            }
        }
Example #7
0
        public static void Execute(ProgramExecutionOptions options)
        {
            if (ProgramUtil.ShowHelpIfNeeded(options))
            {
                return;
            }

            if (CommandLineUtil.ValidateArguments(options.ParsedArguments, Validations))
            {
                var latitudeParam  = CommandLineUtil.FindArgumentByName(options.ParsedArguments, LatitudeParameterName);
                var longitudeParam = CommandLineUtil.FindArgumentByName(options.ParsedArguments, LongitudeParameterName);

                var latitude  = latitudeParam.Value;
                var longitude = longitudeParam.Value;

                float fLatitude;
                float fLongitude;
                if (ValidateCoords(latitude, longitude, out fLatitude, out fLongitude))
                {
                    float imageWidth  = AditionalData.MapTexture.width;
                    float imageHeight = AditionalData.MapTexture.height;

                    var markerPositon = new Vector2(fLatitude, fLongitude);

                    var dimentions = AditionalData.MapDimentions;
                    if (dimentions.Contains(markerPositon))
                    {
                        string title       = string.Format("Map for lat: {0:F3} / lon: {1:F3}", fLatitude, fLongitude);
                        var    imageWindow = WindowUtil.CreateImageWindow(AditionalData.MapTexture, title);

                        var holder         = imageWindow.MainWidget;
                        var markerInstance = NGUITools.AddChild(holder.gameObject, AditionalData.MarkerGameObject);

                        markerInstance.transform.localPosition = GetMarkerPosition(AditionalData.MapTexture, dimentions, markerPositon);
                    }
                    else
                    {
                        var fromDimention = string.Format("[lat {0} / lon {1}]", dimentions.xMin, dimentions.yMin);
                        var toDimention   = string.Format("[lat {0} / lon {1}]", dimentions.xMax, dimentions.yMax);
                        var msg           = "The given positon lies outside the available map. The map data encloses goes from {0} to {1}";
                        msg = string.Format(msg, fromDimention, toDimention);
                        msg = TextUtil.Error(msg);
                        TerminalUtil.ShowText(msg);
                    }
                }
                else
                {
                    var msg = "Invalid coordinates. Please supply latitude and longitude as decimal numers.\nEx: lat 25.6939 log 91.9057";
                    msg = TextUtil.Error(msg);
                    TerminalUtil.ShowText(msg);
                }
            }
            else
            {
                var msg = "Error. Please supply a valid latitude and longitude";
                msg = TextUtil.Error(msg);
                TerminalUtil.ShowText(msg);
            }
        }
Example #8
0
        /// <summary>
        /// Changes the current dir to the given dir.
        /// </summary>
        public static void ChangeDir(HashDir dir)
        {
            var data = DataHolder.DeviceData.CurrentDevice.FileSystem;

            data.CurrentDir = dir;

            TerminalUtil.UpdateCurrentPathLabel();
            TerminalUtil.UpdateCommandBuffer();
        }
Example #9
0
        public static void ExecuteOnDevice(Pair <string, string> deviceArg, Pair <string, string> username, Pair <string, string> hintArg)
        {
            var deviceTarget = deviceArg.Value;
            var device       = DeviceUtil.FindDeviceByIpOrName(deviceTarget);

            if (device == null)
            {
                var msg = string.Format("No device found with IP or Name equal to '{0}'", deviceTarget);
                msg = TextUtil.Error(msg);
                TerminalUtil.ShowText(msg);
            }
            else
            {
                var hasSSH = DeviceUtil.HasProgram(device, ProgramType.SSH);
                if (hasSSH)
                {
                    var user = DeviceUtil.FindUserByName(device, username.Value);
                    if (user == null)
                    {
                        var msg = string.Format("The device '{0}' has no user with name '{1}'.", deviceTarget, username.Value);
                        msg = TextUtil.Error(msg);
                        TerminalUtil.ShowText(msg);
                    }
                    else
                    {
                        var password = user.Password;
                        LoopUtil.RunCoroutine(ExecuteOnPassword(password, hintArg.Value, success =>
                        {
                            if (success)
                            {
                                var msg = "Password found! The password for '{0}' is '{1}'.";
                                msg     = string.Format(msg, user.Username, user.Password);
                                msg     = TextUtil.Success(msg);
                                TerminalUtil.ShowText(msg);
                            }
                            else
                            {
                                var msg = string.Format(
                                    "Unable to find the password of user '{0}' with the given arguments.\nPlease try another set of hints.",
                                    user.Username);
                                msg = TextUtil.Error(msg);
                                TerminalUtil.ShowText(msg);
                            }
                        }));
                    }
                }
                else
                {
                    var msg = "The device '{0}' is not running a SSH instance. We have no way to validate password attempts.";
                    msg = string.Format(msg, deviceTarget);
                    msg = TextUtil.Error(msg);
                    TerminalUtil.ShowText(msg);
                }
            }
        }
Example #10
0
        public static void Execute(ProgramExecutionOptions options)
        {
            if (ProgramUtil.ShowHelpIfNeeded(options))
            {
                return;
            }

            var args = options.ParsedArguments;

            if (CommandLineUtil.ValidateArguments(args, Validations))
            {
                var hintArg = CommandLineUtil.FindArgumentByName(args, HintArgName);
                Pair <string, string> deviceArg;
                Pair <string, string> fileArg;

                var deviceExists = CommandLineUtil.TryGetArgumentByName(args, DeviceArgName, out deviceArg);
                var fileExists   = CommandLineUtil.TryGetArgumentByName(args, FileArgName, out fileArg);
                if (deviceExists && fileExists)
                {
                    var msg = "You need to supply either a file or a device, never both.";
                    msg = TextUtil.Error(msg);
                    TerminalUtil.ShowText(msg);
                }
                else
                {
                    if (deviceExists)
                    {
                        Pair <string, string> usernameArg;
                        var usernameExists = CommandLineUtil.TryGetArgumentByName(args, UsernameArgName, out usernameArg);
                        if (usernameExists)
                        {
                            ExecuteOnDevice(deviceArg, usernameArg, hintArg);
                        }
                        else
                        {
                            var msg = "If you are targeting a device, please supply a username for whose password should be discovered.";
                            msg = TextUtil.Error(msg);
                            TerminalUtil.ShowText(msg);
                        }
                    }
                    else if (fileExists)
                    {
                        ExecuteOnFile(fileArg, hintArg);
                    }
                }
            }
            else
            {
                var msg = "ERROR";
                msg = TextUtil.Error(msg);
                TerminalUtil.ShowText(msg);
            }
        }
Example #11
0
        public void Initialize()
        {
            DebugUtil.Log("TERMINAL COMPONENT INITIALIZED!", Color.green, DebugUtil.DebugCondition.Info, DebugUtil.LogType.Info);

            DataHolder.TerminalData = new TerminalData();
            DataHolder.TerminalData.CommandCache      = SList.Create <string>(50);
            DataHolder.TerminalData.AvailableCommands = SList.Create <string>(20);
            DataHolder.TerminalData.BatchEntries      = SList.Create <TextBatchEntry>(10);
            DataHolder.TerminalData.AllEntries        = SList.Create <TerminalEntry>(100);
            TerminalUtil.FocusOnInput();
            TerminalUtil.CalculateMaxCharLenght();
        }
Example #12
0
        public static void ShowHelpFor(Program program)
        {
            string helpMessage;

            if (string.IsNullOrEmpty(program.HelpText))
            {
                helpMessage = BuildDynamicHelpMessage(program);
            }
            else
            {
                helpMessage = program.HelpText;
            }

            TerminalUtil.ShowText(helpMessage);
        }
Example #13
0
        public static void Execute(ProgramExecutionOptions options)
        {
            if (ProgramUtil.ShowHelpIfNeeded(options))
            {
                return;
            }

            if (CommandLineUtil.ValidateArguments(options.ParsedArguments, Validations))
            {
                var path = options.ParsedArguments[0].Value;

                HashDir  dir;
                HashFile file;

                if (FileSystem.DirExists(path, out dir))
                {
                    FileSystem.ChangeDir(dir);
                }
                else if (FileSystem.FileExistsAndIsAvailable(path, out file))
                {
                    var msg = string.Format("The path '{0}' points to a file. Use 'open {0}' to open this file.", path);
                    msg = TextUtil.Warning(msg);
                    TerminalUtil.ShowText(msg);
                }
                else
                {
                    var msg = string.Format("The path '{0}' points nowhere. Please supply a valid path.", path);
                    msg = TextUtil.Error(msg);
                    TerminalUtil.ShowText(msg);
                }
            }
            else
            {
                string msg    = null;
                var    result = PathValidation.ValidationResult;
                if (MathUtil.ContainsFlag((int)result, (int)ArgValidationResult.EmptyValue))
                {
                    msg = "Please supply a path.";
                }
                else if (MathUtil.ContainsFlag((int)result, (int)ArgValidationResult.NotFound))
                {
                    msg = "Please supply a path.";
                }

                msg = TextUtil.Error(msg);
                TerminalUtil.ShowText(msg);
            }
        }
Example #14
0
        public void OnInputChanged()
        {
            var text = DataHolder.GUIReferences.Input.value;

            if (string.IsNullOrEmpty(text))
            {
                TerminalUtil.ChangeToCommandCacheBuffer();
            }
            else if (text.Contains("\n"))
            {
                StartCoroutine(TerminalUtil.HandlePlayerInput(text));
            }
            else
            {
                TerminalUtil.UpdateCommandBuffer();
            }
        }
Example #15
0
        public static IEnumerator ExecuteOnPassword(string password, string rawGuess, Action <bool> callback)
        {
            var guessArray = rawGuess.Split(';');
            var guess      = string.Concat(guessArray);

            TerminalUtil.BlockPlayerInput("[BLOCKED WHILE RUNNING CRACKER]");

            var percentage = GetEqualPercentage(password, guessArray);

            var msg = "Generating passowords based on given hints... This might take a few seconds.";

            msg = TextUtil.Warning(msg);

            TerminalUtil.ShowText(msg);

            float time = Mathf.Log10(guess.Length);

            time = Mathf.LerpUnclamped(0, 3, time);
            yield return(new WaitForSecondsRealtime(time));

            var random         = new System.Random(guess.Length / guessArray.Length);
            var minCount       = (guessArray.Length * guessArray.Length);
            var passwordsCount = random.Next(minCount, Mathf.CeilToInt((float)(minCount * Math.PI)));

            msg = string.Format("{0} passwords generated.", passwordsCount);

            TerminalUtil.ShowText(msg);

            msg = string.Format("Trying password {0}/{1}", 1, passwordsCount);
            TerminalUtil.ShowText(msg);

            for (int i = 1; i < passwordsCount; i++)
            {
                msg = string.Format("Trying password {0}/{1}", i + 1, passwordsCount);
                TerminalUtil.ChangeLastText(msg);
                yield return(new WaitForSecondsRealtime(.01f));
            }

            TerminalUtil.UnblockPlayerInput();
            yield return(null);

            var success = percentage >= PercentualThresholdToSuccess;

            callback(success);
        }
Example #16
0
        public static void Execute(ProgramExecutionOptions options)
        {
            if (ProgramUtil.ShowHelpIfNeeded(options))
            {
                return;
            }

            if (options.ParsedArguments.Count > 0)
            {
                var programName = options.ParsedArguments[0].Value;
                var program     = Shell.FindProgramByCommand(programName);
                if (program == null)
                {
                    var msg =
                        "'{0}' is not a valid program. You can use 'help' to see help for all programs or 'help <program_name>' to see help about a specific program";
                    msg = TextUtil.ApplyNGUIColor(msg, Constants.Colors.Error);
                    TerminalUtil.ShowText(msg);
                }
                else
                {
                    ShowHelpFor(program);
                    ShowProgramsUsage();
                }
            }
            else
            {
                TerminalUtil.StartTextBatch();

                var programs = ProgramUtil.GetAvailablePrograms(DataHolder.DeviceData.CurrentDevice);
                for (int i = 0; i < programs.Count; i++)
                {
                    var program = programs[i];
                    ShowHelpFor(program);
                }

                ShowProgramsUsage();

                TerminalUtil.EndTextBatch();
            }
        }
Example #17
0
        public static void Execute(ProgramExecutionOptions options)
        {
            var width        = Screen.currentResolution.width;
            var height       = Screen.currentResolution.height;
            var result       = new Texture2D(width, height, TextureFormat.RGB24, false);
            var targetRender = new RenderTexture(width, height, 24);

            Camera.main.targetTexture = targetRender;
            Camera.main.Render();

            RenderTexture.active = targetRender;

            result.ReadPixels(new Rect(0, 0, width, height), 0, 0);
            result.Apply();

            RenderTexture.active      = null;
            Camera.main.targetTexture = null;

            targetRender.Release();
            Object.Destroy(targetRender);

            var printsFolder = FileSystem.FindDirByPath(PrintFolderPath);

            if (printsFolder == null)
            {
                var rootFolder = FileSystem.GetRootDir();
                printsFolder = FileSystem.CreateDir(rootFolder, PrintFolderName);
            }

            var file = FileSystem.CreateImageFile(printsFolder, "print", result);

            var msg = string.Format("Printscreen saved to '{0}'.", file.FullPath);

            msg = TextUtil.Success(msg);
            TerminalUtil.ShowText(msg);

            OpenProgram.OpenImageFile(file, file.Content as ImageFile, false);
        }
Example #18
0
        public void TabPressed()
        {
            TerminalUtil.ChangeToAvailableCommandsBuffer();

            if (Time.time - LastTabPressedTime <= DoubleTabPressedInterval)
            {
                TerminalUtil.ShowAllCommandBufferOptions();
                LastTabPressedTime = 0;
            }
            else
            {
                LastTabPressedTime = Time.time;

                var shiftPressed = Input.GetKey(KeyCode.LeftShift);
                if (shiftPressed)
                {
                    TerminalUtil.NavigateCommandBuffer(-1, true);
                }
                else
                {
                    TerminalUtil.NavigateCommandBuffer(1, true);
                }
            }
        }
Example #19
0
        public static void FilleCommandBufferWithFileSystem(FillBufferFileSystemOptions option)
        {
            var commandBuffer = DataHolder.TerminalData.AvailableCommands;
            var data          = DataHolder.DeviceData.CurrentDevice.FileSystem;

            SList.Clear(commandBuffer);

            var currentDir = data.CurrentDir;

            if (option == FillBufferFileSystemOptions.IncludeAll || option == FillBufferFileSystemOptions.IncludeDir)
            {
                if (currentDir.ParentDir != null)
                {
                    SList.Add(commandBuffer, "..");
                }

                SList.Add(commandBuffer, ".");

                var childs = GetAllAvailableChild(currentDir);
                for (int i = 0; i < childs.Count; i++)
                {
                    SList.Add(commandBuffer, childs[i].FullPath);
                }
            }

            if (option == FillBufferFileSystemOptions.IncludeAll || option == FillBufferFileSystemOptions.IncludeFile)
            {
                var files = GetAvailableFilesFromDir(currentDir);
                for (int i = 0; i < files.Count; i++)
                {
                    SList.Add(commandBuffer, files[i].FullPath);
                }
            }

            TerminalUtil.ChangeToAvailableCommandsBuffer();
        }
Example #20
0
 public static void Execute(ProgramExecutionOptions options)
 {
     TerminalUtil.ShowText(DevicesData);
 }
Example #21
0
        /// <summary>
        /// Executes the dir program.
        /// </summary>
        public static void Execute(ProgramExecutionOptions options)
        {
            if (ProgramUtil.ShowHelpIfNeeded(options))
            {
                return;
            }

            HashDir currentDir = null;

            if (options.ParsedArguments.Count == 0)
            {
                currentDir = DataHolder.DeviceData.CurrentDevice.FileSystem.CurrentDir;
            }
            else
            {
                var desiredDirPath = options.ParsedArguments[0].Value;
                if (!FileSystem.DirExists(desiredDirPath, out currentDir))
                {
                    string msg;

                    HashFile file;
                    if (FileSystem.FileExistsAndIsAvailable(desiredDirPath, out file))
                    {
                        msg = string.Format("The path '{0}' points to a file. Use 'open {0}' to open this file.",
                                            desiredDirPath);
                    }
                    else
                    {
                        msg = string.Format("The path '{0}' points nowhere. Please supply a valid path.",
                                            desiredDirPath);
                    }

                    msg = TextUtil.Error(msg);
                    TerminalUtil.ShowText(msg);
                    return;
                }
            }

            var childs = FileSystem.GetAllAvailableChild(currentDir);
            var files  = FileSystem.GetAvailableFilesFromDir(currentDir);

            if (childs.Count == 0 && files.Count == 0)
            {
                var txt = "EMPTY DIRECTORY!";
                txt = TextUtil.ApplyNGUIColor(txt, LineColor);
                TerminalUtil.ShowText(txt);
            }
            else
            {
                TerminalUtil.StartTextBatch();

                TerminalUtil.ShowText(HeaderLine.FormattedText);

                for (int i = 0; i < childs.Count; i++)
                {
                    var child = childs[i];
                    var line  = CreateLine(child.Name, "DIRECTORY", string.Empty, LineColor, TextModifiers.Italic);
                    TerminalUtil.ShowText(line.FormattedText);
                }

                for (int i = 0; i < files.Count; i++)
                {
                    var file = files[i];

                    var status = FileSystem.GetStatusString(file.Status);
                    var line   = CreateLine(file.FullName, "FILE", status, LineColor, TextModifiers.Italic);
                    TerminalUtil.ShowText(line.FormattedText);
                }

                TerminalUtil.EndTextBatch();
            }
        }
Example #22
0
 public void F1Pressed()
 {
     TerminalUtil.ToggleTerminal();
 }
Example #23
0
 public void EscPressed()
 {
     TerminalUtil.ClearInputText();
 }
Example #24
0
        public static void Execute(ProgramExecutionOptions options)
        {
            if (ProgramUtil.ShowHelpIfNeeded(options))
            {
                return;
            }

            if (CommandLineUtil.ValidateArguments(options.ParsedArguments, Validations))
            {
                Pair <string, string> pathArg;

                // no need to validate this because the argument is required
                CommandLineUtil.TryGetArgumentByName(options.ParsedArguments, PathArgName, out pathArg);
                var path = pathArg.Value;

                bool openOnTerminal = CommandLineUtil.ArgumentExists(options.ParsedArguments, TerminalArgName);

                HashFile file;
                HashDir  dir;
                if (FileSystem.FileExistsAndIsAvailable(path, out file))
                {
                    var permission = FileSystem.GetAccessPermission(file);
                    if (permission < AccessPermission.Editable)
                    {
                        var msg = "You don't have permission to open this file.";
                        msg = TextUtil.Error(msg);
                        TerminalUtil.ShowText(msg);
                    }
                    else
                    {
                        switch (file.FileType)
                        {
                        case HashFileType.Text:
                            var textFile = file.Content as TextFile;
                            OpenTextFile(file, textFile, openOnTerminal);
                            break;

                        case HashFileType.Image:
                            var imageFile = file.Content as ImageFile;
                            OpenImageFile(file, imageFile, openOnTerminal);
                            break;

                        default:
                            DebugUtil.Error(string.Format("The open program can't open file type: {0}", file.FileType));
                            break;
                        }
                    }
                }
                else
                {
                    string msg;
                    if (FileSystem.DirExists(path, out dir))
                    {
                        msg = "The path '{0}' points to a directory. Please use 'cd {0}' to navigate to that directory.";
                    }
                    else
                    {
                        msg = "The path '{0}' points to nowhere. Please supply a valida path.";
                    }

                    msg = string.Format(msg, path);
                    msg = TextUtil.Error(msg);
                    TerminalUtil.ShowText(msg);
                }
            }
            else
            {
                string msg = "Please supply a file path.";
                msg = TextUtil.Error(msg);
                TerminalUtil.ShowText(msg);
            }
        }
Example #25
0
 public void OnInputSubimit()
 {
     StartCoroutine(TerminalUtil.HandlePlayerInput(DataHolder.GUIReferences.Input.value));
 }
Example #26
0
 public static void UpdateDeviceRelatedGUI()
 {
     TerminalUtil.UpdateCurrentPathLabel();
     TerminalUtil.ChangeToAvailableCommandsBuffer();
     TerminalUtil.ResetCommandBufferIndex();
 }
Example #27
0
 private static void PrepareForDream()
 {
     TerminalUtil.HideTerminal();
     WindowUtil.HideAllWindows();
 }
Example #28
0
 public void DownPressed()
 {
     TerminalUtil.ChangeToCommandCacheBuffer();
     TerminalUtil.NavigateCommandBuffer(-1, false);
 }
Example #29
0
 private static void EndDream()
 {
     TerminalUtil.ShowTerminal();
     WindowUtil.ShowAllWindows();
 }
        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);
                }
            }
        }