UncensorBedrock/UncRock/Program.cs

104 lines
4.3 KiB
C#

using Microsoft.Win32;
using System;
using System.IO;
using System.Security.AccessControl;
using System.Security.Principal;
using System.Windows.Forms;
namespace UncRock
{
internal class Program
{
static string GetWindowsAppsFolder()
{
using (RegistryKey appx = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Appx"))
{
string packageRoot = appx.GetValue("PackageRoot").ToString();
return packageRoot;
}
}
static string GetAppFolder(string appName)
{
string[] apps = Directory.GetDirectories(GetWindowsAppsFolder(), "*");
foreach (string app in apps)
{
string folderName = Path.GetFileName(app);
if (folderName.StartsWith(appName))
{
return folderName;
}
}
return null;
}
public static void TakeOwn(string filepath)
{
FileSecurity filePermissions = File.GetAccessControl(filepath);
SecurityIdentifier currentUser = WindowsIdentity.GetCurrent().User;
SecurityIdentifier allUsers = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
try
{
Permissions.EnablePrivilege("SeTakeOwnershipPrivilege");
}
catch (Exception)
{
MessageBox.Show("Failed to obtain SeTakeOwnershipPrivledge", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
filePermissions.SetOwner(currentUser);
File.SetAccessControl(filepath, filePermissions);
filePermissions.SetAccessRuleProtection(false, false);
filePermissions.RemoveAccessRuleAll(new FileSystemAccessRule(allUsers, FileSystemRights.FullControl, AccessControlType.Deny));
filePermissions.RemoveAccessRuleAll(new FileSystemAccessRule(currentUser, FileSystemRights.FullControl, AccessControlType.Deny));
filePermissions.SetAccessRule(new FileSystemAccessRule(allUsers, FileSystemRights.FullControl, AccessControlType.Allow));
filePermissions.SetAccessRule(new FileSystemAccessRule(currentUser, FileSystemRights.FullControl, AccessControlType.Allow));
File.SetAccessControl(filepath, filePermissions);
File.SetAttributes(filepath, FileAttributes.Normal);
}
static void Main(string[] args)
{
string minecraftGameFolder = GetAppFolder("Microsoft.MinecraftUWP");
if(minecraftGameFolder != null)
{
string profFilter = Path.Combine(GetWindowsAppsFolder(), Path.Combine(Path.Combine(minecraftGameFolder, "data"), "profanity_filter.wlist"));
if (File.Exists(profFilter))
{
DialogResult res = MessageBox.Show("Are you sure you want to DELETE the Bedrock profanity_filter.wlist located at:\n\"" + profFilter + "\"?", "Disable Bedrock Profanity Filter?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (res == DialogResult.Yes)
{
try
{
TakeOwn(profFilter);
File.Delete(profFilter);
MessageBox.Show("profanity_filter.wlist was successfully DELETED.", "Bedrock Profanity Filter Disabled", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception e)
{
MessageBox.Show("Failed to delete file: " + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
else
{
MessageBox.Show("Could not find the profanity_filter.wlist\nDid you already delete it?", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
MessageBox.Show("Could not find the minecraft bedrock game folder.\nIs the game installed?", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}