Skip to content

Commit 46a86f5

Browse files
authored
Fix permissions
1 parent 0d4c30d commit 46a86f5

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

DontTouchMyFlash/FlashPwner.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,22 @@ public void TakeOwn(string filepath)
4242
{
4343
FileSecurity fileS = File.GetAccessControl(filepath);
4444

45-
IdentityReference sid = fileS.GetOwner(typeof(SecurityIdentifier));
46-
string ntAccount = sid.Translate(typeof(NTAccount)).ToString();
47-
if(ntAccount == @"NT SERVICE\TrustedInstaller")
48-
{
49-
SecurityIdentifier cu = WindowsIdentity.GetCurrent().User;
50-
fileS.SetOwner(cu);
51-
fileS.SetAccessRule(new FileSystemAccessRule(cu, FileSystemRights.FullControl, AccessControlType.Allow));
45+
SecurityIdentifier cu = WindowsIdentity.GetCurrent().User;
46+
SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
5247

53-
File.SetAccessControl(filepath, fileS);
54-
}
48+
fileS.SetOwner(cu);
49+
fileS.SetAccessRuleProtection(false, false);
50+
51+
fileS.RemoveAccessRuleAll(new FileSystemAccessRule(everyone, FileSystemRights.FullControl, AccessControlType.Deny));
52+
fileS.RemoveAccessRuleAll(new FileSystemAccessRule(cu, FileSystemRights.FullControl, AccessControlType.Deny));
53+
54+
fileS.SetAccessRule(new FileSystemAccessRule(everyone, FileSystemRights.FullControl, AccessControlType.Allow));
55+
fileS.SetAccessRule(new FileSystemAccessRule(cu, FileSystemRights.FullControl , AccessControlType.Allow));
56+
57+
File.SetAccessControl(filepath, fileS);
58+
File.SetAttributes(filepath, FileAttributes.Normal);
5559
}
60+
5661
public bool CheckFileAndAdd(string filepath)
5762
{
5863
try

0 commit comments

Comments
 (0)