Пример #1
0
        void ProcessPNG(bool find = true)
        {
            foreach (PNGChunk chunk in image.Chunks)
            {
                if (chunk.Name == "IDAT")
                {
                    key = (byte[])chunk.Data.Clone();
                    break;
                }
            }
            if (key == null)
            {
                throw new PNGMaskException("PNG has no IDAT chunk for the SteganographyProvider to process.");
            }

            if (find)
            {
                PNGChunk eof = image.Chunks[image.Chunks.Count - 1];
                if (eof.Name == "_EOF")
                {
                    vector = (byte[])eof.Data.Clone();

                    string pass = SteganographyProvider.AskPassword();
                    if (pass != null && pass.Length > 0)
                    {
                        PrepareKey(Encoding.UTF8.GetBytes(pass));
                    }
                }
            }
        }
Пример #2
0
        public bool HideText(string imagePath, string hideText, string password = "", int fileSlot = 0)
        {
            StegoProvider prov;

            if (fileSlot == 0)
            {
                prov = Providers.XOREOF;
            }
            else
            {
                prov = Providers.XORIDAT;
            }

            provider = (SteganographyProvider)Activator.CreateInstance(prov.ProviderType, imagePath, false);
            provider.SetPassword(password, false);

            if (Imprint(DataType.Text, hideText))
            {
                using (FileStream fs = File.Open(imagePath, FileMode.Create, FileAccess.Write, FileShare.Read))
                    provider.WriteToStream(fs);

                return(true);
            }

            return(false);
        }
Пример #3
0
        public bool HideFileSystem(string imagePath, string fileSystemData, string password = "", StorageMethod storageMethod = StorageMethod.EOF)
        {
            StegoProvider prov;

            if (storageMethod == StorageMethod.EOF)
            {
                prov = Providers.XOREOF;
            }
            else
            {
                prov = Providers.XORIDAT;
            }

            provider = (SteganographyProvider)Activator.CreateInstance(prov.ProviderType, imagePath, false);
            provider.SetPassword(password, false);

            if (Imprint(DataType.FileSystem, fileSystemData))
            {
                using (FileStream fs = File.Open(imagePath, FileMode.Create, FileAccess.Write, FileShare.Read))
                    provider.WriteToStream(fs);

                return(true);
            }

            return(false);
        }
Пример #4
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);
        }
Пример #5
0
        private void menuActionInjectIndex_Click(object sender, EventArgs e)
        {
            ImageList imgs;

            ListViewItem[] rows;
            using (LinkIndexBuilder lib = new LinkIndexBuilder())
            {
                lib.ShowDialog();
                if (lib.Canceled)
                {
                    return;
                }

                imgs = lib.imglist;
                rows = lib.rows;
            }

            if (rows.Length < 1)
            {
                return;
            }

            List <string> keys  = new List <string>();
            LinkIndex     index = new LinkIndex();

            foreach (ListViewItem lvi in rows)
            {
                int i = -1;
                if (!keys.Contains(lvi.ImageKey) && imgs.Images.ContainsKey(lvi.ImageKey))
                {
                    keys.Add(lvi.ImageKey);
                    index.Images.Add(imgs.Images[lvi.ImageKey]);
                    i = index.Images.Count - 1;
                }
                if (i < 0)
                {
                    i = keys.IndexOf(lvi.ImageKey);
                }

                index.Rows.Add(new LinkIndexRow(i, lvi.SubItems[0].Text, lvi.SubItems[1].Text));
            }

            Provider prov = GetProvider();

            if (prov == null)
            {
                return;
            }

            provider = (SteganographyProvider)Activator.CreateInstance(prov.ProviderType, pngOriginal, false);
            Imprint(DataType.Index, index, DataType.Index, index);
        }
Пример #6
0
        void ProcessPNG(bool find = true)
        {
            foreach (PNGChunk chunk in image.Chunks)
            {
                if (chunk.Name == "IDAT")
                {
                    key = (byte[])chunk.Data.Clone();
                    break;
                }
            }
            if (key == null)
            {
                throw new PNGMaskException("PNG has no IDAT chunk for the SteganographyProvider to process.");
            }

            if (find)
            {
                PNGChunk pdata = default(PNGChunk);
                bool     skip = true, pdatafound = false;
                foreach (PNGChunk chunk in image.Chunks)
                {
                    if (chunk.Name == "IDAT")
                    {
                        if (skip)
                        {
                            skip = false;
                            continue;
                        }

                        pdata      = chunk;
                        pdatafound = true;
                    }
                }

                if (pdatafound)
                {
                    vector = (byte[])pdata.Data.Clone();

                    string pass = SteganographyProvider.AskPassword();
                    if (pass != null && pass.Length > 0)
                    {
                        PrepareKey(Encoding.UTF8.GetBytes(pass));
                    }
                }
            }
        }
Пример #7
0
        private void menuActionInjectImage_Click(object sender, EventArgs e)
        {
            string path = OpenFileDialog("Image Files (*.png, *.jpg, *.jpeg, *.gif)|*.png;*.jpg;*.jpeg;*.gif");

            if (path == null)
            {
                return;
            }

            Provider prov = GetProvider();

            if (prov == null)
            {
                return;
            }

            provider = (SteganographyProvider)Activator.CreateInstance(prov.ProviderType, pngOriginal, false);
            byte[] img = File.ReadAllBytes(path);
            Imprint(DataType.ImageBytes, img, DataType.Image, Image.FromFile(path));
        }
Пример #8
0
        private void menuActionInjectBinary_Click(object sender, EventArgs e)
        {
            string path = OpenFileDialog("All Files (*.*)|*.*");

            if (path == null)
            {
                return;
            }

            Provider prov = GetProvider();

            if (prov == null)
            {
                return;
            }

            provider = (SteganographyProvider)Activator.CreateInstance(prov.ProviderType, pngOriginal, false);
            byte[] data = File.ReadAllBytes(path);

            Imprint(DataType.Binary, data, DataType.Binary, data);
        }
Пример #9
0
        private void menuActionInjectText_Click(object sender, EventArgs e)
        {
            string data;

            using (Notepad np = new Notepad())
            {
                np.ShowDialog();
                if (np.Canceled)
                {
                    return;
                }
                data = np.TextData;
            }

            Provider prov = GetProvider();

            if (prov == null)
            {
                return;
            }

            provider = (SteganographyProvider)Activator.CreateInstance(prov.ProviderType, pngOriginal, false);
            Imprint(DataType.Text, data, DataType.Text, data);
        }
Пример #10
0
        public override byte[] ExtractData()
        {
            string pass = base.password;

            if (pass != null && pass.Length > 0)
            {
                csprng = SteganographyProvider.PrepareISAAC(Encoding.UTF8.GetBytes(pass));
            }

            byte[] len  = new byte[4];
            int    temp = 0;
            int    j    = 0;

            for (int i = 0; i < 4; i++)
            {
                len[i] |= (byte)(BitmapData[j] & 3);
                IterateChannel(ref temp, ref j);

                len[i] |= (byte)((BitmapData[j] & 3) << 2);
                IterateChannel(ref temp, ref j);

                len[i] |= (byte)((BitmapData[j] & 3) << 4);
                IterateChannel(ref temp, ref j);

                len[i] |= (byte)((BitmapData[j] & 3) << 6);
                IterateChannel(ref temp, ref j);
            }

            int isaac = 0;

            if (csprng != null)
            {
                for (int k = 0; k < len.Length; k++, isaac++)
                {
                    len[k] = (byte)(len[k] ^ csprng.rsl[isaac]);
                }
            }

            int ilen = BitConverter.ToInt32(len, 0);

            ulong maxsize = (ulong)Math.Floor(((double)BitmapDimensions.Width * (double)BitmapDimensions.Height * 3d * 2d) / 8d);

            if (ilen < 1 || (ulong)ilen > maxsize)
            {
                throw new InvalidPasswordException();
            }

            byte[] data = new byte[ilen];

            for (int i = 0; i < ilen && j < BitmapData.Length; i++)
            {
                data[i] |= (byte)(BitmapData[j] & 3);
                IterateChannel(ref temp, ref j);

                data[i] |= (byte)((BitmapData[j] & 3) << 2);
                IterateChannel(ref temp, ref j);

                data[i] |= (byte)((BitmapData[j] & 3) << 4);
                IterateChannel(ref temp, ref j);

                data[i] |= (byte)((BitmapData[j] & 3) << 6);
                IterateChannel(ref temp, ref j);
            }

            if (csprng != null)
            {
                for (int i = 0; i < data.Length; i++, isaac++)
                {
                    if (isaac >= ISAAC.SIZE)
                    {
                        isaac = 0;
                        csprng.Isaac();
                    }

                    data[i] = (byte)(data[i] ^ csprng.rsl[isaac]);
                }
            }

            return(data);
        }
Пример #11
0
        public override void ImprintData(byte[] data)
        {
            string pass = base.password;

            if (pass != null && pass.Length > 0)
            {
                csprng = SteganographyProvider.PrepareISAAC(Encoding.UTF8.GetBytes(pass));
            }

            ulong maxsize = (ulong)Math.Floor(((double)BitmapDimensions.Width * (double)BitmapDimensions.Height * 3d * 2d) / 8d);

            if ((ulong)data.LongLength + 4 > maxsize)
            {
                throw new NotEnoughSpaceException("Not enough space for graphical injection, maximum data size for this image is " + (int)Math.Floor(maxsize / 1024d) + "KB");
            }

            List <byte> tdata = new List <byte>(data);

            byte[] len = BitConverter.GetBytes(data.Length);
            tdata.InsertRange(0, len);
            data  = tdata.ToArray();
            tdata = null;

            if (csprng != null)
            {
                for (int i = 0, isaac = 0; i < data.Length; i++, isaac++)
                {
                    if (isaac >= ISAAC.SIZE)
                    {
                        isaac = 0;
                        csprng.Isaac();
                    }

                    data[i] = (byte)(data[i] ^ csprng.rsl[isaac]);
                }
            }

            int temp = 0;

            for (int i = 0, j = 0; i < data.Length && j < BitmapData.Length; i++)
            {
                byte mask1 = (byte)(data[i] & 3);
                byte mask2 = (byte)((data[i] & 12) >> 2);
                byte mask3 = (byte)((data[i] & 48) >> 4);
                byte mask4 = (byte)((data[i] & 192) >> 6);

                BitmapData[j] &= 252;
                BitmapData[j] |= mask1;
                IterateChannel(ref temp, ref j);

                BitmapData[j] &= 252;
                BitmapData[j] |= mask2;
                IterateChannel(ref temp, ref j);

                BitmapData[j] &= 252;
                BitmapData[j] |= mask3;
                IterateChannel(ref temp, ref j);

                BitmapData[j] &= 252;
                BitmapData[j] |= mask4;
                IterateChannel(ref temp, ref j);
            }
        }
Пример #12
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();
        }