Beispiel #1
0
        private bool ReadEntryHeader(BinaryReader Reader, out ImageHeader Header)
        {
            Header = new ImageHeader();

            if (Reader == null)
            {
                return(false);
            }

            try
            {
                Header.ImageID        = Reader.ReadUInt16();
                Header.ImageType      = (ImageType)Reader.ReadUInt16();
                Header.StartBlock     = Reader.ReadUInt16();
                Header.EndBlock       = Reader.ReadUInt16();
                Header.ExecuteAddress = Reader.ReadUInt32();
                Header.FileSize       = Reader.ReadUInt32();
                Header.ImageName      = Utils.ReadNCString(Reader, 0x20);

                return(CheckEntryHeader(Header));
            }
            catch (Exception)
            {
                return(false);
            }
        }
Beispiel #2
0
        private bool ReadBootHeader(BinaryReader Reader, out BootHeader Header)
        {
            Header = new BootHeader();

            if (Reader == null)
            {
                return(false);
            }

            try
            {
                Header.BootCodeMarker = Reader.ReadUInt32();
                Header.ExecuteAddress = Reader.ReadUInt32();
                Header.ImageSize      = Reader.ReadUInt32();
                Header.SkewMarker     = Reader.ReadUInt32();
                Header.DQSODS         = Reader.ReadUInt32();
                Header.CLKQSDS        = Reader.ReadUInt32();
                Header.DramMarker     = Reader.ReadUInt32();
                Header.DramSize       = Reader.ReadUInt32();
            }
            catch (Exception)
            {
                return(false);
            }

            // Magic check
            if (Header.BootCodeMarker != 0x57425AA5)
            {
                return(false);
            }

            return(true);
        }
Beispiel #3
0
        private bool WriteBootHeader(BinaryWriter Writer, BootHeader Header)
        {
            if (Writer == null)
            {
                return(false);
            }

            try
            {
                Writer.Write(Header.BootCodeMarker);
                Writer.Write(Header.ExecuteAddress);
                Writer.Write(Header.ImageSize);
                Writer.Write(Header.SkewMarker);
                Writer.Write(Header.DQSODS);
                Writer.Write(Header.CLKQSDS);
                Writer.Write(Header.DramMarker);
                Writer.Write(Header.DramSize);
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
        }
Beispiel #4
0
        public bool ReadImage(Stream ImageStream)
        {
            if (ImageStream == null)
            {
                return(false);
            }

            BinaryReader reader    = new BinaryReader(ImageStream);
            uint         numImages = 0;

            // Prepare everything
            Header = new BootHeader();
            if (Images != null)
            {
                Images.Clear();
            }
            Images = new List <ImageEntry>();

            // Our blocksize is 0x20000 bytes / block
            // Seek to the beginning of the file / memorystream for our header block
            // When writing, there is a copy of the entire NandLoader at 0x20000, 0x40000 and 0x60000
            reader.BaseStream.Seek(0x00000, SeekOrigin.Begin);
            if (!ReadBootHeader(reader, out Header))
            {
                return(false);
            }

            // Now seek to block 0 of the last nand page - 1
            // When writing, there is a copy at 0x3f000, 0x5f000 and at 0x7f000
            reader.BaseStream.Seek(0x1f000, SeekOrigin.Begin);
            try
            {
                // Now check the magic
                if (reader.ReadUInt32() != 0x574255aa)
                {
                    return(false);
                }
                // Then read the number of images
                numImages = reader.ReadUInt32();
                // Now skip one 32 bit word
                reader.BaseStream.Seek(sizeof(uint), SeekOrigin.Current);
                // Finally check the last magic
                if (reader.ReadUInt32() != 0x57425963)
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                return(false);
            }

            // Now we can read the image structs
            for (int image = 0; image < numImages; image++)
            {
                ImageHeader head;
                if (!ReadEntryHeader(reader, out head))
                {
                    return(false);
                }

                ImageEntry entry = new ImageEntry(head.ImageName, head.ImageType,
                                                  head.ExecuteAddress);
                if (!ReadEntryData(reader, head, out entry.Data))
                {
                    return(false);
                }

                if (!CheckAddEntry(entry))
                {
                    return(false);
                }

                Images.Add(entry);
            }

            return(true);
        }
Beispiel #5
0
 public NandImage()
 {
     Header = new BootHeader();
     Images = new List <ImageEntry>();
 }