Example #1
0
 public static extern IntPtr CreatePrivateNamespace([In] ref Win32.SECURITY_ATTRIBUTES lpPrivateNamespaceAttributes = null, [In] IntPtr lpBoundaryDescriptor, [In] string lpAliasPrefix);
Example #2
0
 public static extern IntPtr CreateFileMapping([In] uint hFile, [In] ref Win32.SECURITY_ATTRIBUTES lpAttributes = null, [In] int flProtect, [In] int dwMaximumSizeHigh, [In] int dwMaximumSizeLow, [In] string lpName = null);
Example #3
0
        private static int SetupShareMemoryWithSercurity(int nSize)
        {
            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))
                {
                    InSnergyService.PostLog("CreateWellKnownSid " + Marshal.GetLastWin32Error());
                    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))
                {
                    InSnergyService.PostLog("ConvertStringSecurityDescriptorToSecurityDescriptor " + Marshal.GetLastWin32Error());
                    int result = -1;
                    return(result);
                }
                sECURITY_ATTRIBUTES.nLength        = Marshal.SizeOf(sECURITY_ATTRIBUTES);
                sECURITY_ATTRIBUTES.bInheritHandle = false;
                SharedData.hMapFile = Win32.CreateFileMapping(4294967295u, ref sECURITY_ATTRIBUTES, 4, 0, nSize + 1024, "Global\\InSnergySharedName");
                flag = ((long)Marshal.GetLastWin32Error() == 183L);
                if (SharedData.hMapFile == IntPtr.Zero)
                {
                    InSnergyService.PostLog("CreateFileMapping " + Marshal.GetLastWin32Error());
                    int result = -1;
                    return(result);
                }
                SharedData.pMapBuf = Win32.MapViewOfFile(SharedData.hMapFile, 983071, 0, 0, nSize + 128);
                if (SharedData.pMapBuf == IntPtr.Zero)
                {
                    InSnergyService.PostLog("MapViewOfFile " + Marshal.GetLastWin32Error());
                    int result = -1;
                    return(result);
                }
            }
            catch (Exception ex)
            {
                InSnergyService.PostLog(ex.Message + " failed with '" + ex.InnerException.Message);
            }
            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);
        }