internal unsafe object GetValue(string valName)
        {
            object retVal   = null;
            int    type     = 0;
            int    datasize = 0;
            int    ret      = SafeNativeMethods.RegQueryValueEx(this, valName, null, ref type, (byte[])null, ref datasize);

            if (SafeNativeMethods.ERROR_SUCCESS == ret)
            {
                byte[] blob = new byte[datasize];
                ret = SafeNativeMethods.RegQueryValueEx(this, valName, null, ref type, (byte[])blob, ref datasize);

                if (SafeNativeMethods.ERROR_SUCCESS == ret)
                {
                    UnicodeEncoding unicode   = new UnicodeEncoding();
                    string          stringVal = unicode.GetString(blob);

                    switch (type)
                    {
                    case (SafeNativeMethods.REG_BINARY):
                        retVal = blob;
                        break;

                    case (SafeNativeMethods.REG_DWORD):
                        fixed(byte *pBuffer = blob)
                        {
                            retVal = Marshal.ReadInt32((IntPtr)pBuffer);
                        }

                        break;

                    case (SafeNativeMethods.REG_MULTI_SZ):
                        retVal = stringVal.Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries);
                        break;

                    case (SafeNativeMethods.REG_QWORD):
                        fixed(byte *pBuffer = blob)
                        {
                            retVal = Marshal.ReadInt64((IntPtr)pBuffer);
                        }

                        break;

                    case (SafeNativeMethods.REG_EXPAND_SZ):
                    case (SafeNativeMethods.REG_SZ):
                        retVal = stringVal.Trim(new char[] { '\0' });
                        break;

                    default:
                        retVal = blob;
                        break;
                    }
                }
            }

            return(retVal);
        }
Esempio n. 2
0
        public string GetStringValue(string valName)
        {
            int lpType   = 0;
            int lpcbData = 0;

            if ((SafeNativeMethods.RegQueryValueEx(this, valName, null, ref lpType, null, ref lpcbData) == 0) && (lpType == 1))
            {
                byte[]          lpData   = new byte[lpcbData];
                int             num3     = SafeNativeMethods.RegQueryValueEx(this, valName, null, ref lpType, lpData, ref lpcbData);
                UnicodeEncoding encoding = new UnicodeEncoding();
                return(encoding.GetString(lpData));
            }
            return(null);
        }
        public string GetStringValue(string valName)
        {
            int type     = 0;
            int datasize = 0;
            int ret      = SafeNativeMethods.RegQueryValueEx(this, valName, null, ref type, (byte[])null, ref datasize);

            if (ret == SafeNativeMethods.ERROR_SUCCESS)
            {
                if (type == SafeNativeMethods.REG_SZ)
                {
                    byte[] blob = new byte[datasize];
                    ret = SafeNativeMethods.RegQueryValueEx(this, valName, null, ref type, (byte[])blob, ref datasize);
                    UnicodeEncoding unicode = new UnicodeEncoding();
                    return(unicode.GetString(blob));
                }
            }
            return(null);
        }
Esempio n. 4
0
        internal unsafe object GetValue(string valName)
        {
            object obj2     = null;
            int    lpType   = 0;
            int    lpcbData = 0;

            if (SafeNativeMethods.RegQueryValueEx(this, valName, null, ref lpType, null, ref lpcbData) != 0)
            {
                return(obj2);
            }
            byte[] lpData = new byte[lpcbData];
            if (SafeNativeMethods.RegQueryValueEx(this, valName, null, ref lpType, lpData, ref lpcbData) != 0)
            {
                return(obj2);
            }
            string str = new UnicodeEncoding().GetString(lpData);

            switch (lpType)
            {
            case 1:
            case 2:
                return(str.Trim(new char[1]));

            case 3:
                return(lpData);

            case 4:
                fixed(byte *numRef = lpData)
                {
                    obj2 = Marshal.ReadInt32((IntPtr)numRef);
                }

                return(obj2);

            case 5:
            case 6:
            case 8:
            case 9:
            case 10:
                return(lpData);

            case 7:
            {
                char[] separator = new char[1];
                return(str.Split(separator, StringSplitOptions.RemoveEmptyEntries));
            }

            case 11:
                byte[] buffer3;
                if (((buffer3 = lpData) != null) && (buffer3.Length != 0))
                {
                    fixed(byte *numRef2 = buffer3)
                    {
Label_00F6:
                        obj2 = Marshal.ReadInt64((IntPtr)numRef2);
                    }

                    return(obj2);
                }
                numRef2 = null;
                goto Label_00F6;
            }
            return(lpData);
        }