Inheritance: SafeHandleZeroOrMinusOneIsInvalid
コード例 #1
0
ファイル: SevenZipFormat.cs プロジェクト: GiladShoham/RedRock
        public SevenZipFormat(string sevenZipLibPath)
        {
            LibHandle = LoadLibrary(sevenZipLibPath);
              if (LibHandle.IsInvalid)
            throw new Win32Exception();

              IntPtr FunctionPtr = GetProcAddress(LibHandle, "GetHandlerProperty");
              // Not valid dll
              if (FunctionPtr == IntPtr.Zero)
              {
            LibHandle.Close();
            throw new ArgumentException();
              }
        }
コード例 #2
0
        static WebSocketProtocolComponent()
        {
            s_webSocketDllHandle = Interop.Kernel32.LoadLibraryExW(Interop.Libraries.WebSocket, IntPtr.Zero, 0);

            if (!s_webSocketDllHandle.IsInvalid)
            {
                s_supportedVersion = GetSupportedVersion();

                s_ServerFakeRequestHeaders = new Interop.WebSocket.HttpHeader[]
                {
                    new Interop.WebSocket.HttpHeader()
                    {
                        Name = HttpKnownHeaderNames.Connection,
                        NameLength = (uint)HttpKnownHeaderNames.Connection.Length,
                        Value = HttpKnownHeaderNames.Upgrade,
                        ValueLength = (uint)HttpKnownHeaderNames.Upgrade.Length
                    },
                    new Interop.WebSocket.HttpHeader()
                    {
                        Name = HttpKnownHeaderNames.Upgrade,
                        NameLength = (uint)HttpKnownHeaderNames.Upgrade.Length,
                        Value = WebSocketValidate.WebSocketUpgradeToken,
                        ValueLength = (uint)WebSocketValidate.WebSocketUpgradeToken.Length
                    },
                    new Interop.WebSocket.HttpHeader()
                    {
                        Name = HttpKnownHeaderNames.Host,
                        NameLength = (uint)HttpKnownHeaderNames.Host.Length,
                        Value = string.Empty,
                        ValueLength = 0
                    },
                    new Interop.WebSocket.HttpHeader()
                    {
                        Name = HttpKnownHeaderNames.SecWebSocketVersion,
                        NameLength = (uint)HttpKnownHeaderNames.SecWebSocketVersion.Length,
                        Value = s_supportedVersion,
                        ValueLength = (uint)s_supportedVersion.Length
                    },
                    new Interop.WebSocket.HttpHeader()
                    {
                        Name = HttpKnownHeaderNames.SecWebSocketKey,
                        NameLength = (uint)HttpKnownHeaderNames.SecWebSocketKey.Length,
                        Value = s_dummyWebsocketKeyBase64,
                        ValueLength = (uint)s_dummyWebsocketKeyBase64.Length
                    }
                };
            }
        }
コード例 #3
0
 internal static string TryFormatMessage(Microsoft.Win32.SafeHandles.SafeLibraryHandle hModule, uint messageNum, string[] insertionStrings)
 {
     if (insertionStrings.Length != 0)
     {
         string str = UnsafeTryFormatMessage(hModule, messageNum, new string[0]);
         if (str == null)
         {
             return(null);
         }
         int num = 0;
         for (int i = 0; i < str.Length; i++)
         {
             if ((str[i] == '%') && (str.Length > (i + 1)))
             {
                 StringBuilder builder = new StringBuilder();
                 while (((i + 1) < str.Length) && char.IsDigit(str[i + 1]))
                 {
                     builder.Append(str[i + 1]);
                     i++;
                 }
                 i++;
                 if (builder.Length > 0)
                 {
                     int result = -1;
                     if (int.TryParse(builder.ToString(), NumberStyles.None, CultureInfo.InvariantCulture, out result))
                     {
                         num = Math.Max(num, result);
                     }
                 }
             }
         }
         if (num > insertionStrings.Length)
         {
             string[] destinationArray = new string[num];
             Array.Copy(insertionStrings, destinationArray, insertionStrings.Length);
             for (int j = insertionStrings.Length; j < destinationArray.Length; j++)
             {
                 destinationArray[j] = "%" + (j + 1);
             }
             insertionStrings = destinationArray;
         }
     }
     return(UnsafeTryFormatMessage(hModule, messageNum, insertionStrings));
 }
コード例 #4
0
        internal static string UnsafeTryFormatMessage(Microsoft.Win32.SafeHandles.SafeLibraryHandle hModule, uint messageNum, string[] insertionStrings)
        {
            string        str      = null;
            int           num      = 0;
            StringBuilder lpBuffer = new StringBuilder(0x400);
            int           dwFlags  = 0x2800;

            IntPtr[]   ptrArray    = new IntPtr[insertionStrings.Length];
            GCHandle[] handleArray = new GCHandle[insertionStrings.Length];
            GCHandle   handle      = GCHandle.Alloc(ptrArray, GCHandleType.Pinned);

            if (insertionStrings.Length == 0)
            {
                dwFlags |= 0x200;
            }
            try
            {
                for (int i = 0; i < handleArray.Length; i++)
                {
                    handleArray[i] = GCHandle.Alloc(insertionStrings[i], GCHandleType.Pinned);
                    ptrArray[i]    = handleArray[i].AddrOfPinnedObject();
                }
                int num4 = 0x7a;
                while ((num == 0) && (num4 == 0x7a))
                {
                    num = Microsoft.Win32.SafeNativeMethods.FormatMessage(dwFlags, hModule, messageNum, 0, lpBuffer, lpBuffer.Capacity, ptrArray);
                    if (num == 0)
                    {
                        num4 = Marshal.GetLastWin32Error();
                        if (num4 == 0x7a)
                        {
                            lpBuffer.Capacity *= 2;
                        }
                    }
                }
            }
            catch
            {
                num = 0;
            }
            finally
            {
                for (int j = 0; j < handleArray.Length; j++)
                {
                    if (handleArray[j].IsAllocated)
                    {
                        handleArray[j].Free();
                    }
                }
                handle.Free();
            }
            if (num > 0)
            {
                str = lpBuffer.ToString();
                if ((str.Length > 1) && (str[str.Length - 1] == '\n'))
                {
                    str = str.Substring(0, str.Length - 2);
                }
            }
            return(str);
        }
コード例 #5
0
 public static extern IntPtr GetProcAddress(SafeLibraryHandle hModule, string lpProcName);
コード例 #6
0
 public FilterInfo(Microsoft.Win32.SafeHandles.SafeLibraryHandle filterLibrary, Guid filterPersistClass, Nomad.FilterReader.FilterReader.DllGetClassObject getClassObject)
 {
     this.FilterLibrary = filterLibrary;
     this.FilterPersistClass = filterPersistClass;
     this.GetClassObject = getClassObject;
 }
コード例 #7
0
		/// <summary>Constructor to load a dll and be responible for freeing it.</summary>
		/// <param name="handle">Handle to the loaded library</param>
		/// <param name="path">Full path of library to load</param>
		private UnmanagedLibrary(SafeLibraryHandle handle, string path)
		{
			this.Handle = handle;
			this.Path = path;
		}
コード例 #8
0
 protected WdxContent(Microsoft.Win32.SafeHandles.SafeLibraryHandle libHandle)
 {
     this.LibHandle = libHandle;
     IntPtr procAddress = Windows.GetProcAddress(this.LibHandle, "ContentGetDetectString");
     if (procAddress != IntPtr.Zero)
     {
         this.ContentGetDetectString = (ContentGetDetectStringHandler) Marshal.GetDelegateForFunctionPointer(procAddress, typeof(ContentGetDetectStringHandler));
     }
     this.ContentGetSupportedField = (ContentGetSupportedFieldHandler) Marshal.GetDelegateForFunctionPointer(Windows.GetProcAddress(this.LibHandle, "ContentGetSupportedField"), typeof(ContentGetSupportedFieldHandler));
     procAddress = Windows.GetProcAddress(this.LibHandle, "ContentGetValueW");
     if (procAddress != IntPtr.Zero)
     {
         this.ContentGetValueW = (ContentGetValueWHandler) Marshal.GetDelegateForFunctionPointer(procAddress, typeof(ContentGetValueWHandler));
     }
     else
     {
         procAddress = Windows.GetProcAddress(this.LibHandle, "ContentGetValue");
         if (procAddress == IntPtr.Zero)
         {
             throw new ArgumentException();
         }
         this.ContentGetValue = (ContentGetValueHandler) Marshal.GetDelegateForFunctionPointer(procAddress, typeof(ContentGetValueHandler));
     }
     procAddress = Windows.GetProcAddress(this.LibHandle, "ContentGetSupportedFieldFlags");
     if (procAddress != IntPtr.Zero)
     {
         this.ContentGetSupportedFieldFlags = (ContentGetSupportedFieldFlagsHandler) Marshal.GetDelegateForFunctionPointer(procAddress, typeof(ContentGetSupportedFieldFlagsHandler));
     }
     procAddress = Windows.GetProcAddress(this.LibHandle, "ContentSetValueW");
     if (procAddress != IntPtr.Zero)
     {
         this.ContentSetValueW = (ContentSetValueWHandler) Marshal.GetDelegateForFunctionPointer(procAddress, typeof(ContentSetValueWHandler));
     }
     else
     {
         procAddress = Windows.GetProcAddress(this.LibHandle, "ContentSetValue");
         if (procAddress != IntPtr.Zero)
         {
             this.ContentSetValue = (ContentSetValueHandler) Marshal.GetDelegateForFunctionPointer(procAddress, typeof(ContentSetValueHandler));
         }
     }
     procAddress = Windows.GetProcAddress(libHandle, "ContentStopGetValue");
     if (procAddress != IntPtr.Zero)
     {
         this.ContentStopGetValue = (ContentStopGetValueHandler) Marshal.GetDelegateForFunctionPointer(procAddress, typeof(ContentStopGetValueHandler));
     }
     List<WdxFieldInfo> list = new List<WdxFieldInfo>();
     StringBuilder fieldName = new StringBuilder(0x400);
     StringBuilder units = new StringBuilder(fieldName.Capacity);
     int fieldIndex = 0;
     for (int i = this.ContentGetSupportedField(fieldIndex, fieldName, units, fieldName.Capacity); i != 0; i = this.ContentGetSupportedField(++fieldIndex, fieldName, units, fieldName.Capacity))
     {
         WdxFieldInfo item = new WdxFieldInfo {
             FieldName = fieldName.ToString(),
             FieldType = i
         };
         if (units.Length > 0)
         {
             item.Units = units.ToString().Split(new char[] { '|' });
         }
         if (this.ContentGetSupportedFieldFlags != null)
         {
             item.Flags = this.ContentGetSupportedFieldFlags(fieldIndex);
         }
         list.Add(item);
     }
     this.FieldsCollection = new ReadOnlyCollection<WdxFieldInfo>(list);
 }
コード例 #9
0
 public virtual void Dispose()
 {
     if (this.LibHandle != null)
     {
         IntPtr procAddress = Windows.GetProcAddress(this.LibHandle, "ContentPluginUnloading");
         if (procAddress != IntPtr.Zero)
         {
             ContentPluginUnloadingHandler delegateForFunctionPointer = (ContentPluginUnloadingHandler) Marshal.GetDelegateForFunctionPointer(procAddress, typeof(ContentPluginUnloadingHandler));
             delegateForFunctionPointer();
         }
         this.ContentGetDetectString = null;
         this.ContentGetSupportedField = null;
         this.ContentGetValue = null;
         this.ContentGetValueW = null;
         this.ContentGetSupportedFieldFlags = null;
         this.ContentSetValue = null;
         this.ContentSetValueW = null;
         this.ContentStopGetValue = null;
         this.LibHandle.Close();
         this.LibHandle = null;
         this.UpdateMap = null;
     }
 }
コード例 #10
0
ファイル: SevenZipFormat.cs プロジェクト: GiladShoham/RedRock
   private static extern IntPtr GetProcAddress(
 SafeLibraryHandle hModule,
 [MarshalAs(UnmanagedType.LPStr)] string procName);
コード例 #11
0
ファイル: SevenZipFormat.cs プロジェクト: GiladShoham/RedRock
 protected void Dispose(bool disposing)
 {
     if ((LibHandle != null) && !LibHandle.IsClosed)
     LibHandle.Close();
       LibHandle = null;
 }