示例#1
0
        public static void UpdateFinFieldsFromImage(string basePath, DatabaseFin fin)
        {
            // TODO:
            // Probably not the best "flag" to look at.  We're saving OriginalImageFilename in the database for newer fins
            if (string.IsNullOrEmpty(fin.OriginalImageFilename))
            {
                List <ImageMod> imageMods;
                bool            thumbOnly;
                string          originalFilename;
                float           normScale;

                string fullFilename = Path.Combine(basePath, fin.ImageFilename);

                PngHelper.ParsePngText(fullFilename, out normScale, out imageMods, out thumbOnly, out originalFilename);

                fin.ImageMods = imageMods;
                fin.Scale     = normScale;

                // This is a little hacky, but we're going to get the bottom directory name, and append that to
                // the filename below.
                var bottomDirectoryName = Path.GetFileName(Path.GetDirectoryName(fullFilename));

                if (!string.IsNullOrEmpty(originalFilename))
                {
                    originalFilename = Path.Combine(bottomDirectoryName, originalFilename);

                    // TODO Original isn't right -- need to replay imagemods, maybe?
                    fin.OriginalImageFilename = originalFilename;
                    fin.ImageFilename         = originalFilename;
                }
                // TODO: Save these changes back to the database?
            }
        }
示例#2
0
        private static void stegImageByImageType(string path, BitArray baBits, int securityLevel)
        {
            var trimPath = path.ToLower().Trim();

            // Check image type
            if (trimPath.EndsWith(".jpg") || trimPath.EndsWith(".jpeg")) // JPEG
            {
                JpegHelper.StegBinary(path, baBits, securityLevel);
            }
            else if (trimPath.EndsWith(".bmp")) // BITMAP
            {
                BmpHelper.StegBinary(path, baBits, securityLevel);
            }
            else if (trimPath.EndsWith(".png")) // PNG
            {
                PngHelper.StegBinary(path, baBits, securityLevel);
            }
            else if (trimPath.EndsWith(".gif")) // GIF
            {
                GifHelper.StegBinary(path, baBits);
            }
            else if (trimPath.EndsWith(".tif") || trimPath.EndsWith(".tiff")) // TIFF
            {
                TifHelper.StegBinary(path, baBits, securityLevel);
            }
            else if (!string.IsNullOrEmpty(trimPath))
            {
                MessageBox.Show("Wrong extension.", "StegImageUI", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }
示例#3
0
        public static string GetOriginalImageFilenameFromPng(string imageFilename)
        {
            string originalFilename;

            PngHelper.ParsePngText(imageFilename, out _, out _, out _, out originalFilename);

            var bottomDirectoryName = Path.GetFileName(Path.GetDirectoryName(imageFilename));

            if (!string.IsNullOrEmpty(originalFilename))
            {
                return(Path.Combine(bottomDirectoryName, originalFilename));
            }

            return(null);
        }
示例#4
0
        private void getSlotsByImageType(string imagePath)
        {
            var trimPath = imagePath.ToLower().Trim();

            // Check image type
            if (trimPath.EndsWith(".jpg") || trimPath.EndsWith(".jpeg")) // JPEG
            {
                // Available slots not 0 - DCT values 0 won't be overwritten
                var dctCoeffs = JpegHelper.GetDctCoefficients(imagePath);
                // 2 bits for each dct coefficient (0 values are skpped)
                _slots = 2 * dctCoeffs.DctFullAc.Where(s => 0 != s).Count() - HEADER_BITS_LEN;
            }
            else if (trimPath.EndsWith(".bmp")) // BITMAP
            {
                _slots = BmpHelper.GetAvailableSlots(imagePath) - HEADER_BITS_LEN;
            }
            else if (trimPath.EndsWith(".png")) // PNG
            {
                _slots = PngHelper.GetAvailableSlots(imagePath) - HEADER_BITS_LEN;
            }
            else if (trimPath.EndsWith(".gif")) // GIF
            {
                sldSecLevel.Value = 1;
                _slots            = GifHelper.GetAvailableSlots(imagePath) - HEADER_BITS_IDX_LEN;
            }
            else if (trimPath.EndsWith(".tif") || trimPath.EndsWith(".tiff")) // TIFF
            {
                sldSecLevel.Value = 1;
                _slots            = TifHelper.GetAvailableSlots(imagePath) - HEADER_BITS_IDX_LEN;
            }
            if (_slots < 10)
            {
                tbxSlots.Text = tbxSlotsUsed.Text = tbxSlotsLeft.Text = "0";
                MessageBox.Show("Image not suitable for embedding content.", "StegImageUI", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }
示例#5
0
        public static DatabaseFin OpenFinz(string filename)
        {
            if (string.IsNullOrEmpty(filename))
            {
                throw new ArgumentNullException(nameof(filename));
            }

            string uniqueDirectoryName = Path.GetFileName(filename).Replace(".", string.Empty) + "_" + Guid.NewGuid().ToString().Replace("-", string.Empty);
            string fullDirectoryName   = Path.Combine(Path.GetTempPath(), uniqueDirectoryName);

            try
            {
                Directory.CreateDirectory(fullDirectoryName);

                ZipFile.ExtractToDirectory(filename, fullDirectoryName);

                string dbFilename = Path.Combine(fullDirectoryName, FinzDatabaseFilename);

                if (!File.Exists(dbFilename))
                {
                    return(null);
                }

                var db = OpenDatabase(dbFilename, Options.CurrentUserOptions.DefaultCatalogScheme, false);

                // First and only fin
                var fin = db.AllFins[0];

                fin.FinFilename = filename;

                var baseimgfilename = Path.GetFileName(fin.ImageFilename);
                fin.ImageFilename = Path.Combine(fullDirectoryName, baseimgfilename);

                List <ImageMod> imageMods;
                bool            thumbOnly;
                string          originalFilenameFromPng;
                float           normScale;

                // The old version kept this info inside PNG text.  The newer version saves it all in the SQLite database.
                PngHelper.ParsePngText(fin.ImageFilename, out normScale, out imageMods, out thumbOnly, out originalFilenameFromPng);

                if (imageMods != null && imageMods.Count > 0)
                {
                    fin.ImageMods = imageMods;
                }

                if (normScale != 1.0)
                {
                    fin.Scale = normScale;
                }

                string originalFilenameToUse = (string.IsNullOrEmpty(originalFilenameFromPng)) ? fin.OriginalImageFilename : originalFilenameFromPng;

                if (!string.IsNullOrEmpty(originalFilenameToUse))
                {
                    fin.OriginalImageFilename = Path.Combine(fullDirectoryName, Path.GetFileName(originalFilenameToUse));

                    // We're loading the image this way because Bitmap keeps a lock on the original file, and
                    // we want to try to delete the file below.  So we open the file in another object in a using statement
                    // then copy it over to our actual working object.
                    using (var originalImageFromFile = (Bitmap)Image.FromFile(fin.OriginalImageFilename))
                    {
                        fin.OriginalFinImage = new Bitmap(originalImageFromFile);
                        fin.OriginalFinImage?.SetResolution(96, 96);

                        if (fin.ImageMods != null)
                        {
                            fin.FinImage = ModificationHelper.ApplyImageModificationsToOriginal(fin.OriginalFinImage, fin.ImageMods);
                        }
                        else
                        {
                            fin.FinImage = new Bitmap(fin.OriginalFinImage);
                        }

                        fin.FinImage?.SetResolution(96, 96);
                    }
                }

                // TODO: Do something with thumbOnly?

                // We're loading the image this way because Bitmap keeps a lock on the original file, and
                // we want to try to delete the file below.  So we open the file in another object in a using statement
                // then copy it over to our actual working object.
                //using (var imageFromFile = (Bitmap)Image.FromFile(fin.ImageFilename))
                //{
                //	fin.FinImage = new Bitmap(imageFromFile);
                //	fin.FinImage?.SetResolution(96, 96);
                //}

                return(fin);
            }
            catch
            {
                // TODO: Probably should have better handling here
                return(null);
            }
            finally
            {
                try
                {
                    Trace.WriteLine("Trying to remove temporary files for finz file.");

                    SQLiteConnection.ClearAllPools();

                    GC.Collect();
                    GC.WaitForPendingFinalizers();

                    if (Directory.Exists(fullDirectoryName))
                    {
                        Directory.Delete(fullDirectoryName, true);
                    }
                }
                catch (Exception ex)
                {
                    Trace.Write("Couldn't remove temporary files:");
                    Trace.WriteLine(ex);
                }
            }
        }
示例#6
0
        private static StegModel unstegImageByImageType(string path)
        {
            var sm       = new StegModel();
            var trimPath = path.ToLower().Trim();

            // Check image type
            if (trimPath.EndsWith(".jpg") || trimPath.EndsWith(".jpeg")) // JPEG
            {
                var stegStruct = JpegHelper.UnstegBinary(path);
                sm.SecurityLevel = stegStruct.SecurityLevel;
                sm.TotalSize     = stegStruct.TotalSize;
                sm.ContentFull   = stegStruct.ContentFull;
                sm.IsFile        = stegStruct.IsFile;
                sm.ContentSize   = stegStruct.ContentSize;
                sm.Content       = stegStruct.Content;
            }
            else if (trimPath.EndsWith(".bmp")) // BITMAP
            {
                var stegStruct = BmpHelper.UnstegBinary(path);
                sm.SecurityLevel = stegStruct.SecurityLevel;
                sm.TotalSize     = stegStruct.TotalSize;
                sm.ContentFull   = stegStruct.ContentFull;
                sm.IsFile        = stegStruct.IsFile;
                sm.ContentSize   = stegStruct.ContentSize;
                sm.Content       = stegStruct.Content;
            }
            else if (trimPath.EndsWith(".png")) // PNG
            {
                var stegStruct = PngHelper.UnstegBinary(path);
                sm.SecurityLevel = stegStruct.SecurityLevel;
                sm.TotalSize     = stegStruct.TotalSize;
                sm.ContentFull   = stegStruct.ContentFull;
                sm.IsFile        = stegStruct.IsFile;
                sm.ContentSize   = stegStruct.ContentSize;
                sm.Content       = stegStruct.Content;
            }
            else if (trimPath.EndsWith(".gif")) // GIF
            {
                var stegStruct = GifHelper.UnstegBinary(path);
                sm.SecurityLevel = stegStruct.SecurityLevel;
                sm.TotalSize     = stegStruct.TotalSize;
                sm.ContentFull   = stegStruct.ContentFull;
                sm.IsFile        = stegStruct.IsFile;
                sm.ContentSize   = stegStruct.ContentSize;
                sm.Content       = stegStruct.Content;
            }
            else if (trimPath.EndsWith(".tif") || trimPath.EndsWith(".tiff")) // TIFF
            {
                var stegStruct = TifHelper.UnstegBinary(path);
                sm.SecurityLevel = stegStruct.SecurityLevel;
                sm.TotalSize     = stegStruct.TotalSize;
                sm.ContentFull   = stegStruct.ContentFull;
                sm.IsFile        = stegStruct.IsFile;
                sm.ContentSize   = stegStruct.ContentSize;
                sm.Content       = stegStruct.Content;
            }

            else if (!string.IsNullOrEmpty(trimPath))
            {
                MessageBox.Show("Wrong extension.", "StegImageUI", MessageBoxButton.OK, MessageBoxImage.Information);
            }

            return(sm);
        }