Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PdbSymbol"/> class.
 /// </summary>
 /// <param name="module">Module that contains this symbol.</param>
 /// <param name="typeIndex">Type index of the simple build-in type.</param>
 public PdbSymbol(PdbModule module, TypeIndex typeIndex)
     : base(module)
 {
     PdbModule = module;
     Id        = typeIndex.Index;
     Initialize(typeIndex);
 }
Esempio n. 2
0
        /// <summary>
        /// Gets user type fields.
        /// </summary>
        protected override IEnumerable <SymbolField> GetFields()
        {
            TypeIndex fieldListIndex = TypeIndex.None;

            if (typeRecord is ClassRecord classRecord)
            {
                fieldListIndex = classRecord.FieldList;
            }
            else if (typeRecord is UnionRecord unionRecord)
            {
                fieldListIndex = unionRecord.FieldList;
            }

            foreach (TypeRecord field in EnumerateFieldList(fieldListIndex))
            {
                if (field is DataMemberRecord dataMember)
                {
                    yield return(new PdbSymbolField(this, dataMember));
                }
                else if (field is StaticDataMemberRecord staticDataMember)
                {
                    yield return(new PdbSymbolField(this, staticDataMember));
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PdbPointerType"/> class.
 /// </summary>
 /// <param name="pdb">The PDB file reader.</param>
 /// <param name="typeIndex">Type index.</param>
 /// <param name="modifierOptions">The modifier options.</param>
 /// <param name="elementType">PDB type of object pointed to.</param>
 /// <param name="size">The type size in bytes.</param>
 /// <param name="isLValueReference"><c>true</c> if pointer is L-value reference</param>
 /// <param name="isRValueReference"><c>true</c> if pointer is R-value reference</param>
 internal PdbPointerType(PdbFileReader pdb, TypeIndex typeIndex, ModifierOptions modifierOptions, TypeIndex elementType, ulong size, bool isLValueReference, bool isRValueReference)
     : base(pdb, typeIndex, modifierOptions, pdb[elementType].Name + "*", size)
 {
     ElementType       = pdb[elementType];
     IsLValueReference = isLValueReference;
     IsRValueReference = isRValueReference;
 }
Esempio n. 4
0
        public void SimpleTypeKindAndMode()
        {
            TypeIndex typeIndex = new TypeIndex(SimpleTypeKind.Byte, SimpleTypeMode.Direct);

            Assert.Equal(SimpleTypeKind.Byte, typeIndex.SimpleKind);
            Assert.Equal(SimpleTypeMode.Direct, typeIndex.SimpleMode);
        }
Esempio n. 5
0
        public void mark_shadow_lights(List <TES3.REFR> references)
        {
            int count = 0;

            foreach (string lght in priority_list)
            {
                if (count >= 4)
                {
                    return;
                }
                foreach (TES3.REFR r in references)
                {
                    if (TypeIndex.getInstance().get(r.editor_id) != TypeIndex.TYPE.LIGH)
                    {
                        continue;
                    }

                    if (count >= 4)
                    {
                        return;
                    }
                    if (r.editor_id.Contains(lght))
                    {
                        r.editor_id = r.editor_id + "_shadow";
                        count++;
                    }
                }
            }
        }
        /// <summary>
        /// Reads <see cref="FunctionListSymbol"/> from the stream.
        /// </summary>
        /// <param name="reader">Stream binary reader.</param>
        /// <param name="symbolStream">Symbol stream that contains this symbol record.</param>
        /// <param name="symbolStreamIndex">Index in symbol stream <see cref="SymbolStream.References"/> array.</param>
        /// <param name="kind">Symbol record kind.</param>
        /// <param name="dataLength">Record data length.</param>
        public static FunctionListSymbol Read(IBinaryReader reader, SymbolStream symbolStream, int symbolStreamIndex, SymbolRecordKind kind, uint dataLength)
        {
            long start  = reader.Position;
            var  symbol = new FunctionListSymbol
            {
                SymbolStream      = symbolStream,
                SymbolStreamIndex = symbolStreamIndex,
                Kind  = kind,
                Count = reader.ReadUint(),
            };

            symbol.Functions   = new TypeIndex[symbol.Count];
            symbol.Invocations = new uint[symbol.Count];
            for (int i = 0; i < symbol.Functions.Length; i++)
            {
                symbol.Functions[i] = TypeIndex.Read(reader);
            }

            int remaining = (int)(dataLength - (reader.Position - start)) / 4; // 4 = sizeof(uint)

            if (remaining > symbol.Invocations.Length)
            {
                remaining = symbol.Invocations.Length;
            }
            for (int i = 0; i < remaining; i++)
            {
                symbol.Invocations[i] = reader.ReadUint();
            }

            return(symbol);
        }
Esempio n. 7
0
        private void Test(TpiStream tpiStream)
        {
            Assert.Equal(tpiStream.TypeRecordCount, tpiStream.references.Count);
            Assert.NotEmpty(tpiStream.HashValues);
            if (tpiStream.HashAdjusters != null)
            {
                Assert.NotEmpty(tpiStream.HashAdjusters.Dictionary);
            }

            // Verify that type offsets are correct in references array
            foreach (TypeIndexOffset offset in tpiStream.TypeIndexOffsets)
            {
                var reference = tpiStream.references[(int)offset.Type.ArrayIndex];
                Assert.Equal(offset.Offset, reference.DataOffset - RecordPrefix.Size);
            }

            // Verify that all types can be read
            for (int i = 0; i < tpiStream.references.Count; i++)
            {
                Assert.NotNull(tpiStream[TypeIndex.FromArrayIndex(i)]);
            }

            // Check that getting types by kind works correctly
            TypeLeafKind[] kinds = tpiStream.references.Select(r => r.Kind).Distinct().ToArray();

            foreach (TypeLeafKind kind in kinds)
            {
                Assert.Equal(tpiStream.references.Count(r => r.Kind == kind), tpiStream[kind].Length);
            }
        }
 internal object GetInstance(TypeIndex tIndex)
 {
     StartGetInstance(tIndex);
     object instance;
     Binder.BaseTypeConfig cTarget = GetBinderConfig(tIndex);
     if (cTarget != null && cTarget.ActivationObject != null)
     {
          instance = cTarget.ActivationObject.GetInstance(tIndex);
     }
     else
     {
         instance = m_defaultActivationObject.GetInstance(tIndex);
     }
     if (instance == null)
     {
         instance = CreateInstance(tIndex, cTarget);
         if (cTarget != null && cTarget.ActivationObject != null)
         {
             cTarget.ActivationObject.NewInstance(tIndex, instance);
         }
         else
         {
             m_defaultActivationObject.NewInstance(tIndex, instance);
         }
     }
     StopGetInstance(tIndex);
     return instance;
 }
        /// <summary>
        /// Creates a list of fields based on <see cref="TagRecord"/>.<see cref="TagRecord.FieldList"/>.
        /// </summary>
        private List <PdbTypeField> EnumerateFields()
        {
            List <PdbTypeField> fields = new List <PdbTypeField>();

            foreach (TypeRecord field in EnumerateFieldList())
            {
                if (field is DataMemberRecord dataMemberRecord)
                {
                    // Check if this field is stored as bits.
                    TypeIndex typeIndex = dataMemberRecord.Type;

                    if (!typeIndex.IsSimple)
                    {
                        TypeRecord fieldType = Pdb.PdbFile.TpiStream[typeIndex];

                        if (fieldType is BitFieldRecord bitFieldRecord)
                        {
                            fields.Add(new PdbTypeBitField(this, dataMemberRecord, bitFieldRecord));
                            continue;
                        }
                    }

                    // Add it as regular field.
                    fields.Add(new PdbTypeField(this, dataMemberRecord));
                }
            }
            return(fields);
        }
Esempio n. 10
0
        public void ToStringTest()
        {
            TypeIndex typeIndexByte    = new TypeIndex(SimpleTypeKind.Byte, SimpleTypeMode.Direct);
            TypeIndex typeIndexArray10 = TypeIndex.FromArrayIndex(10);

            Assert.NotNull(typeIndexByte.ToString());
            Assert.NotNull(typeIndexArray10.ToString());
        }
Esempio n. 11
0
        public void ArrayIndex()
        {
            TypeIndex typeIndex = TypeIndex.FromArrayIndex(10);

            Assert.False(typeIndex.IsSimple);
            Assert.False(typeIndex.IsNoneType);
            Assert.Equal(10U, typeIndex.ArrayIndex);
        }
Esempio n. 12
0
 /// <summary>
 /// Gets PDB symbol for the specified type index.
 /// </summary>
 /// <param name="index">Type index.</param>
 public PdbSymbol GetSymbol(TypeIndex index)
 {
     if (index.IsSimple)
     {
         return(builtinSymbolsCache[index]);
     }
     return(definedSymbolsCache[(int)index.ArrayIndex]);
 }
Esempio n. 13
0
 /// <summary>
 /// Reads <see cref="MemberPointerInfo"/> from the stream.
 /// </summary>
 /// <param name="reader">Stream binary reader.</param>
 public static MemberPointerInfo Read(IBinaryReader reader)
 {
     return(new MemberPointerInfo
     {
         ContainingType = TypeIndex.Read(reader),
         Representation = (PointerToMemberRepresentation)reader.ReadUshort(),
     });
 }
Esempio n. 14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PdbType"/> class.
 /// </summary>
 /// <param name="pdb">The PDB file reader.</param>
 /// <param name="typeIndex">Type index.</param>
 /// <param name="modifierOptions">The modifier options.</param>
 /// <param name="name">The type name.</param>
 /// <param name="size">The type size in bytes.</param>
 internal PdbType(PdbFileReader pdb, TypeIndex typeIndex, ModifierOptions modifierOptions, string name, ulong size)
 {
     Pdb             = pdb;
     ModifierOptions = modifierOptions;
     TypeIndex       = typeIndex;
     Name            = name;
     Size            = size;
 }
Esempio n. 15
0
 /// <summary>
 /// Reads <see cref="TypeIndexOffset"/> from the stream.
 /// </summary>
 /// <param name="reader">Stream binary reader.</param>
 public static TypeIndexOffset Read(IBinaryReader reader)
 {
     return(new TypeIndexOffset
     {
         Type = TypeIndex.Read(reader),
         Offset = reader.ReadUint(),
     });
 }
 /// <summary>
 /// Reads <see cref="ListContinuationRecord"/> from the stream.
 /// </summary>
 /// <param name="reader">Stream binary reader.</param>
 /// <param name="kind">Type record kind.</param>
 public static ListContinuationRecord Read(IBinaryReader reader, TypeLeafKind kind)
 {
     return(new ListContinuationRecord
     {
         Kind = kind,
         Padding = reader.ReadUshort(),
         ContinuationIndex = TypeIndex.Read(reader),
     });
 }
Esempio n. 17
0
 /// <summary>
 /// Reads <see cref="UdtSymbol"/> from the stream.
 /// </summary>
 /// <param name="reader">Stream binary reader.</param>
 /// <param name="kind">Symbol record kind.</param>
 public static UdtSymbol Read(IBinaryReader reader, SymbolRecordKind kind)
 {
     return(new UdtSymbol
     {
         Kind = kind,
         Type = TypeIndex.Read(reader),
         Name = reader.ReadCString(),
     });
 }
Esempio n. 18
0
        public static bool IsOfType(this ClrInstance instance, TypeIndex typeIndex)
        {
            if (instance.Type == null)
            {
                return(false);
            }

            return(typeIndex.ContainsType(instance.Type));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="PdbType"/> class.
 /// </summary>
 /// <param name="pdb">The PDB file reader.</param>
 /// <param name="typeIndex">Type index.</param>
 /// <param name="tagRecord">The tag record.</param>
 /// <param name="modifierOptions">The modifier options.</param>
 /// <param name="size">The type size in bytes.</param>
 internal PdbUserDefinedType(PdbFileReader pdb, TypeIndex typeIndex, TagRecord tagRecord, ModifierOptions modifierOptions, ulong size)
     : base(pdb, typeIndex, modifierOptions, tagRecord.Name.String, size)
 {
     TagRecord               = tagRecord;
     fieldsCache             = SimpleCache.CreateWithContext(this, CallEnumerateFields);
     staticFieldsCache       = SimpleCache.CreateWithContext(this, CallEnumerateStaticFields);
     baseClassesCache        = SimpleCache.CreateWithContext(this, CallEnumerateBaseClasses);
     virtualBaseClassesCache = SimpleCache.CreateWithContext(this, CallEnumerateVirtualBaseClasses);
 }
Esempio n. 20
0
 /// <summary>
 /// Reads <see cref="StringIdRecord"/> from the stream.
 /// </summary>
 /// <param name="reader">Stream binary reader.</param>
 /// <param name="kind">Type record kind.</param>
 public static StringIdRecord Read(IBinaryReader reader, TypeLeafKind kind)
 {
     return(new StringIdRecord
     {
         Kind = kind,
         Id = TypeIndex.Read(reader),
         String = reader.ReadCString(),
     });
 }
Esempio n. 21
0
        public int GetTypeIndex(AchievementType type)
        {
            if (TypeIndex == null || !TypeIndex.ContainsKey(type))
            {
                return(0);
            }

            return(TypeIndex[type]);
        }
 /// <summary>
 /// Reads <see cref="VirtualFunctionPointerRecord"/> from the stream.
 /// </summary>
 /// <param name="reader">Stream binary reader.</param>
 /// <param name="kind">Type record kind.</param>
 public static VirtualFunctionPointerRecord Read(IBinaryReader reader, TypeLeafKind kind)
 {
     return(new VirtualFunctionPointerRecord
     {
         Kind = kind,
         Padding = reader.ReadUshort(),
         Type = TypeIndex.Read(reader),
     });
 }
Esempio n. 23
0
 /// <summary>
 /// Reads <see cref="ModifierRecord"/> from the stream.
 /// </summary>
 /// <param name="reader">Stream binary reader.</param>
 /// <param name="kind">Type record kind.</param>
 public static ModifierRecord Read(IBinaryReader reader, TypeLeafKind kind)
 {
     return(new ModifierRecord
     {
         Kind = kind,
         ModifiedType = TypeIndex.Read(reader),
         Modifiers = (ModifierOptions)reader.ReadUshort(),
     });
 }
Esempio n. 24
0
 /// <summary>
 /// Reads <see cref="BaseClassRecord"/> from the stream.
 /// </summary>
 /// <param name="reader">Stream binary reader.</param>
 /// <param name="kind">Type record kind.</param>
 public static BaseClassRecord Read(IBinaryReader reader, TypeLeafKind kind)
 {
     return(new BaseClassRecord
     {
         Kind = kind,
         Attributes = MemberAttributes.Read(reader),
         Type = TypeIndex.Read(reader),
         Offset = Convert.ToUInt64(reader.ReadEncodedConstant()),
     });
 }
Esempio n. 25
0
 /// <summary>
 /// Reads <see cref="NestedTypeRecord"/> from the stream.
 /// </summary>
 /// <param name="reader">Stream binary reader.</param>
 /// <param name="kind">Type record kind.</param>
 public static NestedTypeRecord Read(IBinaryReader reader, TypeLeafKind kind)
 {
     return(new NestedTypeRecord
     {
         Kind = kind,
         Padding = reader.ReadUshort(),
         Type = TypeIndex.Read(reader),
         Name = reader.ReadCString(),
     });
 }
Esempio n. 26
0
 /// <summary>
 /// Reads <see cref="BitFieldRecord"/> from the stream.
 /// </summary>
 /// <param name="reader">Stream binary reader.</param>
 /// <param name="kind">Type record kind.</param>
 public static BitFieldRecord Read(IBinaryReader reader, TypeLeafKind kind)
 {
     return(new BitFieldRecord
     {
         Kind = kind,
         Type = TypeIndex.Read(reader),
         BitSize = reader.ReadByte(),
         BitOffset = reader.ReadByte(),
     });
 }
Esempio n. 27
0
 /// <summary>
 /// Reads <see cref="BuildInfoSymbol"/> from the stream.
 /// </summary>
 /// <param name="reader">Stream binary reader.</param>
 /// <param name="symbolStream">Symbol stream that contains this symbol record.</param>
 /// <param name="symbolStreamIndex">Index in symbol stream <see cref="SymbolStream.References"/> array.</param>
 /// <param name="kind">Symbol record kind.</param>
 public static BuildInfoSymbol Read(IBinaryReader reader, SymbolStream symbolStream, int symbolStreamIndex, SymbolRecordKind kind)
 {
     return(new BuildInfoSymbol
     {
         SymbolStream = symbolStream,
         SymbolStreamIndex = symbolStreamIndex,
         Kind = kind,
         BuildId = TypeIndex.Read(reader),
     });
 }
Esempio n. 28
0
 /// <summary>
 /// Gets all type indexes for the specified type record kind.
 /// </summary>
 /// <param name="kind">Type record kind.</param>
 public IEnumerable <TypeIndex> GetIndexes(TypeLeafKind kind)
 {
     for (int i = 0; i < references.Count; i++)
     {
         if (references[i].Kind == kind)
         {
             yield return(TypeIndex.FromArrayIndex(i));
         }
     }
 }
Esempio n. 29
0
 /// <summary>
 /// Reads <see cref="FunctionIdRecord"/> from the stream.
 /// </summary>
 /// <param name="reader">Stream binary reader.</param>
 /// <param name="kind">Type record kind.</param>
 public static FunctionIdRecord Read(IBinaryReader reader, TypeLeafKind kind)
 {
     return(new FunctionIdRecord
     {
         Kind = kind,
         ParentScope = TypeIndex.Read(reader),
         FunctionType = TypeIndex.Read(reader),
         Name = reader.ReadCString(),
     });
 }
Esempio n. 30
0
 /// <summary>
 /// Reads <see cref="MemberFunctionIdRecord"/> from the stream.
 /// </summary>
 /// <param name="reader">Stream binary reader.</param>
 /// <param name="kind">Type record kind.</param>
 public static MemberFunctionIdRecord Read(IBinaryReader reader, TypeLeafKind kind)
 {
     return(new MemberFunctionIdRecord
     {
         Kind = kind,
         ClassType = TypeIndex.Read(reader),
         FunctionType = TypeIndex.Read(reader),
         Name = reader.ReadCString(),
     });
 }
 /// <summary>
 /// Reads <see cref="StaticDataMemberRecord"/> from the stream.
 /// </summary>
 /// <param name="reader">Stream binary reader.</param>
 /// <param name="kind">Type record kind.</param>
 public static StaticDataMemberRecord Read(IBinaryReader reader, TypeLeafKind kind)
 {
     return(new StaticDataMemberRecord
     {
         Kind = kind,
         Attributes = MemberAttributes.Read(reader),
         Type = TypeIndex.Read(reader),
         Name = reader.ReadCString(),
     });
 }
 private void StartGetInstance(TypeIndex tIndex)
 {
     if (m_typeContructionPath.Contains(tIndex))
     {
         throw new Exceptions.CircularDependencyException();
     }
     else
     {
         m_typeContructionPath.Add(tIndex);
     }
 }
            private object CreateInstance(TypeIndex tIndex, Binder.BaseTypeConfig cTarget)
            {
                // try to resolve the type from the custom resolvers
                object resolvedObject = m_binder.ResolveType(tIndex.Type);
                if (resolvedObject != null)
                {
                    CheckConfigForObject(cTarget, resolvedObject);
                    return resolvedObject;
                }

                if (cTarget == null)
                {
                    // for not binded types, find the most suitable constructor
                    if (!m_notBindedConstructorList.ContainsKey(tIndex.Type))
                    {
                        ConstructorInfo constructor = FindConstructor(tIndex.Type);
                        if (constructor == null)
                        {
                            throw new Exceptions.UnboundTypeException();
                        }
                        else
                        {
                            var expr = CreateExpressionConstructor(constructor,
                                ci => ci.GetParameters().Select(p => CreateParameterExpression(p)).ToArray());
                            m_notBindedConstructorList.Add(tIndex.Type, Expression.Lambda<Func<object>>(expr).Compile());
                        }
                    }
                    return m_notBindedConstructorList[tIndex.Type]();
                }
                else
                {
                    // create the object from the binded configuration
                    if (cTarget.Constructor == null)
                    {
                        CreateConstructor(cTarget);
                    }

                    var obj = cTarget.Constructor();
                    if (cTarget.ConstructorType == Binder.BaseTypeConfig.ConstructorTypeConfig.Action)
                    {
                        cTarget.ConstructorAction(obj);
                    }
                    return obj;
                }
            }
 private Binder.BaseTypeConfig GetBinderConfig(TypeIndex tIndex)
 {
     Binder.TypeConfigHandler tHandler = m_binder.GetTargetType(tIndex.Type);
     if (tHandler != null)
     {
         if (tIndex.Attribute == null)
         {
             return tHandler.DefaultConfig;
         }
         else
         {
             Binder.BaseTypeConfig tConfig = tHandler.AttributeConfig(tIndex.Attribute);
             if (tConfig != null)
             {
                 return tConfig;
             }
             else
             {
                 // use the default config when the constructor has a non existing attribute
                 return tHandler.DefaultConfig;
             }
         }
     }
     else
     {
         return null;
     }
 }
 void eventController_RequestStarted(IPlugInEvents sender, TypeIndex t)
 {
     m_currentCallObjectList = new Dictionary<TypeIndex, object>();
 }
 private void StopGetInstance(TypeIndex tIndex)
 {
     m_typeContructionPath.Remove(tIndex);
 }