Skip to content

Commit

Permalink
Fix permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
LiEnby authored Jan 18, 2021
1 parent 0d4c30d commit 46a86f5
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions DontTouchMyFlash/FlashPwner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,22 @@ public void TakeOwn(string filepath)
{
FileSecurity fileS = File.GetAccessControl(filepath);

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

File.SetAccessControl(filepath, fileS);
}
fileS.SetOwner(cu);
fileS.SetAccessRuleProtection(false, false);

fileS.RemoveAccessRuleAll(new FileSystemAccessRule(everyone, FileSystemRights.FullControl, AccessControlType.Deny));
fileS.RemoveAccessRuleAll(new FileSystemAccessRule(cu, FileSystemRights.FullControl, AccessControlType.Deny));

fileS.SetAccessRule(new FileSystemAccessRule(everyone, FileSystemRights.FullControl, AccessControlType.Allow));
fileS.SetAccessRule(new FileSystemAccessRule(cu, FileSystemRights.FullControl , AccessControlType.Allow));

File.SetAccessControl(filepath, fileS);
File.SetAttributes(filepath, FileAttributes.Normal);
}

public bool CheckFileAndAdd(string filepath)
{
try
Expand Down

0 comments on commit 46a86f5

Please sign in to comment.