Example #1
0
        private void LoadMetaDataFromFile(string filePath)
        {
            try
            {
                int    metaSize;
                byte[] metaSizeBytes = new byte[4];

                FileStream metaSizeStream = new FileStream(filePath, FileMode.Open);
                metaSizeStream.Read(metaSizeBytes, 0, 4);
                metaSizeStream.Close();

                metaSize = BitConverter.ToInt32(metaSizeBytes, 0);
                byte[] faesMetaData = new byte[metaSize];

                FileStream faesMeta = new FileStream(filePath, FileMode.Open);
                faesMeta.Read(faesMetaData, 0, metaSize);
                faesMeta.Close();

                try
                {
                    if (metaSize < 7)
                    {
                        LoadLegacyMetaDataFromFile(filePath);
                    }
                    else
                    {
                        ushort faesIdentifierSize;
                        byte[] faesIdentifierSizeBytes = new byte[2];

                        Array.Copy(faesMetaData, 4, faesIdentifierSizeBytes, 0, 2);
                        faesIdentifierSize = BitConverter.ToUInt16(faesIdentifierSizeBytes, 0);

                        byte[] faesIdentifierBytes = new byte[faesIdentifierSize];

                        Array.Copy(faesMetaData, 6, faesIdentifierBytes, 0, Convert.ToInt32(faesIdentifierSize));

                        if (CryptUtils.ConvertBytesToString(faesIdentifierBytes) != CryptUtils.GetCryptIdentifier())
                        {
                            LoadLegacyMetaDataFromFile(filePath);
                        }
                        else
                        {
                            InitWithBytes(faesMetaData);
                        }
                    }
                }
                catch (IOException)
                {
                    Logging.Log("File is already open in another program!", Severity.ERROR);
                }
                catch (Exception)
                {
                    LoadLegacyMetaDataFromFile(filePath);
                }
            }
            catch (Exception)
            {
                LoadLegacyMetaDataFromFile(filePath);
            }
        }
Example #2
0
 /// <summary>
 /// Gets the Password Hint
 /// </summary>
 /// <returns>Password Hint stored in MetaData</returns>
 public string GetPasswordHint()
 {
     if (_passwordHint != null)
     {
         //Removes the old padding character used in older FAES versions, as well as any newlines or special chars. I wish I wasn't stupid and actually zero-padded + checked for special characters in older v1.1.x versions...
         return(CryptUtils.ConvertBytesToString(_passwordHint).TrimEnd('\n', '\r', '¬', '�'));
     }
     else
     {
         return("No Password Hint Set");
     }
 }
Example #3
0
        /// <summary>
        /// Gets the Compression Method used to compress the encrypted file
        /// </summary>
        /// <returns>Compression Mode Type</returns>
        public string GetCompressionMode()
        {
            if (_compressionMode != null)
            {
                string converted = CryptUtils.ConvertBytesToString(_compressionMode);

                if (!String.IsNullOrEmpty(converted))
                {
                    return(converted);
                }
            }
            return("LGYZIP");
        }
Example #4
0
        /// <summary>
        /// Gets the Version of FAES used to encrypt the file
        /// </summary>
        /// <returns>FAES Version</returns>
        public string GetEncryptionVersion()
        {
            if (_encryptionVersion != null)
            {
                string ver = CryptUtils.ConvertBytesToString(_encryptionVersion);

                if (ver.Contains("DEV"))
                {
                    return(ver.Split('_')[0]);
                }
                return(ver);
            }
            return("Unknown version!");
        }
Example #5
0
        /// <summary>
        /// Gets the data at the current offset
        /// </summary>
        /// <param name="offset">Offset from the beginning of the metadata</param>
        /// <param name="totalSize">Total metadata size</param>
        /// <returns>Data at the current offset</returns>
        private byte[] LoadDynamicMetadataChunk(ref int offset, ref int totalSize)
        {
            if (offset < totalSize)
            {
                int    origOffset     = offset;                                  // Saves the starting offset
                byte[] chunkSizeBytes = new byte[2];                             // chunkSize's are always 2 bytes (ushort)

                Array.Copy(_metaData, offset, chunkSizeBytes, 0, 2);             // Gets the size of the next chunk (the data chunk) from the chunkSize
                ushort chunkSize     = BitConverter.ToUInt16(chunkSizeBytes, 0); // Size of the data chunk
                byte[] metaDataChunk = new byte[chunkSize];
                offset += 2;                                                     // Increase offset to be past the chunkSize chunk

                Array.Copy(_metaData, offset, metaDataChunk, 0, chunkSize);      // Gets the data (for the size of the data chunk) from the metadata
                offset += chunkSize;                                             // Increase offset to be past the data chunk

                Logging.Log(String.Format("MetaData | Size: {0}, Converted: {2}, InitialOffset: {3}, FinalOffset: {4}, Raw: {1}", chunkSize, BitConverter.ToString(metaDataChunk), CryptUtils.ConvertBytesToString(metaDataChunk), origOffset, offset), Severity.DEBUG);

                return(metaDataChunk); // Return the data from the data chunk
            }
            else
            {
                throw new IndexOutOfRangeException("Metadata cannot be found at this offset!"); // Something is f****d, this shouldn't happen. Corrupted file?
            }
        }
Example #6
0
 /// <summary>
 /// Gets the FAES Identifier
 /// </summary>
 /// <returns>Gets the FAES Identifier stored in MetaData</returns>
 public string GetFaesIdentifier()
 {
     return(CryptUtils.ConvertBytesToString(_faesIdentifier));
 }
Example #7
0
 /// <summary>
 /// Gets the Original Filename
 /// </summary>
 /// <returns>Gets the Original Filename stored in MetaData</returns>
 public string GetOriginalFileName()
 {
     return(CryptUtils.ConvertBytesToString(_originalFileName));
 }
Example #8
0
        /// <summary>
        /// Automatically adds a Metadata Chunk byte array to a FAESv3 Metadata structure
        /// </summary>
        /// <param name="src">Metadata Chunk</param>
        /// <param name="dst">FAESv3 Metadata structure</param>
        /// <param name="offset">Current offset</param>
        private void MetaDataBlockCopy(byte[] src, ref byte[] dst, ref int offset)
        {
            ushort chunkSize  = Convert.ToUInt16(src.Length); // Size of the data chunk (to store within the chunkSize)
            int    origOffset = offset;

            Array.Copy(BitConverter.GetBytes(chunkSize), 0, dst, offset, 2); // Store the data chunk size (size of the data within the data chunk)
            offset += 2;                                                     // Increase offset to be past the chunkSize chunk
            Array.Copy(src, 0, dst, offset, src.Length);                     // Store the data chunk data
            offset += src.Length;                                            // Increase offset to be past the data chunk

            Logging.Log(String.Format("MetaData | Size: {0}, Converted: {2}, InitialOffset: {3}, FinalOffset: {4}, Raw: {1}", chunkSize, BitConverter.ToString(src), CryptUtils.ConvertBytesToString(src), origOffset, offset), Severity.DEBUG);
        }