Exemplo n.º 1
0
            public PythonArray(string type, [Optional]object initializer) {
                if (type == null || type.Length != 1) throw PythonOps.TypeError("expected character, got {0}", DynamicHelpers.GetPythonType(type));

                _typeCode = type[0];
                _data = CreateData(_typeCode);

                if (initializer != Type.Missing) extend(initializer);
            }
Exemplo n.º 2
0
            public array([NotNull]string type) {
                if (type == null || type.Length != 1) {
                    throw PythonOps.TypeError("expected character, got {0}", PythonTypeOps.GetName(type));
                }

                _typeCode = type[0];
                _data = CreateData(_typeCode);
            }
        public void Test()
        {
            IAbstract i1 = new ArrayData();

            Assert.AreEqual(2.2, i1.Average, MaxMistake);
            IAbstract i2 = new GridData();

            Assert.AreEqual(2.2 / 3, i2.Average, MaxMistake);
        }
        public static string GetCompanyName()
        {
            string surname = NameData.GetSurname();

            string[] strArrays = new string[] { "Inc", "Incorporated", "LLC", "Ltd", "Group", "and Sons", "and Partners", "CIC", "CIO", "Co-Operative", "Society", "LP", "LLP", "General Partnership", "PLC", "Cyf", "Ccc", "Corp.", "Corporation" };
            string   str       = string.Concat(surname, " ", ArrayData.GetElement <string>(strArrays));

            return(str);
        }
Exemplo n.º 5
0
        public static IPickDataSource ConfigurUnityContainer()
        {
            IUnityContainer container = new UnityContainer();

            container.RegisterType <IPickDataSource, ListData>();
            ArrayData DList = container.Resolve <ArrayData>();

            return(DList);
        }
Exemplo n.º 6
0
 // HW buffer FIXME miiight want to use offset?
 public RenderInfo(int cnt, ArrayData format, PrimitiveType renderas, int vboID, int tex = 0)
 {
     offset     = 0;
     count      = cnt;
     renderAs   = renderas;
     dataFormat = format;
     vbo        = vboID;
     texture    = tex;
 }
Exemplo n.º 7
0
        // TODO use glinterleavedarrays possibly
        void PointazDiffa(ArrayData last, ArrayData now)
        {
            var sf = sizeof(float);

            // Last pointaz
            int lver, lcol, ltex, lstride;

            CSTrix(last, out lstride, out lver, out lcol, out ltex);

            // Want dese pointaz bozz
            int ver, col, tex, stride;

            CSTrix(now, out stride, out ver, out col, out tex);

            // Enabel dem if day waznt ooon befar
            if (ver > -1 && lver == -1)
            {
                buffer.ArrayEnabled(ArrayCap.VertexArray, true);
            }
            if (col > -1 && lcol == -1)
            {
                buffer.ArrayEnabled(ArrayCap.ColorArray, true);
            }
            if (tex > -1 && ltex == -1)
            {
                buffer.ArrayEnabled(ArrayCap.TextureCoordArray, true);
            }

            // Configah sum pointerz if dey on (caz strdez couldah changes)
            if (ver > -1)
            {
                buffer.SetPointer(ArrayCap.VertexArray, 2, stride * sf, ver * sf);
            }
            if (col > -1)
            {
                buffer.SetPointer(ArrayCap.ColorArray, 4, stride * sf, col * sf);
            }
            if (tex > -1)
            {
                buffer.SetPointer(ArrayCap.TextureCoordArray, 2, stride * sf, tex * sf);
            }

            // Turn em off if dey aint on no moar
            if (ver == -1 && lver > -1)
            {
                buffer.ArrayEnabled(ArrayCap.VertexArray, false);
            }
            if (col == -1 && lcol > -1)
            {
                buffer.ArrayEnabled(ArrayCap.ColorArray, false);
            }
            if (tex == -1 && ltex > -1)
            {
                buffer.ArrayEnabled(ArrayCap.TextureCoordArray, false);
            }
        }
Exemplo n.º 8
0
 public static T[] GetElement <T>(int count, params T[] array)
 {
     T[] returnArray = new T[count];
     while (count > 0)
     {
         returnArray[count - 1] = ArrayData.GetElement <T>(array);
         count--;
     }
     return(returnArray);
 }
Exemplo n.º 9
0
            public PythonArray([BytesConversion]string type, [Optional]object initializer) {
                if (type == null || type.Length != 1) {
                    throw PythonOps.TypeError("expected character, got {0}", PythonTypeOps.GetName(type));
                }

                _typeCode = type[0];
                _data = CreateData(_typeCode);

                if (initializer != Type.Missing) extend(initializer);
            }
Exemplo n.º 10
0
        public void Write_ABB_DataRecord(string Data_Record_Name, string Module_Name, string Task_Name, Controller aController, List <string> Variables, int ArrayIndex)
        {
            string        L_Module_Name      = Module_Name;
            string        L_Task_Name        = Task_Name;
            string        L_Data_Record_Name = Data_Record_Name;
            List <string> _Variables         = Variables;
            Controller    L_aController      = aController;
            int           _ArrayIndex        = ArrayIndex;
            string        _info;

            try
            {
                //Get the array with the records
                rd_array = aController.Rapid.GetRapidData(Task_Name, Module_Name, "RawIndividuals");
                ad       = (ArrayData)rd_array.Value;
                int aRank = ad.Rank;

                //Read the record
                rd  = L_aController.Rapid.GetRapidData(Task_Name, Module_Name, L_Data_Record_Name);
                rdt = L_aController.Rapid.GetRapidDataType(L_Task_Name, L_Module_Name, L_Data_Record_Name);
                UserDefined processdata = new UserDefined(rdt);

                //Prepare the parameters
                for (int i = 0; i < 5; i++)
                {
                    processdata.Components[i].FillFromString(_Variables[i]);
                }

                //Add the parameters to the array
                rd_array.Value = ad;
                ad[ArrayIndex] = processdata;
            }

            catch (ABB.Robotics.Controllers.RapidDomain.RapidModuleNotFoundException ee)
            {
                _info = "Error: " + ee.Message;
            }
            catch (ABB.Robotics.Controllers.RapidDomain.RapidSymbolNotFoundException ee)
            {
                _info = "Error: " + ee.Message;
            }
            catch (ABB.Robotics.GenericControllerException ee)
            {
                _info = "Error: " + ee.Message;
            }
            catch (System.Exception ee)
            {
                _info = "Error: " + ee.Message;
            }
            finally
            {
                // Release resources
            }
        }
Exemplo n.º 11
0
        private static IArrowArray CreateArray(Field field, int length)
        {
            var creator = new ArrayBufferCreator(length);

            field.DataType.Accept(creator);

            ArrayData data = new ArrayData(field.DataType, length, 0, 0,
                                           new[] { ArrowBuffer.Empty, creator.Buffer });

            return(ArrowArrayFactory.BuildArray(data));
        }
Exemplo n.º 12
0
        public static Array MakeIntArray(int length)
        {
            // The following should be improved once the ArrayBuilder PR goes in
            var intBuilder = new ArrowBuffer.Builder <int>();

            intBuilder.AppendRange(Enumerable.Range(0, length).Select(x => x));
            ArrowBuffer buffer   = intBuilder.Build();
            ArrayData   intData  = new ArrayData(Int32Type.Default, length, 0, 0, new[] { ArrowBuffer.Empty, buffer });
            Array       intArray = ArrowArrayFactory.BuildArray(intData) as Array;

            return(intArray);
        }
Exemplo n.º 13
0
 private void CreateSelfAndChildrenFieldNodes(ArrayData data)
 {
     if (data.DataType is NestedType)
     {
         // flatbuffer struct vectors have to be created in reverse order
         for (int i = data.Children.Length - 1; i >= 0; i--)
         {
             CreateSelfAndChildrenFieldNodes(data.Children[i]);
         }
     }
     Flatbuf.FieldNode.CreateFieldNode(Builder, data.Length, data.NullCount);
 }
Exemplo n.º 14
0
        static byte[] getBytes(ArrayData str)
        {
            int size = Marshal.SizeOf(str);

            byte[] arr = new byte[size];

            IntPtr ptr = Marshal.AllocHGlobal(size);

            Marshal.StructureToPtr(str, ptr, true);
            Marshal.Copy(ptr, arr, 0, size);
            Marshal.FreeHGlobal(ptr);
            return(arr);
        }
Exemplo n.º 15
0
        void IncrementalIndexTest(PrimitiveType pt, bool ver, bool col)
        {
            // test one, just put vertex data in only, same stride, same lenghts.  Check the correct data ends up back in.
            int nd = 5 * buf.primsizes[pt] * (2 + 4); // 5 quads

            for (int i = 0; i < 3; i++)               // 3 times
            {
                int       st = i * nd;
                ArrayData ad = 0 | (ver ? ArrayData.Vertex : 0) | (col ? ArrayData.Color : 0);
                var       r  = new RenderInfo(st, nd, ad, pt);
                for (int j = st; j < st + nd; j++)
                {
                    rd.sofwareBuffer.Add(j);
                }
                rd.bufferInfo.Add(r);
            }
            rp.ProcessRenderBuffer(rd);

            // check we haaave got ...erm...vertexes
            int chk = 0;

            foreach (var p in buf.renderlist)
            {
                Assert.AreEqual(p.pt, pt);
                foreach (var d in p.data)
                {
                    Assert.IsNull(d.t);
                    if (ver)
                    {
                        Assert.AreEqual(d.v.x, chk++);
                        Assert.AreEqual(d.v.y, chk++);
                    }
                    else
                    {
                        Assert.IsNull(d.v);
                    }
                    if (col)
                    {
                        Assert.AreEqual(d.c.a, chk++);
                        Assert.AreEqual(d.c.r, chk++);
                        Assert.AreEqual(d.c.g, chk++);
                        Assert.AreEqual(d.c.b, chk++);
                    }
                    else
                    {
                        Assert.IsNull(d.c);
                    }
                }
            }
            buf.ResetBuffer();
        }
Exemplo n.º 16
0
        /// <summary>
        /// Sets the ICC data (can be null if not used)
        /// </summary>
        /// <param name="inProfileData">Input profile data</param>
        /// <param name="outProfileData">Output profile data</param>
        public void SetICCData(double[][] inProfileData, double[][] outProfileData)
        {
            if (inProfileData != null)
            {
                _InICCData = new ArrayData(inProfileData);
                InICCData  = _InICCData.Pointer;
            }

            if (outProfileData != null)
            {
                _OutICCData = new ArrayData(outProfileData);
                OutICCData  = _OutICCData.Pointer;
            }
        }
Exemplo n.º 17
0
        static ArrayData fromBytes(byte[] arr)
        {
            ArrayData str = new ArrayData();

            int    size = Marshal.SizeOf(str);
            IntPtr ptr  = Marshal.AllocHGlobal(size);

            Marshal.Copy(arr, 0, ptr, size);

            str = (ArrayData)Marshal.PtrToStructure(ptr, str.GetType());
            Marshal.FreeHGlobal(ptr);

            return(str);
        }
Exemplo n.º 18
0
 public DotNetEmbeddedResourceImpl(DotNetResourceProvider resourceProvider, HexBufferSpan span, uint token)
     : base(resourceProvider, span, token)
 {
     if (span.Length < 4)
     {
         throw new ArgumentOutOfRangeException(nameof(span));
     }
     Size    = new StructField <UInt32Data>("Size", new UInt32Data(span.Buffer, span.Start.Position));
     Content = new StructField <VirtualArrayData <ByteData> >("Content", ArrayData.CreateVirtualByteArray(HexBufferSpan.FromBounds(span.Start + 4, span.End)));
     Fields  = new BufferField[] {
         Size,
         Content,
     };
 }
Exemplo n.º 19
0
        //Functions


        public string Read_ABB_DataRecord(string Data_Record_Name, string Module_Name, string Task_Name, Controller aController, int ArrayIndex)
        {
            string Data_Records_Time = " ";

            string     L_Module_Name      = Module_Name;
            string     L_Task_Name        = Task_Name;
            string     L_Data_Record_Name = Data_Record_Name;
            Controller L_aController      = aController;
            string     _info;

            try
            {
                //Get the array with the records
                rd_array = aController.Rapid.GetRapidData(Task_Name, Module_Name, "RawIndividuals");
                ad       = (ArrayData)rd_array.Value;
                int aRank = ad.Rank;

                //Read the record
                rd  = L_aController.Rapid.GetRapidData(Task_Name, Module_Name, L_Data_Record_Name);
                rdt = L_aController.Rapid.GetRapidDataType(L_Task_Name, L_Module_Name, L_Data_Record_Name);
                UserDefined processdata = new UserDefined(rdt);

                processdata = (UserDefined)ad[ArrayIndex];

                //Get the time elapsed using the individual's parameters
                Data_Records_Time = processdata.Components[5].ToString();
                return(Data_Records_Time);
            }

            catch (ABB.Robotics.Controllers.RapidDomain.RapidModuleNotFoundException ee)
            {
                return(_info = "Error: " + ee.Message);
            }
            catch (ABB.Robotics.Controllers.RapidDomain.RapidSymbolNotFoundException ee)
            {
                return(_info = "Error: " + ee.Message);
            }
            catch (ABB.Robotics.GenericControllerException ee)
            {
                return(_info = "Error: " + ee.Message);
            }
            catch (System.Exception ee)
            {
                return(_info = "Error: " + ee.Message);
            }
            finally
            {
                //
            }
        }
Exemplo n.º 20
0
        public void InitDataStream()
        {
            Task tRob1 = controller.Rapid.GetTask("T_ROB1");

            if (tRob1 != null)
            {
                rd_repeat = tRob1.GetRapidData("Module1", "repeat");
                if (rd_repeat.Value is Bool)
                {
                    repeatBool = (Bool)rd_repeat.Value;
                }

                rd_start = tRob1.GetRapidData("Module1", "flag");
                if (rd_start.Value is Num)
                {
                    processFlag = (Num)rd_start.Value;
                }

                rd_targetsNum = tRob1.GetRapidData("Module1", "targetsNum");
                if (rd_targetsNum.Value is Num)
                {
                    processFlag = (Num)rd_start.Value;
                }

                rd_speedLevel = tRob1.GetRapidData("Module1", "speedLevel");
                if (rd_speedLevel.Value is Num)
                {
                    speedLevel = (Num)rd_speedLevel.Value;
                }

                rd_targets = tRob1.GetRapidData("Module1", "tgPos");
                if (rd_targets.IsArray)
                {
                    targets = (ArrayData)rd_targets.Value;
                    int aRank = targets.Rank;
                    maxLength = targets.GetLength(aRank - 1);
                    ArrayModes am = targets.Mode;
                    Debug.WriteLine("ARRAY MODE! ::: " + am.ToString());
                    targets.Mode = ArrayModes.Dynamic;
                }
                else
                {
                    MessageBox.Show("'targets' data is not array!");
                }
                if (rd_targets == null)
                {
                    MessageBox.Show("'targets' data does not exist!");
                }
            }
        }
Exemplo n.º 21
0
    private void GenerateInvertedIndices()
    {
        indexHash = new Hashtable();
        inverted  = new ArrayData[vertices.Length];
        for (int i = 0; i < vertices.Length; ++i)
        {
            if (!indexHash.ContainsKey(vertices[i]))
            {
                indexHash.Add(vertices[i], i);
            }
            inverted[i] = new ArrayData();
            if (inverted[i].tmpConnections == null)
            {
                inverted[i].tmpConnections = new List <int>();
            }
            if (inverted[i].tmpAdjacentIndices == null)
            {
                inverted[i].tmpAdjacentIndices = new List <int>();
            }
        }
        //could probably do this on the fly in the previous loop
        for (int i = 0; i < vertices.Length; ++i)
        {
            if (indexHash.ContainsKey(vertices[i]))
            {
                int index = (int)indexHash[vertices[i]];
                inverted[index].tmpConnections.Add(i);
            }
        }
        for (int i = 0; i < indices.Length; i += 3)
        {
            //for each index add to the adj
            inverted[indices[i]].tmpAdjacentIndices.Add(indices[i + 1]);
            inverted[indices[i]].tmpAdjacentIndices.Add(indices[i + 2]);

            inverted[indices[i + 1]].tmpAdjacentIndices.Add(indices[i + 0]);
            inverted[indices[i + 1]].tmpAdjacentIndices.Add(indices[i + 2]);

            inverted[indices[i + 2]].tmpAdjacentIndices.Add(indices[i + 1]);
            inverted[indices[i + 2]].tmpAdjacentIndices.Add(indices[i + 0]);
        }
        for (int i = 0; i < vertices.Length; ++i)
        {
            inverted[i].UpdateArray();
            inverted[i].UpdateAdjacents();
        }
        GenerateConnections();
    }
Exemplo n.º 22
0
        private void    PopulateMaterials(List <int> materials)
        {
            materials.Clear();

            for (int i = 0; i < this.target.components.Count; i++)
            {
                if (this.target.components[i].type != null &&
                    (typeof(Renderer).IsAssignableFrom(this.target.components[i].type) == true ||                     // Handle all renderers.
                     (typeof(Behaviour).IsAssignableFrom(this.target.components[i].type) == true &&                   // And those bastards like Projector.
                      typeof(MonoBehaviour).IsAssignableFrom(this.target.components[i].type) == false) ||
                     typeof(MaskableGraphic).IsAssignableFrom(this.target.components[i].type) == true))
                {
                    for (int j = 0; j < this.target.components[i].fields.Length; j++)
                    {
                        if (this.target.components[i].fields[j].name.Equals("sharedMaterials") == true)
                        {
                            ArrayData     array           = this.target.components[i].fields[j].value as ArrayData;
                            UnityObject[] sharedMaterials = array.array as UnityObject[];

                            for (int k = 0; k < sharedMaterials.Length; k++)
                            {
                                // Happens when resizing array.
                                if (sharedMaterials[k] == null)
                                {
                                    continue;
                                }

                                if (sharedMaterials[k].instanceID != 0 &&
                                    materials.Contains(sharedMaterials[k].instanceID) == false)
                                {
                                    materials.Add(sharedMaterials[k].instanceID);
                                }
                            }
                        }
                        else if (this.target.components[i].fields[j].name.Equals("material") == true)
                        {
                            UnityObject material = this.target.components[i].fields[j].value as UnityObject;

                            if (material.instanceID != 0 &&
                                materials.Contains(material.instanceID) == false)
                            {
                                materials.Add(material.instanceID);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 23
0
        public void JudgeColor()
        {
            crd_SelectAction = RobotClass.con.Rapid.GetRapidData("T_ROB1", "RobotData", "SelectAction");
            ArrayData pp = (ArrayData)crd_SelectAction.Value;

            switch (((Bool)pp[cPint - 1, 0]).ToString())
            {
            case "False":
                btn_cy1.BackColor = Color.Gainsboro;
                break;

            case "True":
                btn_cy1.BackColor = Color.Red;
                break;

            default:
                btn_cy1.BackColor = Color.Gainsboro;
                break;
            }
            switch (((Bool)pp[cPint - 1, 1]).ToString())
            {
            case "False":
                btn_cy2.BackColor = Color.Gainsboro;
                break;

            case "True":
                btn_cy2.BackColor = Color.Red;
                break;

            default:
                btn_cy2.BackColor = Color.Gainsboro;
                break;
            }
            switch (((Bool)pp[cPint - 1, 2]).ToString())
            {
            case "False":
                btn_cy3.BackColor = Color.Gainsboro;
                break;

            case "True":
                btn_cy3.BackColor = Color.Red;
                break;

            default:
                btn_cy3.BackColor = Color.Gainsboro;
                break;
            }
        }
Exemplo n.º 24
0
        private static void AddArrayMetadata(Type type)
        {
            if (ArrayData.ContainsKey(type))
            {
                return;
            }

            ArrayMetadata data = new ArrayMetadata();

            data.IsArray = type.IsArray;

            if (type.GetInterface("System.Collections.IList") != null)
            {
                data.IsList = true;
            }

            foreach (PropertyInfo p_info in type.GetProperties())
            {
                if (p_info.Name != "Item")
                {
                    continue;
                }

                ParameterInfo[] parameters = p_info.GetIndexParameters();

                if (parameters.Length != 1)
                {
                    continue;
                }

                if (parameters[0].ParameterType == typeof(int))
                {
                    data.ElementType = p_info.PropertyType;
                }
            }

            lock (arrayMetadataLock)
            {
                try
                {
                    ArrayData.Add(type, data);
                }
                catch (ArgumentException)
                {
                    return;
                }
            }
        }
Exemplo n.º 25
0
        ComplexData?GetStructure(BlobDataInfo info, HexPosition position)
        {
            var pos         = info.Span.Start;
            var lengthStart = pos;
            var len         = ReadCompressedUInt32(ref pos) ?? -1;

            if (len < 0)
            {
                return(null);
            }
            if (pos + len > Span.Span.End)
            {
                return(null);
            }
            var lengthSpan = HexSpan.FromBounds(lengthStart, pos);
            var dataSpan   = new HexSpan(lengthSpan.End, (ulong)len);
            var fullSpan   = HexSpan.FromBounds(lengthSpan.Start, dataSpan.End);

            if (!fullSpan.Contains(position))
            {
                return(null);
            }

            switch (info.Kind)
            {
            case BlobDataKind.None:
            case BlobDataKind.TypeSignature:
            case BlobDataKind.Signature:
            case BlobDataKind.Constant:
            case BlobDataKind.CustomAttribute:
            case BlobDataKind.NativeType:
            case BlobDataKind.PermissionSet:
            case BlobDataKind.PublicKey:
            case BlobDataKind.PublicKeyOrToken:
            case BlobDataKind.HashValue:
            case BlobDataKind.Utf8Name:
            case BlobDataKind.Name:
            case BlobDataKind.SequencePoints:
            case BlobDataKind.LocalConstantSig:
            case BlobDataKind.Imports:
            case BlobDataKind.CustomDebugInformationValue:
                var varray = ArrayData.CreateVirtualByteArray(new HexBufferSpan(Span.Buffer, dataSpan));
                return(new BlobHeapRecordData(Span.Buffer, fullSpan, lengthSpan, varray, info.Tokens, this));

            default:
                throw new InvalidOperationException();
            }
        }
Exemplo n.º 26
0
            public TArray Build(MemoryAllocator allocator = default)
            {
                var bufs = new[]
                {
                    NullCount > 0 ? ValidityBuffer.Build(allocator) : ArrowBuffer.Empty,
                    ValueBuffer.Build(ByteWidth, allocator),
                };
                var data = new ArrayData(
                    DataType,
                    Length,
                    NullCount,
                    0,
                    bufs);

                return(Build(data));
            }
Exemplo n.º 27
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="resourceProvider">Owner</param>
        /// <param name="resourceInfo">Resource info</param>
        /// <param name="span">Span</param>
        /// <param name="lengthPosition">Position of 32-bit content length which immediately follows the 7-bit encoded type code</param>
        public MultiResourceArrayDataHeaderData(DotNetMultiFileResources resourceProvider, MultiResourceInfo resourceInfo, HexBufferSpan span, HexPosition lengthPosition)
            : base(resourceProvider, resourceInfo, span)
        {
            var typeCodeSpan = new HexBufferSpan(span.Buffer, HexSpan.FromBounds(span.Start, lengthPosition));

            TypeCode      = new StructField <ResourceTypeCodeData>("TypeCode", ResourceTypeCodeData.Create(typeCodeSpan));
            ContentLength = new StructField <UInt32Data>("ContentLength", new UInt32Data(span.Buffer, lengthPosition));
            var arraySpan = new HexBufferSpan(span.Buffer, HexSpan.FromBounds(lengthPosition + 4, span.End));

            Content = new StructField <VirtualArrayData <ByteData> >("Content", ArrayData.CreateVirtualByteArray(arraySpan));
            Fields  = new BufferField[] {
                TypeCode,
                ContentLength,
                Content,
            };
        }
Exemplo n.º 28
0
        PeDosHeaderDataImpl(HexBufferSpan span)
            : base(span)
        {
            var buffer = span.Buffer;
            var pos    = span.Start.Position;

            Magic    = new StructField <UInt16Data>("e_magic", new UInt16Data(buffer, pos + 0));
            Cblp     = new StructField <UInt16Data>("e_cblp", new UInt16Data(buffer, pos + 2));
            Cp       = new StructField <UInt16Data>("e_cp", new UInt16Data(buffer, pos + 4));
            Crlc     = new StructField <UInt16Data>("e_crlc", new UInt16Data(buffer, pos + 6));
            Cparhdr  = new StructField <UInt16Data>("e_cparhdr", new UInt16Data(buffer, pos + 8));
            Minalloc = new StructField <UInt16Data>("e_minalloc", new UInt16Data(buffer, pos + 0x0A));
            Maxalloc = new StructField <UInt16Data>("e_maxalloc", new UInt16Data(buffer, pos + 0x0C));
            Ss       = new StructField <UInt16Data>("e_ss", new UInt16Data(buffer, pos + 0x0E));
            Sp       = new StructField <UInt16Data>("e_sp", new UInt16Data(buffer, pos + 0x10));
            Csum     = new StructField <UInt16Data>("e_csum", new UInt16Data(buffer, pos + 0x12));
            Ip       = new StructField <UInt16Data>("e_ip", new UInt16Data(buffer, pos + 0x14));
            Cs       = new StructField <UInt16Data>("e_cs", new UInt16Data(buffer, pos + 0x16));
            Lfarlc   = new StructField <UInt16Data>("e_lfarlc", new UInt16Data(buffer, pos + 0x18));
            Ovno     = new StructField <UInt16Data>("e_ovno", new UInt16Data(buffer, pos + 0x1A));
            Res      = new StructField <ArrayData <UInt16Data> >("e_res", ArrayData.CreateUInt16Array(buffer, pos + 0x1C, 4));
            Oemid    = new StructField <UInt16Data>("e_oemid", new UInt16Data(buffer, pos + 0x24));
            Oeminfo  = new StructField <UInt16Data>("e_oeminfo", new UInt16Data(buffer, pos + 0x26));
            Res2     = new StructField <ArrayData <UInt16Data> >("e_res2", ArrayData.CreateUInt16Array(buffer, pos + 0x28, 10));
            Lfanew   = new StructField <FileOffsetData>("e_lfanew", new FileOffsetData(buffer, pos + 0x3C));
            Fields   = new StructField[] {
                Magic,
                Cblp,
                Cp,
                Crlc,
                Cparhdr,
                Minalloc,
                Maxalloc,
                Ss,
                Sp,
                Csum,
                Ip,
                Cs,
                Lfarlc,
                Ovno,
                Res,
                Oemid,
                Oeminfo,
                Res2,
                Lfanew,
            };
        }
Exemplo n.º 29
0
        public void CannotTamperWithData()
        {
            var originalData  = Encoding.UTF8.GetBytes("Hallo!");
            var encryptedData = new List <byte>();
            var decryptedData = new List <byte>();

            IDataSource      myDataSource      = new ArrayData(originalData);
            IDataDestination myDataDestination = new ListData(encryptedData);

            _cryptor.Encrypt(myDataSource, myDataDestination);

            encryptedData[10] = 0x55;

            myDataSource      = new ArrayData(encryptedData.ToArray());
            myDataDestination = new ListData(decryptedData);
            _cryptor.Decrypt(myDataSource, myDataDestination);
        }
Exemplo n.º 30
0
        public FatMethodBodyImpl(DotNetMethodProvider methodProvider, HexBufferSpan span, ReadOnlyCollection <uint> tokens, HexSpan instructionsSpan, HexSpan ehSpan, bool fatEH)
            : base(methodProvider, span, tokens)
        {
            var buffer = span.Buffer;
            var pos    = span.Start.Position;

            Flags_Size     = new StructField <UInt16FlagsData>("Flags", new UInt16FlagsData(buffer, pos, fatHeaderFlagsFlagInfos));
            MaxStack       = new StructField <UInt16Data>("MaxStack", new UInt16Data(buffer, pos + 2));
            CodeSize       = new StructField <UInt32Data>("CodeSize", new UInt32Data(buffer, pos + 4));
            LocalVarSigTok = new StructField <TokenData>("LocalVarSigTok", new TokenData(buffer, pos + 8));
            Instructions   = new StructField <VirtualArrayData <ByteData> >(TinyMethodBodyImpl.InstructionsFieldName, ArrayData.CreateVirtualByteArray(new HexBufferSpan(span.Buffer, instructionsSpan), TinyMethodBodyImpl.InstructionsFieldName));
            if (!ehSpan.IsEmpty)
            {
                ExceptionHandlerTable ehTable;
                if (fatEH)
                {
                    ehTable = new FatExceptionHandlerTableImpl(new HexBufferSpan(buffer, ehSpan));
                }
                else
                {
                    ehTable = new SmallExceptionHandlerTableImpl(new HexBufferSpan(buffer, ehSpan));
                }
                EHTable = new StructField <ExceptionHandlerTable>("EHTable", ehTable);

                var paddingSpan = HexBufferSpan.FromBounds(Instructions.Data.Span.End, EHTable.Data.Span.Start);
                Padding = new StructField <VirtualArrayData <ByteData> >("Padding", ArrayData.CreateVirtualByteArray(paddingSpan));
            }
            var fields = new List <BufferField>(7)
            {
                Flags_Size,
                MaxStack,
                CodeSize,
                LocalVarSigTok,
                Instructions,
            };

            if (Padding is not null)
            {
                fields.Add(Padding);
            }
            if (EHTable is not null)
            {
                fields.Add(EHTable);
            }
            Fields = fields.ToArray();
        }
Exemplo n.º 31
0
 // TODO use glinterleavedarrays possibly
 void CSTrix(ArrayData flags, out int stride, out int ver, out int col, out int tex)
 {
     stride = 0;
     ver    = col = tex = -1;
     if ((flags & ArrayData.Vertex) != 0)
     {
         ver = stride; stride += 2;
     }
     if ((flags & ArrayData.Color) != 0)
     {
         col = stride; stride += 4;
     }
     if ((flags & ArrayData.Texture) != 0)
     {
         tex = stride; stride += 2;
     }
 }
Exemplo n.º 32
0
        public void SimpleArrayTest()
        {
            var cut = new XmlFormatter <ArrayData>();

            var data = new ArrayData
            {
                Names = new[] { "Alice", "Bob", "Charles" }
            };

            cut.Serialize(data, Filename);
            var read = cut.Deserialize(Filename);

            Assert.AreEqual(data.Names.Length, read.Names.Length);
            for (int i = 0; i < data.Names.Length; i++)
            {
                Assert.AreEqual(data.Names[i], read.Names[i], $"Names[{i}]");
            }
        }
Exemplo n.º 33
0
 private static ArrayData CreateData(char typecode) {
     ArrayData data;
     switch (typecode) {
         case 'c': data = new ArrayData<char>(); break;
         case 'b': data = new ArrayData<sbyte>(); break;
         case 'B': data = new ArrayData<byte>(); break;
         case 'u': data = new ArrayData<char>(); break;
         case 'h': data = new ArrayData<short>(); break;
         case 'H': data = new ArrayData<ushort>(); break;
         case 'l':
         case 'i': data = new ArrayData<int>(); break;
         case 'L':
         case 'I': data = new ArrayData<uint>(); break;
         case 'f': data = new ArrayData<float>(); break;
         case 'd': data = new ArrayData<double>(); break;
         default:
             throw PythonOps.ValueError("Bad type code (expected one of 'c', 'b', 'B', 'u', 'H', 'h', 'i', 'I', 'l', 'L', 'f', 'd')");
     }
     return data;
 }
Exemplo n.º 34
0
            private void SliceNoStep(object value, int start, int stop) {
                // replace between start & stop w/ values
                IEnumerator ie = PythonOps.GetEnumerator(value);
                int length = _data.Length;

                ArrayData newData = CreateData(_typeCode);
                for (int i = 0; i < start; i++) {
                    newData.Append(_data.GetData(i));
                }

                while (ie.MoveNext()) {
                    newData.Append(ie.Current);
                }

                for (int i = Math.Max(stop, start); i < _data.Length; i++) {
                    newData.Append(_data.GetData(i));
                }

                _data = newData;
            }
Exemplo n.º 35
0
 internal void Clear() {
     _data = CreateData(_typeCode);
 }
Exemplo n.º 36
0
            public object this[Slice index] {
                get {
                    if (index == null) throw PythonOps.TypeError("expected Slice, got None");

                    int start, stop, step;
                    index.indices(_data.Length, out start, out stop, out step);

                    PythonArray pa = new PythonArray(new string(_typeCode, 1), Type.Missing);
                    if (step < 0) {
                        for (int i = start; i > stop; i += step) {
                            pa._data.Append(_data.GetData(i));
                        }
                    } else {
                        for (int i = start; i < stop; i += step) {
                            pa._data.Append(_data.GetData(i));
                        }
                    }
                    return pa;
                }
                set {
                    if (index == null) throw PythonOps.TypeError("expected Slice, got None");

                    PythonArray pa = value as PythonArray;
                    if (pa != null && pa._typeCode != _typeCode) {
                        throw PythonOps.TypeError("bad array type");
                    }

                    if (index.step != null) {
                        if (Object.ReferenceEquals(value, this)) value = this.tolist();

                        index.DoSliceAssign(SliceAssign, _data.Length, value);
                    } else {
                        int start, stop, step;
                        index.indices(_data.Length, out start, out stop, out step);
                        if (stop < start) {
                            stop = start;
                        }

                        // replace between start & stop w/ values
                        IEnumerator ie = PythonOps.GetEnumerator(value);

                        ArrayData newData = CreateData(_typeCode);
                        for (int i = 0; i < start; i++) {
                            newData.Append(_data.GetData(i));
                        }

                        while (ie.MoveNext()) {
                            newData.Append(ie.Current);
                        }

                        for (int i = stop; i < _data.Length; i++) {
                            newData.Append(_data.GetData(i));
                        }

                        _data = newData;
                    }
                }
            }