-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWin32.cs
More file actions
204 lines (181 loc) · 6.96 KB
/
Win32.cs
File metadata and controls
204 lines (181 loc) · 6.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/* Copyright (C) 2014-2015, Manuel Meitinger
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
namespace Aufbauwerk.Tools.KioskControl
{
static class Win32
{
public sealed class SafeProcessHandle : SafeHandleZeroOrMinusOneIsInvalid
{
SafeProcessHandle() : base(true) { }
protected override bool ReleaseHandle()
{
return CloseHandle(handle);
}
}
public const uint SI_EDIT_PERMS = 0x00000000;
public const uint SI_ADVANCED = 0x00000010;
public const uint SI_NO_ACL_PROTECT = 0x00000200;
public const uint DACL_SECURITY_INFORMATION = 0x00000004;
public const uint SI_ACCESS_GENERAL = 0x00020000;
public const uint SI_ACCESS_SPECIFIC = 0x00010000;
public const ushort SE_SELF_RELATIVE = 0x8000;
public const ushort SE_DACL_PRESENT = 0x0004;
public const uint MAXIMUM_ALLOWED = 0x02000000;
public const uint LMEM_FIXED = 0x0000;
public const int PROCESS_TERMINATE = 0x0001;
public const uint WRITE_DAC = 0x00040000;
public const uint READ_CONTROL = 0x00020000;
public const int ANYSIZE_ARRAY = 1;
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
[DllImport("kernel32", ExactSpelling = true, SetLastError = true)]
public static extern bool CloseHandle
(
IntPtr hObject
);
[DllImport("kernel32", ExactSpelling = true, SetLastError = true)]
public static extern SafeProcessHandle OpenProcess
(
uint dwDesiredAccess,
bool bInheritHandle,
uint dwProcessId
);
[DllImport("kernel32", ExactSpelling = true)]
public static extern uint GetCurrentProcessId();
[DllImport("advapi32", ExactSpelling = true)]
public static extern int GetSecurityDescriptorLength
(
IntPtr pSecurityDescriptor
);
[DllImport("advapi32", ExactSpelling = true, SetLastError = true)]
public static extern bool MakeSelfRelativeSD
(
IntPtr pAbsoluteSD,
IntPtr pSelfRelativeSD,
ref int lpdwBufferLength
);
[DllImport("advapi32", ExactSpelling = true, SetLastError = true)]
public static extern bool GetSecurityDescriptorControl
(
IntPtr pSecurityDescriptor,
out ushort pControl,
out uint lpdwRevision
);
[DllImport("advapi32", ExactSpelling = true, SetLastError = true)]
public static extern bool AccessCheck
(
IntPtr pSecurityDescriptor,
IntPtr ClientToken,
uint DesiredAccess,
ref GENERIC_MAPPING GenericMapping,
ref PRIVILEGE_SET PrivilegeSet,
ref int PrivilegeSetLength,
out uint GrantedAccess,
out bool AccessStatus
);
[DllImport("kernel32", EntryPoint = "RtlMoveMemory")]
public static extern void MoveMemory
(
IntPtr Destination,
IntPtr Source,
int Length
);
[DllImport("kernel32", ExactSpelling = true, SetLastError = true)]
public static extern IntPtr LocalAlloc
(
uint uFlags,
int uBytes
);
[DllImport("kernel32", ExactSpelling = true, SetLastError = true)]
public static extern IntPtr LocalFree
(
IntPtr hMem
);
[DllImport("aclui", ExactSpelling = true, SetLastError = true)]
public static extern bool EditSecurity
(
IntPtr hwndOwner,
ISecurityInformation psi
);
[DllImport("advapi32", ExactSpelling = true, SetLastError = true)]
public static extern void MapGenericMask
(
ref uint AccessMask,
ref GENERIC_MAPPING GenericMapping
);
[StructLayout(LayoutKind.Sequential)]
public struct LUID
{
public uint LowPart;
public int HighPart;
}
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct LUID_AND_ATTRIBUTES
{
public LUID Luid;
public uint Attributes;
}
[StructLayout(LayoutKind.Sequential)]
public struct PRIVILEGE_SET
{
public int PrivilegeCount;
public uint Control;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = ANYSIZE_ARRAY)]
public LUID_AND_ATTRIBUTES[] Privilege;
}
[StructLayout(LayoutKind.Sequential)]
public struct GENERIC_MAPPING
{
public uint GenericRead;
public uint GenericWrite;
public uint GenericExecute;
public uint GenericAll;
}
[StructLayout(LayoutKind.Sequential)]
public struct SI_OBJECT_INFO
{
public uint dwFlags;
public IntPtr hInstance;
public IntPtr pszServerName;
public IntPtr pszObjectName;
public IntPtr pszPageTitle;
public Guid guidObjectType;
}
[StructLayout(LayoutKind.Sequential)]
public struct SI_ACCESS
{
public IntPtr pguid;
public uint mask;
public IntPtr pszName;
public uint dwFlags;
}
[Guid("965FC360-16FF-11d0-91CB-00AA00BBB723")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface ISecurityInformation
{
void GetObjectInformation([Out] out SI_OBJECT_INFO pObjectInfo);
void GetSecurity([In] uint RequestedInformation, [Out] out IntPtr ppSecurityDescriptor, [In] bool fDefault);
void SetSecurity([In] uint SecurityInformation, [In] IntPtr pSecurityDescriptor);
void GetAccessRights([In] IntPtr pguidObjectType, [In] uint dwFlags, [Out] out IntPtr ppAccess, [Out] out int pcAccesses, [Out] out int piDefaultAccess);
void MapGeneric([In] IntPtr pguidObjectType, [In] IntPtr pAceFlags, [In, Out] ref uint pMask);
void GetInheritTypes([Out] out IntPtr ppInheritTypes, [Out] out int pcInheritTypes);
void PropertySheetPageCallback([In] IntPtr hwnd, [In] uint uMsg, [In] uint uPage);
}
}
}