Example #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));
                    }
                }
            }
        }
Example #2
0
    public PNGChunk ReadChunk()
    {
        PNGChunk chunk = new PNGChunk();

        byte[] lengthArray = new byte[4];
        byte[] typeArray   = new byte[4];
        byte[] dataArray   = new byte[] { };
        byte[] crcArray    = new byte[4];

        //Read length and assign it to the ChunkLength
        lengthArray       = fileReader.ReadBytes(4);
        chunk.ChunkLength = ReadLength(lengthArray);

        //Read the chunk type and assign it to the ChunkType
        typeArray       = fileReader.ReadBytes(4);
        chunk.ChunkType = ReadType(typeArray);

        //Read the chunk data and assign it to the ChunkData
        chunk.ChunkData = fileReader.ReadBytes((int)chunk.ChunkLength);


        //Read the crc and assign it the Crc
        crcArray  = fileReader.ReadBytes(4);
        chunk.Crc = ReadLength(crcArray);       //uses same code as the length because it is a 32-bit integer.

        return(chunk);
    }
Example #3
0
        void dIHDR(PNGChunk c)
        {
            IHDRChunk ic = new IHDRChunk(c);

            ind();

            wo("Width: " + ic.Width);
            wo("Height: " + ic.Height);
            wo("BitDepth: " + ic.BitDepth);
            wo("ColorType: " + ic.ColorType + " " + decodeColorType(ic));

            oud();
        }
Example #4
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));
                    }
                }
            }
        }
        /// <summary>
        /// Loads PNG header from stream.
        /// </summary>
        /// <param name="stream">Fully formatted header stream. Position not relevant, but not reset.</param>
        /// <returns>Header length.</returns>
        protected override long Load(Stream stream)
        {
            base.Load(stream);
            byte[] temp = stream.ReadBytes(HeaderSize);

            if (!CheckIdentifier(temp))
            {
                throw new FormatException("Stream is not a PNG Image");
            }

            PNGChunk header = new PNGChunk(temp);

            Width             = MyBitConverter.ToInt32(header.ChunkData, 0, MyBitConverter.Endianness.BigEndian);
            Height            = MyBitConverter.ToInt32(header.ChunkData, 4, MyBitConverter.Endianness.BigEndian);
            BitDepth          = header.ChunkData[8];
            colourType        = (ColourType)header.ChunkData[9];
            CompressionMethod = (CompressionMethods)header.ChunkData[10];
            FilterMethod      = (FilterMethods)header.ChunkData[11];
            InterlaceMethod   = (InterlaceMethdods)header.ChunkData[12];

            return(-1);  // Since we don't know the length of the entire header, no point returning any value.
        }
Example #6
0
    //Loads the chunks of the PNG file from the `filename` in the parameter and returns PNGFile object
    public static PNGFile Load(string fileName)
    {
        PNGFile pngChunkCol = new PNGFile();

        using (PNGFileReader pngReader = new PNGFileReader(fileName))
        {
            PNGChunk pChunk = pngReader.ReadChunk();;
            while (true)
            {
                if (pChunk.ChunkType == "IEND")
                {
                    pngChunkCol.PngChunks.Add(pChunk);
                    break;
                }
                else
                {
                    pngChunkCol.PngChunks.Add(pChunk);
                    pChunk = pngReader.ReadChunk();
                }
            }
        }
        return(pngChunkCol);
    }
Example #7
0
        /// <summary>
        /// Loads PNG header from stream.
        /// </summary>
        /// <param name="stream">Fully formatted header stream. Position not relevant, but not reset.</param>
        /// <returns>Header length.</returns>
        protected override long Load(Stream stream)
        {
            base.Load(stream);
            byte[] temp = stream.ReadBytes(HeaderSize);

            if (!CheckIdentifier(temp))
                throw new FormatException("Stream is not a PNG Image");

            PNGChunk header = new PNGChunk(temp);
            Width = MyBitConverter.ToInt32(header.ChunkData, 0, MyBitConverter.Endianness.BigEndian);
            Height = MyBitConverter.ToInt32(header.ChunkData, 4, MyBitConverter.Endianness.BigEndian);
            BitDepth = header.ChunkData[8];
            colourType = (ColourType)header.ChunkData[9];
            CompressionMethod = (CompressionMethods)header.ChunkData[10];
            FilterMethod = (FilterMethods)header.ChunkData[11];
            InterlaceMethod = (InterlaceMethdods)header.ChunkData[12];

            return -1;  // Since we don't know the length of the entire header, no point returning any value.
        }
Example #8
0
 private void ReadChunk(BinaryReader b)
 {
     PNGChunk c = new PNGChunk();
     byte[] blen = b.ReadBytes(4);
     if (BitConverter.IsLittleEndian)
         Array.Reverse(blen);
     int len = BitConverter.ToInt32(blen, 0);
     c.Type = Encoding.ASCII.GetString(b.ReadBytes(4));
     c.Data = b.ReadBytes((int)len);
     c.RawCRC = b.ReadBytes(4);
     Chunks.Add(c);
 }