Exemple #1
0
        public static IntPtr _CreateEvent(bool bManualReset, bool bInitialState, string lpName)
        {
            SECURITY_DESCRIPTOR sd = new SECURITY_DESCRIPTOR();

            InitializeSecurityDescriptor(ref sd, SECURITY_DESCRIPTOR_REVISION);
            SetSecurityDescriptorDacl(ref sd, true, IntPtr.Zero, false);
            GCHandle sdHandle = GCHandle.Alloc(sd, GCHandleType.Pinned);

            SECURITY_ATTRIBUTES sa = new SECURITY_ATTRIBUTES();

            sa.nLength = Marshal.SizeOf(sa);
            sa.lpSecurityDescriptor = sdHandle.AddrOfPinnedObject();
            sa.bInheritHandle       = 0;
            GCHandle saHandle = GCHandle.Alloc(sa, GCHandleType.Pinned);

            System.IntPtr hEvent = IntPtr.Zero;
            hEvent = CreateEvent(
                saHandle.AddrOfPinnedObject(),
                bManualReset,
                bInitialState,
                lpName
                );

            saHandle.Free();
            sdHandle.Free();
            if (hEvent == (System.IntPtr)(int) - 1)
            {
                return(IntPtr.Zero);
            }
            return(hEvent);
        }
Exemple #2
0
        public static IntPtr _CreateFile(
            string lpFileName,
            EFileAccess dwDesiredAccess,
            EFileShare dwShareMode,
            ECreationDisposition dwCreationDisposition,
            EFileAttributes dwFlagsAndAttributes,
            IntPtr hTemplateFile
            )
        {
            SECURITY_DESCRIPTOR sd = new SECURITY_DESCRIPTOR();

            InitializeSecurityDescriptor(ref sd, SECURITY_DESCRIPTOR_REVISION);
            SetSecurityDescriptorDacl(ref sd, true, IntPtr.Zero, false);
            GCHandle sdHandle = GCHandle.Alloc(sd, GCHandleType.Pinned);

            SECURITY_ATTRIBUTES sa = new SECURITY_ATTRIBUTES();

            sa.nLength = Marshal.SizeOf(sa);
            sa.lpSecurityDescriptor = sdHandle.AddrOfPinnedObject();
            sa.bInheritHandle       = 0;
            GCHandle saHandle = GCHandle.Alloc(sa, GCHandleType.Pinned);

            System.IntPtr hFile = IntPtr.Zero;
            hFile = CreateFile(
                lpFileName,
                dwDesiredAccess,
                dwShareMode,
                saHandle.AddrOfPinnedObject(),
                dwCreationDisposition,
                dwFlagsAndAttributes,
                hTemplateFile
                );

            saHandle.Free();
            sdHandle.Free();
            if (hFile == (System.IntPtr)(int) - 1)
            {
                return(IntPtr.Zero);
            }
            return(hFile);
        }
Exemple #3
0
        public static IntPtr _CreateNamedPipe(string lpName, uint dwOpenMode,
                                              uint dwPipeMode, uint nMaxInstances, uint nOutBufferSize, uint nInBufferSize,
                                              uint nDefaultTimeOut)
        {
            SECURITY_DESCRIPTOR sd = new SECURITY_DESCRIPTOR();

            InitializeSecurityDescriptor(ref sd, SECURITY_DESCRIPTOR_REVISION);
            SetSecurityDescriptorDacl(ref sd, true, IntPtr.Zero, false);
            GCHandle sdHandle = GCHandle.Alloc(sd, GCHandleType.Pinned);

            SECURITY_ATTRIBUTES sa = new SECURITY_ATTRIBUTES();

            sa.nLength = Marshal.SizeOf(sa);
            sa.lpSecurityDescriptor = sdHandle.AddrOfPinnedObject();
            sa.bInheritHandle       = 0;
            GCHandle saHandle = GCHandle.Alloc(sa, GCHandleType.Pinned);

            System.IntPtr hPipe = IntPtr.Zero;
            hPipe = CreateNamedPipe(
                lpName,
                dwOpenMode,
                dwPipeMode,
                nMaxInstances,
                nOutBufferSize,
                nInBufferSize,
                nDefaultTimeOut,
                saHandle.AddrOfPinnedObject()
                );

            saHandle.Free();
            sdHandle.Free();
            if (hPipe == (System.IntPtr)(int) - 1)
            {
                return(IntPtr.Zero);
            }
            return(hPipe);
        }
Exemple #4
0
        public static IntPtr _CreateNamedPipe(string lpName, uint dwOpenMode,
           uint dwPipeMode, uint nMaxInstances, uint nOutBufferSize, uint nInBufferSize,
           uint nDefaultTimeOut)
        {
            SECURITY_DESCRIPTOR sd = new SECURITY_DESCRIPTOR();
            InitializeSecurityDescriptor(ref sd, SECURITY_DESCRIPTOR_REVISION);
            SetSecurityDescriptorDacl(ref sd, true, IntPtr.Zero, false);
            GCHandle sdHandle = GCHandle.Alloc(sd, GCHandleType.Pinned);

            SECURITY_ATTRIBUTES sa = new SECURITY_ATTRIBUTES();
            sa.nLength = Marshal.SizeOf(sa);
            sa.lpSecurityDescriptor = sdHandle.AddrOfPinnedObject();
            sa.bInheritHandle = 0;
            GCHandle saHandle = GCHandle.Alloc(sa, GCHandleType.Pinned);

            System.IntPtr hPipe = IntPtr.Zero;
            hPipe = CreateNamedPipe(
                lpName,
                dwOpenMode,
                dwPipeMode,
                nMaxInstances,
                nOutBufferSize,
                nInBufferSize,
                nDefaultTimeOut,
                saHandle.AddrOfPinnedObject()
            );

            saHandle.Free();
            sdHandle.Free();
            if (hPipe == (System.IntPtr)(int)-1)
            {
                return IntPtr.Zero;
            }
            return hPipe;
        }
Exemple #5
0
        public static IntPtr _CreateEvent(bool bManualReset, bool bInitialState, string lpName)
        {
            SECURITY_DESCRIPTOR sd = new SECURITY_DESCRIPTOR();
            InitializeSecurityDescriptor(ref sd, SECURITY_DESCRIPTOR_REVISION);
            SetSecurityDescriptorDacl(ref sd, true, IntPtr.Zero, false);
            GCHandle sdHandle = GCHandle.Alloc(sd, GCHandleType.Pinned);

            SECURITY_ATTRIBUTES sa = new SECURITY_ATTRIBUTES();
            sa.nLength = Marshal.SizeOf(sa);
            sa.lpSecurityDescriptor = sdHandle.AddrOfPinnedObject();
            sa.bInheritHandle = 0;
            GCHandle saHandle = GCHandle.Alloc(sa, GCHandleType.Pinned);

            System.IntPtr hEvent = IntPtr.Zero;
            hEvent = CreateEvent(
                saHandle.AddrOfPinnedObject(),
                bManualReset,
                bInitialState,
                lpName
            );

            saHandle.Free();
            sdHandle.Free();
            if (hEvent == (System.IntPtr)(int)-1)
            {
                return IntPtr.Zero;
            }
            return hEvent;
        }
Exemple #6
0
        public static IntPtr _CreateFile(
           string lpFileName,
           EFileAccess dwDesiredAccess,
           EFileShare dwShareMode,
           ECreationDisposition dwCreationDisposition,
           EFileAttributes dwFlagsAndAttributes,
           IntPtr hTemplateFile
            )
        {
            SECURITY_DESCRIPTOR sd = new SECURITY_DESCRIPTOR();
            InitializeSecurityDescriptor(ref sd, SECURITY_DESCRIPTOR_REVISION);
            SetSecurityDescriptorDacl(ref sd, true, IntPtr.Zero, false);
            GCHandle sdHandle = GCHandle.Alloc(sd, GCHandleType.Pinned); 

            SECURITY_ATTRIBUTES sa = new SECURITY_ATTRIBUTES();
            sa.nLength = Marshal.SizeOf(sa);
            sa.lpSecurityDescriptor = sdHandle.AddrOfPinnedObject(); 
            sa.bInheritHandle = 0;
            GCHandle saHandle = GCHandle.Alloc(sa, GCHandleType.Pinned); 

            System.IntPtr hFile = IntPtr.Zero;
            hFile = CreateFile(
                lpFileName,
                dwDesiredAccess,
                dwShareMode,
                saHandle.AddrOfPinnedObject(),
                dwCreationDisposition,
                dwFlagsAndAttributes,
                hTemplateFile
            );

            saHandle.Free();
            sdHandle.Free();
            if (hFile == (System.IntPtr)(int)-1)
            {
                return IntPtr.Zero;
            }
            return hFile;
        }
Exemple #7
0
 static extern bool SetSecurityDescriptorDacl(ref SECURITY_DESCRIPTOR sd, bool daclPresent, IntPtr dacl, bool daclDefaulted);
Exemple #8
0
 static extern bool InitializeSecurityDescriptor(ref SECURITY_DESCRIPTOR sd, uint dwRevision);
Exemple #9
0
 static extern bool SetSecurityDescriptorDacl(ref SECURITY_DESCRIPTOR sd, bool daclPresent, IntPtr dacl, bool daclDefaulted);
Exemple #10
0
 static extern bool InitializeSecurityDescriptor(ref SECURITY_DESCRIPTOR sd, uint dwRevision);