Exemple #1
0
        private void menuActionDumpOriginal_Click(object sender, EventArgs e)
        {
            if (pngOriginal == null)
            {
                return;
            }

            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter = "PNG File (*.png)|*.png";

            if (sfd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                sfd.Dispose();
                return;
            }

            string file = sfd.FileName;

            sfd.Dispose();

            using (FileStream fs = File.Open(file, FileMode.Create, FileAccess.Write, FileShare.Read))
                pngOriginal.WriteToStream(fs, true, true);

            MessageBox.Show(this, "Original image was successfully extracted.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Exemple #2
0
        public (DataType t, object data) ReadData(StorageMethod storageSlot)
        {
            DataType t    = DataType.None;
            object   data = null;

            using (MemoryStream stream = new MemoryStream())
            {
                pngOriginal.WriteToStream(stream, true, true);
                stream.Seek(0, SeekOrigin.Begin);
            }

            bool hasEOF = false;
            int  IDATs  = 0;

            foreach (PNGChunk chunk in pngOriginal.Chunks)
            {
                if (chunk.Name == "_EOF")
                {
                    hasEOF = true;
                }
                if (chunk.Name == "IDAT")
                {
                    IDATs++;
                }
            }

            StegoProvider pr = Providers.XOREOF;

            if (storageSlot == StorageMethod.IDAT)
            {
                pr = Providers.XORIDAT;
            }

            if (!hasEOF && storageSlot == StorageMethod.EOF)
            {
                provider = null; Logger.Log($"There is no data in {storageSlot.ToString()}", Logger.LOG_LEVEL.ERR);
            }
            else if (IDATs <= 1)
            {
                provider = null; Logger.Log($"There is no data in {storageSlot.ToString()}", Logger.LOG_LEVEL.ERR);
            }
            else
            {
                try
                {
                    provider = (SteganographyProvider)Activator.CreateInstance(pr.ProviderType, pngOriginal, true);
                    provider.SetPassword(password);
                    t = provider.Extract(out data);
                    return(t, data);
                }
                catch (InvalidPasswordException)
                {
                    Logger.Log("The password was incorrect.", Logger.LOG_LEVEL.ERR);
                }
            }

            return(DataType.None, null);
        }
Exemple #3
0
        void LoadImage(string path)
        {
            pngOriginal = new PNG(path);

            using (MemoryStream stream = new MemoryStream())
            {
                if (imgOriginal.Image != null)
                {
                    imgOriginal.Image.Dispose();
                }
                pngOriginal.WriteToStream(stream, true, true);
                stream.Seek(0, SeekOrigin.Begin);
                Image img = Image.FromStream(stream);
                imgOriginal.Image = img;

                imghandler(imgOriginal, null);
            }

            lblNoFile.Visible = false;

            List <Provider> providers = new List <Provider>(Program.Providers);
            bool            hasEOF    = false;
            bool            hasTXT    = false;
            int             IDATs     = 0;

            foreach (PNGChunk chunk in pngOriginal.Chunks)
            {
                if (chunk.Name == "_EOF")
                {
                    hasEOF = true;
                }
                if (chunk.Name == "tEXt")
                {
                    hasTXT = true;
                }
                if (chunk.Name == "IDAT")
                {
                    IDATs++;
                }
            }

            if (hasEOF)
            {
                providers.Add(Program.XOREOF);
            }
            if (hasTXT)
            {
                providers.Add(Program.XORTXT);
            }
            if (IDATs > 1)
            {
                providers.Add(Program.XORIDAT);
            }

            Provider pr = null;

            if (providers.Count > 0)
            {
                using (SelectProvider prov = new SelectProvider(providers.ToArray()))
                {
                    prov.ShowDialog();
                    pr = prov.SelectedProvider;
                }
            }
            providers = null;

            if (pr == null)
            {
                provider = null; SetHidden(DataType.None, null); tabs.SelectedIndex = 0;
            }
            else
            {
                try
                {
                    provider = (SteganographyProvider)Activator.CreateInstance(pr.ProviderType, pngOriginal, true);

                    DisposeHidden();

                    object   data;
                    DataType t = provider.Extract(out data);
                    hidden = data;
                    SetHidden(t, data);
                    hiddent = t;

                    if (t != DataType.None)
                    {
                        menuActionDumpHidden.Enabled = true;
                    }
                }
                catch (InvalidPasswordException)
                {
                    provider = null; SetHidden(DataType.None, null); tabs.SelectedIndex = 0;

                    MessageBox.Show(this, "The password you entered was incorrect.", "Incorrect Password", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            tabs.Enabled = true;

            menuActionInject.Enabled       = true;
            menuActionDumpOriginal.Enabled = true;

            pngOriginal.RemoveNonCritical();
        }