示例#1
0
        public IEnumerable <List <StructureField> > GetOverlappingClusters(StructureFieldCollection fields)
        {
            int clusterEndOffset = 0;
            List <StructureField> overlappingFields = new List <StructureField>();

            foreach (StructureField field in fields)
            {
                if (overlappingFields.Count == 0)
                {
                    clusterEndOffset = field.Offset + field.DataType.Size;
                }
                else if (FieldOverlaps(field, clusterEndOffset))
                {
                    clusterEndOffset = Math.Max(
                        clusterEndOffset,
                        field.Offset + field.DataType.Size);
                }
                else
                {
                    yield return(overlappingFields);

                    overlappingFields = new List <StructureField>();
                }
                //$REVIEW: what happens if a field has a user-given name?
                AddFieldToCluster(field.Clone(), overlappingFields);
            }
            if (overlappingFields.Count > 0)
            {
                yield return(overlappingFields);
            }
        }
        public void Sfc_Add()
        {
            var sfc = new StructureFieldCollection();

            sfc.Add(4, PrimitiveType.Word32);
            Assert.AreEqual(1, sfc.Count);
        }
示例#3
0
        public void CpaPointerToGlobalStructureField()
        {
            Given_Procedure("proc", m =>
            {
                m.MStore(Ptr32ToInt32(m, 0x123130), Word32(m, 1));
                m.MStore(Ptr32ToInt32(m, 0x123134), Word32(m, 2));
                m.MStore(Ptr32ToInt32(m, 0x123138), Word32(m, 3));
            });
            var strFieldType = new StructureType
            {
                Fields =
                {
                    { 0, PrimitiveType.Int32  },
                    { 4, PrimitiveType.Real32 },
                    { 8, PrimitiveType.Int32  },
                }
            };
            var globalVariables = new StructureFieldCollection
            {
                { 0x123130, strFieldType }
            };

            Given_Program(globalVariables);

            When_RunConstantPointerAnalysis();

            var expected =
                "(struct (123130 (struct" +
                " (0 int32 dw0000)" +
                " (4 real32 r0004)" +
                " (8 int32 dw0008)) t123130))";

            AssertGlobalVariables(expected);
        }
        /// <summary>
        /// Return a collection of fields with BuiltInTypes.
        /// </summary>
        public static StructureFieldCollection GetAllBuiltInTypesFields()
        {
            var collection = new StructureFieldCollection();

            foreach (var builtInType in EncoderCommon.BuiltInTypes)
            {
                if (builtInType == BuiltInType.Null ||
                    builtInType == BuiltInType.Variant ||
                    builtInType == BuiltInType.DataValue ||
                    builtInType == BuiltInType.ExtensionObject ||
                    builtInType >= BuiltInType.Number
                    )
                {
                    continue;
                }

                collection.Add(new StructureField()
                {
                    Name            = builtInType.ToString(),
                    DataType        = new NodeId((uint)builtInType),
                    ArrayDimensions = null,
                    Description     = $"A BuiltInType.{builtInType} property.",
                    IsOptional      = false,
                    MaxStringLength = 0,
                    ValueRank       = -1
                });
            }
            return(collection);
        }
示例#5
0
 public IEnumerable<List<StructureField>> GetOverlappingClusters(StructureFieldCollection fields)
 {
     int clusterEndOffset = 0;
     List<StructureField> overlappingFields = new List<StructureField>();
     foreach (StructureField field in fields)
     {
         if (overlappingFields.Count == 0)
         {
             clusterEndOffset = field.Offset + field.DataType.Size;
         }
         else if (FieldOverlaps(field, clusterEndOffset))
         {
             clusterEndOffset = Math.Max(
                 clusterEndOffset,
                 field.Offset + field.DataType.Size);
         }
         else
         {
             yield return overlappingFields;
             overlappingFields = new List<StructureField>();
         }
         AddFieldToCluster(new StructureField(field.Offset,  field.DataType,field.Name), overlappingFields);
     }
     if (overlappingFields.Count > 0)
         yield return overlappingFields;
 }
示例#6
0
        public IEnumerable <List <StructureField> > GetOverlappingClusters(StructureFieldCollection fields)
        {
            int clusterEndOffset = 0;
            List <StructureField> overlappingFields = new List <StructureField>();

            foreach (StructureField field in fields)
            {
                if (overlappingFields.Count == 0)
                {
                    clusterEndOffset = field.Offset + field.DataType.Size;
                }
                else if (FieldOverlaps(field, clusterEndOffset))
                {
                    clusterEndOffset = Math.Max(
                        clusterEndOffset,
                        field.Offset + field.DataType.Size);
                }
                else
                {
                    yield return(overlappingFields);

                    overlappingFields = new List <StructureField>();
                }
                AddFieldToCluster(new StructureField(field.Offset, field.DataType, field.Name), overlappingFields);
            }
            if (overlappingFields.Count > 0)
            {
                yield return(overlappingFields);
            }
        }
示例#7
0
 public void FcAdd()
 {
     StructureFieldCollection fc = new StructureFieldCollection();
     fc.Add(new StructureField(0, PrimitiveType.Word16, "foo"));
     Assert.IsNotNull(fc.LowerBound(0));
     Assert.IsNotNull(fc.LowerBound(1));
     Assert.IsNull(fc.LowerBound(-1));
 }
示例#8
0
        public void FcAdd()
        {
            StructureFieldCollection fc = new StructureFieldCollection();

            fc.Add(new StructureField(0, PrimitiveType.Word16, "foo"));
            Assert.IsNotNull(fc.LowerBound(0));
            Assert.IsNotNull(fc.LowerBound(1));
            Assert.IsNull(fc.LowerBound(-1));
        }
        public void Sfc_AddDuplicate_DifferentTypes()
        {
            var sfc = new StructureFieldCollection();
            var f1  = sfc.Add(4, PrimitiveType.Word32);
            var f2  = sfc.Add(4, PrimitiveType.Real32);

            Assert.AreEqual(2, sfc.Count);
            Assert.AreSame(PrimitiveType.Real32, f2.DataType);
        }
        public void Sfc_AddDuplicate_SameType()
        {
            var sfc = new StructureFieldCollection();
            var f1  = sfc.Add(4, PrimitiveType.Word32);
            var f2  = sfc.Add(4, PrimitiveType.Word32);

            Assert.AreEqual(1, sfc.Count);
            Assert.AreSame(f1, f2);
        }
示例#11
0
        private void Given_Program(StructureFieldCollection globalVariables)
        {
            this.program = pb.BuildProgram();
            program.Globals.TypeVariable = store.CreateTypeVariable(factory);
            var globalStructure = new StructureType();

            globalStructure.Fields.AddRange(globalVariables);
            program.Globals.TypeVariable.Class.DataType = globalStructure;
        }
        public void Sfc_Add_DecreasingOffset()
        {
            var sfc = new StructureFieldCollection();
            var f1  = sfc.Add(10, PrimitiveType.Word32);
            var f2  = sfc.Add(2, PrimitiveType.Real32);

            Assert.AreEqual(2, sfc.Count);
            Assert.AreSame(PrimitiveType.Real32, sfc.AtOffset(2).DataType);
            Assert.AreSame(PrimitiveType.Word32, sfc.AtOffset(10).DataType);
        }
        private StructureFieldCollection MakeStructureCollection(int nItems)
        {
            var sfc = new StructureFieldCollection();

            for (int i = 0; i < nItems; ++i)
            {
                sfc.Add(i * 4, PrimitiveType.Int32);
            }
            return(sfc);
        }
 private StructureField FindRandomItem(StructureFieldCollection sfc, int maxOffset)
 {
     return(sfc.AtOffset(rand.Next(maxOffset)));
 }