Пример #1
0
        public static int SetupShareMemoryWithSercurity(string strMapFileName, int nSize, ref IntPtr _hMapFile, ref IntPtr _pMapBuf)
        {
            bool   flag     = false;
            IntPtr intPtr   = IntPtr.Zero;
            int    cb       = 68;
            IntPtr arg_12_0 = IntPtr.Zero;

            Win32.SECURITY_ATTRIBUTES sECURITY_ATTRIBUTES = default(Win32.SECURITY_ATTRIBUTES);
            try
            {
                intPtr = Marshal.AllocHGlobal(cb);
                if (!Win32.CreateWellKnownSid(WellKnownSidType.BuiltinAdministratorsSid, IntPtr.Zero, intPtr, ref cb))
                {
                    int result = -1;
                    return(result);
                }
                if (!Win32.ConvertStringSecurityDescriptorToSecurityDescriptor("D:(A;;GA;;;RD)(A;;GA;;;S-1-5-32-544)(A;;GA;;;S-1-5-4)", 1, out sECURITY_ATTRIBUTES.lpSecurityDescriptor, IntPtr.Zero))
                {
                    int result = -1;
                    return(result);
                }
                sECURITY_ATTRIBUTES.nLength        = Marshal.SizeOf(sECURITY_ATTRIBUTES);
                sECURITY_ATTRIBUTES.bInheritHandle = false;
                _hMapFile = Win32.CreateFileMapping(4294967295u, ref sECURITY_ATTRIBUTES, 4, 0, nSize + 1024, strMapFileName);
                flag      = ((long)Marshal.GetLastWin32Error() == 183L);
                if (_hMapFile == IntPtr.Zero)
                {
                    int result = -1;
                    return(result);
                }
                _pMapBuf = Win32.MapViewOfFile(_hMapFile, 983071, 0, 0, nSize + 128);
                if (_pMapBuf == IntPtr.Zero)
                {
                    int result = -1;
                    return(result);
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                if (intPtr != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(intPtr);
                }
                if (sECURITY_ATTRIBUTES.lpSecurityDescriptor != IntPtr.Zero)
                {
                    Win32.LocalFree(sECURITY_ATTRIBUTES.lpSecurityDescriptor);
                }
            }
            if (!flag)
            {
                return(0);
            }
            return(1);
        }
Пример #2
0
 public static extern IntPtr CreateFileMapping([In] uint hFile, [In] ref Win32.SECURITY_ATTRIBUTES lpAttributes, [In] int flProtect, [In] int dwMaximumSizeHigh, [In] int dwMaximumSizeLow, [In] string lpName = null);
Пример #3
0
 public static extern IntPtr CreatePrivateNamespace([In] ref Win32.SECURITY_ATTRIBUTES lpPrivateNamespaceAttributes, [In] IntPtr lpBoundaryDescriptor, [In] string lpAliasPrefix);