コード例 #1
0
        private CustomAttributeData? GetDllImportAttributeData()
        {
            if ((Attributes & MethodAttributes.PinvokeImpl) == 0)
                return null;

            string entryPoint;
            string? dllName = null;
            PInvokeAttributes flags = 0;

            GetPInvoke(out flags, out entryPoint, out dllName);

            CharSet charSet = (flags & PInvokeAttributes.CharSetMask) switch
            {
                PInvokeAttributes.CharSetNotSpec => CharSet.None,
                PInvokeAttributes.CharSetAnsi => CharSet.Ansi,
                PInvokeAttributes.CharSetUnicode => CharSet.Unicode,
                PInvokeAttributes.CharSetAuto => CharSet.Auto,
                // Invalid: default to CharSet.None
                _ => CharSet.None,
            };

            InteropServicesCallingConvention callingConvention = (flags & PInvokeAttributes.CallConvMask) switch
            {
                PInvokeAttributes.CallConvWinapi => InteropServicesCallingConvention.Winapi,
                PInvokeAttributes.CallConvCdecl => InteropServicesCallingConvention.Cdecl,
                PInvokeAttributes.CallConvStdcall => InteropServicesCallingConvention.StdCall,
                PInvokeAttributes.CallConvThiscall => InteropServicesCallingConvention.ThisCall,
                PInvokeAttributes.CallConvFastcall => InteropServicesCallingConvention.FastCall,
                // Invalid: default to CallingConvention.Cdecl
                _ => InteropServicesCallingConvention.Cdecl,
            };

            bool exactSpelling = (flags & PInvokeAttributes.NoMangle) != 0;
            bool setLastError = (flags & PInvokeAttributes.SupportsLastError) != 0;
            bool bestFitMapping = (flags & PInvokeAttributes.BestFitMask) == PInvokeAttributes.BestFitEnabled;
            bool throwOnUnmappableChar = (flags & PInvokeAttributes.ThrowOnUnmappableCharMask) == PInvokeAttributes.ThrowOnUnmappableCharEnabled;
            bool preserveSig = (GetMethodImplementationFlags() & MethodImplAttributes.PreserveSig) != 0;

            var ctorArgs = new CustomAttributeTypedArgument[] {
                new CustomAttributeTypedArgument (typeof(string), dllName),
            };

            Type attrType = typeof(DllImportAttribute);

            var namedArgs = new CustomAttributeNamedArgument[] {
                new CustomAttributeNamedArgument (attrType.GetField ("EntryPoint")!, entryPoint),
                new CustomAttributeNamedArgument (attrType.GetField ("CharSet")!, charSet),
                new CustomAttributeNamedArgument (attrType.GetField ("ExactSpelling")!, exactSpelling),
                new CustomAttributeNamedArgument (attrType.GetField ("SetLastError")!, setLastError),
                new CustomAttributeNamedArgument (attrType.GetField ("PreserveSig")!, preserveSig),
                new CustomAttributeNamedArgument (attrType.GetField ("CallingConvention")!, callingConvention),
                new CustomAttributeNamedArgument (attrType.GetField ("BestFitMapping")!, bestFitMapping),
                new CustomAttributeNamedArgument (attrType.GetField ("ThrowOnUnmappableChar")!, throwOnUnmappableChar)
            };

            return new CustomAttributeData(
                attrType.GetConstructor(new[] { typeof(string) })!,
                ctorArgs,
                namedArgs);
        }
コード例 #2
0
ファイル: RuntimeMethodInfo.cs プロジェクト: hexuwsbg/runtime
        private Attribute GetDllImportAttribute()
        {
            string            entryPoint, dllName = null;
            int               token = MetadataToken;
            PInvokeAttributes flags = 0;

            GetPInvoke(out flags, out entryPoint, out dllName);

            CharSet charSet = CharSet.None;

            switch (flags & PInvokeAttributes.CharSetMask)
            {
            case PInvokeAttributes.CharSetNotSpec: charSet = CharSet.None; break;

            case PInvokeAttributes.CharSetAnsi: charSet = CharSet.Ansi; break;

            case PInvokeAttributes.CharSetUnicode: charSet = CharSet.Unicode; break;

            case PInvokeAttributes.CharSetAuto: charSet = CharSet.Auto; break;

            // Invalid: default to CharSet.None
            default: break;
            }

            CallingConvention callingConvention = InteropServicesCallingConvention.Cdecl;

            switch (flags & PInvokeAttributes.CallConvMask)
            {
            case PInvokeAttributes.CallConvWinapi: callingConvention = InteropServicesCallingConvention.Winapi; break;

            case PInvokeAttributes.CallConvCdecl: callingConvention = InteropServicesCallingConvention.Cdecl; break;

            case PInvokeAttributes.CallConvStdcall: callingConvention = InteropServicesCallingConvention.StdCall; break;

            case PInvokeAttributes.CallConvThiscall: callingConvention = InteropServicesCallingConvention.ThisCall; break;

            case PInvokeAttributes.CallConvFastcall: callingConvention = InteropServicesCallingConvention.FastCall; break;

            // Invalid: default to CallingConvention.Cdecl
            default: break;
            }

            bool exactSpelling         = (flags & PInvokeAttributes.NoMangle) != 0;
            bool setLastError          = (flags & PInvokeAttributes.SupportsLastError) != 0;
            bool bestFitMapping        = (flags & PInvokeAttributes.BestFitMask) == PInvokeAttributes.BestFitEnabled;
            bool throwOnUnmappableChar = (flags & PInvokeAttributes.ThrowOnUnmappableCharMask) == PInvokeAttributes.ThrowOnUnmappableCharEnabled;
            bool preserveSig           = (GetMethodImplementationFlags() & MethodImplAttributes.PreserveSig) != 0;

            return(new DllImportAttribute(dllName)
            {
                EntryPoint = entryPoint,
                CharSet = charSet,
                SetLastError = setLastError,
                ExactSpelling = exactSpelling,
                PreserveSig = preserveSig,
                BestFitMapping = bestFitMapping,
                ThrowOnUnmappableChar = throwOnUnmappableChar,
                CallingConvention = callingConvention
            });
        }
コード例 #3
0
ファイル: ImplMap.cs プロジェクト: petterlopes/ConfuserEx
        /// <summary>
        /// Set or clear flags in <see cref="attributes"/>
        /// </summary>
        /// <param name="set"><c>true</c> if flags should be set, <c>false</c> if flags should
        /// be cleared</param>
        /// <param name="flags">Flags to set or clear</param>
        private void ModifyAttributes(bool set, PInvokeAttributes flags)
        {
#if THREAD_SAFE
            int origVal, newVal;
            do
            {
                origVal = attributes;
                if (set)
                {
                    newVal = origVal | (int)flags;
                }
                else
                {
                    newVal = origVal & ~(int)flags;
                }
            } while (Interlocked.CompareExchange(ref attributes, newVal, origVal) != origVal);
#else
            if (set)
            {
                attributes |= (int)flags;
            }
            else
            {
                attributes &= ~(int)flags;
            }
#endif
        }
コード例 #4
0
 public unsafe ImplMap(byte *ptr, int moduleRefSize, int memberForwardedTagRefSize, int stringHandleSize)
 {
     MappingFlags    = (PInvokeAttributes)Helpers.GetValue(ptr, 2);
     MemberForwarded = Helpers.FromMemberForwardedTag((uint)Helpers.GetValue(ptr + 2, memberForwardedTagRefSize));
     ImportName      = MetadataTokens.StringHandle(Helpers.GetValue(ptr + 2 + memberForwardedTagRefSize, stringHandleSize));
     ImportScope     = MetadataTokens.ModuleReferenceHandle(Helpers.GetValue(ptr + 2 + memberForwardedTagRefSize + stringHandleSize, moduleRefSize));
 }
コード例 #5
0
 public void Read(ClrModuleReader reader)
 {
     this.MappingFlags    = (PInvokeAttributes)reader.Binary.ReadUInt16();
     this.MemberForwarded = reader.ReadCodedIndex <MemberForwarded>();
     this.ImportName      = reader.ReadString();
     this.ImportScope     = reader.ReadTableIndex(TableKind.ModuleRef);
 }
コード例 #6
0
ファイル: ImplMapEntry.cs プロジェクト: BGCX261/zoompe-git
 public void Read(ClrModuleReader reader)
 {
     this.MappingFlags = (PInvokeAttributes)reader.Binary.ReadUInt16();
     this.MemberForwarded = reader.ReadCodedIndex<MemberForwarded>();
     this.ImportName = reader.ReadString();
     this.ImportScope = reader.ReadTableIndex(TableKind.ModuleRef);
 }
コード例 #7
0
ファイル: PInvokeInfo.cs プロジェクト: pusp/o2platform
		public PInvokeInfo (MethodDefinition meth, PInvokeAttributes attrs,
			string entryPoint, ModuleReference mod) : this (meth)
		{
			m_attributes = attrs;
			m_entryPoint = entryPoint;
			m_module = mod;
		}
コード例 #8
0
 public PInvokeInfo(MethodDefinition meth, PInvokeAttributes attrs,
                    string entryPoint, ModuleReference mod) : this(meth)
 {
     m_attributes = attrs;
     m_entryPoint = entryPoint;
     m_module     = mod;
 }
コード例 #9
0
ファイル: ImplMapRow.cs プロジェクト: yonglehou/MOSA-Project
 /// <summary>
 /// Initializes a new instance of the <see cref="ImplMapRow" /> struct.
 /// </summary>
 /// <param name="mappingFlags">The mapping flags.</param>
 /// <param name="memberForwarded">The member forwarded table.</param>
 /// <param name="importNameString">The import name string.</param>
 /// <param name="importScopeTable">The import scope table.</param>
 public ImplMapRow(PInvokeAttributes mappingFlags, Token memberForwarded,
                   HeapIndexToken importNameString, Token importScopeTable)
 {
     MappingFlags     = mappingFlags;
     MemberForwarded  = memberForwarded;
     ImportNameString = importNameString;
     ImportScopeTable = importScopeTable;
 }
コード例 #10
0
ファイル: ImplMapRow.cs プロジェクト: Zahovay/MOSA-Project
        /// <summary>
        /// Initializes a new instance of the <see cref="ImplMapRow" /> struct.
        /// </summary>
        /// <param name="mappingFlags">The mapping flags.</param>
        /// <param name="memberForwarded">The member forwarded table.</param>
        /// <param name="importNameString">The import name string.</param>
        /// <param name="importScopeTable">The import scope table.</param>
        public ImplMapRow(PInvokeAttributes mappingFlags, Token memberForwarded,
			HeapIndexToken importNameString, Token importScopeTable)
        {
            MappingFlags = mappingFlags;
            MemberForwarded = memberForwarded;
            ImportNameString = importNameString;
            ImportScopeTable = importScopeTable;
        }
コード例 #11
0
ファイル: MdBinaryReaderGen.cs プロジェクト: wffy/corert
        } // Read

        public static uint Read(this NativeReader reader, uint offset, out PInvokeAttributes value)
        {
            uint ivalue;

            offset = reader.DecodeUnsigned(offset, out ivalue);
            value  = (PInvokeAttributes)ivalue;
            return(offset);
        } // Read
コード例 #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ImplMapRow"/> struct.
 /// </summary>
 /// <param name="mappingFlags">The mapping flags.</param>
 /// <param name="memberForwardedTableIdx">The member forwarded table idx.</param>
 /// <param name="importNameStringIdx">The import name string idx.</param>
 /// <param name="importScopeTableIdx">The import scope table idx.</param>
 public ImplMapRow(PInvokeAttributes mappingFlags, Token memberForwardedTableIdx,
                   HeapIndexToken importNameStringIdx, Token importScopeTableIdx)
 {
     _mappingFlags            = mappingFlags;
     _memberForwardedTableIdx = memberForwardedTableIdx;
     _importNameStringIdx     = importNameStringIdx;
     _importScopeTableIdx     = importScopeTableIdx;
 }
コード例 #13
0
ファイル: ImplMapRow.cs プロジェクト: davidleon/MOSA-Project
        /// <summary>
        /// Initializes a new instance of the <see cref="ImplMapRow"/> struct.
        /// </summary>
        /// <param name="mappingFlags">The mapping flags.</param>
        /// <param name="memberForwardedTableIdx">The member forwarded table idx.</param>
        /// <param name="importNameStringIdx">The import name string idx.</param>
        /// <param name="importScopeTableIdx">The import scope table idx.</param>
        public ImplMapRow(PInvokeAttributes mappingFlags, Token memberForwardedTableIdx,
			HeapIndexToken importNameStringIdx, Token importScopeTableIdx)
        {
            _mappingFlags = mappingFlags;
            _memberForwardedTableIdx = memberForwardedTableIdx;
            _importNameStringIdx = importNameStringIdx;
            _importScopeTableIdx = importScopeTableIdx;
        }
コード例 #14
0
ファイル: attributes.cs プロジェクト: SixGodZhang/Source
        [System.Security.SecurityCritical]  // auto-generated
        internal static Attribute GetCustomAttribute(RuntimeMethodInfo method)
        {
            if ((method.Attributes & MethodAttributes.PinvokeImpl) == 0)
            {
                return(null);
            }

            MetadataImport    scope = ModuleHandle.GetMetadataImport(method.Module.ModuleHandle.GetRuntimeModule());
            string            entryPoint, dllName = null;
            int               token = method.MetadataToken;
            PInvokeAttributes flags = 0;

            scope.GetPInvokeMap(token, out flags, out entryPoint, out dllName);

            CharSet charSet = CharSet.None;

            switch (flags & PInvokeAttributes.CharSetMask)
            {
            case PInvokeAttributes.CharSetNotSpec: charSet = CharSet.None; break;

            case PInvokeAttributes.CharSetAnsi: charSet = CharSet.Ansi; break;

            case PInvokeAttributes.CharSetUnicode: charSet = CharSet.Unicode; break;

            case PInvokeAttributes.CharSetAuto: charSet = CharSet.Auto; break;

            // Invalid: default to CharSet.None
            default: break;
            }

            CallingConvention callingConvention = CallingConvention.Cdecl;

            switch (flags & PInvokeAttributes.CallConvMask)
            {
            case PInvokeAttributes.CallConvWinapi: callingConvention = CallingConvention.Winapi; break;

            case PInvokeAttributes.CallConvCdecl: callingConvention = CallingConvention.Cdecl; break;

            case PInvokeAttributes.CallConvStdcall: callingConvention = CallingConvention.StdCall; break;

            case PInvokeAttributes.CallConvThiscall: callingConvention = CallingConvention.ThisCall; break;

            case PInvokeAttributes.CallConvFastcall: callingConvention = CallingConvention.FastCall; break;

            // Invalid: default to CallingConvention.Cdecl
            default: break;
            }

            bool exactSpelling         = (flags & PInvokeAttributes.NoMangle) != 0;
            bool setLastError          = (flags & PInvokeAttributes.SupportsLastError) != 0;
            bool bestFitMapping        = (flags & PInvokeAttributes.BestFitMask) == PInvokeAttributes.BestFitEnabled;
            bool throwOnUnmappableChar = (flags & PInvokeAttributes.ThrowOnUnmappableCharMask) == PInvokeAttributes.ThrowOnUnmappableCharEnabled;
            bool preserveSig           = (method.GetMethodImplementationFlags() & MethodImplAttributes.PreserveSig) != 0;

            return(new DllImportAttribute(
                       dllName, entryPoint, charSet, exactSpelling, setLastError, preserveSig,
                       callingConvention, bestFitMapping, throwOnUnmappableChar));
        }
コード例 #15
0
    string StringifyPInvokeAttrs(PInvokeAttributes attrs)
    {
        var sb = new StringBuilder();

        sb.Append(Map(pinvoke_char_set_map, (uint)(attrs & PInvokeAttributes.CharSetMask)));
        sb.Append(Map(pinvoke_cconv_map, (uint)(attrs & PInvokeAttributes.CallConvMask)));
        sb.Append(MapFlags(pinvoke_flags_map, (uint)(attrs)));
        return(sb.ToString());
    }
コード例 #16
0
ファイル: ImplMapData.cs プロジェクト: carriercomm/Proton-1
		private void LoadData(CLIFile pFile)
		{
			MappingFlags = (PInvokeAttributes)pFile.ReadUInt16();
			MemberForwarded.LoadData(pFile);
			ImportName = pFile.ReadStringHeap(pFile.ReadHeapIndex(HeapOffsetSizes.Strings32Bit));
			int moduleRefIndex = 0;
			if (pFile.ModuleRefTable.Length >= 0xFFFF) moduleRefIndex = pFile.ReadInt32() - 1;
			else moduleRefIndex = pFile.ReadUInt16() - 1;
			if (moduleRefIndex >= 0) ImportScope = pFile.ModuleRefTable[moduleRefIndex];
		}
コード例 #17
0
        public ImplMapRow CreateImplMapRow(PInvokeAttributes _mappingFlags, MetadataToken _memberForwarded, uint _importName, uint _importScope)
        {
            ImplMapRow row = new ImplMapRow();

            row.MappingFlags    = _mappingFlags;
            row.MemberForwarded = _memberForwarded;
            row.ImportName      = _importName;
            row.ImportScope     = _importScope;
            return(row);
        }
コード例 #18
0
 void SetFlagValue(PInvokeAttributes flag, bool value)
 {
     if (value)
     {
         Attributes |= flag;
     }
     else
     {
         Attributes &= ~flag;
     }
 }
コード例 #19
0
        public unsafe void GetPInvokeMap(int token, out PInvokeAttributes attributes, out string importName, out string importDll)
        {
            int   attributes1;
            void *pStringHeap1;
            void *pStringHeap2;

            MetadataImport._GetPInvokeMap(this.m_metadataImport2, token, out attributes1, &pStringHeap1, &pStringHeap2);
            importName = new Utf8String(pStringHeap1).ToString();
            importDll  = new Utf8String(pStringHeap2).ToString();
            attributes = (PInvokeAttributes)attributes1;
        }
コード例 #20
0
        public unsafe void GetPInvokeMap(int token, out PInvokeAttributes attributes, out string importName, out string importDll)
        {
            int   num;
            void *voidPtr;
            void *voidPtr2;

            _GetPInvokeMap(this.m_metadataImport2, out MetadataArgs.Skip, token, out num, &voidPtr, &voidPtr2);
            importName = new Utf8String(voidPtr).ToString();
            importDll  = new Utf8String(voidPtr2).ToString();
            attributes = (PInvokeAttributes)num;
        }
コード例 #21
0
ファイル: ImplMap.cs プロジェクト: EmilZhou/dnlib
		/// <summary>
		/// Modify <see cref="attributes"/> property: <see cref="attributes"/> =
		/// (<see cref="attributes"/> &amp; <paramref name="andMask"/>) | <paramref name="orMask"/>.
		/// </summary>
		/// <param name="andMask">Value to <c>AND</c></param>
		/// <param name="orMask">Value to OR</param>
		void ModifyAttributes(PInvokeAttributes andMask, PInvokeAttributes orMask) {
#if THREAD_SAFE
			int origVal, newVal;
			do {
				origVal = attributes;
				newVal = (origVal & (int)andMask) | (int)orMask;
			} while (Interlocked.CompareExchange(ref attributes, newVal, origVal) != origVal);
#else
			attributes = (attributes & (int)andMask) | (int)orMask;
#endif
		}
コード例 #22
0
ファイル: ImplMap.cs プロジェクト: petterlopes/ConfuserEx
        /// <summary>
        /// Modify <see cref="attributes"/> property: <see cref="attributes"/> =
        /// (<see cref="attributes"/> &amp; <paramref name="andMask"/>) | <paramref name="orMask"/>.
        /// </summary>
        /// <param name="andMask">Value to <c>AND</c></param>
        /// <param name="orMask">Value to OR</param>
        private void ModifyAttributes(PInvokeAttributes andMask, PInvokeAttributes orMask)
        {
#if THREAD_SAFE
            int origVal, newVal;
            do
            {
                origVal = attributes;
                newVal  = (origVal & (int)andMask) | (int)orMask;
            } while (Interlocked.CompareExchange(ref attributes, newVal, origVal) != origVal);
#else
            attributes = (attributes & (int)andMask) | (int)orMask;
#endif
        }
コード例 #23
0
        public unsafe void GetPInvokeMap(
            int token,
            out PInvokeAttributes attributes,
            out string importName,
            out string importDll)
        {
            void *_importName, _importDll;

            _GetPInvokeMap(m_metadataImport2, token, out int _attributes, &_importName, &_importDll);
            importName = new MdUtf8String(_importName).ToString();
            importDll  = new MdUtf8String(_importDll).ToString();

            attributes = (PInvokeAttributes)_attributes;
        }
コード例 #24
0
        /// <summary>
        /// Initialises a new instance of the ImplMapMetadataTableRow class
        /// </summary>
        /// <param name="content">The content of the file</param>
        /// <param name="offset">The offset of the current row</param>
        public ImplMapMetadataTableRow(byte[] content, Offset offset, ICodedIndexResolver resolver, IIndexDetails indexDetails)
        {
            this.FileOffset = offset;

            int  sizeOfMemberForwardedIndex = resolver.GetSizeOfIndex(CodedIndexes.MemberForwarded);
            byte sizeOfStringIndex          = indexDetails.GetSizeOfStringIndex();
            byte sizeOfModuleRefIndex       = indexDetails.GetSizeOfIndex(MetadataTables.ModuleRef);

            _mappingFlags  = (PInvokeAttributes)FieldReader.ToUInt16(content, offset.Shift(2));
            _memberForward = resolver.Resolve(CodedIndexes.MemberForwarded,
                                              FieldReader.ToUInt32(content, offset.Shift(sizeOfMemberForwardedIndex), sizeOfMemberForwardedIndex)
                                              );
            _importName  = new StringIndex(content, sizeOfStringIndex, offset);
            _importScope = new Index(content, offset, sizeOfModuleRefIndex);
        }
コード例 #25
0
ファイル: MethodDesc.Interop.cs プロジェクト: tijoytom/corert
 /// <summary>
 /// Converts unmanaged calling convention encoded as PInvokeAttributes to unmanaged 
 /// calling convention encoded as MethodSignatureFlags.
 /// </summary>
 public static MethodSignatureFlags GetUnmanagedCallingConvention(PInvokeAttributes attributes)
 {
     switch (attributes & PInvokeAttributes.CallingConventionMask)
     {
         case PInvokeAttributes.CallingConventionWinApi:
             return MethodSignatureFlags.UnmanagedCallingConventionStdCall; // TODO: CDecl for varargs
         case PInvokeAttributes.CallingConventionCDecl:
             return MethodSignatureFlags.UnmanagedCallingConventionCdecl;
         case PInvokeAttributes.CallingConventionStdCall:
             return MethodSignatureFlags.UnmanagedCallingConventionStdCall;
         case PInvokeAttributes.CallingConventionThisCall:
             return MethodSignatureFlags.UnmanagedCallingConventionThisCall;
         default:
             throw new BadImageFormatException();
     }
 }
コード例 #26
0
        /// <summary>
        /// Charset for marshalling strings
        /// </summary>
        private PInvokeAttributes GetCharSet()
        {
            PInvokeAttributes charset = _importMetadata.Attributes & PInvokeAttributes.CharSetMask;

            if (charset == 0)
            {
                // ECMA-335 II.10.1.5 - Default value is Ansi.
                charset = PInvokeAttributes.CharSetAnsi;
            }

            if (charset == PInvokeAttributes.CharSetAuto)
            {
                charset = PInvokeAttributes.CharSetUnicode;
            }

            return(charset);
        }
コード例 #27
0
ファイル: ImplMap.cs プロジェクト: EmilZhou/dnlib
		/// <summary>
		/// Set or clear flags in <see cref="attributes"/>
		/// </summary>
		/// <param name="set"><c>true</c> if flags should be set, <c>false</c> if flags should
		/// be cleared</param>
		/// <param name="flags">Flags to set or clear</param>
		void ModifyAttributes(bool set, PInvokeAttributes flags) {
#if THREAD_SAFE
			int origVal, newVal;
			do {
				origVal = attributes;
				if (set)
					newVal = origVal | (int)flags;
				else
					newVal = origVal & ~(int)flags;
			} while (Interlocked.CompareExchange(ref attributes, newVal, origVal) != origVal);
#else
			if (set)
				attributes |= (int)flags;
			else
				attributes &= ~(int)flags;
#endif
		}
コード例 #28
0
ファイル: MethodDesc.Interop.cs プロジェクト: ebeworld/corert
        /// <summary>
        /// Converts unmanaged calling convention encoded as PInvokeAttributes to unmanaged
        /// calling convention encoded as MethodSignatureFlags.
        /// </summary>
        public static MethodSignatureFlags GetUnmanagedCallingConvention(PInvokeAttributes attributes)
        {
            switch (attributes & PInvokeAttributes.CallingConventionMask)
            {
            case PInvokeAttributes.CallingConventionWinApi:
                return(MethodSignatureFlags.UnmanagedCallingConventionStdCall);    // TODO: CDecl for varargs

            case PInvokeAttributes.CallingConventionCDecl:
                return(MethodSignatureFlags.UnmanagedCallingConventionCdecl);

            case PInvokeAttributes.CallingConventionStdCall:
                return(MethodSignatureFlags.UnmanagedCallingConventionStdCall);

            case PInvokeAttributes.CallingConventionThisCall:
                return(MethodSignatureFlags.UnmanagedCallingConventionThisCall);

            default:
                throw new BadImageFormatException();
            }
        }
コード例 #29
0
		internal static string ToString(PInvokeAttributes flags) {
			var sb = new StringBuilder();

			switch ((flags & PInvokeAttributes.CharSetMask)) {
			case PInvokeAttributes.CharSetNotSpec: sb.Append("CharSetNotSpec"); break;
			case PInvokeAttributes.CharSetAnsi: sb.Append("CharSetAnsi"); break;
			case PInvokeAttributes.CharSetUnicode: sb.Append("CharSetUnicode"); break;
			case PInvokeAttributes.CharSetAuto: sb.Append("CharSetAuto"); break;
			}

			if ((flags & PInvokeAttributes.NoMangle) != 0)
				sb.Append(" | NoMangle");

			switch ((flags & PInvokeAttributes.BestFitMask)) {
			case PInvokeAttributes.BestFitUseAssem: sb.Append(" | BestFitUseAssem"); break;
			case PInvokeAttributes.BestFitEnabled: sb.Append(" | BestFitEnabled"); break;
			case PInvokeAttributes.BestFitDisabled: sb.Append(" | BestFitDisabled"); break;
			default: sb.Append(" | BestFit_UNKNOWN"); break;
			}

			switch ((flags & PInvokeAttributes.ThrowOnUnmappableCharMask)) {
			case PInvokeAttributes.ThrowOnUnmappableCharUseAssem: sb.Append(" | ThrowOnUnmappableCharUseAssem"); break;
			case PInvokeAttributes.ThrowOnUnmappableCharEnabled: sb.Append(" | ThrowOnUnmappableCharEnabled"); break;
			case PInvokeAttributes.ThrowOnUnmappableCharDisabled: sb.Append(" | ThrowOnUnmappableCharDisabled"); break;
			default: sb.Append(" | ThrowOnUnmappableChar_UNKNOWN"); break;
			}

			if ((flags & PInvokeAttributes.SupportsLastError) != 0)
				sb.Append(" | SupportsLastError");

			switch ((flags & PInvokeAttributes.CallConvMask)) {
			case PInvokeAttributes.CallConvWinapi: sb.Append(" | CallConvWinapi"); break;
			case PInvokeAttributes.CallConvCdecl: sb.Append(" | CallConvCdecl"); break;
			case PInvokeAttributes.CallConvStdcall: sb.Append(" | CallConvStdcall"); break;
			case PInvokeAttributes.CallConvThiscall: sb.Append(" | CallConvThiscall"); break;
			case PInvokeAttributes.CallConvFastcall: sb.Append(" | CallConvFastcall"); break;
			default: sb.Append(" | CallConv_UNKNOWN"); break;
			}

			return sb.ToString();
		}
コード例 #30
0
 private void Add(PInvokeAttributes a)
 {
 }
コード例 #31
0
        } // Read

        public static uint Read(this NativeReader reader, uint offset, out PInvokeAttributes value)
        {
            uint ivalue;
            offset = reader.DecodeUnsigned(offset, out ivalue);
            value = (PInvokeAttributes)ivalue;
            return offset;
        } // Read
コード例 #32
0
 void Add(PInvokeAttributes a)
 {
 }
コード例 #33
0
        private CustomAttributeData GetDllImportAttributeData()
        {
            if ((Attributes & MethodAttributes.PinvokeImpl) == 0)
            {
                return(null);
            }

            string            entryPoint, dllName = null;
            PInvokeAttributes flags = 0;

            GetPInvoke(out flags, out entryPoint, out dllName);

            CharSet charSet;

            switch (flags & PInvokeAttributes.CharSetMask)
            {
            case PInvokeAttributes.CharSetNotSpec:
                charSet = CharSet.None;
                break;

            case PInvokeAttributes.CharSetAnsi:
                charSet = CharSet.Ansi;
                break;

            case PInvokeAttributes.CharSetUnicode:
                charSet = CharSet.Unicode;
                break;

            case PInvokeAttributes.CharSetAuto:
                charSet = CharSet.Auto;
                break;

            // Invalid: default to CharSet.None
            default:
                charSet = CharSet.None;
                break;
            }

            InteropServicesCallingConvention callingConvention;

            switch (flags & PInvokeAttributes.CallConvMask)
            {
            case PInvokeAttributes.CallConvWinapi:
                callingConvention = InteropServicesCallingConvention.Winapi;
                break;

            case PInvokeAttributes.CallConvCdecl:
                callingConvention = InteropServicesCallingConvention.Cdecl;
                break;

            case PInvokeAttributes.CallConvStdcall:
                callingConvention = InteropServicesCallingConvention.StdCall;
                break;

            case PInvokeAttributes.CallConvThiscall:
                callingConvention = InteropServicesCallingConvention.ThisCall;
                break;

            case PInvokeAttributes.CallConvFastcall:
                callingConvention = InteropServicesCallingConvention.FastCall;
                break;

            // Invalid: default to CallingConvention.Cdecl
            default:
                callingConvention = InteropServicesCallingConvention.Cdecl;
                break;
            }

            bool exactSpelling         = (flags & PInvokeAttributes.NoMangle) != 0;
            bool setLastError          = (flags & PInvokeAttributes.SupportsLastError) != 0;
            bool bestFitMapping        = (flags & PInvokeAttributes.BestFitMask) == PInvokeAttributes.BestFitEnabled;
            bool throwOnUnmappableChar = (flags & PInvokeAttributes.ThrowOnUnmappableCharMask) == PInvokeAttributes.ThrowOnUnmappableCharEnabled;
            bool preserveSig           = (GetMethodImplementationFlags() & MethodImplAttributes.PreserveSig) != 0;

            var ctorArgs = new CustomAttributeTypedArgument [] {
                new CustomAttributeTypedArgument(typeof(string), dllName),
            };

            var attrType = typeof(DllImportAttribute);

            var namedArgs = new CustomAttributeNamedArgument [] {
                new CustomAttributeNamedArgument(attrType.GetField("EntryPoint"), entryPoint),
                new CustomAttributeNamedArgument(attrType.GetField("CharSet"), charSet),
                new CustomAttributeNamedArgument(attrType.GetField("ExactSpelling"), exactSpelling),
                new CustomAttributeNamedArgument(attrType.GetField("SetLastError"), setLastError),
                new CustomAttributeNamedArgument(attrType.GetField("PreserveSig"), preserveSig),
                new CustomAttributeNamedArgument(attrType.GetField("CallingConvention"), callingConvention),
                new CustomAttributeNamedArgument(attrType.GetField("BestFitMapping"), bestFitMapping),
                new CustomAttributeNamedArgument(attrType.GetField("ThrowOnUnmappableChar"), throwOnUnmappableChar)
            };

            return(new CustomAttributeData(
                       attrType.GetConstructor(new[] { typeof(string) }),
                       ctorArgs,
                       namedArgs));
        }
コード例 #34
0
        internal static string ToString(PInvokeAttributes flags)
        {
            var sb = new StringBuilder();

            switch ((flags & PInvokeAttributes.CharSetMask))
            {
            case PInvokeAttributes.CharSetNotSpec: sb.Append("CharSetNotSpec"); break;

            case PInvokeAttributes.CharSetAnsi: sb.Append("CharSetAnsi"); break;

            case PInvokeAttributes.CharSetUnicode: sb.Append("CharSetUnicode"); break;

            case PInvokeAttributes.CharSetAuto: sb.Append("CharSetAuto"); break;
            }

            if ((flags & PInvokeAttributes.NoMangle) != 0)
            {
                sb.Append(" | NoMangle");
            }

            switch ((flags & PInvokeAttributes.BestFitMask))
            {
            case PInvokeAttributes.BestFitUseAssem: sb.Append(" | BestFitUseAssem"); break;

            case PInvokeAttributes.BestFitEnabled: sb.Append(" | BestFitEnabled"); break;

            case PInvokeAttributes.BestFitDisabled: sb.Append(" | BestFitDisabled"); break;

            default: sb.Append(" | BestFit_UNKNOWN"); break;
            }

            switch ((flags & PInvokeAttributes.ThrowOnUnmappableCharMask))
            {
            case PInvokeAttributes.ThrowOnUnmappableCharUseAssem: sb.Append(" | ThrowOnUnmappableCharUseAssem"); break;

            case PInvokeAttributes.ThrowOnUnmappableCharEnabled: sb.Append(" | ThrowOnUnmappableCharEnabled"); break;

            case PInvokeAttributes.ThrowOnUnmappableCharDisabled: sb.Append(" | ThrowOnUnmappableCharDisabled"); break;

            default: sb.Append(" | ThrowOnUnmappableChar_UNKNOWN"); break;
            }

            if ((flags & PInvokeAttributes.SupportsLastError) != 0)
            {
                sb.Append(" | SupportsLastError");
            }

            switch ((flags & PInvokeAttributes.CallConvMask))
            {
            case PInvokeAttributes.CallConvWinapi: sb.Append(" | CallConvWinapi"); break;

            case PInvokeAttributes.CallConvCdecl: sb.Append(" | CallConvCdecl"); break;

            case PInvokeAttributes.CallConvStdcall: sb.Append(" | CallConvStdcall"); break;

            case PInvokeAttributes.CallConvThiscall: sb.Append(" | CallConvThiscall"); break;

            case PInvokeAttributes.CallConvFastcall: sb.Append(" | CallConvFastcall"); break;

            default: sb.Append(" | CallConv_UNKNOWN"); break;
            }

            return(sb.ToString());
        }
コード例 #35
0
ファイル: ImplMapVM.cs プロジェクト: BahNahNah/dnSpy
 void SetFlagValue(PInvokeAttributes flag, bool value)
 {
     if (value)
         Attributes |= flag;
     else
         Attributes &= ~flag;
 }
コード例 #36
0
        } // Write

        public static void Write(this NativeWriter writer, PInvokeAttributes value)
        {
            writer.WriteUnsigned((uint)value);
        } // Write
コード例 #37
0
ファイル: ImplMap.cs プロジェクト: bprg/dnlib
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="scope">Scope</param>
 /// <param name="name">Name</param>
 /// <param name="flags">Flags</param>
 public ImplMapUser(ModuleRef scope, UTF8String name, PInvokeAttributes flags)
 {
     this.module = scope;
     this.name = name;
     this.attributes = (int)flags;
 }
コード例 #38
0
 bool GetFlagValue(PInvokeAttributes flag)
 {
     return((Attributes & flag) != 0);
 }
コード例 #39
0
        [System.Security.SecurityCritical]  // auto-generated
        public unsafe void GetPInvokeMap(
            int token, 
            out PInvokeAttributes attributes, 
            out String importName, 
            out String importDll)
        {
            int _attributes;
            void* _importName, _importDll;
            _GetPInvokeMap(m_metadataImport2, token, out _attributes, &_importName, &_importDll);
            importName = new Utf8String(_importName).ToString();
            importDll = new Utf8String(_importDll).ToString();

            attributes = (PInvokeAttributes)_attributes;
        }
コード例 #40
0
ファイル: MonoMethod.cs プロジェクト: Profit0004/mono
		internal extern void GetPInvoke (out PInvokeAttributes flags, out string entryPoint, out string dllName);
コード例 #41
0
        internal static Attribute GetCustomAttribute(RuntimeMethodInfo method)
        {
            if ((method.Attributes & MethodAttributes.PinvokeImpl) == MethodAttributes.PrivateScope)
            {
                return(null);
            }
            MetadataImport    metadataImport    = ModuleHandle.GetMetadataImport(method.Module.ModuleHandle.GetRuntimeModule());
            string            dllName           = null;
            int               metadataToken     = method.MetadataToken;
            PInvokeAttributes pinvokeAttributes = PInvokeAttributes.CharSetNotSpec;
            string            entryPoint;

            metadataImport.GetPInvokeMap(metadataToken, out pinvokeAttributes, out entryPoint, out dllName);
            CharSet charSet = CharSet.None;

            switch (pinvokeAttributes & PInvokeAttributes.CharSetMask)
            {
            case PInvokeAttributes.CharSetNotSpec:
                charSet = CharSet.None;
                break;

            case PInvokeAttributes.CharSetAnsi:
                charSet = CharSet.Ansi;
                break;

            case PInvokeAttributes.CharSetUnicode:
                charSet = CharSet.Unicode;
                break;

            case PInvokeAttributes.CharSetMask:
                charSet = CharSet.Auto;
                break;
            }
            CallingConvention callingConvention  = CallingConvention.Cdecl;
            PInvokeAttributes pinvokeAttributes2 = pinvokeAttributes & PInvokeAttributes.CallConvMask;

            if (pinvokeAttributes2 <= PInvokeAttributes.CallConvCdecl)
            {
                if (pinvokeAttributes2 != PInvokeAttributes.CallConvWinapi)
                {
                    if (pinvokeAttributes2 == PInvokeAttributes.CallConvCdecl)
                    {
                        callingConvention = CallingConvention.Cdecl;
                    }
                }
                else
                {
                    callingConvention = CallingConvention.Winapi;
                }
            }
            else if (pinvokeAttributes2 != PInvokeAttributes.CallConvStdcall)
            {
                if (pinvokeAttributes2 != PInvokeAttributes.CallConvThiscall)
                {
                    if (pinvokeAttributes2 == PInvokeAttributes.CallConvFastcall)
                    {
                        callingConvention = CallingConvention.FastCall;
                    }
                }
                else
                {
                    callingConvention = CallingConvention.ThisCall;
                }
            }
            else
            {
                callingConvention = CallingConvention.StdCall;
            }
            bool exactSpelling         = (pinvokeAttributes & PInvokeAttributes.NoMangle) > PInvokeAttributes.CharSetNotSpec;
            bool setLastError          = (pinvokeAttributes & PInvokeAttributes.SupportsLastError) > PInvokeAttributes.CharSetNotSpec;
            bool bestFitMapping        = (pinvokeAttributes & PInvokeAttributes.BestFitMask) == PInvokeAttributes.BestFitEnabled;
            bool throwOnUnmappableChar = (pinvokeAttributes & PInvokeAttributes.ThrowOnUnmappableCharMask) == PInvokeAttributes.ThrowOnUnmappableCharEnabled;
            bool preserveSig           = (method.GetMethodImplementationFlags() & MethodImplAttributes.PreserveSig) > MethodImplAttributes.IL;

            return(new DllImportAttribute(dllName, entryPoint, charSet, exactSpelling, setLastError, preserveSig, callingConvention, bestFitMapping, throwOnUnmappableChar));
        }
コード例 #42
0
ファイル: MDAPI.cs プロジェクト: arkanoid1/dnSpy
		public unsafe static bool GetPinvokeMapProps(IMetaDataImport mdi, uint token, out PInvokeAttributes attrs, out uint moduleToken) {
			attrs = 0;
			moduleToken = 0;
			if (mdi == null)
				return false;

			uint dwMappingFlags, mrImportDLL;
			int hr = mdi.GetPinvokeMap(token, new IntPtr(&dwMappingFlags), IntPtr.Zero, 0, IntPtr.Zero, new IntPtr(&mrImportDLL));
			if (hr != 0)
				return false;
			attrs = (PInvokeAttributes)dwMappingFlags;
			moduleToken = mrImportDLL;
			return true;
		}
コード例 #43
0
ファイル: MethodDesc.Interop.cs プロジェクト: tijoytom/corert
 public PInvokeMetadata(string module, string entrypoint, PInvokeAttributes attributes)
 {
     Name = entrypoint;
     Module = module;
     Attributes = attributes;
 }
コード例 #44
0
ファイル: ImplMapVM.cs プロジェクト: BahNahNah/dnSpy
 bool GetFlagValue(PInvokeAttributes flag)
 {
     return (Attributes & flag) != 0;
 }
コード例 #45
0
ファイル: ImplMap.cs プロジェクト: petterlopes/ConfuserEx
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="scope">Scope</param>
 /// <param name="name">Name</param>
 /// <param name="flags">Flags</param>
 public ImplMapUser(ModuleRef scope, UTF8String name, PInvokeAttributes flags)
 {
     this.module     = scope;
     this.name       = name;
     this.attributes = (int)flags;
 }
コード例 #46
0
ファイル: PInvokeInfo.cs プロジェクト: peterwald/cecil
 public PInvokeInfo(PInvokeAttributes attributes, string entryPoint, ModuleReference module)
 {
     this.attributes = (ushort) attributes;
     this.entry_point = entryPoint;
     this.module = module;
 }
コード例 #47
0
 internal extern void GetPInvoke(out PInvokeAttributes flags, out string entryPoint, out string dllName);
コード例 #48
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="scope">Scope</param>
		/// <param name="name">Name</param>
		/// <param name="flags">Flags</param>
		public ImplMapUser(ModuleRef scope, UTF8String name, PInvokeAttributes flags) {
			this.scope = scope;
			this.name = name;
			this.flags = flags;
		}
コード例 #49
0
ファイル: MetadataImport.cs プロジェクト: randomize/VimConfig
 public unsafe void GetPInvokeMap(int token, out PInvokeAttributes attributes, out string importName, out string importDll)
 {
     int num;
     void* voidPtr;
     void* voidPtr2;
     _GetPInvokeMap(this.m_metadataImport2, out MetadataArgs.Skip, token, out num, &voidPtr, &voidPtr2);
     importName = new Utf8String(voidPtr).ToString();
     importDll = new Utf8String(voidPtr2).ToString();
     attributes = (PInvokeAttributes) num;
 }
コード例 #50
0
ファイル: ildasm.cs プロジェクト: sesef/mono
	string StringifyPInvokeAttrs (PInvokeAttributes attrs) {
		var sb = new StringBuilder ();
		sb.Append (Map (pinvoke_char_set_map, (uint)(attrs & PInvokeAttributes.CharSetMask)));
		sb.Append (Map (pinvoke_cconv_map, (uint)(attrs & PInvokeAttributes.CallConvMask)));
		sb.Append (MapFlags (pinvoke_flags_map, (uint)(attrs)));
		return sb.ToString ();
	}		
コード例 #51
0
ファイル: MethodDesc.Interop.cs プロジェクト: noahfalk/corert
 public PInvokeMetadata(string name, PInvokeAttributes attributes)
 {
     Name = name;
     Attributes = attributes;
 }
コード例 #52
0
 public ImplMapRow CreateImplMapRow(PInvokeAttributes _mappingFlags, MetadataToken _memberForwarded, uint _importName, uint _importScope)
 {
     ImplMapRow row = new ImplMapRow ();
     row.MappingFlags = _mappingFlags;
     row.MemberForwarded = _memberForwarded;
     row.ImportName = _importName;
     row.ImportScope = _importScope;
     return row;
 }
コード例 #53
0
ファイル: Rows.cs プロジェクト: emtees/old-code
		/// <summary>
		///  Fills the row from the array of bytes.
		/// </summary>
		unsafe public void FromRawData(byte [] buff, int offs)
		{
			if (buff == null) throw new Exception("buff == null");
			if (offs + Size > buff.Length) throw new Exception("bounds");

		
			this.MappingFlags = (PInvokeAttributes) LEBitConverter.ToUInt16(buff, offs);
			offs += sizeof (ushort);
			this.MemberForwarded = TabsDecoder.DecodeToken(CodedTokenId.MemberForwarded, LEBitConverter.ToInt32(buff, offs));
			offs += 4;
			this.ImportName = LEBitConverter.ToInt32(buff, offs);
			offs += 4;
			this.ImportScope = LEBitConverter.ToInt32(buff, offs);
			
		}
コード例 #54
0
ファイル: PInvokeInfo.cs プロジェクト: yonder/mono
 public PInvokeInfo(PInvokeAttributes attributes, string entryPoint, ModuleReference module)
 {
     this.attributes  = (ushort)attributes;
     this.entry_point = entryPoint;
     this.module      = module;
 }
コード例 #55
0
ファイル: MethodDesc.Interop.cs プロジェクト: dVakulen/corert
 public PInvokeMetadata(string name, PInvokeAttributes attributes)
 {
     Name       = name;
     Attributes = attributes;
 }