示例#1
0
        public void Delete()
        {
            int result = OffRegHive.CatchException(() => key_.Delete());

            hive_.MarkAsModified();
            Win32Exception.CheckResult(result);
        }
示例#2
0
        public void DeleteValue(string lpValueName)
        {
            int result = OffRegHive.CatchException(() => key_.DeleteValue(lpValueName));

            hive_.MarkAsModified();
            Win32Exception.CheckResult(result);
        }
示例#3
0
        public void SetValue(
            string lpValueName,
            Win32Api.RegValueType dwType,
            IntPtr lpData,
            int cbData)
        {
            int result;

            if (!DoUni2AnsiConversion ||
                !DataTransformer.IsStringType(dwType))
            {
                result = OffRegHive.CatchException(() =>
                                                   key_.SetValueUnmanaged(lpValueName, (OffregLib.RegValueType)dwType, lpData, cbData));
                hive_.MarkAsModified();
                Win32Exception.CheckResult(result);
                return;
            }
            string str = Marshal.PtrToStringAnsi(lpData, cbData);

            using (HGlobalPtr pStr =
                       new HGlobalPtr(Marshal.StringToHGlobalUni(str)))
            {
                result = OffRegHive.CatchException(() =>
                                                   key_.SetValueUnmanaged(lpValueName, (OffregLib.RegValueType)dwType,
                                                                          pStr.Ptr, cbData * sizeof(char)));
                hive_.MarkAsModified();
                Win32Exception.CheckResult(result);
            }
        }
示例#4
0
        public void EnumValue(
            uint dwIndex,
            IntPtr lpValueName,
            /*ref UInt32*/ IntPtr lpcchValueName,
            IntPtr lpReserved,
            /*ref Win32Api.RegValueType*/ IntPtr lpType,
            IntPtr lpData,
            /*ref UInt32*/ IntPtr lpcbData)
        {
            if (!DoUni2AnsiConversion)
            {
                OffRegHive.ConvertException(() =>
                                            key_.EnumValueUnmanaged(dwIndex, lpValueName,
                                                                    lpcchValueName, lpType, lpData, lpcbData));
                return;
            }
            int cchValueName = 0;

            if (lpcchValueName != IntPtr.Zero)
            {
                cchValueName = Marshal.ReadInt32(lpcchValueName);
            }
            using (Uni2AnsiConverter nameConverter =
                       new Uni2AnsiConverter(new Data(lpValueName, lpcchValueName, Data.CountIn.Chars)))
            {
                try
                {
                    Data dst = new Data(lpData, lpcbData, Data.CountIn.Bytes);
                    // Sandboxie-generated reghives might contain REG_SZ values stored in ansi format
                    // we need to detect them and avoid conversion for them
                    if (!DataTransformer.TryAlterData(lpType,
                                                      dst, (newpdwType, newDst) =>
                    {
                        // EnumValue takes buffer size WITH null character
                        // but returns WITHOUT, so we need to reset input
                        // param to allow multiple calls to the operation
                        if (lpcchValueName != IntPtr.Zero)
                        {
                            Marshal.WriteInt32(lpcchValueName, cchValueName);
                        }
                        return(OffRegHive.CatchException(() => key_.EnumValueUnmanaged(
                                                             dwIndex, nameConverter.UnicodeStr,
                                                             lpcchValueName, newpdwType, newDst.Ptr, newDst.PCount)));
                    },
                                                      (result, type) => (result == Win32Api.Error.ERROR_SUCCESS ||
                                                                         result == Win32Api.Error.ERROR_MORE_DATA) &&
                                                      DataTransformer.IsStringType(type),
                                                      (type, pSrcData, cbSrcData) =>
                                                      dst.FillWithString(new BytesString(pSrcData, cbSrcData), StringFormat.Ansi,
                                                                         Data.NullCharHandling.NotAddingIfNotPresent)))
                    {
                        throw new FileNotFoundException();
                    }
                    nameConverter.Convert();
                }
                catch (Win32Exception ex)
                {
                    if (ex.ErrorCode == (int)Win32Api.Error.ERROR_MORE_DATA)
                    {
                        // Assumming that in case of ERROR_MORE_DATA lpcchValueName is
                        // filled with correct value
                        nameConverter.Convert();
                    }
                    throw;
                }
            }
        }