Esempio n. 1
0
        public unsafe void Extractor_StructModel_Test()
        {
            Assemblies.ResolveExecuting();

            StructModel[] structure = new StructModel[] { new StructModel(83948930), new StructModel(45453), new StructModel(5435332) };
            structure[0].Alias = "FirstAlias";
            structure[0].Name  = "FirstName";
            structure[1].Alias = "SecondAlia";
            structure[1].Name  = "SecondName";
            structure[2].Alias = "ThirdAlias";
            structure[2].Name  = "ThirdName";

            StructModels structures = new StructModels(structure);

            int size = Marshal.SizeOf(structure[0]);

            byte *pserial = Extraction.ValueStructureToPointer(structure[0]);

            StructModel structure2 = new StructModel();
            ValueType   o          = structure2;

            o = Extraction.PointerToValueStructure(pserial, o, 0);

            structure2 = (StructModel)o;

            structure2.Alias = "FirstChange";
        }
 /// <summary>
 /// The PointerToStructure.
 /// </summary>
 /// <param name="binary">The binary<see cref="IntPtr"/>.</param>
 /// <param name="structure">The structure<see cref="object"/>.</param>
 /// <returns>The <see cref="object"/>.</returns>
 public unsafe static object PointerToStructure(IntPtr binary, object structure)
 {
     if (structure is ValueType)
     {
         Type t = structure.GetType();
         if (t.IsLayoutSequential)
         {
             return(Extraction.PointerToValueStructure((byte *)(binary.ToPointer()), structure, 0));
         }
         else
         {
             return(PointerToStructure(binary, structure.GetType(), 0));
         }
     }
     else
     {
         Marshal.PtrToStructure(binary, structure);
     }
     return(structure);
 }
 /// <summary>
 /// The PointerToStructure.
 /// </summary>
 /// <param name="binary">The binary<see cref="byte*"/>.</param>
 /// <param name="structure">The structure<see cref="ValueType"/>.</param>
 /// <returns>The <see cref="ValueType"/>.</returns>
 public unsafe static ValueType PointerToStructure(byte *binary, ValueType structure)
 {
     return(Extraction.PointerToValueStructure(binary, structure, 0));
 }