diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0b40e16 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.vs/* +UncRock/obj/* +UncRock/bin/* diff --git a/UncRock.sln b/UncRock.sln new file mode 100644 index 0000000..7101b33 --- /dev/null +++ b/UncRock.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32611.2 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UncRock", "UncRock\UncRock.csproj", "{5F177C56-7CE7-4C5E-B007-9148B61EEF1A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5F177C56-7CE7-4C5E-B007-9148B61EEF1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5F177C56-7CE7-4C5E-B007-9148B61EEF1A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5F177C56-7CE7-4C5E-B007-9148B61EEF1A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5F177C56-7CE7-4C5E-B007-9148B61EEF1A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {929C3E9A-A8DA-4E32-B363-DB2D8F08B322} + EndGlobalSection +EndGlobal diff --git a/UncRock/App.config b/UncRock/App.config new file mode 100644 index 0000000..77ed642 --- /dev/null +++ b/UncRock/App.config @@ -0,0 +1,6 @@ + + + + + + diff --git a/UncRock/Permissions.cs b/UncRock/Permissions.cs new file mode 100644 index 0000000..6ef15e3 --- /dev/null +++ b/UncRock/Permissions.cs @@ -0,0 +1,118 @@ + +using System; +using System.ComponentModel; +using System.Runtime.InteropServices; + +namespace UncRock +{ + public static class Permissions + { + [DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + internal static extern bool LookupPrivilegeValue(string lpsystemname, string lpname, [MarshalAs(UnmanagedType.Struct)] ref Luid lpLuid); + + [DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + internal static extern bool AdjustTokenPrivileges(IntPtr tokenhandle, [MarshalAs(UnmanagedType.Bool)] bool disableAllPrivileges, [MarshalAs(UnmanagedType.Struct)] ref TokenPrivledges newstate, uint bufferlength, IntPtr previousState, IntPtr returnlength); + + internal const int SePrivledgeEnabled = 0x00000002; + internal const int ErrorNotAllAssigned = 1300; + internal const UInt32 TokenQuery = 0x0008; + internal const UInt32 TokenAdjustPrivledges = 0x0020; + + [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] + internal static extern IntPtr GetCurrentProcess(); + + [DllImport("Advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + internal static extern bool OpenProcessToken(IntPtr processHandle, uint desiredAccesss, out IntPtr tokenHandle); + + [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + internal static extern Boolean CloseHandle(IntPtr hObject); + + [StructLayout(LayoutKind.Sequential)] + internal struct Luid + { + internal Int32 LowPart; + internal UInt32 HighPart; + } + + [StructLayout(LayoutKind.Sequential)] + internal struct TokenPrivledges + { + internal Int32 PrivilegeCount; + internal Luid Luid; + internal Int32 Attributes; + } + public static void EnablePrivilege(string securityEntity) + { + + string securityEntityValue = securityEntity; + try + { + Luid locallyUniqueIdentifier = new Luid(); + + if (LookupPrivilegeValue(null, securityEntityValue, ref locallyUniqueIdentifier)) + { + TokenPrivledges tokenPrivledges = new TokenPrivledges(); + tokenPrivledges.PrivilegeCount = 1; + tokenPrivledges.Attributes = SePrivledgeEnabled; + tokenPrivledges.Luid = locallyUniqueIdentifier; + + IntPtr tokenHandle = IntPtr.Zero; + try + { + IntPtr currentProcess = GetCurrentProcess(); + if (OpenProcessToken(currentProcess, TokenAdjustPrivledges | TokenQuery, out tokenHandle)) + { + if (AdjustTokenPrivileges(tokenHandle, false, ref tokenPrivledges, 1024, IntPtr.Zero, IntPtr.Zero)) + { + Int32 lastError = Marshal.GetLastWin32Error(); + if (lastError == ErrorNotAllAssigned) + { + Win32Exception win32Exception = new Win32Exception(); + throw new InvalidOperationException("AdjustTokenPrivileges fail.", win32Exception); + } + } + else + { + Win32Exception win32Exception = new Win32Exception(); + throw new InvalidOperationException("AdjustTokenPrivileges fail.", win32Exception); + } + } + else + { + Win32Exception win32Exception = new Win32Exception(); + + string exceptionMessage = "OpenProcessToken fail. Process: " + currentProcess.ToInt32().ToString(); + + throw new InvalidOperationException(exceptionMessage, win32Exception); + } + } + finally + { + if (tokenHandle != IntPtr.Zero) + CloseHandle(tokenHandle); + } + } + else + { + Win32Exception win32Exception = new Win32Exception(); + + string exceptionMessage = "LookupPrivilegeValue failed. SecurityEntityValue: " + securityEntityValue.ToString(); + + throw new InvalidOperationException(exceptionMessage, win32Exception); + } + } + catch (Exception e) + { + string exceptionMessage = "GrandPrivilege failed. SecurityEntity: " + securityEntityValue.ToString(); + + throw new InvalidOperationException(exceptionMessage, e); + } + } + + + } +} diff --git a/UncRock/Program.cs b/UncRock/Program.cs new file mode 100644 index 0000000..d1a6cf4 --- /dev/null +++ b/UncRock/Program.cs @@ -0,0 +1,103 @@ +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); + } + } + } +} diff --git a/UncRock/Properties/AssemblyInfo.cs b/UncRock/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..69c893e --- /dev/null +++ b/UncRock/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Uncensor Bedrock")] +[assembly: AssemblyDescription("Permanantly Disables the Bedrock Profanity Filter")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Li")] +[assembly: AssemblyProduct("Uncensor Bedrock")] +[assembly: AssemblyCopyright("Public Domain 2022")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("5f177c56-7ce7-4c5e-b007-9148b61eef1a")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/UncRock/UncRock.csproj b/UncRock/UncRock.csproj new file mode 100644 index 0000000..e20df12 --- /dev/null +++ b/UncRock/UncRock.csproj @@ -0,0 +1,90 @@ + + + + + Debug + AnyCPU + {5F177C56-7CE7-4C5E-B007-9148B61EEF1A} + WinExe + UncRock + Uncensor Bedrock + v2.0 + 512 + false + true + + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + none + true + bin\Release\ + prompt + 4 + + + app.manifest + + + unrock.ico + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + False + .NET Framework 3.5 SP1 + true + + + + \ No newline at end of file diff --git a/UncRock/UncRock.csproj.user b/UncRock/UncRock.csproj.user new file mode 100644 index 0000000..9c755a1 --- /dev/null +++ b/UncRock/UncRock.csproj.user @@ -0,0 +1,13 @@ + + + + publish\ + + + + + + en-US + false + + \ No newline at end of file diff --git a/UncRock/app.manifest b/UncRock/app.manifest new file mode 100644 index 0000000..580f56a --- /dev/null +++ b/UncRock/app.manifest @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/UncRock/unrock.ico b/UncRock/unrock.ico new file mode 100644 index 0000000..6161360 Binary files /dev/null and b/UncRock/unrock.ico differ