Click here to Skip to main content
15,897,704 members
Articles / Programming Languages / C++

Keystroke Monitoring

,
Rate me:
Please Sign up or sign in to vote.
4.93/5 (53 votes)
19 Oct 2009CPOL6 min read 103.4K   4.7K   164  
In this article, we will consider the methods of hooking keyboard data in the kernel mode.
#ifndef _YVALS
#define _YVALS

extern "C"{
    #include <ntifs.h>
}

#ifndef _WCHAR_T_DEFINED
typedef unsigned short wchar_t;
#define _WCHAR_T_DEFINED
#endif

#ifndef _WCTYPE_T_DEFINED
typedef unsigned short wint_t;
typedef unsigned short wctype_t;
#define _WCTYPE_T_DEFINED
#endif

#ifndef _PTRDIFF_T_DEFINED
#ifdef  _WIN64
typedef __int64             ptrdiff_t;
#else
typedef int            ptrdiff_t;
#endif
#define _PTRDIFF_T_DEFINED
#endif

#ifndef __CRTDECL
    #define __CRTDECL   __cdecl
#endif

#define __CLR_OR_THIS_CALL

#ifndef _HAS_EXCEPTIONS
    #define  _HAS_EXCEPTIONS  1	/* predefine as 0 to disable exceptions */
#endif /* _HAS_EXCEPTIONS */

#if defined(__cplusplus)
    #define _STD_BEGIN	namespace std {
    #define _STD_END	}
    #define _STD	::std::

    /*
    We use the stdext (standard extension) namespace to contain extensions that are not part of the current standard
    */
    #define _STDEXT_BEGIN	namespace stdext {
    #define _STDEXT_END		}
    #define _STDEXT	    ::stdext::

    #ifdef _STD_USING
    #define _C_STD_BEGIN	namespace std {	/* only if *.c compiled as C++ */
    #define _C_STD_END	}
    #define _CSTD	::std::

    #else /* _STD_USING */
    /* #define _GLOBAL_USING	*.h in global namespace, c* imports to std */

    #define _C_STD_BEGIN
    #define _C_STD_END
    #define _CSTD	::
    #endif /* _STD_USING */
#else /* __cplusplus */
    #define _STD_BEGIN
    #define _STD_END
#endif

_C_STD_BEGIN

typedef int _Mbstatet;

_C_STD_END

__inline wchar_t * __CRTDECL wmemchr(const wchar_t *_S, wchar_t _C, size_t _N)
{
    for (; 0 < _N; ++_S, --_N)
        if (*_S == _C)
            return (wchar_t *)(_S);
    return (0); 
}

#define _CRT_SECURE_WMEMMOVE(dest, destsize, source, count) ::memmove((dest), (source), (count)*sizeof(wchar_t))
#define _CRT_SECURE_WMEMCPY(dest, destsize, source, count) memcpy((dest), (source), (count)*sizeof(wchar_t))
#define _CRT_SECURE_MEMCPY(dest, destsize, source, count) ::memcpy((dest), (source), (count))
#define _CRT_SECURE_MEMMOVE(dest, destsize, source, count) ::memmove((dest), (source), (count))

_STD_BEGIN

class _Lockit
{	// lock while object in existence -- MUST NEST
public:
    explicit _Lockit()
    {	// do nothing
    }

    explicit _Lockit(int)
    {	// do nothing
    }

    ~_Lockit()
    {	// do nothing
    }
};

_STD_END

#define _DEBUG_ERROR(msg) DbgPrint(msg)

/* MULTITHREAD PROPERTIES */
/* LOCK MACROS */
#define _LOCK_LOCALE	0
#define _LOCK_MALLOC	1
#define _LOCK_STREAM	2
#define _LOCK_DEBUG		3
#define _MAX_LOCK		4	/* one more than highest lock number */

#ifdef __cplusplus
_STD_BEGIN
typedef bool _Bool;
_STD_END
#endif /* __cplusplus */

/* VC++ COMPILER PARAMETERS */
#define _LONGLONG	__int64
#define _ULONGLONG	unsigned __int64
#define _LLONG_MAX	0x7fffffffffffffff
#define _ULLONG_MAX	0xffffffffffffffff

#define EOF     (-1)

#ifndef _HAS_IMMUTABLE_SETS
#define _HAS_IMMUTABLE_SETS 0
#endif /* _HAS_IMMUTABLE_SETS */

#ifndef _HAS_STRICT_CONFORMANCE
#define _HAS_STRICT_CONFORMANCE 0
#endif /* _HAS_STRICT_CONFORMANCE */

#ifndef _HAS_TRADITIONAL_STL
#define _HAS_TRADITIONAL_STL 0
#endif /* _HAS_TRADITIONAL_STL */

#define _SECURE_VALIDATION_DEFAULT false

#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer Apriorit Inc.
United States United States
ApriorIT is a software research and development company specializing in cybersecurity and data management technology engineering. We work for a broad range of clients from Fortune 500 technology leaders to small innovative startups building unique solutions.

As Apriorit offers integrated research&development services for the software projects in such areas as endpoint security, network security, data security, embedded Systems, and virtualization, we have strong kernel and driver development skills, huge system programming expertise, and are reals fans of research projects.

Our specialty is reverse engineering, we apply it for security testing and security-related projects.

A separate department of Apriorit works on large-scale business SaaS solutions, handling tasks from business analysis, data architecture design, and web development to performance optimization and DevOps.

Official site: https://www.apriorit.com
Clutch profile: https://clutch.co/profile/apriorit
This is a Organisation

33 members

Written By
Software Developer (Senior) AptiorIT
Ukraine Ukraine
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions