Example #1
0
        /// <summary>
        /// Fills the available command buffer with the current available options.
        /// </summary>
        public static void UpdateCommandBuffer()
        {
            var references = DataHolder.GUIReferences;
            var data       = DataHolder.TerminalData;

            SList.Clear(data.AvailableCommands);

            var currentText = references.Input.value;

            var programName = CommandLineUtil.GetCommandName(currentText);
            var program     = Shell.FindProgramByCommand(programName);

            Action bufferFiller;

            if (program == null)
            {
                bufferFiller = null;
            }
            else
            {
                bufferFiller = Shell.GetProgramBufferFillerMethod(program);
            }

            if (bufferFiller == null)
            {
                FileSystem.FilleCommandBufferWithFileSystem(FillBufferFileSystemOptions.IncludeAll);
            }
            else
            {
                bufferFiller();
            }

            ChangeToAvailableCommandsBuffer();
        }
Example #2
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 #3
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 #4
0
        public static bool ShowHelpIfNeeded(ProgramExecutionOptions options)
        {
            if (options.ParsedArguments.Count > 0)
            {
                if (CommandLineUtil.ArgumentExists(options.ParsedArguments, "h"))
                {
                    HelpProgram.ShowHelpFor(options.ProgramReference);
                    return(true);
                }
            }

            return(false);
        }
Example #5
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 #6
0
        /// <summary>
        /// Handles a command line.
        /// </summary>
        public static bool IsCommandLineValid(string rawCommandLine)
        {
            var command = CommandLineUtil.GetCommandName(rawCommandLine);

            if (string.IsNullOrEmpty(command))
            {
                return(false);
            }
            var program = FindProgramByCommand(command);

            if (program == null)
            {
                return(false);
            }
            return(true);
        }
Example #7
0
        /// <summary>
        /// Returns the program execution options for the given commandLine.
        /// If the commandline is not valid, returns default.
        /// </summary>
        public static ProgramExecutionOptions GetProgramExecutionOptions(string rawCommandLine)
        {
            if (!IsCommandLineValid(rawCommandLine))
            {
                return(default(ProgramExecutionOptions));
            }

            var command      = CommandLineUtil.GetCommandName(rawCommandLine);
            var rawArguments = CommandLineUtil.RemoveCommandFromCommandLine(rawCommandLine);
            var program      = FindProgramByCommand(command);

            var options = new ProgramExecutionOptions();

            options.ProgramReference = program;
            options.RawCommandLine   = rawCommandLine;
            options.ParsedArguments  = CommandLineUtil.GetArgumentsFromCommandLine(rawArguments);

            return(options);
        }
Example #8
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);
            }
        }
        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);
                }
            }
        }
Example #10
0
        public static void Execute(ProgramExecutionOptions options)
        {
            if (ProgramUtil.ShowHelpIfNeeded(options))
            {
                return;
            }

            bool      everythingOk = true;
            int       count        = 0;
            ClearMode mode         = ClearMode.Top;

            if (options.ParsedArguments.Count == 0)
            {
                count = DataHolder.TerminalData.AllEntries.Count;
            }
            else if (CommandLineUtil.ValidateArguments(options.ParsedArguments, Validations))
            {
                Pair <string, string> modeArg;
                Pair <string, string> countArg;

                bool modePresent =
                    CommandLineUtil.TryGetArgumentByName(options.ParsedArguments, ModeArgName, out modeArg);
                bool countPresent =
                    CommandLineUtil.TryGetArgumentByName(options.ParsedArguments, CountArgName, out countArg);

                if (modePresent && !countPresent)
                {
                    var msg = "You need to supply the number of line to clear when using the mode argument.";
                    msg = TextUtil.Error(msg);
                    TerminalUtil.ShowText(msg);
                    everythingOk = false;
                }

                if (countPresent && !modePresent)
                {
                    var msg =
                        "You need to supply the mode argument when removing a specific quantity of lines.";
                    msg = TextUtil.Error(msg);
                    TerminalUtil.ShowText(msg);
                    everythingOk = false;
                }

                if (everythingOk)
                {
                    if (!MiscUtil.TryParseEnum(modeArg.Value, out mode))
                    {
                        var msg = string.Format("'{0}' is not a valid clear mode. It must be either 'top' or 'down'.",
                                                modeArg.Value);
                        msg = TextUtil.Error(msg);
                        TerminalUtil.ShowText(msg);
                        everythingOk = false;
                    }
                    else if (!int.TryParse(countArg.Value, out count))
                    {
                        var msg = string.Format("'{0}' is not a valid number of lines!", countArg.Value);
                        msg = TextUtil.Error(msg);
                        TerminalUtil.ShowText(msg);
                        everythingOk = false;
                    }
                }
            }
            else
            {
                everythingOk = false;

                var modeResult  = ModeValidation.ValidationResult;
                var countResult = CountValidation.ValidationResult;

                if (MathUtil.ContainsFlag((int)modeResult, (int)ArgValidationResult.EmptyValue))
                {
                    var msg = "The 'mode' argument must be either 'top' or 'down'.";
                    msg = TextUtil.Error(msg);
                    TerminalUtil.ShowText(msg);
                }
                else if (MathUtil.ContainsFlag((int)modeResult, (int)ArgValidationResult.Duplicated))
                {
                    var msg = "Please supply only one 'mode' argument.";
                    msg = TextUtil.Error(msg);
                    TerminalUtil.ShowText(msg);
                }
            }

            if (everythingOk)
            {
                if (mode == ClearMode.Bottom)
                {
                    TerminalUtil.RemoveTextEntries(count, TerminalEntryRemoveType.NewerEntries);
                }
                else
                {
                    TerminalUtil.RemoveTextEntries(count, TerminalEntryRemoveType.OlderEntries);
                }
            }
        }