Beispiel #1
0
 public void SetParameters(FilePlaceholder audioFile, int bitsToUse, List <string> fileToEmbed)
 {
     this.audioFile      = audioFile;
     this.bitsToUse      = bitsToUse;
     this.decryptedFiles = new List <FilePlaceholder>();
     this.filesToEmbed   = filesToEmbed;
 }
Beispiel #2
0
        public Task <FilePlaceholder> CreateOrOverwriteFile(string[] allowedTypes = null)
        {
            // for consistency with other platforms, only allow selecting of a single file.
            // would be nice if we passed a "file options" to override picking multiple files & directories
            var savePanel = new NSSavePanel();

            savePanel.CanCreateDirectories = true;

            // macOS allows the file types to contain UTIs, filename extensions or a combination of the two.
            // If no types are specified, all files are selectable.
            if (allowedTypes != null)
            {
                savePanel.AllowedFileTypes = allowedTypes;
            }

            FilePlaceholder data = null;

            var result = savePanel.RunModal();

            if (result == 1)
            {
                // Nab the first file
                var url = savePanel.Url;

                if (url != null)
                {
                    var path     = url.Path;
                    var fileName = Path.GetFileName(path);
                    data = new FilePlaceholder(path, fileName, saveAction);
                }
            }

            return(Task.FromResult(data));
        }
Beispiel #3
0
        private async Task StreamSetter(Stream stream, FilePlaceholder placeHolder)
        {
            try
            {
                using (var fileStream = File.Create(placeHolder.FilePath))
                {
                    await stream.CopyToAsync(fileStream);

                    await fileStream.FlushAsync();
                }
            }
            finally
            {
                placeHolder.Dispose();
            }
        }
Beispiel #4
0
        private async Task saveAction(Stream stream, FilePlaceholder placeHolder, StorageFile file)
        {
            try
            {
                using (var fileStream = await file.OpenStreamForWriteAsync())
                {
                    await stream.CopyToAsync(fileStream);

                    await fileStream.FlushAsync();
                }
            }
            finally
            {
                placeHolder.Dispose();
            }
        }
Beispiel #5
0
        /// <summary>
        /// File creater implementation for WPF; uses the Win32 SaveFileDialog from
        /// PresentationFoundation reference assembly.
        /// </summary>
        /// <param name="allowedTypes">
        /// Specifies one or multiple allowed types. When null, all file types
        /// can be selected while picking.
        /// On WPF, specify strings like this: "Data type (*.ext)|*.ext", which
        /// corresponds how the Windows file open dialog specifies file types.
        /// </param>
        /// <returns>file data of picked file, or null when picking was cancelled</returns>
        public Task <FilePlaceholder> CreateOrOverwriteFile(string[] allowedTypes = null)
        {
            var picker = new Microsoft.Win32.SaveFileDialog();

            if (allowedTypes != null)
            {
                picker.Filter = string.Join("|", allowedTypes);
            }

            var result = picker.ShowDialog();

            if (result == null || result == false)
            {
                return(Task.FromResult <FilePlaceholder>(null));
            }

            var fileName = Path.GetFileName(picker.FileName);

            var data = new FilePlaceholder(picker.FileName, fileName, saveAction);

            return(Task.FromResult <FilePlaceholder>(data));
        }
Beispiel #6
0
        /// <summary>
        /// Called when file has been picked successfully
        /// </summary>
        /// <param name="destination">file picker picked destination</param>
        /// /// <param name="creation">we want to create a file</param>
        private async void OnFilePicked(NSUrl destination, bool creation = false)
        {
            if (destination == null || !destination.IsFileUrl)
            {
                this.Handler?.Invoke(this, null);
                return;
            }

            var document = new GenericDocument(destination);
            var success  = await document.OpenAsync();

            if (!success)
            {
                this.Handler?.Invoke(this, null);
                return;
            }

            async Task StreamSetter(Stream stream, FilePlaceholder placeholder)
            {
                document.DataStream = stream;

                try
                {
                    if (!await document.SaveAsync(destination, creation ? UIDocumentSaveOperation.ForCreating : UIDocumentSaveOperation.ForOverwriting))
                    {
                        throw new Exception("Failed to Save Document.");
                    }
                }
                finally
                {
                    await document.CloseAsync();
                }
            }

            var placeHolder = new FilePlaceholder(destination.AbsoluteString, destination.LastPathComponent, StreamSetter, b => document.Dispose());

            this.Handler?.Invoke(null, placeHolder);
        }
Beispiel #7
0
 public void SetParameters(int bitsToUse, FilePlaceholder audioFile, List <FilePlaceholder> files)
 {
     crypto.SetParameters(audioFile, bitsToUse,
                          files.Select(x => x.FullFilePath).ToList());
 }
Beispiel #8
0
        public async Task <FilePlaceholder> CreateOrOverwriteFile(string[] allowedTypes = null)
        {
            var picker = new Windows.Storage.Pickers.FileSavePicker
            {
                SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary,
            };

            if (allowedTypes != null)
            {
                var hasAtleastOneType = false;

                for (var i = 0; i < allowedTypes.Length; i++)
                {
                    var type = allowedTypes[i];

                    if (type.StartsWith("."))
                    {
                        throw new Exception("Bad UWP string ordering");
                    }

                    var list = new List <string>();

                    for (int j = i + 1; j < allowedTypes.Length; j++)
                    {
                        var extension = allowedTypes[j];
                        if (!extension.StartsWith("."))
                        {
                            break;
                        }
                        else
                        {
                            list.Add(extension);
                            i = j;
                        }
                    }

                    if (list.Count == 0)
                    {
                        throw new Exception("Bad UWP string ordering");
                    }

                    picker.FileTypeChoices.Add(type, list);
                    hasAtleastOneType = true;
                }

                if (!hasAtleastOneType)
                {
                    picker.FileTypeChoices.Add("All Files", new List <string> {
                        "*"
                    });
                }
            }
            else
            {
                picker.FileTypeChoices.Add("All Files", new List <string> {
                    "*"
                });
            }

            var file = await picker.PickSaveFileAsync();

            if (file == null)
            {
                return(null);
            }

            var placeHolder = new FilePlaceholder(file.Path, file.Name, (stream, holder) => saveAction(stream, holder, file));

            return(placeHolder);
        }
Beispiel #9
0
        //private asd(List<byte[]> samples, List<byte> outerMsg) {

        //	// Testing validity of the algorithms:

        //	List<byte> outerMsg2 = RecreateOuterMsgFromSamples(samples); // Valid!

        //	// Inner msg = OuterMsg - 4B for inner msg size:
        //	byte[] innerMsg = new byte[outerMsg2.Count - 4];

        //	for (int i = 4; i < outerMsg2.Count; i++)
        //	{
        //		innerMsg[i - 4] = outerMsg2[i];
        //	}

        //	RecreateMsg(innerMsg.ToList());

        //	bool same = true;

        //	if (outerMsg2.Count != outerMsg.Count)
        //	{
        //		Console.WriteLine("Not the same size!");
        //		return;
        //	}

        //	for (int i = 0; i < outerMsg.Count; i++)
        //	{
        //		if (outerMsg[i] != outerMsg2[i])
        //		{
        //			Console.WriteLine("Different values!");
        //			same = false;
        //			break;
        //		}
        //	}

        //	if (same)
        //		Console.WriteLine("Same!");
        //	else
        //		Console.WriteLine("NOT same!");
        //	///////////////////////////////////////////////////////////////////////////////

        //}


        /// <summary>
        /// Gets the whole message as list of bytes and recreates files
        /// from it.
        /// </summary>
        /// <param name="msg">List of bytes representing the message
        /// sent through audio file.</param>
        private List <Tuple <string, int> > RecreateMsg(List <byte> msg)
        {
            try
            {
                int    numOfFiles;
                string fileName = string.Empty;

                int    fileNameLength;
                int    fileSize;
                byte[] numOfFilesInBytes = new byte[4];

                byte[] simplerMsg = msg.ToArray();
                int    index      = 4;

                // Get number of files:
                numOfFiles = BitConverter.ToInt32(simplerMsg, index);
                index     += 4;

                List <Tuple <string, int> > fileNamesWithSize
                    = new List <Tuple <string, int> >();

                for (int i = 0; i < numOfFiles; i++)
                {
                    // Get file name length:
                    fileNameLength = BitConverter.ToInt32(simplerMsg, index);
                    index         += 4;

                    // Get file name:
                    fileName = Encoding.ASCII.GetString(simplerMsg, index,
                                                        fileNameLength);
                    index += fileNameLength;

                    // Get file size:
                    fileSize = BitConverter.ToInt32(simplerMsg, index);
                    index   += 4;

                    // Add file name and file size to the list of files:
                    fileNamesWithSize.Add(
                        new Tuple <string, int>(fileName, fileSize));
                }

                // Check and create necessary directory:
                if (!System.IO.Directory.Exists(Environment.GetFolderPath(
                                                    Environment.SpecialFolder.Desktop) +
                                                "\\Digitalna Forenzika"))
                {
                    System.IO.Directory.CreateDirectory(Environment
                                                        .GetFolderPath(Environment.SpecialFolder.Desktop) +
                                                        "\\Digitalna Forenzika");
                }

                List <byte> fileData = new List <byte>();
                foreach (Tuple <string, int> fileWithSize in fileNamesWithSize)
                {
                    FilePlaceholder fp = new FilePlaceholder();
                    fp.FileName     = fileWithSize.Item1;
                    fp.FullFilePath = "";

                    fileData = new List <byte>();

                    for (int i = 0; i < fileWithSize.Item2; i++)
                    {
                        fileData.Add(simplerMsg[index]);
                        index++;
                    }

                    fp.FileBinary = fileData.ToArray();

                    decryptedFiles.Add(fp);
                }

                return(fileNamesWithSize);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.Message);
            }

            return(new List <Tuple <string, int> >());
        }