Initial commit

This commit is contained in:
Daniel
2021-05-15 03:40:58 +03:00
commit f4c3bc5671
58 changed files with 5358 additions and 0 deletions
+87
View File
@@ -0,0 +1,87 @@
<?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>{D00F629B-455A-42DE-B2FA-A3759A3095AE}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CleanFlashCommon</RootNamespace>
<AssemblyName>CleanFlashCommon</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<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' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Runtime.Serialization" />
<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.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ExitedProcess.cs" />
<Compile Include="FileUtil.cs" />
<Compile Include="GradientButton.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="HandleUtil.cs" />
<Compile Include="ImageCheckBox.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="ImageCheckBox.Designer.cs">
<DependentUpon>ImageCheckBox.cs</DependentUpon>
</Compile>
<Compile Include="InstallException.cs" />
<Compile Include="IProgressForm.cs" />
<Compile Include="ProcessRunner.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="RedirectionManager.cs" />
<Compile Include="RegistryManager.cs" />
<Compile Include="SmoothProgressBar.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="SystemInfo.cs" />
<Compile Include="Uninstaller.cs" />
<Compile Include="UpdateChecker.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="flashLogo.png" />
<Content Include="icon.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
+12
View File
@@ -0,0 +1,12 @@
namespace CleanFlashCommon {
public class ExitedProcess {
public int ExitCode { get; set; }
public string Output { get; set; }
public bool IsSuccessful {
get {
return ExitCode == 0;
}
}
}
}
+102
View File
@@ -0,0 +1,102 @@
using System.IO;
using System.Linq;
using System.Security.AccessControl;
using System.Security.Principal;
using System.Threading;
namespace CleanFlashCommon {
public class FileUtil {
public static void TakeOwnership(string filename) {
FileSecurity security = new FileSecurity();
SecurityIdentifier sid = WindowsIdentity.GetCurrent().User;
security.SetOwner(sid);
security.SetAccessRule(new FileSystemAccessRule(sid, FileSystemRights.FullControl, AccessControlType.Allow));
File.SetAccessControl(filename, security);
// Remove read-only attribute
File.SetAttributes(filename, File.GetAttributes(filename) & ~FileAttributes.ReadOnly);
}
public static void RecursiveDelete(DirectoryInfo rootDir, DirectoryInfo baseDir, string filename) {
if (!baseDir.Exists) {
return;
}
if (!baseDir.FullName.StartsWith(rootDir.FullName)) {
// Sanity check.
return;
}
foreach (DirectoryInfo dir in baseDir.EnumerateDirectories()) {
RecursiveDelete(rootDir, dir, filename);
}
foreach (FileInfo file in baseDir.GetFiles()) {
if (!file.FullName.StartsWith(rootDir.FullName)) {
// Sanity check.
continue;
}
if (filename == null || file.Name.Equals(filename)) {
DeleteFile(file);
}
}
if (!Directory.EnumerateFileSystemEntries(baseDir.FullName).Any()) {
try {
baseDir.Delete();
} catch {
HandleUtil.KillProcessesUsingFile(baseDir.FullName);
baseDir.Delete();
}
}
}
public static void DeleteFile(FileInfo file) {
if (!file.Exists) {
return;
}
try {
file.IsReadOnly = false;
file.Delete();
} catch {
for (int i = 0; i < 10; ++i) {
try {
TakeOwnership(file.FullName);
file.IsReadOnly = false;
file.Delete();
return;
} catch {
// Try again after sleeping.
Thread.Sleep(500);
}
}
HandleUtil.KillProcessesUsingFile(file.FullName);
file.Delete();
}
}
public static void RecursiveDelete(DirectoryInfo baseDir) {
RecursiveDelete(baseDir, baseDir, null);
}
public static void RecursiveDelete(string baseDir, string filename) {
DirectoryInfo dirInfo = new DirectoryInfo(baseDir);
RecursiveDelete(dirInfo, dirInfo, filename);
}
public static void RecursiveDelete(string baseDir) {
DirectoryInfo dirInfo = new DirectoryInfo(baseDir);
RecursiveDelete(dirInfo, dirInfo, null);
}
public static void DeleteFile(string file) {
DeleteFile(new FileInfo(file));
}
}
}
+91
View File
@@ -0,0 +1,91 @@
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace CleanFlashCommon {
public class GradientButton : Button {
public Color Color1 { get; set; }
public Color Color2 { get; set; }
public double HoverAlpha { get; set; }
public double DisableAlpha { get; set; }
private bool Hovered = false;
public GradientButton() {
Color1 = Color.Black;
Color2 = Color.White;
HoverAlpha = 0.875;
DisableAlpha = 0.644;
}
protected override void OnMouseDown(MouseEventArgs mevent) {
Hovered = false;
base.OnMouseDown(mevent);
Refresh();
}
protected override void OnMouseUp(MouseEventArgs mevent) {
Hovered = true;
base.OnMouseUp(mevent);
Refresh();
}
protected override void OnMouseEnter(EventArgs e) {
Hovered = true;
base.OnMouseEnter(e);
Refresh();
}
protected override void OnMouseLeave(EventArgs e) {
Hovered = false;
base.OnMouseLeave(e);
Refresh();
}
protected override void OnPaint(PaintEventArgs e) {
Color c1 = Color1;
Color c2 = Color2;
Color c3 = BackColor;
Color c4 = ForeColor;
if (!Enabled) {
c1 = Color.FromArgb(255, (int)(c1.R * DisableAlpha), (int)(c1.G * DisableAlpha), (int)(c1.B * DisableAlpha));
c2 = Color.FromArgb(255, (int)(c2.R * DisableAlpha), (int)(c2.G * DisableAlpha), (int)(c2.B * DisableAlpha));
c3 = Color.FromArgb(255, (int)(c3.R * DisableAlpha), (int)(c3.G * DisableAlpha), (int)(c3.B * DisableAlpha));
c4 = Color.FromArgb(255, (int)(c4.R * DisableAlpha), (int)(c4.G * DisableAlpha), (int)(c4.B * DisableAlpha));
} else if (!Hovered) {
c1 = Color.FromArgb(255, (int)(c1.R * HoverAlpha), (int)(c1.G * HoverAlpha), (int)(c1.B * HoverAlpha));
c2 = Color.FromArgb(255, (int)(c2.R * HoverAlpha), (int)(c2.G * HoverAlpha), (int)(c2.B * HoverAlpha));
}
SizeF size = e.Graphics.MeasureString(Text, Font);
using (Brush brush = new LinearGradientBrush(ClientRectangle, c1, c2, 90.0F)) {
e.Graphics.FillRectangle(brush, ClientRectangle);
}
int thickness = 1;
int halfThickness = thickness / 2;
using (Pen pen = new Pen(c3, thickness)) {
e.Graphics.DrawRectangle(
pen, new Rectangle(
halfThickness, halfThickness,
ClientRectangle.Width - thickness, ClientRectangle.Height - thickness
)
);
}
Point point = new Point(
(ClientRectangle.Width - (int)size.Width) / 2,
(ClientRectangle.Height - (int)size.Height) / 2
);
using (Brush brush = new SolidBrush(c4)) {
e.Graphics.DrawString(Text, Font, new SolidBrush(c3), new Point(point.X + 1, point.Y + 1));
e.Graphics.DrawString(Text, Font, brush, point);
}
}
}
}
+527
View File
@@ -0,0 +1,527 @@
// Taken from: https://github.com/Walkman100/FileLocks
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Text;
using System.Threading;
using Microsoft.Win32.SafeHandles;
using System.Diagnostics;
using System.Linq;
namespace CleanFlashCommon {
public static class HandleUtil {
private static Dictionary<string, string> deviceMap;
private const string networkDevicePrefix = "\\Device\\LanmanRedirector\\";
private const int MAX_PATH = 260;
private const int handleTypeTokenCount = 27;
private static readonly string[] handleTypeTokens = new string[] {
"", "", "Directory", "SymbolicLink", "Token",
"Process", "Thread", "Unknown7", "Event", "EventPair", "Mutant",
"Unknown11", "Semaphore", "Timer", "Profile", "WindowStation",
"Desktop", "Section", "Key", "Port", "WaitablePort",
"Unknown21", "Unknown22", "Unknown23", "Unknown24",
"IoCompletion", "File"
};
internal enum NT_STATUS {
STATUS_SUCCESS = 0x00000000,
STATUS_BUFFER_OVERFLOW = unchecked((int)0x80000005L),
STATUS_INFO_LENGTH_MISMATCH = unchecked((int)0xC0000004L)
}
internal enum SYSTEM_INFORMATION_CLASS {
SystemBasicInformation = 0,
SystemPerformanceInformation = 2,
SystemTimeOfDayInformation = 3,
SystemProcessInformation = 5,
SystemProcessorPerformanceInformation = 8,
SystemHandleInformation = 16,
SystemInterruptInformation = 23,
SystemExceptionInformation = 33,
SystemRegistryQuotaInformation = 37,
SystemLookasideInformation = 45
}
internal enum OBJECT_INFORMATION_CLASS {
ObjectBasicInformation = 0,
ObjectNameInformation = 1,
ObjectTypeInformation = 2,
ObjectAllTypesInformation = 3,
ObjectHandleInformation = 4
}
[Flags]
internal enum ProcessAccessRights {
PROCESS_DUP_HANDLE = 0x00000040
}
[Flags]
internal enum DuplicateHandleOptions {
DUPLICATE_CLOSE_SOURCE = 0x1,
DUPLICATE_SAME_ACCESS = 0x2
}
private enum SystemHandleType {
OB_TYPE_UNKNOWN = 0,
OB_TYPE_TYPE = 1,
OB_TYPE_DIRECTORY,
OB_TYPE_SYMBOLIC_LINK,
OB_TYPE_TOKEN,
OB_TYPE_PROCESS,
OB_TYPE_THREAD,
OB_TYPE_UNKNOWN_7,
OB_TYPE_EVENT,
OB_TYPE_EVENT_PAIR,
OB_TYPE_MUTANT,
OB_TYPE_UNKNOWN_11,
OB_TYPE_SEMAPHORE,
OB_TYPE_TIMER,
OB_TYPE_PROFILE,
OB_TYPE_WINDOW_STATION,
OB_TYPE_DESKTOP,
OB_TYPE_SECTION,
OB_TYPE_KEY,
OB_TYPE_PORT,
OB_TYPE_WAITABLE_PORT,
OB_TYPE_UNKNOWN_21,
OB_TYPE_UNKNOWN_22,
OB_TYPE_UNKNOWN_23,
OB_TYPE_UNKNOWN_24,
OB_TYPE_IO_COMPLETION,
OB_TYPE_FILE
};
[StructLayout(LayoutKind.Sequential)]
private struct SYSTEM_HANDLE_ENTRY {
public int OwnerPid;
public byte ObjectType;
public byte HandleFlags;
public short HandleValue;
public int ObjectPointer;
public int AccessMask;
}
[DllImport("ntdll.dll")]
internal static extern NT_STATUS NtQuerySystemInformation(
[In] SYSTEM_INFORMATION_CLASS SystemInformationClass,
[In] IntPtr SystemInformation,
[In] int SystemInformationLength,
[Out] out int ReturnLength);
[DllImport("ntdll.dll")]
internal static extern NT_STATUS NtQueryObject(
[In] IntPtr Handle,
[In] OBJECT_INFORMATION_CLASS ObjectInformationClass,
[In] IntPtr ObjectInformation,
[In] int ObjectInformationLength,
[Out] out int ReturnLength);
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern SafeProcessHandle OpenProcess(
[In] ProcessAccessRights dwDesiredAccess,
[In, MarshalAs(UnmanagedType.Bool)] bool bInheritHandle,
[In] int dwProcessId);
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool DuplicateHandle(
[In] IntPtr hSourceProcessHandle,
[In] IntPtr hSourceHandle,
[In] IntPtr hTargetProcessHandle,
[Out] out SafeObjectHandle lpTargetHandle,
[In] int dwDesiredAccess,
[In, MarshalAs(UnmanagedType.Bool)] bool bInheritHandle,
[In] DuplicateHandleOptions dwOptions);
[DllImport("kernel32.dll")]
internal static extern IntPtr GetCurrentProcess();
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern int GetProcessId(
[In] IntPtr Process);
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool CloseHandle(
[In] IntPtr hObject);
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern int QueryDosDevice(
[In] string lpDeviceName,
[Out] StringBuilder lpTargetPath,
[In] int ucchMax);
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
internal sealed class SafeObjectHandle : SafeHandleZeroOrMinusOneIsInvalid {
private SafeObjectHandle() : base(true) { }
internal SafeObjectHandle(IntPtr preexistingHandle, bool ownsHandle) : base(ownsHandle) {
base.SetHandle(preexistingHandle);
}
protected override bool ReleaseHandle() {
return CloseHandle(base.handle);
}
}
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
internal sealed class SafeProcessHandle : SafeHandleZeroOrMinusOneIsInvalid {
private SafeProcessHandle()
: base(true) { }
internal SafeProcessHandle(IntPtr preexistingHandle, bool ownsHandle)
: base(ownsHandle) {
base.SetHandle(preexistingHandle);
}
protected override bool ReleaseHandle() {
return CloseHandle(base.handle);
}
}
private sealed class OpenFiles : IEnumerable<string> {
private readonly int processId;
internal OpenFiles(int processId) {
this.processId = processId;
}
public IEnumerator<string> GetEnumerator() {
NT_STATUS ret;
int length = 0x10000;
// Loop, probing for required memory.
do {
IntPtr ptr = IntPtr.Zero;
RuntimeHelpers.PrepareConstrainedRegions();
try {
RuntimeHelpers.PrepareConstrainedRegions();
try { } finally {
// CER guarantees that the address of the allocated
// memory is actually assigned to ptr if an
// asynchronous exception occurs.
ptr = Marshal.AllocHGlobal(length);
}
ret = NtQuerySystemInformation(SYSTEM_INFORMATION_CLASS.SystemHandleInformation, ptr, length, out int returnLength);
if (ret == NT_STATUS.STATUS_INFO_LENGTH_MISMATCH) {
// Round required memory up to the nearest 64KB boundary.
length = (returnLength + 0xffff) & ~0xffff;
} else if (ret == NT_STATUS.STATUS_SUCCESS) {
int handleCount = Marshal.ReadInt32(ptr);
int offset = sizeof(int);
int size = Marshal.SizeOf(typeof(SYSTEM_HANDLE_ENTRY));
for (int i = 0; i < handleCount; i++) {
SYSTEM_HANDLE_ENTRY handleEntry = (SYSTEM_HANDLE_ENTRY) Marshal.PtrToStructure((IntPtr)((int)ptr + offset), typeof(SYSTEM_HANDLE_ENTRY));
if (handleEntry.OwnerPid == processId) {
IntPtr handle = (IntPtr) handleEntry.HandleValue;
SystemHandleType handleType;
if (GetHandleType(handle, handleEntry.OwnerPid, out handleType) && handleType == SystemHandleType.OB_TYPE_FILE) {
if (GetFileNameFromHandle(handle, handleEntry.OwnerPid, out string devicePath)) {
if (ConvertDevicePathToDosPath(devicePath, out string dosPath)) {
if (File.Exists(dosPath)) {
yield return dosPath;
} else if (Directory.Exists(dosPath)) {
yield return dosPath;
}
}
}
}
}
offset += size;
}
}
} finally {
// CER guarantees that the allocated memory is freed,
// if an asynchronous exception occurs.
Marshal.FreeHGlobal(ptr);
}
} while (ret == NT_STATUS.STATUS_INFO_LENGTH_MISMATCH);
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
return GetEnumerator();
}
}
private class FileNameFromHandleState : IDisposable {
private readonly ManualResetEvent _mr;
public IntPtr Handle { get; }
public string FileName { get; set; }
public bool RetValue { get; set; }
public FileNameFromHandleState(IntPtr handle) {
_mr = new ManualResetEvent(false);
this.Handle = handle;
}
public bool WaitOne(int wait) {
return _mr.WaitOne(wait, false);
}
public void Set() {
try {
_mr.Set();
} catch { }
}
public void Dispose() {
if (_mr != null) {
_mr.Close();
}
}
}
private static bool GetFileNameFromHandle(IntPtr handle, out string fileName) {
IntPtr ptr = IntPtr.Zero;
RuntimeHelpers.PrepareConstrainedRegions();
try {
int length = 0x200; // 512 bytes
RuntimeHelpers.PrepareConstrainedRegions();
try { } finally {
// CER guarantees the assignment of the allocated
// memory address to ptr, if an ansynchronous exception
// occurs.
ptr = Marshal.AllocHGlobal(length);
}
NT_STATUS ret = NtQueryObject(handle, OBJECT_INFORMATION_CLASS.ObjectNameInformation, ptr, length, out length);
if (ret == NT_STATUS.STATUS_BUFFER_OVERFLOW) {
RuntimeHelpers.PrepareConstrainedRegions();
try { } finally {
// CER guarantees that the previous allocation is freed,
// and that the newly allocated memory address is
// assigned to ptr if an asynchronous exception occurs.
Marshal.FreeHGlobal(ptr);
ptr = Marshal.AllocHGlobal(length);
}
ret = NtQueryObject(handle, OBJECT_INFORMATION_CLASS.ObjectNameInformation, ptr, length, out length);
}
if (ret == NT_STATUS.STATUS_SUCCESS) {
fileName = Marshal.PtrToStringUni((IntPtr)((int)ptr + 8), (length - 9) / 2);
return fileName.Length != 0;
}
} finally {
// CER guarantees that the allocated memory is freed,
// if an asynchronous exception occurs.
Marshal.FreeHGlobal(ptr);
}
fileName = string.Empty;
return false;
}
private static void GetFileNameFromHandle(object state) {
FileNameFromHandleState s = (FileNameFromHandleState)state;
s.RetValue = GetFileNameFromHandle(s.Handle, out string fileName);
s.FileName = fileName;
s.Set();
}
private static bool GetFileNameFromHandle(IntPtr handle, out string fileName, int wait) {
using (FileNameFromHandleState f = new FileNameFromHandleState(handle)) {
ThreadPool.QueueUserWorkItem(new WaitCallback(GetFileNameFromHandle), f);
if (f.WaitOne(wait)) {
fileName = f.FileName;
return f.RetValue;
} else {
fileName = string.Empty;
return false;
}
}
}
private static bool GetFileNameFromHandle(IntPtr handle, int processId, out string fileName) {
IntPtr currentProcess = GetCurrentProcess();
bool remote = processId != GetProcessId(currentProcess);
SafeProcessHandle processHandle = null;
SafeObjectHandle objectHandle = null;
try {
if (remote) {
processHandle = OpenProcess(ProcessAccessRights.PROCESS_DUP_HANDLE, true, processId);
if (DuplicateHandle(processHandle.DangerousGetHandle(), handle, currentProcess, out objectHandle, 0, false, DuplicateHandleOptions.DUPLICATE_SAME_ACCESS)) {
handle = objectHandle.DangerousGetHandle();
}
}
return GetFileNameFromHandle(handle, out fileName, 200);
} finally {
if (remote) {
if (processHandle != null) {
processHandle.Close();
}
if (objectHandle != null) {
objectHandle.Close();
}
}
}
}
private static string GetHandleTypeToken(IntPtr handle) {
NtQueryObject(handle, OBJECT_INFORMATION_CLASS.ObjectTypeInformation, IntPtr.Zero, 0, out int length);
IntPtr ptr = IntPtr.Zero;
RuntimeHelpers.PrepareConstrainedRegions();
try {
RuntimeHelpers.PrepareConstrainedRegions();
try { } finally {
if (length >= 0) {
ptr = Marshal.AllocHGlobal(length);
}
}
if (NtQueryObject(handle, OBJECT_INFORMATION_CLASS.ObjectTypeInformation, ptr, length, out length) == NT_STATUS.STATUS_SUCCESS) {
return Marshal.PtrToStringUni((IntPtr)((int)ptr + 0x60));
}
} finally {
Marshal.FreeHGlobal(ptr);
}
return string.Empty;
}
private static string GetHandleTypeToken(IntPtr handle, int processId) {
IntPtr currentProcess = GetCurrentProcess();
bool remote = processId != GetProcessId(currentProcess);
SafeProcessHandle processHandle = null;
SafeObjectHandle objectHandle = null;
try {
if (remote) {
processHandle = OpenProcess(ProcessAccessRights.PROCESS_DUP_HANDLE, true, processId);
if (DuplicateHandle(processHandle.DangerousGetHandle(), handle, currentProcess, out objectHandle, 0, false, DuplicateHandleOptions.DUPLICATE_SAME_ACCESS)) {
handle = objectHandle.DangerousGetHandle();
}
}
return GetHandleTypeToken(handle);
} finally {
if (remote) {
if (processHandle != null) {
processHandle.Close();
}
if (objectHandle != null) {
objectHandle.Close();
}
}
}
}
private static bool GetHandleTypeFromToken(string token, out SystemHandleType handleType) {
for (int i = 1; i < handleTypeTokenCount; i++) {
if (handleTypeTokens[i] == token) {
handleType = (SystemHandleType) i;
return true;
}
}
handleType = SystemHandleType.OB_TYPE_UNKNOWN;
return false;
}
private static bool GetHandleType(IntPtr handle, int processId, out SystemHandleType handleType) {
string token = GetHandleTypeToken(handle, processId);
return GetHandleTypeFromToken(token, out handleType);
}
private static bool ConvertDevicePathToDosPath(string devicePath, out string dosPath) {
EnsureDeviceMap();
int i = devicePath.Length;
while (i > 0 && (i = devicePath.LastIndexOf('\\', i - 1)) != -1) {
if (deviceMap.TryGetValue(devicePath.Substring(0, i), out string drive)) {
dosPath = string.Concat(drive, devicePath.Substring(i));
return dosPath.Length != 0;
}
}
dosPath = string.Empty;
return false;
}
private static void EnsureDeviceMap() {
if (deviceMap == null) {
Dictionary<string, string> localDeviceMap = BuildDeviceMap();
Interlocked.CompareExchange(ref deviceMap, localDeviceMap, null);
}
}
private static Dictionary<string, string> BuildDeviceMap() {
string[] logicalDrives = Environment.GetLogicalDrives();
Dictionary<string, string> localDeviceMap = new Dictionary<string, string>(logicalDrives.Length);
StringBuilder lpTargetPath = new StringBuilder(MAX_PATH);
foreach (string drive in logicalDrives) {
string lpDeviceName = drive.Substring(0, 2);
QueryDosDevice(lpDeviceName, lpTargetPath, MAX_PATH);
localDeviceMap.Add(NormalizeDeviceName(lpTargetPath.ToString()), lpDeviceName);
}
localDeviceMap.Add(networkDevicePrefix.Substring(0, networkDevicePrefix.Length - 1), "\\");
return localDeviceMap;
}
private static string NormalizeDeviceName(string deviceName) {
if (string.Compare(deviceName, 0, networkDevicePrefix, 0, networkDevicePrefix.Length, StringComparison.InvariantCulture) == 0) {
string shareName = deviceName.Substring(deviceName.IndexOf('\\', networkDevicePrefix.Length) + 1);
return string.Concat(networkDevicePrefix, shareName);
}
return deviceName;
}
/// <summary>
/// Gets the open files enumerator.
/// </summary>
/// <param name="processId">The process id.</param>
/// <returns></returns>
public static IEnumerable<string> GetOpenFilesEnumerator(int processId) {
return new OpenFiles(processId);
}
public static List<Process> GetProcessesUsingFile(string fName) {
List<Process> result = new List<Process>();
foreach (Process p in Process.GetProcesses()) {
try {
if (GetOpenFilesEnumerator(p.Id).Contains(fName)) {
result.Add(p);
}
} catch { } // Some processes will fail.
}
return result;
}
public static void KillProcessesUsingFile(string fName) {
foreach (Process process in GetProcessesUsingFile(fName).OrderBy(o => o.StartTime)) {
try {
process.Kill();
process.WaitForExit();
} catch {
// Oh well...
}
}
}
}
}
+7
View File
@@ -0,0 +1,7 @@
namespace CleanFlashCommon {
public interface IProgressForm {
void UpdateProgressLabel(string text, bool tick);
void TickProgress();
}
}
+32
View File
@@ -0,0 +1,32 @@
namespace CleanFlashCommon {
public partial class ImageCheckBox {
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing) {
if (disposing && (components != null)) {
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent() {
components = new System.ComponentModel.Container();
}
#endregion
}
}
+11
View File
@@ -0,0 +1,11 @@
using System;
using System.Windows.Forms;
namespace CleanFlashCommon {
public partial class ImageCheckBox : CheckBox {
protected override void OnCheckedChanged(EventArgs e) {
ImageIndex = Checked ? 1 : 0;
base.OnCheckedChanged(e);
}
}
}
+10
View File
@@ -0,0 +1,10 @@
using System;
namespace CleanFlashCommon {
public class InstallException : Exception {
public InstallException(string message) : base(message) {
}
}
}
+46
View File
@@ -0,0 +1,46 @@
using System.Diagnostics;
using System.Text;
namespace CleanFlashCommon {
public class ProcessRunner {
public static ExitedProcess RunProcess(ProcessStartInfo startInfo) {
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
StringBuilder outputBuilder = new StringBuilder();
Process process = new Process {
StartInfo = startInfo
};
DataReceivedEventHandler outputHandler = new DataReceivedEventHandler(
delegate (object sender, DataReceivedEventArgs e) {
outputBuilder.AppendLine(e.Data);
}
);
process.OutputDataReceived += outputHandler;
process.ErrorDataReceived += outputHandler;
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
process.CancelOutputRead();
process.CancelErrorRead();
return new ExitedProcess {
ExitCode = process.ExitCode,
Output = outputBuilder.ToString().Trim()
};
}
public static Process RunUnmanagedProcess(ProcessStartInfo startInfo) {
Process process = new Process {
StartInfo = startInfo
};
process.Start();
process.WaitForExit();
return process;
}
}
}
@@ -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("CleanFlashCommon")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CleanFlashCommon")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[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("d00f629b-455a-42de-b2fa-a3759a3095ae")]
// 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")]
+96
View File
@@ -0,0 +1,96 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace CleanFlashCommon.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CleanFlashCommon.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to [HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION]
///&quot;FlashHelperService.exe&quot;=-
///
///[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Control Panel\Extended Properties\System.ControlPanel.Category]
///&quot;${SYSTEM_64_PATH}\\FlashPlayerCPLApp.cpl&quot;=-
///
///[-HKEY_CURRENT_USER\Software\FlashCenter]
///[-HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Paths\FlashCenter.exe]
///[-HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninsta [rest of string was truncated]&quot;;.
/// </summary>
internal static string uninstallRegistry {
get {
return ResourceManager.GetString("uninstallRegistry", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to [HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION]
///&quot;FlashHelperService.exe&quot;=-
///
///[HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Control Panel\Extended Properties\System.ControlPanel.Category]
///&quot;${SYSTEM_32_PATH}\\FlashPlayerCPLApp.cpl&quot;=-
///
///[-HKEY_LOCAL_MACHINE\Software\Classes\Wow6432Node\CLSID\{B019E3BF-E7E5-453C-A2E4-D2C18CA0866F}]
///[-HKEY_LOCAL_MACHINE\Software\Classes\Wow6432Node\CLSID\{D27CDB6E-AE6D-11cf-96B8- [rest of string was truncated]&quot;;.
/// </summary>
internal static string uninstallRegistry64 {
get {
return ResourceManager.GetString("uninstallRegistry64", resourceCulture);
}
}
}
}
+249
View File
@@ -0,0 +1,249 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="uninstallRegistry" xml:space="preserve">
<value>[HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION]
"FlashHelperService.exe"=-
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Control Panel\Extended Properties\System.ControlPanel.Category]
"${SYSTEM_64_PATH}\\FlashPlayerCPLApp.cpl"=-
[-HKEY_CURRENT_USER\Software\FlashCenter]
[-HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Paths\FlashCenter.exe]
[-HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\FlashCenter]
[-HKEY_LOCAL_MACHINE\Software\Classes\AppID\{119DA84B-E3DB-4D47-A8DD-7FF6D5804689}]
[-HKEY_LOCAL_MACHINE\Software\Classes\AppID\{B9020634-CE8F-4F09-9FBC-D108A73A4676}]
[-HKEY_LOCAL_MACHINE\Software\Classes\TypeLib\{37EF68ED-16D3-4191-86BF-AB731D75AAB7}]
[-HKEY_LOCAL_MACHINE\System\ControlSet001\services\Flash Helper Service]
[-HKEY_LOCAL_MACHINE\System\ControlSet001\services\FlashCenterService]
[-HKEY_LOCAL_MACHINE\System\CurrentControlSet\services\Flash Helper Service]
[-HKEY_LOCAL_MACHINE\System\CurrentControlSet\services\FlashCenterService]
[-HKEY_LOCAL_MACHINE\Software\Classes\MacromediaFlashPaper.MacromediaFlashPaper]
[-HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Low Rights\ElevationPolicy\{FAF199D2-BFA7-4394-A4DE-044A08E59B32}]
[-HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\FlashPlayerUpdateService.exe]
[-HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\FlashUtil32_${VERSION_PATH}_ActiveX.exe]
[-HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\FlashUtil64_${VERSION_PATH}_ActiveX.exe]
[-HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\FlashUtil32_${VERSION_PATH}_Plugin.exe]
[-HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\FlashUtil64_${VERSION_PATH}_Plugin.exe]
[-HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\FlashPlayerPlugin_${VERSION_PATH}.exe]
[-HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\FlashUtil32_${VERSION_PATH}_pepper.exe]
[-HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\FlashUtil64_${VERSION_PATH}_pepper.exe]
[-HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Internet Explorer\Low Rights\ElevationPolicy\{FAF199D2-BFA7-4394-A4DE-044A08E59B32}]
[-HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Adobe Flash Player ActiveX]
[-HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Adobe Flash Player NPAPI]
[-HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Adobe Flash Player PPAPI]
[-HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\Clean Flash Player]
[-HKEY_LOCAL_MACHINE\Software\Classes\.mfp]
[-HKEY_LOCAL_MACHINE\Software\Classes\.sol]
[-HKEY_LOCAL_MACHINE\Software\Classes\.sor]
[-HKEY_LOCAL_MACHINE\Software\Classes\.spl]
[-HKEY_LOCAL_MACHINE\Software\Classes\.swf]
[-HKEY_LOCAL_MACHINE\Software\Classes\AppID\{B9020634-CE8F-4F09-9FBC-D108A73A4676}]
[-HKEY_LOCAL_MACHINE\Software\Classes\CLSID\{B019E3BF-E7E5-453C-A2E4-D2C18CA0866F}]
[-HKEY_LOCAL_MACHINE\Software\Classes\CLSID\{D27CDB6E-AE6D-11cf-96B8-444553540000}]
[-HKEY_LOCAL_MACHINE\Software\Classes\FlashFactory.FlashFactory]
[-HKEY_LOCAL_MACHINE\Software\Classes\FlashFactory.FlashFactory.1]
[-HKEY_LOCAL_MACHINE\Software\Classes\Interface\{299817DA-1FAC-4CE2-8F48-A108237013BD}]
[-HKEY_LOCAL_MACHINE\Software\Classes\Interface\{307F64C0-621D-4D56-BBC6-91EFC13CE40D}]
[-HKEY_LOCAL_MACHINE\Software\Classes\Interface\{57A0E747-3863-4D20-A811-950C84F1DB9B}]
[-HKEY_LOCAL_MACHINE\Software\Classes\Interface\{86230738-D762-4C50-A2DE-A753E5B1686F}]
[-HKEY_LOCAL_MACHINE\Software\Classes\Interface\{D27CDB6C-AE6D-11CF-96B8-444553540000}]
[-HKEY_LOCAL_MACHINE\Software\Classes\Interface\{D27CDB6D-AE6D-11CF-96B8-444553540000}]
[-HKEY_LOCAL_MACHINE\Software\Classes\MIME\Database\Content Type\application/futuresplash]
[-HKEY_LOCAL_MACHINE\Software\Classes\MIME\Database\Content Type\application/x-shockwave-flash]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash.1]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash.2]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash.3]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash.4]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash.5]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash.6]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash.7]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash.8]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash.9]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash.10]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash.11]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash.12]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash.13]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash.14]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash.15]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash.16]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash.17]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash.18]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash.19]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash.20]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash.21]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash.22]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash.23]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash.24]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash.25]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash.26]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash.27]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash.28]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash.29]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash.30]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash.31]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash.32]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash.33]
[-HKEY_LOCAL_MACHINE\Software\Classes\ShockwaveFlash.ShockwaveFlash.34]
[-HKEY_LOCAL_MACHINE\Software\Classes\TypeLib\{57A0E746-3863-4D20-A811-950C84F1DB9B}]
[-HKEY_LOCAL_MACHINE\Software\Classes\TypeLib\{D27CDB6B-AE6D-11CF-96B8-444553540000}]
[-HKEY_LOCAL_MACHINE\Software\Classes\TypeLib\{FAB3E735-69C7-453B-A446-B6823C6DF1C9}]
[-HKEY_LOCAL_MACHINE\Software\Macromedia]
[-HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\ActiveX Compatibility\{D27CDB6E-AE6D-11CF-96B8-444553540000}]
[-HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\ActiveX Compatibility\{D27CDB70-AE6D-11cf-96B8-444553540000}]
[-HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\NavigatorPluginsList\Shockwave Flash]
[-HKEY_LOCAL_MACHINE\Software\MozillaPlugins\@adobe.com/FlashPlayer]
[-HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\miniconfig]
[-HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\miniconfig]</value>
</data>
<data name="uninstallRegistry64" xml:space="preserve">
<value>[HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION]
"FlashHelperService.exe"=-
[HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Control Panel\Extended Properties\System.ControlPanel.Category]
"${SYSTEM_32_PATH}\\FlashPlayerCPLApp.cpl"=-
[-HKEY_LOCAL_MACHINE\Software\Classes\Wow6432Node\CLSID\{B019E3BF-E7E5-453C-A2E4-D2C18CA0866F}]
[-HKEY_LOCAL_MACHINE\Software\Classes\Wow6432Node\CLSID\{D27CDB6E-AE6D-11cf-96B8-444553540000}]
[-HKEY_LOCAL_MACHINE\Software\Classes\Wow6432Node\CLSID\{D27CDB70-AE6D-11cf-96B8-444553540000}]
[-HKEY_LOCAL_MACHINE\Software\Classes\Wow6432Node\Interface\{299817DA-1FAC-4CE2-8F48-A108237013BD}]
[-HKEY_LOCAL_MACHINE\Software\Classes\Wow6432Node\Interface\{307F64C0-621D-4D56-BBC6-91EFC13CE40D}]
[-HKEY_LOCAL_MACHINE\Software\Classes\Wow6432Node\Interface\{57A0E747-3863-4D20-A811-950C84F1DB9B}]
[-HKEY_LOCAL_MACHINE\Software\Classes\Wow6432Node\Interface\{86230738-D762-4C50-A2DE-A753E5B1686F}]
[-HKEY_LOCAL_MACHINE\Software\Classes\Wow6432Node\Interface\{D27CDB6C-AE6D-11CF-96B8-444553540000}]
[-HKEY_LOCAL_MACHINE\Software\Classes\Wow6432Node\Interface\{D27CDB6D-AE6D-11CF-96B8-444553540000}]
[-HKEY_LOCAL_MACHINE\Software\Wow6432Node\Macromedia]
[-HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Internet Explorer\ActiveX Compatibility\{D27CDB6E-AE6D-11CF-96B8-444553540000}]
[-HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Internet Explorer\ActiveX Compatibility\{D27CDB70-AE6D-11cf-96B8-444553540000}]
[-HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Internet Explorer\NavigatorPluginsList\Shockwave Flash]
[-HKEY_LOCAL_MACHINE\Software\Wow6432Node\MozillaPlugins\@adobe.com/FlashPlayer]</value>
</data>
</root>
+33
View File
@@ -0,0 +1,33 @@
using System;
using System.Runtime.InteropServices;
namespace CleanFlashCommon {
public class RedirectionManager {
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool Wow64DisableWow64FsRedirection(ref IntPtr ptr);
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool Wow64RevertWow64FsRedirection(IntPtr ptr);
public static IntPtr DisableRedirection() {
IntPtr redirectionPtr = (IntPtr)(-1);
try {
Wow64DisableWow64FsRedirection(ref redirectionPtr);
} catch {
// No Wow64 redirection possible.
}
return redirectionPtr;
}
public static void EnableRedirection(IntPtr redirectionPtr) {
try {
Wow64RevertWow64FsRedirection(redirectionPtr);
} catch {
// No Wow64 redirection possible.
}
}
}
}
+40
View File
@@ -0,0 +1,40 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
namespace CleanFlashCommon {
public class RegistryManager {
public static void ApplyRegistry(string registryContents) {
registryContents = "Windows Registry Editor Version 5.00\n\n" + SystemInfo.FillString(registryContents);
string filename = Path.GetTempFileName();
File.WriteAllText(filename, registryContents);
Directory.SetCurrentDirectory(Path.GetDirectoryName(filename));
ExitedProcess process = ProcessRunner.RunProcess(
new ProcessStartInfo {
FileName = "reg.exe",
Arguments = "import " + Path.GetFileName(filename),
UseShellExecute = false,
CreateNoWindow = true
}
);
File.Delete(filename);
if (!process.IsSuccessful) {
throw new InstallException(string.Format("Failed to apply changes to registry: error code {0}\n\n{1}", process.ExitCode, process.Output));
}
}
public static void ApplyRegistry(List<string> registryContents) {
ApplyRegistry(string.Join("\n\n", registryContents));
}
public static void ApplyRegistry(params string[] registryContents) {
ApplyRegistry(string.Join("\n\n", registryContents));
}
}
}
+164
View File
@@ -0,0 +1,164 @@
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace CleanFlashCommon {
public class SmoothProgressBar : UserControl {
int min = 0;
int max = 100;
int val = 0;
Color Color1 = Color.Black;
Color Color2 = Color.White;
protected override void OnResize(EventArgs e) {
Invalidate();
}
protected override void OnPaint(PaintEventArgs e) {
using (Graphics graphics = e.Graphics) {
using (Brush brush = new LinearGradientBrush(ClientRectangle, Color1, Color2, 0.0F)) {
float percent = (val - min) / (float)(max - min);
Rectangle rect = ClientRectangle;
// Calculate area for drawing the progress.
rect.Width = (int)(rect.Width * percent);
// Draw the progress meter.
graphics.FillRectangle(brush, rect);
}
// Draw a three-dimensional border around the control.
Draw3DBorder(graphics);
}
}
public int Minimum {
get {
return min;
}
set {
min = Math.Max(0, Math.Min(max, value));
if (val < min) {
val = min;
}
Invalidate();
}
}
public int Maximum {
get {
return max;
}
set {
if (value < min) {
min = value;
}
max = value;
if (val > max) {
val = max;
}
Invalidate();
}
}
public int Value {
get {
return val;
}
set {
int oldValue = val;
// Make sure that the value does not stray outside the valid range.
if (value < min) {
val = min;
} else if (value > max) {
val = max;
} else {
val = value;
}
// Invalidate only the changed area.
float percent;
Rectangle newValueRect = ClientRectangle;
Rectangle oldValueRect = ClientRectangle;
// Use a new value to calculate the rectangle for progress.
percent = (val - min) / (float)(max - min);
newValueRect.Width = (int)(newValueRect.Width * percent);
// Use an old value to calculate the rectangle for progress.
percent = (oldValue - min) / (float)(max - min);
oldValueRect.Width = (int)(oldValueRect.Width * percent);
Rectangle updateRect = new Rectangle();
// Find only the part of the screen that must be updated.
if (newValueRect.Width > oldValueRect.Width) {
updateRect.X = oldValueRect.Size.Width;
updateRect.Width = newValueRect.Width - oldValueRect.Width;
} else {
updateRect.X = newValueRect.Size.Width;
updateRect.Width = oldValueRect.Width - newValueRect.Width;
}
updateRect.Height = Height;
// Invalidate the intersection region only.
Invalidate(updateRect);
}
}
public Color ProgressBarColor1 {
get {
return Color1;
}
set {
Color1 = value;
// Invalidate the control to get a repaint.
Invalidate();
}
}
public Color ProgressBarColor2 {
get {
return Color2;
}
set {
Color2 = value;
// Invalidate the control to get a repaint.
Invalidate();
}
}
private void Draw3DBorder(Graphics g) {
int PenWidth = (int)Pens.White.Width;
g.DrawLine(Pens.DarkGray,
new Point(ClientRectangle.Left, ClientRectangle.Top),
new Point(ClientRectangle.Width - PenWidth, ClientRectangle.Top));
g.DrawLine(Pens.DarkGray,
new Point(ClientRectangle.Left, ClientRectangle.Top),
new Point(ClientRectangle.Left, ClientRectangle.Height - PenWidth));
g.DrawLine(Pens.White,
new Point(ClientRectangle.Left, ClientRectangle.Height - PenWidth),
new Point(ClientRectangle.Width - PenWidth, ClientRectangle.Height - PenWidth));
g.DrawLine(Pens.White,
new Point(ClientRectangle.Width - PenWidth, ClientRectangle.Top),
new Point(ClientRectangle.Width - PenWidth, ClientRectangle.Height - PenWidth));
}
}
}
+83
View File
@@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.IO;
namespace CleanFlashCommon {
public class SystemInfo {
private static string system32Path = Environment.GetFolderPath(Environment.SpecialFolder.SystemX86);
private static string system64Path = Environment.GetFolderPath(Environment.SpecialFolder.System);
private static string macromed32Path = Path.Combine(system32Path, "Macromed");
private static string macromed64Path = Path.Combine(system64Path, "Macromed");
private static string flash32Path = Path.Combine(macromed32Path, "Flash");
private static string flash64Path = Path.Combine(macromed64Path, "Flash");
private static string version = UpdateChecker.GetFlashVersion();
private static string versionPath = version.Replace(".", "_");
private static string versionComma = version.Replace(".", ",");
private static Dictionary<string, string> replacementStrings = new Dictionary<string, string>() {
{ "${SYSTEM_32_PATH}", system32Path.Replace(@"\", @"\\") },
{ "${SYSTEM_64_PATH}", system64Path.Replace(@"\", @"\\") },
{ "${FLASH_32_PATH}", flash32Path.Replace(@"\", @"\\") },
{ "${FLASH_64_PATH}", flash64Path.Replace(@"\", @"\\") },
{ "${VERSION}", version },
{ "${VERSION_PATH}", versionPath },
{ "${VERSION_COMMA}", versionComma }
};
public static string GetSystem32Path() {
return system32Path;
}
public static string GetSystem64Path() {
return system64Path;
}
public static string[] GetSystemPaths() {
if (Environment.Is64BitOperatingSystem) {
return new string[] { system32Path, system64Path };
} else {
return new string[] { system32Path };
}
}
public static string GetMacromed32Path() {
return macromed32Path;
}
public static string GetMacromed64Path() {
return macromed64Path;
}
public static string[] GetMacromedPaths() {
if (Environment.Is64BitOperatingSystem) {
return new string[] { macromed32Path, macromed64Path };
} else {
return new string[] { macromed32Path };
}
}
public static string GetFlash32Path() {
return flash32Path;
}
public static string GetFlash64Path() {
return flash64Path;
}
public static string GetVersionPath() {
return versionPath;
}
public static Dictionary<string, string> GetReplacementStrings() {
return replacementStrings;
}
public static string FillString(string str) {
// Some registry values require special strings to be filled out.
foreach (KeyValuePair<string, string> pair in replacementStrings) {
str = str.Replace(pair.Key, pair.Value);
}
return str;
}
}
}
+166
View File
@@ -0,0 +1,166 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
namespace CleanFlashCommon {
public class Uninstaller {
private static string[] PROCESSES_TO_KILL = new string[] {
// Flash Center-related processes
"fcbrowser", "fcbrowsermanager", "fclogin", "fctips", "flashcenter",
"flashcenterservice", "flashcenteruninst", "flashplay", "update", "wow_helper",
"dummy_cmd", "flashhelperservice",
// Flash Player-related processes
"flashplayerapp",
// Browsers that might be using Flash Player right now
"opera", "iexplore", "chrome", "chromium", "brave", "vivaldi", "basilisk", "msedge",
"seamonkey", "palemoon", "plugin-container"
};
public static void UninstallRegistry() {
if (Environment.Is64BitOperatingSystem) {
RegistryManager.ApplyRegistry(Properties.Resources.uninstallRegistry, Properties.Resources.uninstallRegistry64);
} else {
RegistryManager.ApplyRegistry(Properties.Resources.uninstallRegistry);
}
}
public static void DeleteTask(string task) {
ProcessRunner.RunUnmanagedProcess(
new ProcessStartInfo {
FileName = "schtasks.exe",
Arguments = "/delete /tn \"" + task + "\" /f",
UseShellExecute = false,
CreateNoWindow = true
}
);
}
public static void StopService(string service) {
ProcessRunner.RunUnmanagedProcess(
new ProcessStartInfo {
FileName = "net.exe",
Arguments = "stop \"" + service + "\"",
UseShellExecute = false,
CreateNoWindow = true
}
);
}
public static void DeleteService(string service) {
// First, stop the service.
StopService(service);
ProcessRunner.RunUnmanagedProcess(
new ProcessStartInfo {
FileName = "sc.exe",
Arguments = "delete \"" + service + "\"",
UseShellExecute = false,
CreateNoWindow = true
}
);
}
public static void DeleteFlashCenter() {
// Remove Flash Center from Program Files
FileUtil.RecursiveDelete(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "FlashCenter"));
if (Environment.Is64BitOperatingSystem) {
// Remove Flash Center from Program Files (x86)
FileUtil.RecursiveDelete(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "FlashCenter"));
}
// Remove start menu shortcuts
FileUtil.RecursiveDelete(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Microsoft", "Windows", "Start Menu", "Programs", "Flash Center"));
// Remove Flash Center cache and user data
FileUtil.RecursiveDelete(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Flash_Center"));
// Remove shared start menu shortcuts
FileUtil.RecursiveDelete(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu), "Programs", "Flash Center"));
FileUtil.RecursiveDelete(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Programs", "Flash Center"));
// Remove Desktop shortcut
FileUtil.DeleteFile(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory), "Flash Center.lnk"));
// Remove spyware dropped by Flash Center in the temporary folder
string tempFolder = Path.GetTempPath();
foreach (string dir in Directory.GetDirectories(tempFolder)) {
string parentName = Path.GetFileName(dir);
if (parentName.Length == 11 && parentName.EndsWith(".tmp")) {
FileUtil.RecursiveDelete(dir);
}
}
// Remove Quick Launch shortcuts from Internet Explorer
FileUtil.RecursiveDelete(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Microsoft", "Internet Explorer", "Quick Launch"), "Flash Center.lnk");
}
public static void DeleteFlashPlayer() {
// Remove Macromedia folder from System32 and SysWOW64
foreach (string dir in SystemInfo.GetMacromedPaths()) {
FileUtil.RecursiveDelete(dir);
}
// Remove Flash Player control panel applications
foreach (string systemDir in SystemInfo.GetSystemPaths()) {
FileUtil.DeleteFile(Path.Combine(systemDir, "FlashPlayerApp.exe"));
FileUtil.DeleteFile(Path.Combine(systemDir, "FlashPlayerCPLApp.cpl"));
}
}
public static void StopProcesses() {
// Stop all processes that might interfere with the install process
List<Process> processes = Process.GetProcesses()
.Where(process => PROCESSES_TO_KILL.Contains(process.ProcessName.ToLower()))
.OrderBy(o => o.StartTime)
.ToList();
foreach (Process process in processes) {
if (process.HasExited) {
// This process has already exited, no point to kill it
continue;
}
try {
process.Kill();
process.WaitForExit();
} catch {
// Could not kill process...
}
}
}
public static void Uninstall(IProgressForm form) {
// Uninstallation of Flash consists of the following steps:
// 1. Delete all auto-updater tasks.
// 2. Delete all Flash Player services.
// 3. Delete all Flash Center services.
// 4. Exit all browsers and other processes that may interfere with uninstallation.
// 5. Remove all Flash Player references from the registry.
// 6. Remove Flash Center files from the file system.
// 7. Remove Flash Player files from the file system.
form.UpdateProgressLabel("Stopping Flash auto-updater task...", true);
DeleteTask("Adobe Flash Player Updater");
form.UpdateProgressLabel("Stopping Flash auto-updater service...", true);
DeleteService("AdobeFlashPlayerUpdateSvc");
form.UpdateProgressLabel("Stopping Flash Center services...", true);
DeleteService("Flash Helper Service");
form.TickProgress();
DeleteService("FlashCenterService");
form.UpdateProgressLabel("Exiting all browsers...", true);
StopProcesses();
form.UpdateProgressLabel("Cleaning up registry...", true);
UninstallRegistry();
form.UpdateProgressLabel("Removing Flash Center...", true);
DeleteFlashCenter();
form.UpdateProgressLabel("Removing Flash Player...", true);
DeleteFlashPlayer();
}
}
}
+83
View File
@@ -0,0 +1,83 @@
using System;
using System.Linq;
using System.Text;
using System.Net;
using System.Runtime.Serialization.Json;
using System.Xml;
using System.Xml.Linq;
namespace CleanFlashCommon {
public class Version {
private string name;
private string version;
private string url;
public Version(string name, string version, string url) {
this.name = name;
this.version = version;
this.url = url;
}
public string GetName() {
return name;
}
public string GetVersion() {
return version;
}
public string GetUrl() {
return url;
}
}
public class UpdateChecker {
private static readonly string FLASH_VERSION = "34.0.0.155";
private static readonly string VERSION = "v34.0.0.155";
private static readonly string AUTHOR = "cleanflash";
private static readonly string REPO = "installer";
private static readonly string USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36";
public static string GetAPILink() {
return "https://api.github.com/repos/" + AUTHOR + "/" + REPO + "/releases/latest";
}
public static string GetFlashVersion() {
return FLASH_VERSION;
}
public static string GetCurrentVersion() {
return VERSION;
}
private static Version GetLatestVersionUnsafe() {
using (WebClient client = new WebClient()) {
client.Headers.Add("user-agent", USER_AGENT);
string release = client.DownloadString(GetAPILink());
XmlDictionaryReader jsonReader = JsonReaderWriterFactory.CreateJsonReader(Encoding.UTF8.GetBytes(release), new XmlDictionaryReaderQuotas());
XElement root = XElement.Load(jsonReader);
string name = root.Descendants("name").FirstOrDefault().Value;
string tag = root.Descendants("tag_name").FirstOrDefault().Value;
string url = root.Descendants("html_url").FirstOrDefault().Value;
if (!url.StartsWith("https://")) {
// This is a suspicious URL... We shouldn't trust it.
return null;
}
return new Version(name, tag, url);
}
}
public static Version GetLatestVersion() {
try {
return GetLatestVersionUnsafe();
} catch (Exception e) {
Console.WriteLine(e);
return null;
}
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 257 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 448 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB