Advertisement
ModerkaScripts

Secure Launcher

May 12th, 2024
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.77 KB | None | 0 0
  1. using System.Diagnostics;
  2. using System.Runtime.CompilerServices;
  3. using System.Security.Cryptography;
  4. using System.Text;
  5.  
  6. static byte[] GenerateByte()
  7. {
  8.     int length = new Random().Next(2, 7);
  9.     byte[] numArray = new byte[length];
  10.     for (int index = 0; index < length; ++index)
  11.     numArray[index] = 0;
  12.     return numArray;
  13. }
  14.  
  15. static string GenerateRandomString(int length)
  16. {
  17.     Random random = new Random();
  18.     StringBuilder stringBuilder = new StringBuilder(length);
  19.     for (int index = 0; index < length; ++index)
  20.     stringBuilder.Append("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"[random.Next("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz".Length)]);
  21.     return stringBuilder.ToString();
  22. }
  23.  
  24. static void ShuffleMD5(string file)
  25. {
  26.     int num = new FileInfo(file).Length > 1048576L ? 1048576 : 4096;
  27.     byte[] numArray = GenerateByte();
  28.     using (FileStream fileStream = new FileStream(file, (FileMode)6))
  29.     fileStream.Write(numArray, 0, numArray.Length);
  30.     using (MD5 md5 = MD5.Create())
  31.     {
  32.         using (FileStream fileStream = new FileStream(file, (FileMode)3, (FileAccess)1, (FileShare)1, num))
  33.         Console.WriteLine("New MD5 hash: " + BitConverter.ToString(md5.ComputeHash(fileStream)).Replace("-", ""));
  34.     }
  35. }
  36.  
  37. static string ShuffleName(string currentDirectory, string oldFilePath)
  38. {
  39.     Path.GetFileNameWithoutExtension(oldFilePath);
  40.     string randomString = GenerateRandomString(8);
  41.     string newFilePath = Path.Combine(currentDirectory, randomString + ".exe");
  42.     try
  43.     {
  44.         File.Move(oldFilePath, newFilePath);
  45.         DefaultInterpolatedStringHandler interpolatedStringHandler = new DefaultInterpolatedStringHandler(17, 2);
  46.         interpolatedStringHandler.AppendLiteral("Renamed '");
  47.         interpolatedStringHandler.AppendFormatted(oldFilePath);
  48.         interpolatedStringHandler.AppendLiteral("' to '");
  49.         interpolatedStringHandler.AppendFormatted(newFilePath);
  50.         interpolatedStringHandler.AppendLiteral("'.");
  51.         Console.WriteLine(interpolatedStringHandler.ToStringAndClear());
  52.     }
  53.     catch (IOException ex)
  54.     {
  55.         Console.WriteLine("An error occurred: " + ex.Message);
  56.     }
  57.     return newFilePath;
  58. }
  59.  
  60. static void main()
  61. {
  62.     try
  63.     {
  64.         string baseDirectory = AppContext.BaseDirectory;
  65.         string processName = Process.GetCurrentProcess().ProcessName;
  66.         List<string> list = Enumerable.ToList(Enumerable.Where((IEnumerable<string>)Directory.GetFiles(baseDirectory, "*.exe"), (file => !string.Equals(Path.GetFileName(file), processName + ".exe"))));
  67.         if (list.Count == 1)
  68.         {
  69.             Console.WriteLine("Found exe, obscuring.");
  70.             Console.WriteLine(list[0]);
  71.             Console.WriteLine("Shuffling Hash, one moment..");
  72.             ShuffleMD5(list[0]);
  73.             Console.WriteLine("Shuffling exe name, one moment..");
  74.             string newFileName = ShuffleName(baseDirectory, list[0]);
  75.             Console.WriteLine("Shuffling complete, launching exe.");
  76.             Process.Start(new ProcessStartInfo()
  77.             {
  78.                 FileName = newFileName,
  79.                 UseShellExecute = true
  80.             });
  81.         }
  82.         else
  83.         {
  84.             Console.WriteLine("Couldn't find exe or too many exe files in folder.");
  85.             Console.ReadLine();
  86.         }
  87.         Thread.Sleep(5000);
  88.     }
  89.     catch (Exception ex)
  90.     {
  91.         DefaultInterpolatedStringHandler interpolatedStringHandler = new DefaultInterpolatedStringHandler(20, 1);
  92.         interpolatedStringHandler.AppendLiteral("There was an error: ");
  93.         interpolatedStringHandler.AppendFormatted(ex);
  94.         Console.WriteLine(interpolatedStringHandler.ToStringAndClear());
  95.         Console.ReadLine();
  96.     }
  97. }
  98.  
  99. main();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement