Upload src

This commit is contained in:
Li 2022-07-23 16:53:48 +12:00
parent f9dee24d4f
commit da1e6a2a9f
10 changed files with 473 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
.vs/*
UncRock/obj/*
UncRock/bin/*

25
UncRock.sln Normal file
View File

@ -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

6
UncRock/App.config Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v2.0.50727"/></startup>
</configuration>

118
UncRock/Permissions.cs Normal file
View File

@ -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);
}
}
}
}

103
UncRock/Program.cs Normal file
View File

@ -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);
}
}
}
}

View File

@ -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")]

90
UncRock/UncRock.csproj Normal file
View File

@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{5F177C56-7CE7-4C5E-B007-9148B61EEF1A}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>UncRock</RootNamespace>
<AssemblyName>Uncensor Bedrock</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>unrock.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Permissions.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="app.manifest" />
</ItemGroup>
<ItemGroup>
<Content Include="unrock.ico" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishUrlHistory>publish\</PublishUrlHistory>
<InstallUrlHistory />
<SupportUrlHistory />
<UpdateUrlHistory />
<BootstrapperUrlHistory />
<ErrorReportUrlHistory />
<FallbackCulture>en-US</FallbackCulture>
<VerifyUploadedFiles>false</VerifyUploadedFiles>
</PropertyGroup>
</Project>

79
UncRock/app.manifest Normal file
View File

@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC Manifest Options
If you want to change the Windows User Account Control level replace the
requestedExecutionLevel node with one of the following.
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
Specifying requestedExecutionLevel element will disable file and registry virtualization.
Remove this element if your application requires this virtualization for backwards
compatibility.
-->
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of the Windows versions that this application has been tested on
and is designed to work with. Uncomment the appropriate elements
and Windows will automatically select the most compatible environment. -->
<!-- Windows Vista -->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->
<!-- Windows 7 -->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->
<!-- Windows 8 -->
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->
<!-- Windows 8.1 -->
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->
<!-- Windows 10 -->
<!--<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />-->
</application>
</compatibility>
<!-- Indicates that the application is DPI-aware and will not be automatically scaled by Windows at higher
DPIs. Windows Presentation Foundation (WPF) applications are automatically DPI-aware and do not need
to opt in. Windows Forms applications targeting .NET Framework 4.6 that opt into this setting, should
also set the 'EnableWindowsFormsHighDpiAutoResizing' setting to 'true' in their app.config.
Makes the application long-path aware. See https://docs.microsoft.com/windows/win32/fileio/maximum-file-path-limitation -->
<!--
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
</windowsSettings>
</application>
-->
<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
<!--
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
-->
</assembly>

BIN
UncRock/unrock.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 KiB