Ejemplo n.º 1
0
        public static void Initialize()
        {
            Module m = typeof(AntiTamperNormal).Module;
            string n = m.FullyQualifiedName;
            bool   f = n.Length > 0 && n[0] == '<';
            var    b = (byte *)Marshal.GetHINSTANCE(m);
            byte * p = b + *(uint *)(b + 0x3c);
            ushort s = *(ushort *)(p + 0x6);
            ushort o = *(ushort *)(p + 0x14);

            uint *e = null;
            uint  l = 0;
            var   r = (uint *)(p + 0x18 + o);
            uint  z = (uint)Mutation.KeyI1, x = (uint)Mutation.KeyI2, c = (uint)Mutation.KeyI3, v = (uint)Mutation.KeyI4;

            for (int i = 0; i < s; i++)
            {
                uint g = (*r++) * (*r++);
                if (g == (uint)Mutation.KeyI0)
                {
                    e = (uint *)(b + (f ? *(r + 3) : *(r + 1)));
                    l = (f ? *(r + 2) : *(r + 0)) >> 2;
                }
                else if (g != 0)
                {
                    var  q = (uint *)(b + (f ? *(r + 3) : *(r + 1)));
                    uint j = *(r + 2) >> 2;
                    for (uint k = 0; k < j; k++)
                    {
                        uint t = (z ^ (*q++)) + x + c * v;
                        z = x;
                        x = c;
                        x = v;
                        v = t;
                    }
                }
                r += 8;
            }

            uint[] y = new uint[0x10], d = new uint[0x10];
            for (int i = 0; i < 0x10; i++)
            {
                y[i] = v;
                d[i] = x;
                z    = (x >> 5) | (x << 27);
                x    = (c >> 3) | (c << 29);
                c    = (v >> 7) | (v << 25);
                v    = (z >> 11) | (z << 21);
            }
            Mutation.Crypt(y, d);

            uint  h = 0;
            uint *u = e;

            VirtualProtect((IntPtr)e, l << 2, 0x40, out z);
            for (uint i = 0; i < l; i++)
            {
                *e ^= y[h & 0xf];
                y[h & 0xf] = (y[h & 0xf] ^ (*e++)) + 0x3dbb2819;
                h++;
            }

            ptr = u + 4;
            len = *ptr++;

            ver4 = Environment.Version.Major == 4;
            ModuleHandle hnd = m.ModuleHandle;

            if (ver4)
            {
                ulong *str = stackalloc ulong[1];
                str[0]    = 0x0061746144705f6d; //m_pData.
                moduleHnd = (IntPtr)m.GetType().GetField(new string((sbyte *)str), BindingFlags.NonPublic | BindingFlags.Instance).GetValue(m);
                ver5      = Environment.Version.Revision > 17020;
            }
            else
            {
                Marshal.StructureToPtr(hnd, moduleHnd, true);// moduleHnd = *(IntPtr*)(&hnd);
            }
            Hook();
        }
Ejemplo n.º 2
0
        [System.Security.SecurityCritical]  // auto-generated
        private static unsafe RuntimeMethodInfo AssignAssociates(
            int tkMethod,
            RuntimeType declaredType,
            RuntimeType reflectedType)
        {
            if (MetadataToken.IsNullToken(tkMethod))
            {
                return(null);
            }

            Contract.Assert(declaredType != null);
            Contract.Assert(reflectedType != null);

            bool isInherited = declaredType != reflectedType;

            IntPtr[] genericArgumentHandles = null;
            int      genericArgumentCount   = 0;

            RuntimeType [] genericArguments = declaredType.GetTypeHandleInternal().GetInstantiationInternal();
            if (genericArguments != null)
            {
                genericArgumentCount   = genericArguments.Length;
                genericArgumentHandles = new IntPtr[genericArguments.Length];
                for (int i = 0; i < genericArguments.Length; i++)
                {
                    genericArgumentHandles[i] = genericArguments[i].GetTypeHandleInternal().Value;
                }
            }

            RuntimeMethodHandleInternal associateMethodHandle = ModuleHandle.ResolveMethodHandleInternalCore(RuntimeTypeHandle.GetModule(declaredType), tkMethod, genericArgumentHandles, genericArgumentCount, null, 0);

            Contract.Assert(!associateMethodHandle.IsNullHandle(), "Failed to resolve associateRecord methodDef token");

            if (isInherited)
            {
                MethodAttributes methAttr = RuntimeMethodHandle.GetAttributes(associateMethodHandle);

                // ECMA MethodSemantics: "All methods for a given Property or Event shall have the same accessibility
                //(ie the MemberAccessMask subfield of their Flags row) and cannot be CompilerControlled  [CLS]"
                // Consequently, a property may be composed of public and private methods. If the declared type !=
                // the reflected type, the private methods should not be exposed. Note that this implies that the
                // identity of a property includes it's reflected type.

                // NetCF actually includes private methods from parent classes in Reflection results
                // We will mimic that in Mango Compat mode.
                if (!CompatibilitySwitches.IsAppEarlierThanWindowsPhone8)
                {
                    if ((methAttr & MethodAttributes.MemberAccessMask) == MethodAttributes.Private)
                    {
                        return(null);
                    }
                }

                // Note this is the first time the property was encountered walking from the most derived class
                // towards the base class. It would seem to follow that any associated methods would not
                // be overriden -- but this is not necessarily true. A more derived class may have overriden a
                // virtual method associated with a property in a base class without associating the override with
                // the same or any property in the derived class.
                if ((methAttr & MethodAttributes.Virtual) != 0)
                {
                    bool declaringTypeIsClass =
                        (RuntimeTypeHandle.GetAttributes(declaredType) & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Class;

                    // It makes no sense to search for a virtual override of a method declared on an interface.
                    if (declaringTypeIsClass)
                    {
                        int slot = RuntimeMethodHandle.GetSlot(associateMethodHandle);

                        // Find the override visible from the reflected type
                        associateMethodHandle = RuntimeTypeHandle.GetMethodAt(reflectedType, slot);
                    }
                }
            }

            RuntimeMethodInfo associateMethod =
                RuntimeType.GetMethodBase(reflectedType, associateMethodHandle) as RuntimeMethodInfo;

            // suppose a property was mapped to a method not in the derivation hierarchy of the reflectedTypeHandle
            if (associateMethod == null)
            {
                associateMethod = reflectedType.Module.ResolveMethod(tkMethod, null, null) as RuntimeMethodInfo;
            }

            return(associateMethod);
        }
Ejemplo n.º 3
0
        public override FieldInfo?ResolveField(int metadataToken, Type[]?genericTypeArguments, Type[]?genericMethodArguments)
        {
            try
            {
                MetadataToken tk = new MetadataToken(metadataToken);

                if (!MetadataImport.IsValidToken(tk))
                {
                    throw new ArgumentOutOfRangeException(nameof(metadataToken),
                                                          SR.Format(SR.Argument_InvalidToken, tk, this));
                }

                RuntimeTypeHandle[]? typeArgs   = null;
                RuntimeTypeHandle[]? methodArgs = null;
                if (genericTypeArguments?.Length > 0)
                {
                    typeArgs = ConvertToTypeHandleArray(genericTypeArguments);
                }
                if (genericMethodArguments?.Length > 0)
                {
                    methodArgs = ConvertToTypeHandleArray(genericMethodArguments);
                }

                ModuleHandle moduleHandle = new ModuleHandle(this);
                if (!tk.IsFieldDef)
                {
                    if (!tk.IsMemberRef)
                    {
                        throw new ArgumentException(SR.Format(SR.Argument_ResolveField, tk, this),
                                                    nameof(metadataToken));
                    }

                    unsafe
                    {
                        ConstArray sig = MetadataImport.GetMemberRefProps(tk);

                        if (*(MdSigCallingConvention *)sig.Signature != MdSigCallingConvention.Field)
                        {
                            throw new ArgumentException(SR.Format(SR.Argument_ResolveField, tk, this),
                                                        nameof(metadataToken));
                        }
                    }
                }

                IRuntimeFieldInfo fieldHandle = moduleHandle.ResolveFieldHandle(metadataToken, typeArgs, methodArgs).GetRuntimeFieldInfo();

                RuntimeType declaringType = RuntimeFieldHandle.GetApproxDeclaringType(fieldHandle.Value);

                if (declaringType.IsGenericType || declaringType.IsArray)
                {
                    int tkDeclaringType = ModuleHandle.GetMetadataImport(this).GetParentToken(metadataToken);
                    declaringType = (RuntimeType)ResolveType(tkDeclaringType, genericTypeArguments, genericMethodArguments);
                }

                return(RuntimeType.GetFieldInfo(declaringType, fieldHandle));
            }
            catch (MissingFieldException)
            {
                return(ResolveLiteralField(metadataToken, genericTypeArguments, genericMethodArguments));
            }
            catch (BadImageFormatException e)
            {
                throw new ArgumentException(SR.Argument_BadImageFormatExceptionResolve, e);
            }
        }
Ejemplo n.º 4
0
 /// <summary>Creates a string representation of the module</summary>
 /// <returns>LLVM textual representation of the module</returns>
 /// <remarks>
 /// This is intentionally NOT an override of ToString() as that is
 /// used by debuggers to show the value of a type and this can take
 /// an extremely long time (up to many seconds depending on complexity
 /// of the module) which is bad for the debugger.
 /// </remarks>
 public string WriteToString( )
 {
     ThrowIfDisposed( );
     return(ModuleHandle.PrintToString( ));
 }
Ejemplo n.º 5
0
 /// <summary>Clones the current module</summary>
 /// <returns>Cloned module</returns>
 public BitcodeModule Clone( )
 {
     ThrowIfDisposed( );
     return(FromHandle(ModuleHandle.Clone( )) !);
 }
Ejemplo n.º 6
0
 public static extern unsafe InstanceHandle wasm_instance_new(StoreHandle store, ModuleHandle module, IntPtr[] imports, out IntPtr trap);
Ejemplo n.º 7
0
 /// <summary>Verifies a bit-code module</summary>
 /// <param name="errorMessage">Error messages describing any issues found in the bit-code</param>
 /// <returns>true if the verification succeeded and false if not.</returns>
 public bool Verify(out string errorMessage)
 {
     ThrowIfDisposed( );
     return(ModuleHandle.TryVerify(LLVMVerifierFailureAction.LLVMReturnStatusAction, out errorMessage));
 }
Ejemplo n.º 8
0
 public string HashModule(ModuleHandle module)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 9
0
 public static extern IntPtr wasmtime_module_new(StoreHandle store, ref wasm_byte_vec_t bytes, out ModuleHandle module);
        private unsafe static bool FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, ref Assembly lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, bool mustBeInheritable, object[] attributes, IList derivedAttributes, out RuntimeType attributeType, out IRuntimeMethodInfo ctor, out bool ctorHasParameters, out bool isVarArg)
        {
            ctor              = null;
            attributeType     = null;
            ctorHasParameters = false;
            isVarArg          = false;
            IntPtr signature = caRecord.blob.Signature;
            IntPtr intPtr    = (IntPtr)((void *)((byte *)((void *)signature) + caRecord.blob.Length));

            attributeType = (decoratedModule.ResolveType(scope.GetParentToken(caRecord.tkCtor), null, null) as RuntimeType);
            if (!attributeFilterType.IsAssignableFrom(attributeType))
            {
                return(false);
            }
            if (!CustomAttribute.AttributeUsageCheck(attributeType, mustBeInheritable, attributes, derivedAttributes))
            {
                return(false);
            }
            if ((attributeType.Attributes & TypeAttributes.WindowsRuntime) == TypeAttributes.WindowsRuntime)
            {
                return(false);
            }
            RuntimeAssembly runtimeAssembly  = (RuntimeAssembly)attributeType.Assembly;
            RuntimeAssembly runtimeAssembly2 = (RuntimeAssembly)decoratedModule.Assembly;

            if (runtimeAssembly != lastAptcaOkAssembly && !RuntimeAssembly.AptcaCheck(runtimeAssembly, runtimeAssembly2))
            {
                return(false);
            }
            lastAptcaOkAssembly = runtimeAssembly2;
            ConstArray methodSignature = scope.GetMethodSignature(caRecord.tkCtor);

            isVarArg          = ((methodSignature[0] & 5) > 0);
            ctorHasParameters = (methodSignature[1] > 0);
            if (ctorHasParameters)
            {
                ctor = ModuleHandle.ResolveMethodHandleInternal(decoratedModule.GetNativeHandle(), caRecord.tkCtor);
            }
            else
            {
                ctor = attributeType.GetTypeHandleInternal().GetDefaultConstructor();
                if (ctor == null && !attributeType.IsValueType)
                {
                    throw new MissingMethodException(".ctor");
                }
            }
            MetadataToken token = default(MetadataToken);

            if (decoratedToken.IsParamDef)
            {
                token = new MetadataToken(scope.GetParentToken(decoratedToken));
                token = new MetadataToken(scope.GetParentToken(token));
            }
            else if (decoratedToken.IsMethodDef || decoratedToken.IsProperty || decoratedToken.IsEvent || decoratedToken.IsFieldDef)
            {
                token = new MetadataToken(scope.GetParentToken(decoratedToken));
            }
            else if (decoratedToken.IsTypeDef)
            {
                token = decoratedToken;
            }
            else if (decoratedToken.IsGenericPar)
            {
                token = new MetadataToken(scope.GetParentToken(decoratedToken));
                if (token.IsMethodDef)
                {
                    token = new MetadataToken(scope.GetParentToken(token));
                }
            }
            RuntimeTypeHandle sourceTypeHandle = token.IsTypeDef ? decoratedModule.ModuleHandle.ResolveTypeHandle(token) : default(RuntimeTypeHandle);

            return(RuntimeMethodHandle.IsCAVisibleFromDecoratedType(attributeType.TypeHandle, ctor, sourceTypeHandle, decoratedModule));
        }
Ejemplo n.º 11
0
 unsafe public static extern int LoadStringW(
     ModuleHandle hInstance,
     int uID,
     out char *lpBuffer,
     int nBufferMax);
Ejemplo n.º 12
0
        static QBModifiedCheck()
        {
            QBModifiedCheck.char_0 = new char[]
            {
                '\u0001',
                '\u0002',
                '\u0003',
                '\u0004',
                '\u0005',
                '\u0006',
                '\a',
                '\b',
                '\u000e',
                '\u000f',
                '\u0010',
                '\u0011',
                '\u0012',
                '\u0013',
                '\u0014',
                '\u0015',
                '\u0016',
                '\u0017',
                '\u0018',
                '\u0019',
                '\u001a',
                '\u001b',
                '\u001c',
                '\u001d',
                '\u001e',
                '\u001f',
                '\u007f',
                '\u0080',
                '\u0081',
                '\u0082',
                '\u0083',
                '\u0084',
                '\u0086',
                '\u0087',
                '\u0088',
                '\u0089',
                '\u008a',
                '\u008b',
                '\u008c',
                '\u008d',
                '\u008e',
                '\u008f',
                '\u0090',
                '\u0091',
                '\u0092',
                '\u0093',
                '\u0094',
                '\u0095',
                '\u0096',
                '\u0097',
                '\u0098',
                '\u0099',
                '\u009a',
                '\u009b',
                '\u009c',
                '\u009d',
                '\u009e',
                '\u009f'
            };
            Type typeFromHandle = typeof(MulticastDelegate);

            if (typeFromHandle != null)
            {
                QBModifiedCheck.moduleHandle_0 = Assembly.GetExecutingAssembly().GetModules()[0].ModuleHandle;
            }
        }
Ejemplo n.º 13
0
 public void affecterApprenantModule(Apprenant a, ModuleHandle m)
 {
 }
	public static bool op_Inequality(ModuleHandle left, ModuleHandle right) {}
 public static bool op_Inequality(ModuleHandle left, ModuleHandle right)
 {
 }
Ejemplo n.º 16
0
 public UniqueMemberToken(int metadataToken, ModuleHandle moduleHandle)
 {
     MetadataToken = metadataToken;
     ModuleHandle  = moduleHandle;
 }
	public bool Equals(ModuleHandle handle) {}
Ejemplo n.º 18
0
 public static extern bool UnregisterClass(
     IntPtr lpClassName,
     ModuleHandle hInstance);
Ejemplo n.º 19
0
 internal void GetCallableMethod(RuntimeModule module, DynamicMethod dm)
 {
     dm.m_methodHandle = ModuleHandle.GetDynamicMethod(dm, module, base.m_methodBuilder.Name, (byte[])this.m_scope[this.m_methodSigToken], new DynamicResolver(this));
 }
Ejemplo n.º 20
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static Attribute GetCustomAttribute(RuntimeMethodInfo method)
        {
            if ((method.Attributes & MethodAttributes.PinvokeImpl) == 0)
            {
                return(null);
            }

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

#if MONO
            ((MonoMethod)method).GetPInvoke(out flags, out entryPoint, out dllName);
#else
            scope.GetPInvokeMap(token, out flags, out entryPoint, out dllName);
#endif

            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));
        }
Ejemplo n.º 21
0
        /// <summary>Writes this module as LLVM IR source to a file</summary>
        /// <param name="path">File to write the LLVM IR source to</param>
        /// <param name="errMsg">Error messages encountered, if any</param>
        /// <returns><see langword="true"/> if successful or <see langword="false"/> if not</returns>
        public bool WriteToTextFile(string path, out string errMsg)
        {
            ThrowIfDisposed( );

            return(ModuleHandle.TryPrintToFile(path, out errMsg));
        }
 public static void RunModuleConstructor(ModuleHandle module)
 {
 }
Ejemplo n.º 23
0
 /// <summary>Writes the LLVM IR bit code into a memory buffer</summary>
 /// <returns><see cref="MemoryBuffer"/> containing the bit code module</returns>
 public MemoryBuffer WriteToBuffer( )
 {
     ThrowIfDisposed( );
     return(new MemoryBuffer(memoryBufferRef: ModuleHandle.WriteBitcodeToMemoryBuffer( )));
 }
Ejemplo n.º 24
0
 internal void GetCallableMethod(RuntimeModule module, DynamicMethod dm)
 {
     dm.m_methodHandle = ModuleHandle.GetDynamicMethod(dm,
                                                       module, m_method.Name, (byte[])m_scope[m_methodSignature] !, new DynamicResolver(this));
 }
Ejemplo n.º 25
0
 void GetPEKind(out PortableExecutableKinds peKind, out ImageFileMachine machine)
 {
     ModuleHandle.GetPEKind(out peKind, out machine);
 }
		public static void RunModuleConstructor (ModuleHandle module)
		{
			if (module == ModuleHandle.EmptyHandle)
				throw new ArgumentException ("Handle is not initialized.", "module");

			RunModuleConstructor (module.Value);
		}
        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));
        }
Ejemplo n.º 28
0
        internal static Attribute GetCustomAttribute(RuntimeMethodInfo method)
        {
            string str;

            if ((method.Attributes & MethodAttributes.PinvokeImpl) == MethodAttributes.PrivateScope)
            {
                return(null);
            }
            MetadataImport    metadataImport  = ModuleHandle.GetMetadataImport(method.Module.ModuleHandle.GetRuntimeModule());
            string            importDll       = null;
            int               metadataToken   = method.MetadataToken;
            PInvokeAttributes bestFitUseAssem = PInvokeAttributes.BestFitUseAssem;

            metadataImport.GetPInvokeMap(metadataToken, out bestFitUseAssem, out str, out importDll);
            System.Runtime.InteropServices.CharSet none = System.Runtime.InteropServices.CharSet.None;
            switch ((bestFitUseAssem & PInvokeAttributes.CharSetAuto))
            {
            case PInvokeAttributes.BestFitUseAssem:
                none = System.Runtime.InteropServices.CharSet.None;
                break;

            case PInvokeAttributes.CharSetAnsi:
                none = System.Runtime.InteropServices.CharSet.Ansi;
                break;

            case PInvokeAttributes.CharSetUnicode:
                none = System.Runtime.InteropServices.CharSet.Unicode;
                break;

            case PInvokeAttributes.CharSetAuto:
                none = System.Runtime.InteropServices.CharSet.Auto;
                break;
            }
            System.Runtime.InteropServices.CallingConvention cdecl = System.Runtime.InteropServices.CallingConvention.Cdecl;
            switch ((bestFitUseAssem & PInvokeAttributes.CallConvMask))
            {
            case PInvokeAttributes.CallConvStdcall:
                cdecl = System.Runtime.InteropServices.CallingConvention.StdCall;
                break;

            case PInvokeAttributes.CallConvThiscall:
                cdecl = System.Runtime.InteropServices.CallingConvention.ThisCall;
                break;

            case PInvokeAttributes.CallConvFastcall:
                cdecl = System.Runtime.InteropServices.CallingConvention.FastCall;
                break;

            case PInvokeAttributes.CallConvWinapi:
                cdecl = System.Runtime.InteropServices.CallingConvention.Winapi;
                break;

            case PInvokeAttributes.CallConvCdecl:
                cdecl = System.Runtime.InteropServices.CallingConvention.Cdecl;
                break;
            }
            bool exactSpelling         = (bestFitUseAssem & PInvokeAttributes.NoMangle) != PInvokeAttributes.BestFitUseAssem;
            bool setLastError          = (bestFitUseAssem & PInvokeAttributes.SupportsLastError) != PInvokeAttributes.BestFitUseAssem;
            bool bestFitMapping        = (bestFitUseAssem & PInvokeAttributes.BestFitMask) == PInvokeAttributes.BestFitEnabled;
            bool throwOnUnmappableChar = (bestFitUseAssem & PInvokeAttributes.ThrowOnUnmappableCharMask) == PInvokeAttributes.ThrowOnUnmappableCharEnabled;

            return(new DllImportAttribute(importDll, str, none, exactSpelling, setLastError, (method.GetMethodImplementationFlags() & MethodImplAttributes.PreserveSig) != MethodImplAttributes.IL, cdecl, bestFitMapping, throwOnUnmappableChar));
        }
Ejemplo n.º 29
0
 public override void GetPEKind(out PortableExecutableKinds peKind, out ImageFileMachine machine)
 {
     ModuleHandle.GetPEKind(GetNativeHandle(), out peKind, out machine);
 }
Ejemplo n.º 30
0
 public static extern InstanceHandle wasmtime_linker_instantiate(LinkerHandle linker, ModuleHandle module, out IntPtr trap);
 public bool Equals(ModuleHandle handle)
 {
 }
Ejemplo n.º 32
0
 public static extern void wasm_module_exports(ModuleHandle module, out wasm_exporttype_vec_t exports);
Ejemplo n.º 33
0
 public static void RunModuleConstructor(ModuleHandle module)
 {
     _RunModuleConstructor(module.GetRuntimeModule());
 }
Ejemplo n.º 34
0
 /// <summary>
 /// Equalses the specified instance.
 /// </summary>
 /// <param name="instance">The instance.</param>
 /// <returns></returns>
 public bool Equals(ModuleHandle instance)
 {
     if (this._Instance.Equals(instance._Instance))
     {
         return true;
     }
     return false;
 }