From 7568ab4239f8cf191fa7edee030d1a6388fcc3de Mon Sep 17 00:00:00 2001 From: ttwiz_z Date: Sun, 11 Feb 2024 12:48:29 +0300 Subject: [PATCH] Project publication --- Program.cs | 99 +++++++++++++++++++++++++++++++++++++++++++ SecureLauncher.csproj | 10 +++++ SecureLauncher.sln | 25 +++++++++++ 3 files changed, 134 insertions(+) create mode 100644 Program.cs create mode 100644 SecureLauncher.csproj create mode 100644 SecureLauncher.sln diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..fe8432a --- /dev/null +++ b/Program.cs @@ -0,0 +1,99 @@ +using System.Diagnostics; +using System.Runtime.CompilerServices; +using System.Security.Cryptography; +using System.Text; + +main(); + +static byte[] GenerateByte() +{ + int length = new Random().Next(2, 7); + byte[] numArray = new byte[length]; + for (int index = 0; index < length; ++index) + numArray[index] = 0; + return numArray; +} + +static string GenerateRandomString(int length) +{ + Random random = new Random(); + StringBuilder stringBuilder = new StringBuilder(length); + for (int index = 0; index < length; ++index) + stringBuilder.Append("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"[random.Next("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz".Length)]); + return stringBuilder.ToString(); +} + +static void ShuffleMD5(string file) +{ + int num = new FileInfo(file).Length > 1048576L ? 1048576 : 4096; + byte[] numArray = GenerateByte(); + using (FileStream fileStream = new FileStream(file, (FileMode)6)) + (fileStream).Write(numArray, 0, numArray.Length); + using (MD5 md5 = MD5.Create()) + { + using (FileStream fileStream = new FileStream(file, (FileMode)3, (FileAccess)1, (FileShare)1, num)) + Console.WriteLine("New MD5 hash: " + BitConverter.ToString((md5).ComputeHash(fileStream)).Replace("-", "")); + } +} + +static string ShuffleName(string currentDirectory, string oldFilePath) +{ + Path.GetFileNameWithoutExtension(oldFilePath); + string randomString = GenerateRandomString(8); + string str = Path.Combine(currentDirectory, randomString + ".exe"); + try + { + File.Move(oldFilePath, str); + DefaultInterpolatedStringHandler interpolatedStringHandler = new DefaultInterpolatedStringHandler(17, 2); + interpolatedStringHandler.AppendLiteral("Renamed '"); + interpolatedStringHandler.AppendFormatted(oldFilePath); + interpolatedStringHandler.AppendLiteral("' to '"); + interpolatedStringHandler.AppendFormatted(str); + interpolatedStringHandler.AppendLiteral("'."); + Console.WriteLine(interpolatedStringHandler.ToStringAndClear()); + } + catch (IOException ex) + { + Console.WriteLine("An error occurred: " + ex.Message); + } + return str; +} + +static void main() +{ + try + { + string baseDirectory = AppContext.BaseDirectory; + string processName = Process.GetCurrentProcess().ProcessName; + List list = Enumerable.ToList(Enumerable.Where((IEnumerable)Directory.GetFiles(baseDirectory, "*.exe"), (file => !string.Equals(Path.GetFileName(file), processName + ".exe")))); + if (list.Count == 1) + { + Console.WriteLine("Found exe, obscuring."); + Console.WriteLine(list[0]); + Console.WriteLine("Shuffling Hash, one moment.."); + ShuffleMD5(list[0]); + Console.WriteLine("Shuffling exe name, one moment.."); + string str = ShuffleName(baseDirectory, list[0]); + Console.WriteLine("Shuffling complete, launching exe."); + Process.Start(new ProcessStartInfo() + { + FileName = str, + UseShellExecute = true + }); + } + else + { + Console.WriteLine("Couldn't find exe or too many exe files in folder."); + Console.ReadLine(); + } + Thread.Sleep(5000); + } + catch (Exception ex) + { + DefaultInterpolatedStringHandler interpolatedStringHandler = new DefaultInterpolatedStringHandler(20, 1); + interpolatedStringHandler.AppendLiteral("There was an error: "); + interpolatedStringHandler.AppendFormatted(ex); + Console.WriteLine(interpolatedStringHandler.ToStringAndClear()); + Console.ReadLine(); + } +} diff --git a/SecureLauncher.csproj b/SecureLauncher.csproj new file mode 100644 index 0000000..206b89a --- /dev/null +++ b/SecureLauncher.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/SecureLauncher.sln b/SecureLauncher.sln new file mode 100644 index 0000000..bb39bc7 --- /dev/null +++ b/SecureLauncher.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34525.116 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecureLauncher", "SecureLauncher.csproj", "{6C8F1516-95C1-4D25-8F3B-3447109EEE7D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6C8F1516-95C1-4D25-8F3B-3447109EEE7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6C8F1516-95C1-4D25-8F3B-3447109EEE7D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6C8F1516-95C1-4D25-8F3B-3447109EEE7D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6C8F1516-95C1-4D25-8F3B-3447109EEE7D}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A72BF84F-DB99-44EB-AECB-53A00AF37F5E} + EndGlobalSection +EndGlobal