示例#1
0
        public void AddMaster(EbmlSig element, long size)
        {
            var newNode = new EbmlNodeMaster(element, size);

            nodes.Add(newNode);
        }
示例#2
0
            EbmlNodeMaster ParseTree(EbmlSig element)
            {
                string err           = null;
                var    contentLenBuf = ReadMTF(Data.fbs, out long contentLen);

                if (contentLen < 0)
                {
                    return(null);
                }
                Data.ValidSize += contentLenBuf.Length;

                var  newMaster = new EbmlNodeMaster(element, contentLenBuf.Length + contentLen);
                var  buf       = new byte[3];
                long stop      = Data.ValidSize + contentLen;

                while (Data.ValidSize < stop)
                {
                    Data.fbs.Position = Data.ValidSize;
                    var got = Data.fbs.Read(buf, 0, 3);
                    if (got < 3)
                    {
                        err = "File corrupt or truncated"; goto FATAL;
                    }

                    EbmlNode newNode;

                    foreach (var item in masterSigs)
                    {
                        if (item.SigIsStartOf(buf))
                        {
                            Data.fbs.Position = Data.ValidSize = Data.ValidSize + item.Signature.Count;
                            newNode           = ParseTree(item);
                            if (IssueModel.Data.HasFatal)
                            {
                                if (newNode != null)
                                {
                                    newMaster.AddNode(newNode);
                                }
                                return(newMaster);
                            }
                            goto NEXT;
                        }
                    }

                    foreach (var item in leafSigs)
                    {
                        if (item.SigIsStartOf(buf))
                        {
                            Data.fbs.Position = Data.ValidSize = Data.ValidSize + item.Signature.Count;

                            byte[] payload    = null;
                            byte[] payloadHdr = ReadMTF(Data.fbs, out long payloadLen);
                            if (payloadHdr == null)
                            {
                                err = "File truncated or corrupt"; goto FATAL;
                            }

                            if ((item.Flag & ParseFlag.Persist) != 0)
                            {
                                payload = new byte[payloadLen];
                                got     = Data.fbs.Read(payload, 0, (int)payloadLen);
                            }

                            if (buf[0] != CrcSig.Sig32)
                            {
                                newNode = new EbmlNodeLeaf(item, payload);
                            }
                            else
                            {
                                ++Data.CrcCount;
                                long hashStart = Data.ValidSize + payloadHdr.Length + payloadLen;
                                long hashCount;
                                if (newMaster.Nodes.Count == 0)
                                {
                                    hashCount = contentLen - 5 - payloadHdr.Length;
                                }
                                else
                                {
                                    IssueModel.Add("Misplaced CRC");
                                    hashCount = 0;
                                }
                                newNode = new EbmlNodeCRC(item, payload, hashStart, hashCount);
                            }

                            Data.ValidSize += payloadHdr.Length + payloadLen;
                            goto NEXT;
                        }
                    }
                    err = $"Unknown element [{buf[0]:X2}][{buf[1]:X2}][{buf[2]:X2}]";
                    goto FATAL;
NEXT:
                    newMaster.AddNode(newNode);
                }
                if (Data.ValidSize == stop)
                {
                    return(newMaster);
                }

                err = "Positional error";
FATAL:
                err += String.Format(" at {0:X}.", Data.ValidSize);
                IssueModel.Add(err, Severity.Fatal);
                return(newMaster);
            }
示例#3
0
 public EbmlNodeMaster(EbmlSig element, long size) : base(element)
 {
     this.Size  = size;
     this.nodes = new List <EbmlNode>();
 }
示例#4
0
 public EbmlNodeCRC(EbmlSig element, byte[] payload, long start, long count) : base(element)
 {
     this.Start       = start;
     this.Count       = count;
     this.StoredCRC32 = ConvertTo.FromLit32ToUInt32(payload, 0);
 }
示例#5
0
 public EbmlNodeLeaf(EbmlSig element, long size) : base(element, size)
 {
     this.payload = null;
 }
示例#6
0
 public EbmlNodeLeaf(EbmlSig element, byte[] payload) : base(element, payload == null? 0 : payload.Length)
 {
     this.payload = payload;
 }
示例#7
0
 public EbmlNode(EbmlSig element, long size = 0)
 {
     this.Size    = size;
     this.Element = element;
 }