Beispiel #1
0
        public LeafContainerBase ReadTypeDirect(bool hasSize = true)
        {
            long typeStartOffset = Position;

            UInt16 size = 0;

            if (hasSize)
            {
                size = ReadUInt16();
            }
            LeafType leafType = ReadEnum <LeafType>();

            ILeaf typeSym = CreateLeafStream(leafType);

            typeSym.Read();

            ConsumePadding();

#if !PEFF
            long   typeDataSize = size + sizeof(UInt16);
            UInt32 typeHash     = PerformAt(typeStartOffset, () => {
                byte[] typeData = ReadBytes((int)typeDataSize);
                return(HasherV2.HashBufferV8(typeData, 0xFFFFFFFF));
            });
#endif

            return(new DirectLeafProvider(0, leafType, typeSym));
        }
Beispiel #2
0
        /// <summary>
        /// Read a varying ILeaf which can be either a ILeaf type or a raw data marker
        /// </summary>
        /// <param name="dataSize"></param>
        /// <param name="leafType"></param>
        /// <returns>true if we found a ILeaf, false if we found raw data marker</returns>
        public ILeafContainer ReadVaryingType(out uint dataSize)
        {
            UInt16 leafValue = ReadUInt16();

            if (leafValue < (ushort)LeafType.LF_NUMERIC)
            {
                // $TODO: ILeafValue is not a ILeaf marker, but it's still a valid ushort
                // do we need to save this?
                dataSize = 0;
                return(null);
            }

            if (!Enum.IsDefined(typeof(LeafType), leafValue))
            {
                throw new InvalidDataException($"Unknown ILeaf type {leafValue} while computing ILeaf data size");
            }

            LeafType leafType = (LeafType)leafValue;

            dataSize = PrimitiveDataSizes[leafType];
            Seek(-2, SeekOrigin.Current);

            ILeafContainer leaf = new TypeDataReader(ctx, this).ReadTypeDirect(hasSize: false);

            //ILeafContainer leaf = new TypeDataReader(ctx, this).ReadTypeLazy(hasSize: false);
            return(leaf);
        }
Beispiel #3
0
 public TypeDataWriter(
     IServiceContainer ctx, SpanStream stream,
     LeafType type, bool hasSize = true
     ) : base(stream)
 {
     this.ctx     = ctx;
     this.type    = type;
     this.hasSize = hasSize;
 }
Beispiel #4
0
        private static string CallingConvention(LeafType lt)
        {
            switch (lt)
            {
            default: throw new NotImplementedException($"Unknown calling convention {lt}.");

            case LeafType.C_NEAR:
                return("__cdecl");
            }
        }
Beispiel #5
0
        private int ReturnAddressSize(LeafType callingConvention)
        {
            switch (callingConvention)
            {
            case LeafType.C_NEAR: return(2);

            case LeafType.C_FAR: return(4);
            }
            throw new NotImplementedException();
        }
Beispiel #6
0
        public Guid AddItem(Guid fatherGuid, string xpath, string name, LeafType type, bool isUnique, Method URLGrabMethode = null, bool isURLRelative = true)
        {
            var guid = Guid.NewGuid();
            var l    = new Leaf()
            {
                Id = guid, Xpath = xpath, IsURLRelative = isURLRelative, IsUniqe = isUnique, Type = type, Name = name, URLGrabMethode = URLGrabMethode
            };

            Tree.Add(l, GuidToModelNode[fatherGuid]);
            XpathToModelNode.Add(xpath, l);
            GuidToModelNode.Add(guid, l);
            return(guid);
        }
        public void LeafTest(LeafType leafType, string fun, string expected)
        {
            // arrange
            var leaf = new LeafComponent
            {
                Fun = fun
            };

            // act
            var code = _generator.GenerateCode(leaf);

            // assert
            code.Should().Be(expected);
        }
Beispiel #8
0
            /// <summary>
            /// Used when creating new leaf node later (after loading).
            /// </summary>
            _Node(_Node target, bool after, LeafType type, string name, bool canClose)
            {
                _pm       = target._pm;
                _leaf     = new() { addedLater = true, name = name, canClose = canClose };
                _elem     = _leaf.panel = new() { Tag = this, UseLayoutRounding = true };
                _leafType = type;
                _dontSave = true;
                _Dictionary.Add(name, this);
                _AddToParentWhenMovingOrAddingLater(target, after);
            }

            public void Save(XmlWriter x)
            {
                if (Parent == null)                   //mark to not save stack/tab nodes without savable leaf descendants
                {
                    _Children(this);
Beispiel #9
0
        public LeafContainerBase ReadTypeDirect(bool hasSize = true)
        {
            long typeStartOffset = Position;

            UInt16 size = 0;

            if (hasSize)
            {
                size = ReadUInt16();
                if (size == 0)
                {
                    throw new InvalidDataException("Leaf size field cannot be 0");
                }
            }
            LeafType leafType = ReadEnum <LeafType>();

            ILeaf typeSym = CreateLeafStream(leafType);

            typeSym.Read();

            Position += (typeSym as LeafBase).Length;
            ConsumePadding();

            // for PDB 1.0: hash collides with padding, and is not properly encoded sometimes
            AlignStream(2);

#if !PEFF
            long   typeDataSize = size + sizeof(UInt16);
            UInt32 typeHash     = PerformAt(typeStartOffset, () => {
                byte[] typeData = ReadBytes((int)typeDataSize);
                return(HasherV2.HashBufferV8(typeData, 0xFFFFFFFF));
            });
#endif

            return(new DirectLeafProvider(0, leafType, typeSym));
        }
 public DirectLeafProvider(uint typeIndex, LeafType type, ILeaf data)
 {
     this.typeIndex = typeIndex;
     this.type      = type;
     this.data      = data;
 }
Beispiel #11
0
            /// <summary>
            /// Used to create nodes when loading from XML.
            /// </summary>
            _Node(KPanels pm, XElement x, _Node parent, int index)
            {
                _pm    = pm;
                _index = index;

                string tag = x.Name.LocalName;

                if (parent == null)                   //the root XML element
                {
                    if (tag != "stack")
                    {
                        throw new ArgumentException("XML root element must be 'stack'");
                    }
                    _pm._rootStack = this;
                }
                else
                {
                    parent.AddChild(this);
                }

                switch (tag)
                {
                case "stack":
                    _stack = new _StackFields {
                        isVertical = x.Attr("o") == "v"
                    };
                    _elem = _stack.grid = new Grid();
                    break;

                case "tab":
                    _tab  = new();
                    _elem = _tab.tc = new _TabControl();
                    break;

                case "panel":
                case "toolbar":
                case "document":
                    _leaf      = new();
                    _elem      = _leaf.panel = new();
                    _leafType  = tag[0] switch { 'p' => LeafType.Panel, 't' => LeafType.Toolbar, _ => LeafType.Document };
                    _leaf.name = x.Attr("name") ?? throw new ArgumentException("XML element without 'name'");
                    _Dictionary.Add(_leaf.name, this);
                    break;

                default: throw new ArgumentException("unknown XML tag");
                }
                _elem.UseLayoutRounding = true;
                _elem.Tag = this;

                if (parent != null)
                {
                    if (!_IsDocument)
                    {
                        _savedDockState = (_DockState)(x.Attr("state", 0) & 3);
                        _floatSavedRect = x.Attr("floatRect");
                    }
                    if (!_IsStack)
                    {
                        x.Attr(out _captionAt, "captionAt");
                    }

                    if (_ParentIsStack)
                    {
                        _dockedSize = _GridLengthFromString(x.Attr("z"));                         //height in vertical stack or width in horizontal stack
                        _AddToStack(moving: false, _index == 0 ? 0 : x.Attr("s", c_defaultSplitterSize));

                        var flags = (_Flags)x.Attr("flags", 0);
                        if (flags.Has(_Flags.Splitter_ResizeNearest) && _splitter != null)
                        {
                            _splitter.ResizeNearest = true;
                        }

                        if (_IsTab)
                        {
                            _InitTabControl();
                        }
                    }
                    else
                    {
                        _AddToTab(moving: false);
                    }
                }

                if (!_IsLeaf)                   //stack or tab
                {
                    if (_ParentIsTab)
                    {
                        throw new ArgumentException(tag + " in 'tab'");
                    }
                    int i = 0;
                    foreach (var e in x.Elements())
                    {
                        new _Node(_pm, e, this, i++);
                    }
                    Debug.Assert(i > 0);

                    if (_IsTab && i > 0)
                    {
                        _tab.tc.SelectedIndex = Math.Clamp(x.Attr("active", 0), 0, i - 1);
                    }
                }

                //print.it(new string('\t', parent?.Level ?? 0) + _ntype, _ptype, Name, _indexInParent);

                if (parent == null)                   //the root XML element
                {
                    int          nVisible = 0; _Node firstHidden = null;
                    List <_Node> aFloat = null;
                    foreach (var v in Descendants())
                    {
                        if (!v._IsStack)
                        {
                            if (v._IsVisibleReally(true))
                            {
                                nVisible++;
                            }
                            else
                            {
                                firstHidden ??= v;
                            }
                        }
                        var ds = v._savedDockState;
                        if (ds == _DockState.Float)
                        {
                            (aFloat ??= new()).Add(v);
                        }
                        else if (ds != 0)
                        {
                            v._SetDockState(ds);
                        }
                    }
                    if (nVisible == 0 && firstHidden != null)                       //if all non-stack hidden, unhide one, else user cannot unhide any because there are no captions to show the context menu
                    {
                        firstHidden._SetDockState(0);
                    }
                    if (aFloat != null)
                    {
                        DependencyPropertyChangedEventHandler eh = null;
                        eh = (_, e) => {
                            if (e.NewValue is bool visible && visible)
                            {
                                _stack.grid.IsVisibleChanged -= eh;
                                _stack.grid.Dispatcher.InvokeAsync(() => { foreach (var v in aFloat)
                                                                           {
                                                                               v._SetDockState(_DockState.Float);
                                                                           }
                                                                   });
                            }
                        };
                        _stack.grid.IsVisibleChanged += eh;
                    }

                    //timer.after(1000, _ => _Test(5));
                    ////timer.after(5000, _ => _Test(0));
                    //void _Test(int margin) {
                    //	foreach (var v in Descendants(true)) {
                    //		if (v._IsStack) v._stack.grid.Background = (v.Level & 3) switch { 0 => Brushes.CornflowerBlue, 1 => Brushes.Khaki, 2 => Brushes.YellowGreen, _ => Brushes.LightYellow };
                    //		if(v!=this) v._elem.Margin = new Thickness(margin);
                    //		if (v._splitter != null) v._splitter.Visibility = Visibility.Collapsed;
                    //	}
                    //}

                    ////_stack.grid.PreviewMouseMove += _RootGrid_PreviewMouseMove;
                }
            }
Beispiel #12
0
 public static SchemaFieldSelector From(string name, bool phi, LeafType type)
 {
     return(new SchemaFieldSelector {
         Mask = phi, Phi = phi, Required = true, Type = type, Name = name
     });
 }
Beispiel #13
0
        private ILeaf CreateLeafStream(LeafType leafType)
        {
            switch (leafType)
            {
            case LeafType.LF_ALIAS:
                return(new LF_ALIAS(ctx, this));

            case LeafType.LF_ARGLIST:
                return(new LF_ARGLIST(ctx, this));

            case LeafType.LF_ARRAY:
                return(new LF_ARRAY(ctx, this));

            case LeafType.LF_BCLASS:
                return(new LF_BCLASS(ctx, this));

            case LeafType.LF_BITFIELD:
                return(new LF_BITFIELD(ctx, this));

            case LeafType.LF_CHAR:
                return(new LF_CHAR(ctx, this));

            case LeafType.LF_CLASS:
            case LeafType.LF_STRUCTURE:
            case LeafType.LF_INTERFACE:
                return(new LF_CLASS_STRUCTURE_INTERFACE(ctx, this));

            case LeafType.LF_ENUM:
                return(new LF_ENUM(ctx, this));

            case LeafType.LF_ENUMERATE:
            case LeafType.LF_ENUMERATE_ST:
                return(new LF_ENUMERATE(ctx, this));

            case LeafType.LF_FIELDLIST:
                return(new LF_FIELDLIST(ctx, this));

            case LeafType.LF_INDEX:
                return(new LF_INDEX(ctx, this));

            case LeafType.LF_LONG:
                return(new LF_LONG(ctx, this));

            case LeafType.LF_MEMBER:
                return(new LF_MEMBER(ctx, this));

            case LeafType.LF_METHOD:
                return(new LF_METHOD(ctx, this));

            case LeafType.LF_METHODLIST:
                return(new LF_METHODLIST(ctx, this));

            case LeafType.LF_MODIFIER:
                return(new LF_MODIFIER(ctx, this));

            case LeafType.LF_MFUNCTION:
                return(new LF_MFUNCTION(ctx, this));

            case LeafType.LF_NESTTYPE:
                return(new LF_NESTTYPE(ctx, this));

            case LeafType.LF_ONEMETHOD:
                return(new LF_ONEMETHOD(ctx, this));

            case LeafType.LF_POINTER:
                return(new LF_POINTER(ctx, this));

            case LeafType.LF_PROCEDURE:
                return(new LF_PROCEDURE(ctx, this));

            case LeafType.LF_QUADWORD:
                return(new LF_QUADWORD(ctx, this));

            case LeafType.LF_REAL32:
                return(new LF_REAL32(ctx, this));

            case LeafType.LF_REAL64:
                return(new LF_REAL64(ctx, this));

            case LeafType.LF_SHORT:
                return(new LF_SHORT(ctx, this));

            case LeafType.LF_STMEMBER:
                return(new LF_STMEMBER(ctx, this));

            case LeafType.LF_ULONG:
                return(new LF_ULONG(ctx, this));

            case LeafType.LF_UNION:
                return(new LF_UNION(ctx, this));

            case LeafType.LF_UQUADWORD:
                return(new LF_UQUADWORD(ctx, this));

            case LeafType.LF_USHORT:
                return(new LF_USHORT(ctx, this));

            case LeafType.LF_VARSTRING:
                return(new LF_VARSTRING(ctx, this));

            case LeafType.LF_VBCLASS:
            case LeafType.LF_IVBCLASS:
                return(new LF_VBCLASS(ctx, this));

            case LeafType.LF_VFTABLE:
                return(new LF_VFTABLE(ctx, this));

            case LeafType.LF_VFTPATH_16t:
                return(new LF_VFTPATH_16t(ctx, this));

            case LeafType.LF_VFUNCTAB:
                return(new LF_VFUNCTAB(ctx, this));

            case LeafType.LF_VTSHAPE:
                return(new LF_VTSHAPE(ctx, this));

            case LeafType.SPECIAL_BUILTIN:
                throw new InvalidDataException("SPECIAL_BUILTIN is a custom ILeaf marker, it can't be present in a valid ctx file");

            default:
                throw new NotImplementedException($"Leaf {leafType} not supported yet");
            }
        }
Beispiel #14
0
 protected TypeDataWriter CreateWriter(LeafType type, bool hasSize = true)
 {
     return(new TypeDataWriter(ctx, stream, type, hasSize));
 }