Beispiel #1
0
 public MarshalInfo(UnmanagedMarshal marshal)
 {
     UnmanagedType = marshal.GetUnmanagedType;
     ArraySubType  = marshal.BaseType;
     SizeConst     = marshal.ElementCount;
     IidGuid       = marshal.IIDGuid;
 }
        public override void ApplyAttributeBuilder(Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
        {
#if false
            if (a.Type == pa.MarshalAs)
            {
                UnmanagedMarshal marshal = a.GetMarshal(this);
                if (marshal != null)
                {
                    builder.SetMarshal(marshal);
                }
                return;
            }
#endif
            if (a.HasSecurityAttribute)
            {
                a.Error_InvalidSecurityParent();
                return;
            }

            if (a.Type == pa.Dynamic)
            {
                a.Error_MisusedDynamicAttribute();
                return;
            }

            builder.SetCustomAttribute((ConstructorInfo)ctor.GetMetaInfo(), cdata);
        }
Beispiel #3
0
        public void TestSetMarshalComplete()
        {
            FieldBuilder field = _tb.DefineField("name",
                                                 typeof(string), FieldAttributes.Public);

            _tb.CreateType();
            field.SetMarshal(UnmanagedMarshal.DefineSafeArray(UnmanagedType.BStr));
        }
Beispiel #4
0
    public static void Main()
    {
        // Create a dynamic assembly and module to contain the
        // subclass of MulticastDelegate that we will create

        AssemblyName asmName = new AssemblyName();

        asmName.Name = "DynamicAssembly";

        AssemblyBuilder asmBuilder =
            AppDomain.CurrentDomain.DefineDynamicAssembly(
                asmName, AssemblyBuilderAccess.Run);

        ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule
                                       ("DynamicModule");

        TypeBuilder typeBuilder = modBuilder.DefineType("MyType",
                                                        TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.Sealed,
                                                        typeof(System.MulticastDelegate));

        ConstructorBuilder cb = typeBuilder.DefineConstructor(
            MethodAttributes.Public | MethodAttributes.HideBySig |
            MethodAttributes.RTSpecialName | MethodAttributes.SpecialName,
            CallingConventions.Standard,
            new Type[] { typeof(Object), typeof(IntPtr) });

        cb.SetImplementationFlags(MethodImplAttributes.Runtime |
                                  MethodImplAttributes.Managed);

        MethodBuilder mb = typeBuilder.DefineMethod(
            "Invoke",
            MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.
            HideBySig,
            typeof(void),
            new Type[] { typeof(int) });

        mb.SetImplementationFlags(MethodImplAttributes.Runtime |
                                  MethodImplAttributes.Managed);
        ParameterBuilder pb = mb.DefineParameter(1, ParameterAttributes.HasFieldMarshal, "foo");

        pb.SetMarshal(UnmanagedMarshal.DefineUnmanagedMarshal(UnmanagedType.I2));

        // Create an instance of the delegate type and invoke it -- just to test

        Type     myDelegateType = typeBuilder.CreateType();
        Delegate d = Delegate.CreateDelegate(myDelegateType, typeof
                                             (Testing), "Method");

        d.DynamicInvoke(new object[] { 8 });

        DelegateList delegateList = new DelegateList();

        delegateList.del = d;
        IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(delegateList));

        // The execption seems to occur at this statement:
        Marshal.StructureToPtr(delegateList, ptr, false);
    }
Beispiel #5
0
 /* to build a ParameterInfo for the return type of a method */
 internal ParameterInfo(Type type, MemberInfo member, UnmanagedMarshal marshalAs)
 {
     this.ClassImpl    = type;
     this.MemberImpl   = member;
     this.NameImpl     = "";
     this.PositionImpl = -1;             // since parameter positions are zero-based, return type pos is -1
     this.AttrsImpl    = ParameterAttributes.Retval;
     this.marshalAs    = marshalAs;
 }
Beispiel #6
0
 internal ParameterInfo(Type type, MemberInfo member, UnmanagedMarshal marshalAs)
 {
     this.ClassImpl    = type;
     this.MemberImpl   = member;
     this.NameImpl     = string.Empty;
     this.PositionImpl = -1;
     this.AttrsImpl    = ParameterAttributes.Retval;
     this.marshalAs    = marshalAs;
 }
    public static Type CreateType(AppDomain currentDomain)
    {
        // Create an assembly.
        AssemblyName myAssemblyName = new AssemblyName();

        myAssemblyName.Name = "DynamicAssembly";
        AssemblyBuilder myAssembly =
            currentDomain.DefineDynamicAssembly(myAssemblyName, AssemblyBuilderAccess.RunAndSave);
        // Create a dynamic module in Dynamic Assembly.
        ModuleBuilder myModuleBuilder = myAssembly.DefineDynamicModule("MyModule", "MyModule.mod");
        // Define a public class named "MyClass" in the assembly.
        TypeBuilder myTypeBuilder  = myModuleBuilder.DefineType("MyClass", TypeAttributes.Public);
        TypeBuilder myTypeBuilder2 = myModuleBuilder.DefineType("MyClass2",
                                                                TypeAttributes.Public | TypeAttributes.BeforeFieldInit | TypeAttributes.SequentialLayout | TypeAttributes.AnsiClass | TypeAttributes.Sealed);
        FieldBuilder myFieldBuilder1 = myTypeBuilder2.DefineField("myBytes1",
                                                                  typeof(byte), FieldAttributes.Public);
        FieldBuilder myFieldBuilder2 = myTypeBuilder2.DefineField("myBytes2",
                                                                  typeof(byte), FieldAttributes.Public);
        FieldBuilder myFieldBuilder3 = myTypeBuilder2.DefineField("myErrorCode",
                                                                  typeof(short), FieldAttributes.Public);
        FieldBuilder myFieldBuilder4 = myTypeBuilder2.DefineField("myReserved1",
                                                                  typeof(short), FieldAttributes.Public);
        FieldBuilder myFieldBuilder5 = myTypeBuilder2.DefineField("myReserved2",
                                                                  typeof(short), FieldAttributes.Public);
        FieldBuilder myFieldBuilder6 = myTypeBuilder2.DefineField("myPathName",
                                                                  typeof(char[]), FieldAttributes.Public);

        myFieldBuilder6.SetMarshal(UnmanagedMarshal.DefineByValArray(128));
        myFieldBuilder6.SetOffset(4);
        Type myType1 = myTypeBuilder2.CreateType();

        // Create the PInvoke method for 'OpenFile' method of 'Kernel32.dll'.
        Type[]        myParameters    = { typeof(string), myType1, typeof(uint) };
        MethodBuilder myMethodBuilder = myTypeBuilder.DefinePInvokeMethod("OpenFile",
                                                                          "kernel32.dll", MethodAttributes.Public | MethodAttributes.Static | MethodAttributes.HideBySig,
                                                                          CallingConventions.Standard, typeof(IntPtr),
                                                                          myParameters, CallingConvention.Winapi, CharSet.None);
        Type            myAttributeType   = typeof(MethodImplAttribute);
        ConstructorInfo myConstructorInfo =
            myAttributeType.GetConstructor(new Type[1] {
            typeof(MethodImplOptions)
        });
        CustomAttributeBuilder myAttributeBuilder = new CustomAttributeBuilder(myConstructorInfo,
                                                                               new object[1] {
            MethodImplOptions.PreserveSig
        });

        myMethodBuilder.SetCustomAttribute(myAttributeBuilder);
        ParameterBuilder myParameterBuilder2 = myMethodBuilder.DefineParameter(2,
                                                                               ParameterAttributes.Out, "myClass2");
        Type myType = myTypeBuilder.CreateType();

        myAssembly.Save("EmittedAssembly.dll");
        return(myType);
    }
Beispiel #8
0
        public override void ApplyAttributeBuilder(Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
        {
            if (a.Type == pa.FieldOffset)
            {
                status |= Status.HAS_OFFSET;

                if (!Parent.PartialContainer.HasExplicitLayout)
                {
                    Report.Error(636, Location, "The FieldOffset attribute can only be placed on members of types marked with the StructLayout(LayoutKind.Explicit)");
                    return;
                }

                if ((ModFlags & Modifiers.STATIC) != 0 || this is Const)
                {
                    Report.Error(637, Location, "The FieldOffset attribute is not allowed on static or const fields");
                    return;
                }
            }

            if (a.Type == pa.FixedBuffer)
            {
                Report.Error(1716, Location, "Do not use 'System.Runtime.CompilerServices.FixedBuffer' attribute. Use the 'fixed' field modifier instead");
                return;
            }

#if false
            if (a.Type == pa.MarshalAs)
            {
                UnmanagedMarshal marshal = a.GetMarshal(this);
                if (marshal != null)
                {
                    FieldBuilder.SetMarshal(marshal);
                }
                return;
            }
#endif
            if ((a.HasSecurityAttribute))
            {
                a.Error_InvalidSecurityParent();
                return;
            }

            if (a.Type == pa.Dynamic)
            {
                a.Error_MisusedDynamicAttribute();
                return;
            }

            FieldBuilder.SetCustomAttribute((ConstructorInfo)ctor.GetMetaInfo(), cdata);
        }
Beispiel #9
0
        internal object[] GetPseudoCustomAttributes()
        {
            int count = 0;

            if (IsNotSerialized)
            {
                count++;
            }

            if (DeclaringType.IsExplicitLayout)
            {
                count++;
            }
#if !MICRO_LIB
            UnmanagedMarshal marshalAs = UMarshal;
            if (marshalAs != null)
            {
                count++;
            }
#endif
            if (count == 0)
            {
                return(null);
            }
            object[] attrs = new object [count];
            count = 0;

            if (IsNotSerialized)
            {
                attrs [count++] = new NonSerializedAttribute();
            }
            if (DeclaringType.IsExplicitLayout)
            {
                attrs [count++] = new FieldOffsetAttribute(GetFieldOffset());
            }
#if !MICRO_LIB
            if (marshalAs != null)
            {
                attrs [count++] = marshalAs.ToMarshalAsAttribute();
            }
#endif
            return(attrs);
        }
Beispiel #10
0
    public static void ContainerMethod(TypeBuilder myDynamicType)
    {
        // <Snippet1>

        MethodBuilder myMethod = myDynamicType.DefineMethod("MyMethodReturnsMarshal",
                                                            MethodAttributes.Public,
                                                            typeof(uint),
                                                            new Type[] { typeof(string) });

        // We want the return value of our dynamic method to be marshalled as
        // an 64-bit (8-byte) signed integer, instead of the default 32-bit
        // unsigned int as specified above. The UnmanagedMarshal class can perform
        // the type conversion.

        UnmanagedMarshal marshalMeAsI8 = UnmanagedMarshal.DefineUnmanagedMarshal(
            System.Runtime.InteropServices.UnmanagedType.I8);

        myMethod.SetMarshal(marshalMeAsI8);

        // </Snippet1>
    }
Beispiel #11
0
        public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb, PredefinedAttributes pa)
        {
#if !NET_2_0
            if (a.Type == pa.MarshalAs)
            {
                UnmanagedMarshal marshal = a.GetMarshal(this);
                if (marshal != null)
                {
                    builder.SetMarshal(marshal);
                }
                return;
            }
#endif
            if (a.HasSecurityAttribute)
            {
                a.Error_InvalidSecurityParent();
                return;
            }

            builder.SetCustomAttribute(cb);
        }
        internal object[] GetPseudoCustomAttributes()
        {
            int num = 0;

            if (this.IsNotSerialized)
            {
                num++;
            }
            if (this.DeclaringType.IsExplicitLayout)
            {
                num++;
            }
            UnmanagedMarshal umarshal = this.UMarshal;

            if (umarshal != null)
            {
                num++;
            }
            if (num == 0)
            {
                return(null);
            }
            object[] array = new object[num];
            num = 0;
            if (this.IsNotSerialized)
            {
                array[num++] = new NonSerializedAttribute();
            }
            if (this.DeclaringType.IsExplicitLayout)
            {
                array[num++] = new FieldOffsetAttribute(this.GetFieldOffset());
            }
            if (umarshal != null)
            {
                array[num++] = umarshal.ToMarshalAsAttribute();
            }
            return(array);
        }
        private Assembly ProcessStructureAssembly(string structureName)
        {
            string location       = _cacheLocation + structureName + ".dll";
            string upperVersion   = structureName.ToUpper();
            string lowerVersion   = structureName.ToLower();
            string profileVersion = "_" + upperVersion;

            if (_structureDictionary.ContainsKey(structureName))
            {
                return(_structureDictionary[structureName]);
            }
            FileInfo fiCheck = new FileInfo(location);

            if (fiCheck.Exists)
            {
                var dll = Assembly.LoadFile(location);
                if (dll != null)
                {
                    _structureDictionary.Add(structureName, dll);
                    return(dll);
                }
                return(null);
            }
            AppDomain       myDomain        = AppDomain.CurrentDomain;
            AssemblyName    assemblyName    = new AssemblyName(structureName + "Assembly");
            AssemblyBuilder assemblyBuilder = myDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save);
            ModuleBuilder   moduleBuilder   = assemblyBuilder.DefineDynamicModule(structureName + "Module", structureName + ".dll");
            TypeBuilder     typeBuilder     = moduleBuilder.DefineType("liveforensics." + upperVersion, TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.ExplicitLayout | TypeAttributes.BeforeFieldInit | TypeAttributes.AnsiClass, typeof(ValueType), PackingSize.Size1);
            List <Tuple <int, string, string, int> > entryList = new List <Tuple <int, string, string, int> >();
            FileInfo fi = new FileInfo(_profileRoot + @"v1.0\nt\GUID\" + _requestedImage);

            if (fi.Exists)
            {
                try
                {
                    byte[] json = null;
                    using (FileStream original = fi.OpenRead())
                    {
                        using (GZipStream gzStream = new GZipStream(original, CompressionMode.Decompress))
                        {
                            MemoryStream final = new MemoryStream();
                            gzStream.CopyTo(final);
                            long len = final.Length;
                            json = final.ToArray();
                        }
                    }
                    string theJson    = Encoding.UTF8.GetString(json);
                    var    parsedJson = JObject.Parse(theJson);
                    foreach (dynamic item in parsedJson["$STRUCTS"][profileVersion][1])
                    {
                        string name = item.Name;
                        var    val  = item.Value;
                        int    w    = (int)val[0];
                        var    v    = val[1];
                        string a    = v[0].ToString();
                        int    size = (int)GetEntrySize(a);
                        if (a == "Array")
                        {
                            int    arraySize = 0;
                            string arrayType = "";
                            foreach (KeyValuePair <string, JToken> k in (JObject)v[1])
                            {
                                if (k.Key == "target")
                                {
                                    arrayType = k.Value.ToString();
                                }
                                if (k.Key == "count")
                                {
                                    arraySize = (int)k.Value;
                                }
                            }
                            size = (int)GetEntrySize(arrayType) * arraySize;
                        }
                        else if (a == "BitField")
                        {
                            foreach (KeyValuePair <string, JToken> k in (JObject)v[1])
                            {
                                if (k.Key == "target")
                                {
                                    size = (int)GetEntrySize(k.Value.ToString());
                                }
                            }
                        }
                        entryList.Add(new Tuple <int, string, string, int>(w, name, a, size));
                    }
                    entryList.Sort();
                    FieldBuilder field = null;
                    foreach (var entry in entryList)
                    {
                        if (GetEntryType(entry.Item3) != null)
                        {
                            field = typeBuilder.DefineField(entry.Item2, GetEntryType(entry.Item3), FieldAttributes.Public);
                            field.SetOffset(entry.Item1);
                        }
                        else if (entry.Item4 == 1)
                        {
                            field = typeBuilder.DefineField(entry.Item2, typeof(byte), FieldAttributes.Public);
                            field.SetOffset(entry.Item1);
                        }
                        else if (entry.Item4 == 2)
                        {
                            field = typeBuilder.DefineField(entry.Item2, typeof(UInt16), FieldAttributes.Public);
                            field.SetOffset(entry.Item1);
                        }
                        else if (entry.Item4 == 4)
                        {
                            field = typeBuilder.DefineField(entry.Item2, typeof(UInt32), FieldAttributes.Public);
                            field.SetOffset(entry.Item1);
                        }
                        else if (entry.Item4 == 8)
                        {
                            field = typeBuilder.DefineField(entry.Item2, typeof(UInt64), FieldAttributes.Public);
                            field.SetOffset(entry.Item1);
                        }
                        else
                        {
                            field = typeBuilder.DefineField(entry.Item2, typeof(byte[]), FieldAttributes.Public);
                            field.SetMarshal(UnmanagedMarshal.DefineByValArray(entry.Item4));
                            field.SetOffset(entry.Item1);
                        }
                    }
                    Type ptType = typeBuilder.CreateType();
                    assemblyBuilder.Save(structureName + ".dll");
                    FileInfo fiMove = new FileInfo(Environment.CurrentDirectory + "\\" + structureName + ".dll");
                    if (fiMove.Exists)
                    {
                        fiMove.MoveTo(location);
                    }
                    var dll = Assembly.LoadFile(location);
                    if (dll != null)
                    {
                        _structureDictionary.Add(structureName, dll);
                        return(dll);
                    }
                    return(null);
                }
                catch (Exception ex)
                {
                    throw new ArgumentException("Error: " + ex.Message);
                }
            }
            return(null);
        }
Beispiel #14
0
        public Assembly ProcessStructureAssembly(string structureName)
        {
            string noUnderscoreVersion = structureName;

            if (noUnderscoreVersion.StartsWith("_"))
            {
                noUnderscoreVersion = noUnderscoreVersion.TrimStart(new char[] { '_' });
            }
            string location = _cacheLocation + noUnderscoreVersion + ".dll";

            //string upperVersion = structureName.ToUpper();
            //string lowerVersion = structureName.ToLower();
            //string profileVersion = "_" + upperVersion;
            if (_structureDictionary.ContainsKey(structureName))
            {
                return(_structureDictionary[structureName]);
            }
            FileInfo fiCheck = new FileInfo(location);

            if (fiCheck.Exists)
            {
                var dll = Assembly.LoadFile(location);
                if (dll != null)
                {
                    _structureDictionary.Add(structureName, dll);
                    return(dll);
                }
                return(null);
            }
            AppDomain       myDomain        = AppDomain.CurrentDomain;
            AssemblyName    assemblyName    = new AssemblyName(noUnderscoreVersion + "Assembly");
            AssemblyBuilder assemblyBuilder = myDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save);
            ModuleBuilder   moduleBuilder   = assemblyBuilder.DefineDynamicModule(noUnderscoreVersion + "Module", noUnderscoreVersion + ".dll");
            TypeBuilder     typeBuilder     = moduleBuilder.DefineType("liveforensics." + noUnderscoreVersion, TypeAttributes.Public /*| TypeAttributes.Sealed*/ | TypeAttributes.ExplicitLayout /*| TypeAttributes.BeforeFieldInit*/ | TypeAttributes.AnsiClass, typeof(ValueType), PackingSize.Size1);
            List <Tuple <int, string, string, int, bool> > entryList = new List <Tuple <int, string, string, int, bool> >();
            FileInfo fi = new FileInfo(_profileRoot + @"v1.0\nt\GUID\" + _requestedImage);

            if (fi.Exists)
            {
                try
                {
                    Debug.WriteLine("PROCESSING: " + structureName);
                    byte[] json = null;
                    using (FileStream original = fi.OpenRead())
                    {
                        using (GZipStream gzStream = new GZipStream(original, CompressionMode.Decompress))
                        {
                            MemoryStream final = new MemoryStream();
                            gzStream.CopyTo(final);
                            long len = final.Length;
                            json = final.ToArray();
                        }
                    }
                    string        theJson       = Encoding.UTF8.GetString(json);
                    var           parsedJson    = JObject.Parse(theJson);
                    HashSet <int> unmanagedList = new HashSet <int>();
                    foreach (dynamic item in parsedJson["$STRUCTS"][structureName][1])
                    {
                        string name        = item.Name;
                        var    val         = item.Value;
                        int    fieldOffset = (int)val[0];
                        var    v           = val[1];
                        string fieldType   = v[0].ToString();
                        int    size        = (int)GetEntrySize(fieldType);
                        if (fieldType == "Array")
                        {
                            int    arraySize = 0;
                            string arrayType = "";
                            foreach (KeyValuePair <string, JToken> k in (JObject)v[1])
                            {
                                if (k.Key == "target")
                                {
                                    arrayType = k.Value.ToString();
                                }
                                if (k.Key == "count")
                                {
                                    arraySize = (int)k.Value;
                                }
                            }
                            size = (int)GetEntrySize(arrayType) * arraySize;
                        }
                        else if (fieldType == "BitField")
                        {
                            foreach (KeyValuePair <string, JToken> k in (JObject)v[1])
                            {
                                if (k.Key == "target")
                                {
                                    size = (int)GetEntrySize(k.Value.ToString());
                                }
                            }
                        }
                        else if (fieldType == "UnicodeString")
                        {
                            foreach (KeyValuePair <string, JToken> k in (JObject)v[1])
                            {
                                if (k.Key == "length")
                                {
                                    size = ((int)k.Value) * 2;
                                }
                            }
                        }
                        if (GetEntryType(fieldType) != null || size == 1 || size == 2 || size == 4 | size == 8)
                        {
                            entryList.Add(new Tuple <int, string, string, int, bool>(fieldOffset, name, fieldType, size, false));
                        }
                        else
                        {
                            entryList.Add(new Tuple <int, string, string, int, bool>(fieldOffset, name, fieldType, size, true));
                            unmanagedList.Add(fieldOffset);
                        }
                    }
                    entryList.Sort();

                    FieldBuilder field = null;

                    foreach (var entry in entryList)
                    {
                        if (!entry.Item5 && unmanagedList.Contains(entry.Item1))
                        {
                            Debug.WriteLine("Entry: " + entry + " <-- REMOVED");
                            continue;
                        }
                        Debug.WriteLine("Entry: " + entry);
                        if (GetEntryType(entry.Item3) != null)
                        {
                            field = typeBuilder.DefineField(entry.Item2, GetEntryType(entry.Item3), FieldAttributes.Public);
                            field.SetOffset(entry.Item1);
                            Debug.WriteLine("[FieldOffset(" + entry.Item1 + ")]");
                            Debug.WriteLine("public " + GetEntryType(entry.Item3).ToString() + " " + entry.Item2 + ";");
                        }
                        else if (entry.Item4 == 1)
                        {
                            field = typeBuilder.DefineField(entry.Item2, typeof(byte), FieldAttributes.Public);
                            field.SetOffset(entry.Item1);
                            Debug.WriteLine("[FieldOffset(" + entry.Item1 + ")]");
                            Debug.WriteLine("public byte " + entry.Item2 + ";");
                        }
                        else if (entry.Item4 == 2)
                        {
                            field = typeBuilder.DefineField(entry.Item2, typeof(UInt16), FieldAttributes.Public);
                            field.SetOffset(entry.Item1);
                            Debug.WriteLine("[FieldOffset(" + entry.Item1 + ")]");
                            Debug.WriteLine("public UInt16 " + entry.Item2 + ";");
                        }
                        else if (entry.Item4 == 4)
                        {
                            field = typeBuilder.DefineField(entry.Item2, typeof(UInt32), FieldAttributes.Public);
                            field.SetOffset(entry.Item1);
                            Debug.WriteLine("[FieldOffset(" + entry.Item1 + ")]");
                            Debug.WriteLine("public UInt32 " + entry.Item2 + ";");
                        }
                        else if (entry.Item4 == 8)
                        {
                            field = typeBuilder.DefineField(entry.Item2, typeof(UInt64), FieldAttributes.Public);
                            field.SetOffset(entry.Item1);
                            Debug.WriteLine("[FieldOffset(" + entry.Item1 + ")]");
                            Debug.WriteLine("public UInt64 " + entry.Item2 + ";");
                        }
                        else
                        {
                            field = typeBuilder.DefineField(entry.Item2, typeof(byte[]), FieldAttributes.Public);
                            field.SetMarshal(UnmanagedMarshal.DefineByValArray(entry.Item4));
                            field.SetOffset(entry.Item1);
                            Debug.WriteLine("[FieldOffset(" + entry.Item1 + ")]");
                            Debug.WriteLine("[MarshalAs(UnmanagedType.ByValArray, SizeConst = " + entry.Item4 + ")]");
                            Debug.WriteLine("public byte[] " + entry.Item2 + ";");
                            /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
                        }
                    }
                    Type ptType = typeBuilder.CreateType();
                    assemblyBuilder.Save(noUnderscoreVersion + ".dll");
                    FileInfo fiMove = new FileInfo(Environment.CurrentDirectory + "\\" + noUnderscoreVersion + ".dll");
                    if (fiMove.Exists)
                    {
                        fiMove.MoveTo(location);
                    }
                    var dll = Assembly.LoadFile(location);
                    if (dll != null)
                    {
                        _structureDictionary.Add(structureName, dll);
                        return(dll);
                    }
                    return(null);
                }
                catch (Exception ex)
                {
                    throw new ArgumentException("Error: " + ex.Message);
                }
            }
            return(null);
        }
 public void SetMarshal(UnmanagedMarshal unmanagedMarshal)
 {
 }
	// Methods
	public virtual void SetMarshal(UnmanagedMarshal unmanagedMarshal) {}
	public void SetMarshal(UnmanagedMarshal unmanagedMarshal) {}
 // Methods
 public virtual void SetMarshal(UnmanagedMarshal unmanagedMarshal)
 {
 }
Beispiel #19
0
 public virtual void SetMarshal(UnmanagedMarshal unmanagedMarshal) => throw new PlatformNotSupportedException();