Exemplo n.º 1
0
        public static LocatedNullable <Guid> GetOptionalGuid(
            this XElement elem, string name, Guid?defaultValue = null)
        {
            if (elem == null)
            {
                throw new ArgumentNullException(nameof(elem));
            }

            XAttribute attrib = elem.Attribute(name);

            if (attrib == null)
            {
                return(Located.Create(defaultValue));
            }

            if (!Guid.TryParseExact(attrib.Value, "B", out var value))
            {
                throw CreateInvalidNumberValueException <byte>(attrib);
            }

            return(Located.Create((Guid?)value, attrib.GetValueLocation()));
        }
Exemplo n.º 2
0
        public static LocatedNullable <ushort> GetOptionalUInt16(
            this XElement elem, string name, ushort?defaultValue = null)
        {
            if (elem == null)
            {
                throw new ArgumentNullException(nameof(elem));
            }

            XAttribute attrib = elem.Attribute(name);

            if (attrib == null)
            {
                return(Located.Create(defaultValue));
            }

            if (!TryParse(attrib.Value, NumberFormat.HexDec, out ushort value))
            {
                throw CreateInvalidNumberValueException <ushort>(attrib);
            }

            return(Located.Create((ushort?)value, attrib.GetValueLocation()));
        }
Exemplo n.º 3
0
        private List <Task> ReadTasks(BinaryReader r)
        {
            var tasks       = new List <Task>();
            var taskEntries = new List <TaskEntry>();

            ReadMagic(r, CrimsonTags.TASK);
            var length = r.ReadUInt32();
            var count  = r.ReadUInt32();

            for (uint i = 0; i < count; ++i)
            {
                long   offset     = r.BaseStream.Position;
                var    value      = r.ReadUInt32();
                var    messageId  = r.ReadUInt32();
                var    guid       = r.ReadGuid();
                var    nameOffset = r.ReadUInt32();
                string name       = r.ReadCountedStringAt(nameOffset);
                taskEntries.Add(
                    new TaskEntry {
                    Value     = value,
                    MessageId = messageId,
                    Guid      = guid,
                    Name      = name,
                });

                var task = new Task(QName.Parse(name, nsr), Located.Create((ushort)value));
                task.Guid    = guid == Guid.Empty ? null : (Guid?)guid;
                task.Message = ResolveMessage(messageId);
                MarkObject(offset, task);
                tasks.Add(task);
            }

            foreach (var task in taskEntries)
            {
            }

            return(tasks);
        }
Exemplo n.º 4
0
        public static LocatedRef <QName> GetOptionalQName(
            this XElement elem, string name, QName defaultValue = null)
        {
            if (elem == null)
            {
                throw new ArgumentNullException(nameof(elem));
            }
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            XAttribute attrib = elem.Attribute(name);

            if (attrib == null)
            {
                return(Located.Create(defaultValue));
            }

            return(Located.Create(
                       QName.Parse(attrib.Value, new XElementNamespaceResolver(elem)),
                       attrib.GetValueLocation()));
        }
Exemplo n.º 5
0
        private List <Tuple <ushort, Opcode> > ReadOpcodes(BinaryReader r)
        {
            var opcodes       = new List <Tuple <ushort, Opcode> >();
            var opcodeEntries = new List <OpcodeEntry>();

            ReadMagic(r, CrimsonTags.OPCO);
            var length = r.ReadUInt32();
            var count  = r.ReadUInt32();

            for (uint i = 0; i < count; ++i)
            {
                long   offset     = r.BaseStream.Position;
                var    taskId     = r.ReadUInt16();
                var    value      = r.ReadUInt16();
                var    messageId  = r.ReadUInt32();
                var    nameOffset = r.ReadUInt32();
                string name       = r.ReadCountedStringAt(nameOffset);
                opcodeEntries.Add(
                    new OpcodeEntry {
                    TaskId    = taskId,
                    Value     = value,
                    MessageId = messageId,
                    Name      = name,
                });

                var opcode = new Opcode(QName.Parse(name, nsr), Located.Create((byte)value));
                opcode.Message = ResolveMessage(messageId);
                MarkObject(offset, opcode);
                opcodes.Add(Tuple.Create(taskId, opcode));
            }

            foreach (var opcode in opcodeEntries)
            {
            }

            return(opcodes);
        }
Exemplo n.º 6
0
        private Tuple <Map, MapEntry> ReadMap(BinaryReader r)
        {
            long offset = r.BaseStream.Position;

            uint magic = r.ReadUInt32();

            if (magic != CrimsonTags.VMAP && magic != CrimsonTags.BMAP)
            {
                throw new InternalException("Unknown map magic {0}", magic);
            }

            uint length     = r.ReadUInt32();
            uint nameOffset = r.ReadUInt32();
            uint flags      = r.ReadUInt32();
            uint count      = r.ReadUInt32();

            var itemEntries = new List <MapItemEntry>();

            for (uint i = 0; i < count; ++i)
            {
                var value     = r.ReadUInt32();
                var messageId = r.ReadUInt32();
                itemEntries.Add(new MapItemEntry {
                    Value = value, MessageId = messageId
                });
            }

            if (r.BaseStream.Position != offset + length)
            {
                throw new IOException();
            }

            string name     = r.ReadCountedStringAt(nameOffset);
            var    mapEntry = new MapEntry {
                Flags = (MapFlags)flags,
                Name  = name,
                Items = itemEntries
            };
            var map = magic == CrimsonTags.VMAP ? new ValueMap(name) : (Map) new BitMap(name);

            foreach (var itemEntry in itemEntries)
            {
                var value = Located.Create(itemEntry.Value);
                var ls    = ResolveMessage(itemEntry.MessageId);

                MapItem item;
                if (magic == CrimsonTags.VMAP)
                {
                    item = new ValueMapItem(
                        (ValueMap)map, value, ls);
                }
                else
                {
                    item = new BitMapItem((BitMap)map, value, ls);
                }
                map.Items.Add(item);
            }

            MarkObject(offset, map);

            return(Tuple.Create(map, mapEntry));
        }
Exemplo n.º 7
0
        private Provider ReadWevtBlock(Guid providerId, BinaryReader r)
        {
            ReadMagic(r, CrimsonTags.WEVT);
            uint length    = r.ReadUInt32();
            uint messageId = r.ReadUInt32();
            uint count     = r.ReadUInt32();

            var lists = new List <ProviderListOffset>();

            for (uint i = 0; i < count; ++i)
            {
                var plo = new ProviderListOffset();
                plo.Type   = (EventFieldKind)r.ReadUInt32();
                plo.Offset = r.ReadUInt32();
                lists.Add(plo);
            }

            var providerMessage = ResolveMessage(messageId);

            string providerName = string.Format(
                CultureInfo.InvariantCulture, "Provider_{0:N}", providerId);
            string providerSymbol = providerName;
            Guid?  controlGuid    = null;
            Guid?  groupGuid      = null;

            var allOpcodes = new List <Tuple <ushort, Opcode> >();
            var levels     = new List <Level>();
            var tasks      = new List <Task>();
            var keywords   = new List <Keyword>();
            var events     = new List <Event>();
            var channels   = new List <Channel>();
            var maps       = new List <Map>();
            var templates  = new List <Template>();
            var filters    = new List <Filter>();
            Dictionary <uint, EventAttributeInfo> eventAttribMap = null;

            foreach (var list in lists)
            {
                r.BaseStream.Position = list.Offset;
                switch (list.Type)
                {
                case EventFieldKind.Level:
                    levels.AddRange(ReadLevels(r));
                    break;

                case EventFieldKind.Task:
                    tasks.AddRange(ReadTasks(r));
                    break;

                case EventFieldKind.Opcode:
                    allOpcodes.AddRange(ReadOpcodes(r));
                    break;

                case EventFieldKind.Keyword:
                    keywords.AddRange(ReadKeywords(r));
                    break;

                case EventFieldKind.Event:
                    events.AddRange(ReadEvents(r));
                    break;

                case EventFieldKind.Channel:
                    channels.AddRange(ReadChannels(r));
                    break;

                case EventFieldKind.Maps:
                    maps.AddRange(ReadMaps(r));
                    break;

                case EventFieldKind.Template:
                    templates.AddRange(ReadTemplates(r));
                    break;

                case EventFieldKind.Filter:
                    filters.AddRange(ReadFilters(r));
                    break;

                case EventFieldKind.ProviderAttribs:
                    ReadProviderAttribs(r, out providerName, out controlGuid, out groupGuid);
                    break;

                case EventFieldKind.EventAttribs:
                    eventAttribMap = ReadEventAttribs(r);
                    break;

                default:
                    break;
                }
            }

            if (eventAttribMap != null)
            {
                foreach (var evt in events)
                {
                    var key = evt.Value.Value | (uint)(evt.Version.Value << 16);

                    if (eventAttribMap.TryGetValue(key, out var entry))
                    {
                        if (entry.Name != null)
                        {
                            evt.Name = entry.Name;
                        }
                        if (entry.Attributes != null)
                        {
                            evt.Attributes.AddRange(entry.Attributes);
                        }
                    }
                }
            }

            var provider = new Provider(providerName, Located.Create(providerId), providerName)
            {
                Message     = providerMessage,
                ControlGuid = controlGuid,
                GroupGuid   = groupGuid,
            };

            provider.Levels.AddRange(levels);
            provider.Tasks.AddRange(tasks);
            provider.Keywords.AddRange(keywords);
            provider.Events.AddRange(events);
            provider.Channels.AddRange(channels);
            provider.Maps.AddRange(maps);
            provider.Templates.AddRange(templates);
            provider.Filters.AddRange(filters);

            provider.Opcodes.AddRange(allOpcodes.Where(x => x.Item1 == 0).Select(x => x.Item2));
            foreach (var taskSpecificOpcode in allOpcodes.Where(x => x.Item1 != 0))
            {
                var task = provider.Tasks.First(x => x.Value == taskSpecificOpcode.Item1);
                task.Opcodes.Add(taskSpecificOpcode.Item2);
            }

            return(provider);
        }