Exemple #1
0
    public TestDelegate()
    {
        base.Name = "Delegate";

        this.nativeLib          = new UnmanagedLibrary("Native");
        this.doWithNoParameters =
            this.nativeLib.GetUnmanagedFunction
            <DelegateWithNoParameters>(
                "DoWithNoParameters"
                );
        this.doWithInt =
            this.nativeLib.GetUnmanagedFunction
            <DelegateWithInt>(
                "DoWithInt"
                );
        this.doWithDouble =
            this.nativeLib.GetUnmanagedFunction
            <DelegateWithDouble>(
                "DoWithDouble"
                );
        this.doWithIntPointer =
            this.nativeLib.GetUnmanagedFunction
            <DelegateWithIntPointer>(
                "DoWithIntPointer"
                );
        this.doWithDoublePointer =
            this.nativeLib.GetUnmanagedFunction
            <DelegateWithDoublePointer>(
                "DoWithDoublePointer"
                );
    }
Exemple #2
0
        public static void Open(bool DebugFlag)
        {
            string        thisAssemblyPath   = new Uri(typeof(SSH2Library).Assembly.CodeBase).LocalPath;
            string        thisAssemblyFolder = Path.GetDirectoryName(thisAssemblyPath);
            List <string> libPaths           = new List <string>();
            ArrayList     libArray           = new ArrayList();

            string dllDirectoryPath = Path.Combine(thisAssemblyFolder, "libssh2");
            string vcruntimePath    = Path.Combine(dllDirectoryPath, "vcruntime140");
            string libssh2Path      = Path.Combine(dllDirectoryPath, "libssh2");
            string zlib1Path        = Path.Combine(dllDirectoryPath, "zlib1");

            if (_libSSH2 != null)
            {
                return;
            }

            try
            {
                libPaths.Add(Path.Combine(thisAssemblyFolder, "libssh2"));
                libPaths.Add(libssh2Path);
                libPaths.Add("libssh2");
                libSSH2Name = UnmanagedLibrary.FirstValidLibraryPath(libPaths.ToArray());
                _libSSH2    = new UnmanagedLibrary(libPaths.ToArray(), DebugFlag);
                libPaths.Clear();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: Loading library libssh2 !\n" + ex.Message);
                libPaths.Clear();
            }
        }
Exemple #3
0
        static LibZmq()
        {
            NativeLib = new UnmanagedLibrary(LibraryName);

            AssignCommonDelegates();
            AssignCurrentVersion(out MajorVersion, out MinorVersion, out PatchVersion);

            if (MajorVersion >= 3)
            {
                zmq_getmsgopt = NativeLib.GetUnmanagedFunction<ZmqGetMsgOptProc>("zmq_getmsgopt");
                zmq_recvmsg = NativeLib.GetUnmanagedFunction<ZmqRecvMsgProc>("zmq_recvmsg");
                zmq_sendmsg = NativeLib.GetUnmanagedFunction<ZmqSendMsgProc>("zmq_sendmsg");
                zmq_msg_init_data = NativeLib.GetUnmanagedFunction<ZmqMsgInitDataProc>("zmq_msg_init_data");
                zmq_msg_move = NativeLib.GetUnmanagedFunction<ZmqMsgMoveProc>("zmq_msg_move");

                PollTimeoutRatio = 1;
            }
            else if (MajorVersion == 2)
            {
                zmq_recvmsg = NativeLib.GetUnmanagedFunction<ZmqRecvMsgProc>("zmq_recv");
                zmq_sendmsg = NativeLib.GetUnmanagedFunction<ZmqSendMsgProc>("zmq_send");

                PollTimeoutRatio = 1000;
            }
        }
Exemple #4
0
        public PythonAPI(PythonVersion pyVer)
        {
            string dllName = pyVer.ToString().ToLower();
            _pythonLibrary = new UnmanagedLibrary(dllName);

            Py_Initialize = _pythonLibrary.GetUnmanagedFunction<Action>("Py_Initialize");
            Py_IsInitialized = _pythonLibrary.GetUnmanagedFunction<FuncInt>("Py_IsInitialized");
            Py_Finalize = _pythonLibrary.GetUnmanagedFunction<Action>("Py_Finalize");
            PyEval_InitThreads = _pythonLibrary.GetUnmanagedFunction<Action>("PyEval_InitThreads");
            PyGILState_Ensure = _pythonLibrary.GetUnmanagedFunction<FuncIntPtr>("PyGILState_Ensure");
            PyGILState_Release = _pythonLibrary.GetUnmanagedFunction<ActionIntPtr>("PyGILState_Release");
            PyThreadState_Get = _pythonLibrary.GetUnmanagedFunction<FuncIntPtr>("PyThreadState_Get");

            PyRun_String = _pythonLibrary.GetUnmanagedFunction<FuncStringIntIntPtrIntPtrIntPtr>("PyRun_String");

            PyErr_Print = _pythonLibrary.GetUnmanagedFunction<Action>("PyErr_Print");
            PyErr_Occurred = _pythonLibrary.GetUnmanagedFunction<FuncIntPtr>("PyErr_Occurred");
            PyErr_Clear = _pythonLibrary.GetUnmanagedFunction<Action>("PyErr_Clear");
            PyErr_Fetch = _pythonLibrary.GetUnmanagedFunction<ActionRIntPtrRIntPtrRIntPtr>("PyErr_Fetch");

            PyImport_AddModule = _pythonLibrary.GetUnmanagedFunction<FuncStringIntPtr>("PyImport_AddModule");
            PyModule_GetDict = _pythonLibrary.GetUnmanagedFunction<FuncIntPtrIntPtr>("PyModule_GetDict");

            Py_IncRef = _pythonLibrary.GetUnmanagedFunction<ActionIntPtr>("Py_IncRef");
            Py_DecRef = _pythonLibrary.GetUnmanagedFunction<ActionIntPtr>("Py_DecRef");

            PyObject_HasAttrString = _pythonLibrary.GetUnmanagedFunction<FuncIntPtrStringInt>("PyObject_HasAttrString");
            PyObject_GetAttrString = _pythonLibrary.GetUnmanagedFunction<FuncIntPtrStringIntPtr>("PyObject_GetAttrString");
            PyObject_SetAttrString = _pythonLibrary.GetUnmanagedFunction<FuncIntPtrStringIntPtrInt>("PyObject_SetAttrString");
            PyObject_Str = _pythonLibrary.GetUnmanagedFunction<FuncIntPtrIntPtr>("PyObject_Str");
            PyObject_Compare = _pythonLibrary.GetUnmanagedFunction<FuncIntPtrIntPtrInt>("PyObject_Compare");
            PyCallable_Check = _pythonLibrary.GetUnmanagedFunction<FuncIntPtrInt>("PyCallable_Check");
            PyObject_CallObject = _pythonLibrary.GetUnmanagedFunction<FuncIntPtrIntPtrIntPtr>("PyObject_CallObject");
            PyObject_Length = _pythonLibrary.GetUnmanagedFunction<FuncIntPtrInt>("PyObject_Length");
            PyObject_Dir = _pythonLibrary.GetUnmanagedFunction<FuncIntPtrIntPtr>("PyObject_Dir");
            PyObject_Type = _pythonLibrary.GetUnmanagedFunction<FuncIntPtrIntPtr>("PyObject_Type");
            PyObject_IsInstance = _pythonLibrary.GetUnmanagedFunction<FuncIntPtrIntPtrInt>("PyObject_IsInstance");

            PyString_FromString = _pythonLibrary.GetUnmanagedFunction<FuncStringIntPtr>("PyString_FromString");
            PyString_AsString = _pythonLibrary.GetUnmanagedFunction<FuncIntPtrIntPtr>("PyString_AsString");

            PySys_GetObject = _pythonLibrary.GetUnmanagedFunction<FuncStringIntPtr>("PySys_GetObject");

            PyInt_AsLong = _pythonLibrary.GetUnmanagedFunction<FuncIntPtrInt>("PyInt_AsLong");
            PyLong_AsLongLong = _pythonLibrary.GetUnmanagedFunction<FuncIntPtrLong>("PyLong_AsLongLong");

            PyFloat_AsDouble = _pythonLibrary.GetUnmanagedFunction<FuncIntPtrDouble>("PyFloat_AsDouble");

            PyTuple_New = _pythonLibrary.GetUnmanagedFunction<FuncIntIntPtr>("PyTuple_New");
            PyTuple_SetItem = _pythonLibrary.GetUnmanagedFunction<FuncIntPtrIntIntPtrInt>("PyTuple_SetItem");

            PyType_Type = _pythonLibrary.GetGlobalVar("PyType_Type");
            PyBaseObject_Type = _pythonLibrary.GetGlobalVar("PyBaseObject_Type");
            PyString_Type = _pythonLibrary.GetGlobalVar("PyString_Type");
            PyUnicode_Type = _pythonLibrary.GetGlobalVar("PyUnicode_Type");
            PyInt_Type = _pythonLibrary.GetGlobalVar("PyInt_Type");
            PyLong_Type = _pythonLibrary.GetGlobalVar("PyLong_Type");
            PyBool_Type = _pythonLibrary.GetGlobalVar("PyBool_Type");
            PyFloat_Type = _pythonLibrary.GetGlobalVar("PyFloat_Type");
        }
Exemple #5
0
        static zmq()
        {
            try { NativeLibSodium = Platform.LoadUnmanagedLibrary(SodiumLibraryName); }
            catch (System.IO.FileNotFoundException) { }

            NativeLib = Platform.LoadUnmanagedLibrary(LibraryName);

            int major, minor, patch;
            version(out major, out minor, out patch);
            Version = new Version(major, minor, patch);

            // Trigger static constructor
            var noSym = ZSymbol.None;

            if (major >= 4)
            {
                // Current Version 4

                // Use default delegate settings from field initializers.
                // "Compatability" is done by "disabling" old methods, or "redirecting" to new methods,
                // so the developer is forced to work against the latest API

                if (minor == 0)
                {
                    sizeof_zmq_msg_t = sizeof_zmq_msg_t_v3;
                }
            }
            else // if (major >= 3)
            {
                // TODO: Backwards compatability for v3

                throw VersionNotSupported(null, ">= 4");
            }
            // else { }
        }
Exemple #6
0
        private static AccessBridgeEntryPointsLegacy LoadEntryPointsLegacy(UnmanagedLibrary library)
        {
            var functions = new AccessBridgeEntryPointsLegacy();

            LoadEntryPointsImpl(library, functions);
            return(functions);
        }
Exemple #7
0
        public void Load()
        {
            if (this.yukkuri == null)
            {
                this.yukkuri = new UnmanagedLibrary(YukkuriDllName);
            }

            if (this.yukkuriDriver == null)
            {
                this.yukkuriDriver = new UnmanagedLibrary(YukkuriDriverDllName);
            }

            if (this.yukkuriDriver == null)
            {
                return;
            }

            if (this.SyntheDelegate == null)
            {
                this.SyntheDelegate =
                    this.yukkuriDriver.GetUnmanagedFunction <Synthe>(nameof(Synthe));
            }

            if (this.FreeWaveDelegate == null)
            {
                this.FreeWaveDelegate =
                    this.yukkuriDriver.GetUnmanagedFunction <FreeWave>(nameof(FreeWave));
            }
        }
        static LibXs()
        {
            NativeLib = new UnmanagedLibrary(LibraryName);

            AssignDelegates();
            AssignCurrentVersion(out MajorVersion, out MinorVersion, out PatchVersion);
        }
Exemple #9
0
    public static bool NativeLoadLibrary(UnmanagedLibrary __instance, ref IntPtr __result, String path)
    {
        if (Dl is null)
        {
            throw new NullReferenceException(nameof(Dl));
        }

        var libraryHandle = Dl.open(path, RTLD_NOW);

        if (libraryHandle == IntPtr.Zero && __instance.ThrowOnLoadFailure)
        {
            var errPtr = Dl.error();
            var msg    = Marshal.PtrToStringAnsi(errPtr);
            if (!String.IsNullOrEmpty(msg))
            {
                throw new TeximpException($"Error loading unmanaged library from path: {path}\n\n{msg}");
            }
            else
            {
                throw new TeximpException($"Error loading unmanaged library from path: {path}");
            }
        }

        __result = libraryHandle;

        return(false);
    }
Exemple #10
0
 static NativeMethods()
 {
     var user32 = new UnmanagedLibrary( "user32" );
     _pGetGestureInfoPtr = user32.GetUnmanagedFunction<GetGestureInfoPtr>( "GetGestureInfo" );
     _pCloseGestureInfoHandle = user32.GetUnmanagedFunction<CloseGestureInfoHandlePtr>( "CloseGestureInfoHandle" );
     _pSetGestureConfig = user32.GetUnmanagedFunction<SetGestureConfigPtr>( "SetGestureConfig" );
 }
Exemple #11
0
 public void AddResourceFileDifferences(string baseResourcesPath, string modifiedResourcesPath)
 {
     using (UnmanagedLibrary unmanagedLibrary1 = new UnmanagedLibrary(baseResourcesPath))
     {
         using (UnmanagedLibrary unmanagedLibrary2 = new UnmanagedLibrary(modifiedResourcesPath))
         {
             string fileName = Path.GetFileName(baseResourcesPath);
             foreach (IResource resource in Enumerable.Where <IResource>(unmanagedLibrary2[(object)10], (Func <IResource, bool>)(o => o.Name.EndsWith(".png", StringComparison.OrdinalIgnoreCase))))
             {
                 bool   flag1  = true;
                 byte[] bytes1 = ResourceExtensions.GetBytes(unmanagedLibrary1.GetResource(resource.Name, (object)10));
                 byte[] bytes2 = ResourceExtensions.GetBytes(resource);
                 if (bytes1 != null && bytes1.Length == bytes2.Length)
                 {
                     bool flag2 = true;
                     for (int index = 0; index < bytes1.Length; ++index)
                     {
                         if ((int)bytes1[index] != (int)bytes2[index])
                         {
                             flag2 = false;
                             break;
                         }
                     }
                     flag1 = !flag2;
                 }
                 if (flag1)
                 {
                     this.ThemeItems.Add((IThemeItem) new ImageResourceThemeItem(fileName, resource.Name, bytes2));
                 }
             }
         }
     }
 }
 protected override void Dispose(bool isDisposing)
 {
     if (isDisposing && this.muiFile != null)
     {
         using (UnmanagedLibrary unmanagedLibrary = new UnmanagedLibrary(this.muiFile))
         {
             foreach (object index in unmanagedLibrary.ResourceTypes)
             {
                 string str = index as string;
                 if ((str == null || !(str == "MUI")) && (str != null || (int)index != 16))
                 {
                     foreach (Resource resource1 in unmanagedLibrary[index])
                     {
                         IResource resource2 = resource1.ID.HasValue ? this.GetResource(resource1.ID.Value, index) : this.GetResource(resource1.Name, index);
                         foreach (ushort num in resource1.Languages)
                         {
                             resource2.Update(resource1.GetBytes(new ushort?(num)), new ushort?(num));
                         }
                     }
                 }
             }
         }
     }
     base.Dispose(isDisposing);
     if (this.mode != UnmanagedLibraryAccess.Write)
     {
         return;
     }
     this.OnMediaCenterLibraryUpdated(new MediaCenterLibraryUpdatedEventArgs(this.File));
 }
Exemple #13
0
 public static void Close()
 {
     if (_libSSH2 != null)
     {
         _libSSH2.Close();
         _libSSH2 = null;
     }
 }
 public void Free()
 {
     if (this.yukkuriLib != null)
     {
         this.yukkuriLib.Dispose();
         this.yukkuriLib = null;
     }
 }
Exemple #15
0
 protected NativeApiContainer(ref NativeApiContext ctx)
 {
     _lib         = ctx.Library;
     _entryPoints = new IntPtr[ctx.SlotCount ?? 0];
     if ((ctx.Strategy & Strategy.Strategy2) != 0)
     {
         LoadProperties();
     }
 }
Exemple #16
0
    public TestCalli()
    {
        base.Name = "Calli";

        this.nativeLib = new UnmanagedLibrary("Native");

        IntPtr nativeMethodAddress =
            this.nativeLib.GetUnmanagedFunctionAddress(
                "DoWithNoParameters"
                );

        this.doWithNoParameters =
            GetCalliDelegate
            <DelegateWithNoParameters>(
                nativeMethodAddress
                );

        nativeMethodAddress =
            this.nativeLib.GetUnmanagedFunctionAddress(
                "DoWithInt"
                );
        this.doWithInt =
            GetCalliDelegate
            <DelegateWithInt>(
                nativeMethodAddress
                );

        nativeMethodAddress =
            this.nativeLib.GetUnmanagedFunctionAddress(
                "DoWithDouble"
                );
        this.doWithDouble =
            GetCalliDelegate
            <DelegateWithDouble>(
                nativeMethodAddress
                );

        nativeMethodAddress =
            this.nativeLib.GetUnmanagedFunctionAddress(
                "DoWithIntPointer"
                );
        this.doWithIntPointer =
            GetCalliDelegate
            <DelegateWithIntPointer>(
                nativeMethodAddress
                );

        nativeMethodAddress =
            this.nativeLib.GetUnmanagedFunctionAddress(
                "DoWithDoublePointer"
                );
        this.doWithDoublePointer =
            GetCalliDelegate
            <DelegateWithDoublePointer>(
                nativeMethodAddress
                );
    }
Exemple #17
0
        internal static NativeApiContainer UseStrategyOne(UnmanagedLibrary unmanagedLibrary, Type type, Strategy strat)
        {
            var ctx = new NativeApiContext(unmanagedLibrary, strat);

            return((NativeApiContainer)Activator.CreateInstance(
                       (GetImplementationInDomain(type, AppDomain.CurrentDomain) ?? LibraryBuilder
                        .CreateAssembly(BuilderOptions.GetDefault(type))
                        .GetTypes().FirstOrDefault(type.IsAssignableFrom)) ??
                       throw new InvalidOperationException("Failed to create type."), ctx));
        }
 private void Release()
 {
     if (_disposed)
     {
         throw new ObjectDisposedException(GetType().FullName);
     }
     if (_libraryHandle != IntPtr.Zero)
     {
         UnmanagedLibrary.Unload(_libraryHandle);
         _libraryHandle = IntPtr.Zero;
     }
 }
        static LibZmq()
        {
            NativeLib = new UnmanagedLibrary(LibraryName);

            AssignCommonDelegates();
            AssignCurrentVersion(out MajorVersion, out MinorVersion, out PatchVersion);

            if (MajorVersion >= 3)
            {
                zmq_msg_get = NativeLib.GetUnmanagedFunction<ZmqMsgGetProc>("zmq_msg_get");
                zmq_msg_init_data = NativeLib.GetUnmanagedFunction<ZmqMsgInitDataProc>("zmq_msg_init_data");
                zmq_msg_move = NativeLib.GetUnmanagedFunction<ZmqMsgMoveProc>("zmq_msg_move");

                var zmq_msg_recv_impl = NativeLib.GetUnmanagedFunction<ZmqMsgRecvProc>("zmq_msg_recv");
                zmq_msg_recv = zmq_msg_recv_impl;
                //used to receive raw buffer (rjoshi)
                var zmq_buffer_recv_impl = NativeLib.GetUnmanagedFunction<ZmqBufferRecvProc>("zmq_recv");
                zmq_buffer_recv = zmq_buffer_recv_impl;

                var zmq_msg_send_impl = NativeLib.GetUnmanagedFunction<ZmqMsgSendProc>("zmq_msg_send");
                zmq_msg_send = zmq_msg_send_impl;
                //used to send raw buffer (rjoshi)
                var zmq_buffer_send_impl = NativeLib.GetUnmanagedFunction<ZmqBufferSendProc>("zmq_send");
                zmq_buffer_send = zmq_buffer_send_impl;

                zmq_ctx_new = NativeLib.GetUnmanagedFunction<ZmqCtxNewProc>("zmq_ctx_new");
                zmq_ctx_destroy = NativeLib.GetUnmanagedFunction<ZmqCtxDestroyProc>("zmq_ctx_destroy");
                zmq_ctx_get = NativeLib.GetUnmanagedFunction<ZmqCtxGetProc>("zmq_ctx_get");
                zmq_ctx_set = NativeLib.GetUnmanagedFunction<ZmqCtxSetProc>("zmq_ctx_set");
                zmq_ctx_set_monitor = NativeLib.GetUnmanagedFunction<ZmqCtxSetMonitorProc>("zmq_ctx_set_monitor");

                zmq_unbind = NativeLib.GetUnmanagedFunction<ZmqBindProc>("zmq_unbind");
                zmq_disconnect = NativeLib.GetUnmanagedFunction<ZmqConnectProc>("zmq_disconnect");

                PollTimeoutRatio = 1;
                ZmqMsgTSize = Zmq3MsgTSize;
            }
            else if (MajorVersion == 2)
            {
                var zmq_msg_recv_impl = NativeLib.GetUnmanagedFunction<ZmqMsgRecvProc>("zmq_recv");
                var zmq_msg_send_impl = NativeLib.GetUnmanagedFunction<ZmqMsgSendProc>("zmq_send");
                zmq_msg_send = (msg, sck, flags) => zmq_msg_send_impl(sck, msg, flags);
                zmq_msg_recv = (msg, sck, flags) => zmq_msg_recv_impl(sck, msg, flags);

                var zmq_init = NativeLib.GetUnmanagedFunction<ZmqInitProc>("zmq_init");
                zmq_ctx_new = () => zmq_init(1);
                zmq_ctx_destroy = NativeLib.GetUnmanagedFunction<ZmqCtxDestroyProc>("zmq_term");

                PollTimeoutRatio = 1000;
                ZmqMsgTSize = Zmq2MsgTSize;
            }
        }
        public void Free()
        {
            if (this.lib != null)
            {
                this.lib.Dispose();
                this.lib = null;
            }

            if (File.Exists(DllName))
            {
                File.Delete(DllName);
            }
        }
        private void Initialize()
        {
            if (IsModuleLoaded("AquesTalk"))
            {
                return;
            }

            if (!File.Exists(DllName))
            {
                File.WriteAllBytes(DllName, Resources.AquesTalk);
            }

            this.lib = new UnmanagedLibrary(DllName);
        }
Exemple #22
0
        public void Free()
        {
            if (this.yukkuriLib != null)
            {
                this.IsLoadedAppKey = false;

                this.SetDevKeyDelegate = null;
                this.SynthesizeDelegate = null;
                this.SynthesizeUTF16Delegate = null;
                this.FreeWaveDelegate = null;

                this.yukkuriLib.Dispose();
                this.yukkuriLib = null;
            }
        }
        const int MinD3DX9Version = 32; // DirectX SDK December 2006

        public static UnmanagedLibrary LoadDirectX9()
        {
            for (var ver = MaxD3DX9Version; ver >= MinD3DX9Version; --ver)
            {
                var dllname = "d3dx9_" + Convert.ToString(ver) + ".dll";
                var handle  = UnmanagedLibrary.LoadLibrary(
                    dllname,
                    false);
                if (handle != null)
                {
                    return(handle);
                }
            }
            throw new Exception("DX9 dll couldn't be located");
        }
        public RglibInterface(string libraryPath)
        {
            try {
                if (!string.IsNullOrEmpty(libraryPath))
                {
                    _libraryHandle = UnmanagedLibrary.Load(libraryPath);
                }

                _delegates = new Delegates(_libraryHandle);
            }
            catch (Exception ex) {
                Console.WriteLine(ex.Message);
                Release();
                throw;
            }
        }
Exemple #25
0
        public void Free()
        {
            if (this.yukkuriDriver != null)
            {
                this.IsLoadedAppKey = false;

                this.SyntheDelegate   = null;
                this.FreeWaveDelegate = null;

                this.yukkuriDriver.Dispose();
                this.yukkuriDriver = null;

                this.yukkuri.Dispose();
                this.yukkuri = null;
            }
        }
 /// <summary>
 /// Initializes new instance of MockDelegates class
 /// </summary>
 /// <param name="libraryHandle">Handle to the PKCS#11 library</param>
 internal MockDelegates(IntPtr libraryHandle)
 {
     // Get delegates from the dynamically loaded shared PKCS#11 library
     if (libraryHandle != IntPtr.Zero)
     {
         this.C_GetUnmanagedStructSizeList = UnmanagedLibrary.GetFunctionDelegate <C_GetUnmanagedStructSizeListDelegate>(libraryHandle, "C_GetUnmanagedStructSizeList");
         this.C_EjectToken       = UnmanagedLibrary.GetFunctionDelegate <C_EjectTokenDelegate>(libraryHandle, "C_EjectToken");
         this.C_InteractiveLogin = UnmanagedLibrary.GetFunctionDelegate <C_InteractiveLoginDelegate>(libraryHandle, "C_InteractiveLogin");
     }
     // Get delegates from the statically linked PKCS#11 library
     else
     {
         this.C_GetUnmanagedStructSizeList = NativeMethods.C_GetUnmanagedStructSizeList;
         this.C_EjectToken       = NativeMethods.C_EjectToken;
         this.C_InteractiveLogin = NativeMethods.C_InteractiveLogin;
     }
 }
Exemple #27
0
        /// <summary>
        /// Get delegates with C_GetFunctionList function from the dynamically loaded shared PKCS#11 library
        /// </summary>
        /// <param name="libraryHandle">Handle to the PKCS#11 library</param>
        private void InitializeWithGetFunctionList(IntPtr libraryHandle)
        {
            IntPtr cGetFunctionListPtr = UnmanagedLibrary.GetFunctionPointer(libraryHandle, "C_GetFunctionList");
            C_GetFunctionListDelegate cGetFunctionList = UnmanagedLibrary.GetDelegateForFunctionPointer <C_GetFunctionListDelegate>(cGetFunctionListPtr);

            IntPtr functionList = IntPtr.Zero;

            CKR rv = (CKR)Convert.ToUInt32(cGetFunctionList(out functionList));

            if ((rv != CKR.CKR_OK) || (functionList == IntPtr.Zero))
            {
                throw new Pkcs11Exception("C_GetFunctionList", rv);
            }

            CK_FUNCTION_LIST ckFunctionList = (CK_FUNCTION_LIST)UnmanagedMemory.Read(functionList, typeof(CK_FUNCTION_LIST));

            Initialize(ckFunctionList);
        }
Exemple #28
0
        protected override void Load()
        {
            string attribute = this.LinkElement.GetAttribute("ResourceProviderId");

            this.titleId = this.GetTitleId();
            int.TryParse(this.titleId, out this.titleID);
            this.imageBaseName = this.LinkElement.GetAttribute("ImageBaseName");
            if (attribute == "Spotlight")
            {
                this.resourceFile = PackageQuickLink.GetPackagePath("MCESpotlight", "MCESpotlight", "SpotlightResources.dll");
            }
            else if (attribute == "NetTV")
            {
                this.resourceFile = PackageQuickLink.GetPackagePath("NetTV", "Browse", "NetTVResources.dll");
            }
            else
            {
                if (!(attribute == "NetOpSM"))
                {
                    throw new ArgumentException("Unknown provider: " + attribute);
                }
                this.resourceFile = PackageQuickLink.GetPackagePath("MCEClientUX", "NetOp", "SMResources.dll");
            }
            if (File.Exists(this.resourceFile))
            {
                using (UnmanagedLibrary unmanagedLibrary = new UnmanagedLibrary(this.resourceFile))
                {
                    this.Title = ResourceExtensions.GetStringResource((IResourceLibrary)unmanagedLibrary, this.titleID);
                    byte[] bytes1 = ResourceExtensions.GetBytes(unmanagedLibrary.GetResource(this.imageBaseName + ".NoFocus.png", (object)10));
                    if (bytes1 != null)
                    {
                        BitmapDecoder bitmapDecoder = BitmapDecoder.Create((Stream) new MemoryStream(bytes1), BitmapCreateOptions.None, BitmapCacheOption.Default);
                        this.SetValue(XmlQuickLink.NonFocusImageProperty, (object)bitmapDecoder.Frames[0]);
                    }
                    byte[] bytes2 = ResourceExtensions.GetBytes(unmanagedLibrary.GetResource(this.imageBaseName + ".Focus.png", (object)10));
                    if (bytes2 != null)
                    {
                        BitmapDecoder bitmapDecoder = BitmapDecoder.Create((Stream) new MemoryStream(bytes2), BitmapCreateOptions.None, BitmapCacheOption.Default);
                        this.SetValue(XmlQuickLink.ImageProperty, (object)bitmapDecoder.Frames[0]);
                    }
                }
            }
            this.SetValue(XmlQuickLink.IsValidPropertyKey, (object)(string.IsNullOrEmpty(this.Title) ? false : (this.Image != null ? true : false)));
        }
Exemple #29
0
        public void Free()
        {
            if (this.kanji2KoeLib != null)
            {
                // ハンドルを開放する
                if (this.kanji2KoeHandle != IntPtr.Zero)
                {
                    this.releaseDelegate?.Invoke(this.kanji2KoeHandle);
                    this.kanji2KoeHandle = IntPtr.Zero;
                }

                this.createDelegate  = null;
                this.releaseDelegate = null;
                this.convertDelegate = null;

                this.kanji2KoeLib.Dispose();
                this.kanji2KoeLib = null;
            }
        }
Exemple #30
0
        public void Load()
        {
            if (this.yukkuri == null)
            {
                if (!File.Exists(this.YukkuriDllName))
                {
                    throw new FileNotFoundException(
                              $"{Path.GetFileName(this.YukkuriDllName)} が見つかりません。アプリケーションの配置を確認してください。",
                              this.YukkuriDllName);
                }

                this.yukkuri = new UnmanagedLibrary(this.YukkuriDllName);
            }

            if (this.yukkuriDriver == null)
            {
                if (!File.Exists(this.YukkuriDriverDllName))
                {
                    throw new FileNotFoundException(
                              $"{Path.GetFileName(this.YukkuriDriverDllName)} が見つかりません。アプリケーションの配置を確認してください。",
                              this.YukkuriDriverDllName);
                }

                this.yukkuriDriver = new UnmanagedLibrary(this.YukkuriDriverDllName);
            }

            if (this.yukkuriDriver == null)
            {
                return;
            }

            if (this.SyntheDelegate == null)
            {
                this.SyntheDelegate =
                    this.yukkuriDriver.GetUnmanagedFunction <Synthe>(nameof(Synthe));
            }

            if (this.FreeWaveDelegate == null)
            {
                this.FreeWaveDelegate =
                    this.yukkuriDriver.GetUnmanagedFunction <FreeWave>(nameof(FreeWave));
            }
        }
Exemple #31
0
        public void Load()
        {
            if (this.kanji2KoeLib == null)
            {
                this.kanji2KoeLib = new UnmanagedLibrary(this.Kanji2KoeDllName);
            }

            if (this.kanji2KoeLib == null)
            {
                return;
            }

            if (this.createDelegate == null)
            {
                this.createDelegate =
                    this.kanji2KoeLib.GetUnmanagedFunction <AqKanji2Koe_Create>(nameof(AqKanji2Koe_Create));

                // 言語処理モジュールのインスタンスを生成しそのハンドルを取得する
                int err = 0;
                this.kanji2KoeHandle = this.createDelegate.Invoke(
                    this.Kanji2KoeDictionaryName,
                    ref err);
            }

            if (this.releaseDelegate == null)
            {
                this.releaseDelegate =
                    this.kanji2KoeLib.GetUnmanagedFunction <AqKanji2Koe_Release>(nameof(AqKanji2Koe_Release));
            }

            if (this.convertDelegate == null)
            {
                this.convertDelegate =
                    this.kanji2KoeLib.GetUnmanagedFunction <AqKanji2Koe_Convert>(nameof(AqKanji2Koe_Convert));
            }

            if (this.convertWDelegate == null)
            {
                this.convertWDelegate =
                    this.kanji2KoeLib.GetUnmanagedFunction <AqKanji2Koe_ConvertW>(nameof(AqKanji2Koe_ConvertW));
            }
        }
Exemple #32
0
        internal static NativeApiContainer Activate(UnmanagedLibrary lib, Type type, Strategy strategy)
        {
            NativeApiContainer container = null;

            if (strategy == Strategy.Infer)
            {
                if (type.IsAbstract)
                {
                    container = UseStrategyOne(lib, type, strategy);
                    // TODO if (properties.Any(x => x.Type.IsFunctionPointer)){UseStrategyTwo();}
                }
                else
                {
                    // TODO UseStrategyTwo
                    throw new NotImplementedException(
                              "Strategy 2 has not been implemented yet, please use strategy 1 by making your class abstract.");
                }
            }

            return(container);
        }
Exemple #33
0
        internal static bool NativeLoadLibrary(UnmanagedLibrary __instance, ref IntPtr __result, String path)
        {
            var libraryHandle = dl.open(path, RTLD_NOW);

            if (libraryHandle == IntPtr.Zero && __instance.ThrowOnLoadFailure)
            {
                var errPtr = dl.error();
                var msg    = Marshal.PtrToStringAnsi(errPtr);
                if (!String.IsNullOrEmpty(msg))
                {
                    throw new TeximpException(String.Format("Error loading unmanaged library from path: {0}\n\n{1}", path, msg));
                }
                else
                {
                    throw new TeximpException(String.Format("Error loading unmanaged library from path: {0}", path));
                }
            }

            __result = libraryHandle;

            return(false);
        }
        public void Load()
        {
            if (!NetiveMethods.IsModuleLoaded(YukkuriLibName))
            {
                this.yukkuriLib = new UnmanagedLibrary(YukkuriDllName);
            }

            if (this.yukkuriLib != null)
            {
                if (this.SynthesizeDelegate == null)
                {
                    this.SynthesizeDelegate =
                        this.yukkuriLib.GetUnmanagedFunction <AquesTalk_Synthe>(nameof(AquesTalk_Synthe));
                }

                if (this.FreeWaveDelegate == null)
                {
                    this.FreeWaveDelegate =
                        this.yukkuriLib.GetUnmanagedFunction <AquesTalk_FreeWave>(nameof(AquesTalk_FreeWave));
                }
            }
        }
Exemple #35
0
        /// <summary>
        /// Obtains a list of unmanaged struct sizes.
        /// This method should be used only for testing purposes with PKCS11-MOCK module.
        /// </summary>
        /// <param name="pkcs11">Instance of the extended class</param>
        /// <param name="sizeList">
        /// If set to null then the number of sizes is returned in "count" parameter, without actually returning a list of sizes.
        /// If not set to null then "count" parameter must contain the lenght of sizeList array and size list is returned in "sizeList" parameter.
        /// </param>
        /// <param name="count">Location that receives the number of sizes</param>
        /// <returns>CKR_ARGUMENTS_BAD, CKR_BUFFER_TOO_SMALL, CKR_OK</returns>
        public static CKR C_GetUnmanagedStructSizeList(this LLA81.Pkcs11 pkcs11, ulong[] sizeList, ref ulong count)
        {
            if (pkcs11.Disposed)
            {
                throw new ObjectDisposedException(pkcs11.GetType().FullName);
            }

            Delegates.C_GetUnmanagedStructSizeListDelegate8x cGetUnmanagedStructSizeList = null;

            if (pkcs11.LibraryHandle != IntPtr.Zero)
            {
                IntPtr cGetUnmanagedStructSizeListPtr = UnmanagedLibrary.GetFunctionPointer(pkcs11.LibraryHandle, "C_GetUnmanagedStructSizeList");
                cGetUnmanagedStructSizeList = UnmanagedLibrary.GetDelegateForFunctionPointer <Delegates.C_GetUnmanagedStructSizeListDelegate8x>(cGetUnmanagedStructSizeListPtr);
            }
            else
            {
                cGetUnmanagedStructSizeList = NativeMethods.C_GetUnmanagedStructSizeList8x;
            }

            ulong rv = cGetUnmanagedStructSizeList(sizeList, ref count);

            return((CKR)Convert.ToUInt32(rv));
        }
        /// <summary>
        /// Logs a user into a token interactively.
        /// This method should be used only for testing purposes with PKCS11-MOCK module.
        /// </summary>
        /// <param name="pkcs11">Instance of the extended class</param>
        /// <param name="session">The session's handle</param>
        /// <returns>CKR_CRYPTOKI_NOT_INITIALIZED, CKR_SESSION_HANDLE_INVALID, CKR_USER_ALREADY_LOGGED_IN, CKR_USER_ANOTHER_ALREADY_LOGGED_IN, CKR_OK</returns>
        public static CKR C_InteractiveLogin(this LLA41.Pkcs11 pkcs11, uint session)
        {
            if (pkcs11.Disposed)
            {
                throw new ObjectDisposedException(pkcs11.GetType().FullName);
            }

            Delegates.C_InteractiveLogin4x cInteractiveLogin = null;

            if (pkcs11.LibraryHandle != IntPtr.Zero)
            {
                IntPtr cInteractiveLoginPtr = UnmanagedLibrary.GetFunctionPointer(pkcs11.LibraryHandle, "C_InteractiveLogin");
                cInteractiveLogin = UnmanagedLibrary.GetDelegateForFunctionPointer <Delegates.C_InteractiveLogin4x>(cInteractiveLoginPtr);
            }
            else
            {
                cInteractiveLogin = NativeMethods.C_InteractiveLogin4x;
            }

            uint rv = cInteractiveLogin(session);

            return((CKR)rv);
        }
        /// <summary>
        /// Ejects token from slot.
        /// This method should be used only for testing purposes with PKCS11-MOCK module.
        /// </summary>
        /// <param name="pkcs11">Instance of the extended class</param>
        /// <param name="slotId">The ID of the token's slot</param>
        /// <returns>CKR_CRYPTOKI_NOT_INITIALIZED, CKR_SLOT_ID_INVALID, CKR_OK</returns>
        public static CKR C_EjectToken(this LLA81.Pkcs11 pkcs11, ulong slotId)
        {
            if (pkcs11.Disposed)
            {
                throw new ObjectDisposedException(pkcs11.GetType().FullName);
            }

            Delegates.C_EjectToken8x cEjectToken = null;

            if (pkcs11.LibraryHandle != IntPtr.Zero)
            {
                IntPtr cEjectTokenPtr = UnmanagedLibrary.GetFunctionPointer(pkcs11.LibraryHandle, "C_EjectToken");
                cEjectToken = UnmanagedLibrary.GetDelegateForFunctionPointer <Delegates.C_EjectToken8x>(cEjectTokenPtr);
            }
            else
            {
                cEjectToken = NativeMethods.C_EjectToken8x;
            }

            ulong rv = cEjectToken(slotId);

            return((CKR)Convert.ToUInt32(rv));
        }
Exemple #38
0
        private static void LoadEntryPointsImpl(UnmanagedLibrary library, object functions)
        {
            var publicMembers = BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance;

            foreach (var property in functions.GetType().GetProperties(publicMembers))
            {
                var name = property.Name;

                // All entry point names have lower case, except for "Windows_run"
                switch (name)
                {
                case "Windows_run":
                    break;

                default:
                    name = char.ToLower(name[0], CultureInfo.InvariantCulture) + name.Substring(1);
                    break;
                }

                // Event setters have a "FP" suffix
                if (name.StartsWith("set") && name != "setTextContents")
                {
                    name += "FP";
                }

                try {
                    var function = library.GetUnmanagedFunction(name, property.PropertyType);
                    if (function == null)
                    {
                        throw new ApplicationException(string.Format("Function {0} not found in AccessBridge", name));
                    }
                    property.SetValue(functions, function, null);
                } catch (Exception e) {
                    throw new ArgumentException(string.Format("Error loading function {0} from access bridge library", name), e);
                }
            }
        }
Exemple #39
0
        static Utils()
        {
            var sysroot = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
            var f40 = Path.Combine(sysroot, "Microsoft.NET", Environment.Is64BitProcess ? "Framework64" : "Framework", "v4.0.30319", "fusion.dll");
            var f20 = Path.Combine(sysroot, "Microsoft.NET", Environment.Is64BitProcess ? "Framework64" : "Framework", "v2.0.50727", "fusion.dll");

            if (File.Exists(f40)) {
                var f40dll = LoadLibrary(f40);
                if (f40dll != IntPtr.Zero) {
                    Net40Fusion = new UnmanagedLibrary(f40dll);
                    CreateAssemblyEnum40 = (CreateAssemblyEnumDelegate)Marshal.GetDelegateForFunctionPointer(Net40Fusion.GetProcAddr("CreateAssemblyEnum"), typeof (CreateAssemblyEnumDelegate));
                    CreateAssemblyNameObject40 = (CreateAssemblyNameObjectDelegate)Marshal.GetDelegateForFunctionPointer(Net40Fusion.GetProcAddr("CreateAssemblyNameObject"), typeof (CreateAssemblyNameObjectDelegate));
                    CreateAssemblyCache40 = (CreateAssemblyCacheDelegate)Marshal.GetDelegateForFunctionPointer(Net40Fusion.GetProcAddr("CreateAssemblyCache"), typeof (CreateAssemblyCacheDelegate));
                    CreateInstallReferenceEnum40 = (CreateInstallReferenceEnumDelegate)Marshal.GetDelegateForFunctionPointer(Net40Fusion.GetProcAddr("CreateInstallReferenceEnum"), typeof (CreateInstallReferenceEnumDelegate));
                }
            }

            if (File.Exists(f20)) {
                var f20dll = LoadLibrary(f20);
                if (f20dll != IntPtr.Zero) {
                    Net20Fusion = new UnmanagedLibrary(f20dll);
                    CreateAssemblyEnum20 = (CreateAssemblyEnumDelegate)Marshal.GetDelegateForFunctionPointer(Net20Fusion.GetProcAddr("CreateAssemblyEnum"), typeof (CreateAssemblyEnumDelegate));
                    CreateAssemblyNameObject20 = (CreateAssemblyNameObjectDelegate)Marshal.GetDelegateForFunctionPointer(Net20Fusion.GetProcAddr("CreateAssemblyNameObject"), typeof (CreateAssemblyNameObjectDelegate));
                    CreateAssemblyCache20 = (CreateAssemblyCacheDelegate)Marshal.GetDelegateForFunctionPointer(Net20Fusion.GetProcAddr("CreateAssemblyCache"), typeof (CreateAssemblyCacheDelegate));
                    CreateInstallReferenceEnum20 = (CreateInstallReferenceEnumDelegate)Marshal.GetDelegateForFunctionPointer(Net20Fusion.GetProcAddr("CreateInstallReferenceEnum"), typeof (CreateInstallReferenceEnumDelegate));
                }
            }
        }
 static Libunqlite()
 {
     NativeLib = new UnmanagedLibrary(LibraryName);
     AssignCommonDelegates();
 }
Exemple #41
0
		static crypto()
		{
			NativeLib = Platform.LoadUnmanagedLibrary(LibraryName);
		}