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

            nodes.Add(newNode);
        }
Exemple #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);
            }
Exemple #3
0
 public EbmlStackItem(EbmlNodeMaster node, int index = 0)
 {
     this.Node = node; this.Index = index;
 }