示例#1
0
        private async Task OnCommand(string command, string args)
        {
            using var containerStream = new FileStream(_path, FileMode.OpenOrCreate);
            using var container       = new CryptoContainer(containerStream, _key);
            switch (command)
            {
            case "add":
            case "get":
                var opts = args.Split("path=", StringSplitOptions.TrimEntries);

                var name = opts[0];
                var path = opts[1];

                path = path.Trim('"');

                var get = command == "get";

                var mode   = get ? FileMode.Create : FileMode.Open;
                var access = get ? FileAccess.Write : FileAccess.Read;

                using (var stream = File.Open(path, mode, access))
                {
                    if (get)
                    {
                        await container.GetAsync(name, stream, Aretha.WriteProgress());
                    }
                    else
                    {
                        await container.AddAsync(name, stream, true, Aretha.WriteProgress());
                    }
                }
                return;

            case "delete":
                var deleted = container.Delete(args);
                if (deleted)
                {
                    Speak("File deleted successfully");
                }
                else
                {
                    Speak("Deletion failed.");
                }
                break;

            case "extract":
                if (args.ToLower().StartsWith("path="))
                {
                    args = args.Remove(0, "path=".Length);
                }
                args = args.Trim('"');
                await container.ExtractContainerAsync(args, Aretha.WriteProgress());

                break;
            }
        }
示例#2
0
        public async Task Inject(Jector jector)
        {
            var inputPath  = GetPath("Provide path to file to be written into:", true);
            var dataPath   = GetPath("Provide a path to the file to be hidden:", true);
            var outputPath = GetPath("Provide a path where the file copy with hidden data will be saved:", false);

            if (inputPath == outputPath)
            {
                Speak("The input file cannot be the same as the save file!");
                await Inject(jector);

                return;
            }
            else if (inputPath == dataPath)
            {
                Speak("The input file cannot be the same as the data file. What will be the point?");
                await Inject(jector);

                return;
            }
            else if (dataPath == outputPath)
            {
                Speak("The data file cannot be the same as the save file");
                await Inject(jector);
            }

            Speak("Executing Command. Please Wait");

            try
            {
                using var source      = File.OpenRead(inputPath);
                using var destination = File.OpenWrite(outputPath);
                using var data        = File.OpenRead(dataPath);
                await jector.InjectAsync(source, destination, data, Aretha.WriteProgress());

                Speak($"Command Executed Successfully!");
            }
            catch (Exception ex)
            {
                Aretha.SoulFailed(Soul.Anubis, ex);
            }
        }
示例#3
0
        public async Task Eject(Jector jector)
        {
            var inputPath = GetPath("Provide a path to file containing hidden data:", true);

            if (inputPath == null)
            {
                return;
            }

            var outputPath = GetPath("Provide a path where the hidden file will be saved: ", false);

            if (outputPath == null)
            {
                return;
            }

            if (inputPath == outputPath)
            {
                Speak("The input file cannot be the same as the save file!");
                await Inject(jector);

                return;
            }

            Speak("Executing Command. Please Wait");

            try
            {
                using var source      = File.OpenRead(inputPath);
                using var destination = File.OpenWrite(outputPath);

                await jector.EjectAsync(source, destination, Aretha.WriteProgress());

                Speak($"Command Executed Successfully!");
            }
            catch (Exception ex)
            {
                Aretha.SoulFailed(Soul.Anubis, ex);
            }
        }
示例#4
0
        public async void WaitForCommand(string[] args = null)
        {
            try
            {
                List <string> cmdlets;
                if (args == null || args.Length == 0)
                {
                    var cmd = Ask();
                    if (cmd == null)
                    {
                        return;
                    }

                    cmdlets = new List <string>(cmd.Split(' '));
                }
                else
                {
                    cmdlets = new List <string>(args);
                }

                Jector jector;

                var type = GetJectorType(cmdlets[0]);

                //make the jector:
                var jectorBuilder = new JectorBuilder().WithType(type);

                var response = Ask("Do you want to ensure a successful write?", true);

                //if (response == null) return;

                if (response == "y")
                {
                    jectorBuilder.WithRequiredSuccess();
                }

                response = Ask("Do you want to use the default end of file marker?", true);
                //if (response == null) return;

                if (response == "n")
                {
                    response = Ask("What end of file marker would you like to use?", false, true);
                    //if (response == null) return;

                    jectorBuilder.WithEOF(response);
                }

                jector = jectorBuilder.Build();

                if (cmdlets[1].ToLower() == "inject")
                {
                    await Inject(jector);
                }
                else if (cmdlets[1].ToLower() == "eject")
                {
                    await Eject(jector);
                }

                Aretha.SoulSucceeded(Soul.Anubis);
            }
            catch (Exception ex)
            {
                Aretha.SoulFailed(Soul.Anubis, ex);
                return;
            }
        }
示例#5
0
 public string GetPath(string text, bool input, bool confirm = true)
 {
     return(Aretha.GetPath(text, input, confirm, Soul.Anubis));
 }
示例#6
0
 public string Ask(string question = null, bool isYN = false, bool isCase = false)
 {
     return(Aretha.Ask(question, isYN, Soul.Anubis, isCase));
 }
示例#7
0
 public void Speak(string text)
 {
     Aretha.Speak(text, Soul.Anubis);
 }
示例#8
0
        public async void WaitForCommand(string[] args = null)
        {
            List <string> cmdlets;

            string cmd;

            if (args == null || args.Length == 0)
            {
                cmd = Ask();
                if (cmd == null)
                {
                    return;
                }

                cmdlets = new List <string>(cmd.Split(' '));
            }
            else
            {
                cmdlets = new List <string>(args);
                StringBuilder sb = new();

                for (int i = 0; i < cmdlets.Count; i++)
                {
                    sb.Append(cmdlets[i]);

                    if (i != cmdlets.Count - 1)
                    {
                        sb.Append(' ');
                    }
                }

                cmd = sb.ToString();
            }

            while (true)
            {
                try
                {
                    if (cmdlets[0] == "back")
                    {
                        Aretha.SoulSucceeded(Soul.Horus);
                        return;
                    }
                    else if (cmdlets[0] == "use")
                    {
                        switch (cmdlets[1])
                        {
                        case "vigenere":
                        case "caesar":
                        case "playfair":
                            await new HorusClassical().OnSession(cmdlets[1]);
                            break;

                        case "crypto-file":
                            await new HorusFile().OnSession();
                            break;

                        case "crypto-container":
                            await new HorusContainer().OnSession();
                            break;

                        case "enigma-machine":
                            await new HorusEnigma().OnSession();
                            break;

                        default:
                            throw new InvalidOperationException("Unknown operation");
                        }
                    }
                    else if (cmdlets[0] == "hash")
                    {
                        var input = Ask(isCase: true);
                        Speak(Horus.Horus.GetHash(input));
                    }
                    else if (cmdlets[0] == "id")
                    {
                        if (cmdlets.Count == 1)
                        {
                            Speak(Horus.Horus.GenerateId(IdKind.Guid));
                        }
                        else
                        {
                            int max = 12;
                            if (cmdlets.Count > 2)
                            {
                                if (!int.TryParse(cmdlets[2], out max))
                                {
                                    throw new InvalidOperationException("Value for length must be number");
                                }
                            }

                            IdKind kind = cmdlets[1] switch
                            {
                                "standard" => IdKind.Standard,
                                "date-time" => IdKind.DateTime,
                                "guid" => IdKind.Guid,
                                "random" => IdKind.Random,
                                "hash" => IdKind.Hash,
                                _ => throw new InvalidOperationException("Unkown ID Kind")
                            };

                            Speak(Horus.Horus.GenerateId(kind, max));
                        }
                    }

                    cmdlets = new List <string>(Ask().Split(' '));
                }
                catch (Exception ex)
                {
                    Aretha.SoulFailed(Soul.Horus, ex);
                    return;
                }
            }
        }
示例#9
0
 public void Speak(string text)
 {
     Aretha.Speak(text, Soul.Horus);
 }