Skip to content

Commit

Permalink
first
Browse files Browse the repository at this point in the history
Initial commit, lots of files.
  • Loading branch information
calebtt committed May 3, 2015
0 parents commit ea0e4f4
Show file tree
Hide file tree
Showing 51 changed files with 1,892 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Auto detect text files and perform LF normalization
* text=auto

# Custom for Visual Studio
*.cs diff=csharp

# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
43 changes: 43 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk

# =========================
# Operating System Files
# =========================

# OSX
# =========================

.DS_Store
.AppleDouble
.LSOverride

# Thumbnails
._*

# Files that might appear on external disk
.Spotlight-V100
.Trashes

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
28 changes: 28 additions & 0 deletions HookProcDLL/HookProcDLL.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SetHooksClassLibrary", "SetHooksClassLibrary\SetHooksClassLibrary.vcxproj", "{8424E327-0206-47AB-A3BD-A85A864A2CBD}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HookProcDLL", "HookProcDLL\HookProc DLL.vcxproj", "{5A8C2462-C8F7-4CD6-B673-58CFD2C720B5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8424E327-0206-47AB-A3BD-A85A864A2CBD}.Debug|Win32.ActiveCfg = Debug|Win32
{8424E327-0206-47AB-A3BD-A85A864A2CBD}.Debug|Win32.Build.0 = Debug|Win32
{8424E327-0206-47AB-A3BD-A85A864A2CBD}.Release|Win32.ActiveCfg = Release|Win32
{8424E327-0206-47AB-A3BD-A85A864A2CBD}.Release|Win32.Build.0 = Release|Win32
{5A8C2462-C8F7-4CD6-B673-58CFD2C720B5}.Debug|Win32.ActiveCfg = Debug|Win32
{5A8C2462-C8F7-4CD6-B673-58CFD2C720B5}.Debug|Win32.Build.0 = Debug|Win32
{5A8C2462-C8F7-4CD6-B673-58CFD2C720B5}.Release|Win32.ActiveCfg = Release|Win32
{5A8C2462-C8F7-4CD6-B673-58CFD2C720B5}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Binary file added HookProcDLL/HookProcDLL.suo
Binary file not shown.
Binary file added HookProcDLL/HookProcDLL.v12.suo
Binary file not shown.
136 changes: 136 additions & 0 deletions HookProcDLL/HookProcDLL/HookClass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#include "stdafx.h"
#include "HookClass.h"

namespace HookDLL
{

//The error checking procedures take an integer that will help with debugging, it is only a temporary measure.
HookClass::HookClass()
{
dllHandle = ::LoadLibrary(HOOK_DLL_NAME2);
if(!dllHandle)
{
std::cerr << "Load Lib fail." << std::endl;
throw std::exception("Load library failure.");
}

HOOKPROC keyProc = (HOOKPROC)::GetProcAddress(dllHandle, "keyboardHookProcedure");
HOOKPROC proc = (HOOKPROC)::GetProcAddress(dllHandle, "mouseHookProcedure");
int err = CheckHookProc(proc, 2);
int err2 = CheckHookProc(keyProc, 3);

if(err != 0 || err2 != 0)
{
//Cleanup
CleanupLibraries();
throw std::exception("Get proc addresses failure.");
}


std::cout << "Located mouse proc.\nSetting hook." << std::endl;
hooks.push_back(::SetWindowsHookExA(WH_MOUSE_LL, proc, dllHandle, NULL));
std::cout << "Located keyboard proc.\nSetting hook." << std::endl;
hooks.push_back(::SetWindowsHookExA(WH_KEYBOARD_LL, keyProc, dllHandle, NULL));


err = CheckHook(hooks[0], 3);
err2 = CheckHook(hooks[1], 4);

if(err != 0 || err2 != 0)
{
CleanupHooks(hooks, this->hookCount);
CleanupLibraries();
throw std::exception("Set hooks failure.");
}

std::cout << "\nAll hooks set.\n";
}

HookClass::HookClass(bool kbd, bool mse)
{
throw std::string("unfinished");
dllHandle = NULL;
dllHandle = ::LoadLibrary(HOOK_DLL_NAME);
if(!dllHandle)
{
std::cerr << "Load Lib fail." << std::endl;
throw std::exception("Load library failure.");
}

HOOKPROC keyProc = (HOOKPROC)::GetProcAddress(dllHandle, "keyboardHookProcedure");
int err2 = CheckHookProc(keyProc, 3);
if(err2 != 0)
{
//Cleanup
CleanupLibraries();
throw std::exception("Get proc addresses failure.");
}
std::cout << "Located keyboard proc.\nSetting hook." << std::endl;
hooks.push_back(::SetWindowsHookExA(WH_KEYBOARD_LL, keyProc, dllHandle, NULL));

HOOKPROC proc = (HOOKPROC)::GetProcAddress(dllHandle, "mouseHookProcedure");
int err = CheckHookProc(proc, 2);


std::cout << "Located mouse proc.\nSetting hook." << std::endl;
hooks.push_back(::SetWindowsHookExA(WH_MOUSE_LL, proc, dllHandle, NULL));


err = CheckHook(hooks[0], 3);
err2 = CheckHook(hooks[1], 4);

if(err != 0 || err2 != 0)
{
CleanupHooks(hooks, this->hookCount);
CleanupLibraries();
throw std::exception("Set hooks failure.");
}

std::cout << "\nAll hooks set.\n";
}
HookClass::~HookClass()
{
CleanupHooks(hooks,hookCount);
CleanupLibraries();
}

int HookClass::CheckHookProc(HOOKPROC proc, int ret)
{
if(!proc)
{
std::cerr << "Last error: " << ::GetLastError() << std::endl;
std::cerr << "Get proc addr fail." << std::endl;
return ret;
}
return 0;
}


int HookClass::CheckHook(HHOOK hook, int ret)
{
if(!hook)
{
std::cerr << "Last error: " << ::GetLastError() << std::endl;
std::cerr << "Set hook fail." << std::endl;
return ret;
}
return 0;
}
void HookClass::CleanupHooks(std::vector<HHOOK> hooks, size_t size = hookCount)
{
BOOL ret = FALSE;
for(size_t i = 0; i < size; i++)
{
ret = ::UnhookWindowsHookEx(hooks[i]);
if(ret)
std::cerr << "Hook unhooked." << std::endl;
else
std::cerr << "Hook ALREADY unhooked." << std::endl;
}
}
void HookClass::CleanupLibraries()
{
FreeLibrary(dllHandle);
}

}
28 changes: 28 additions & 0 deletions HookProcDLL/HookProcDLL/HookClass.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once
#include "stdafx.h"
#include <windows.h>


namespace HookDLL
{


class HookClass
{
const char *HOOK_DLL_NAME2 = "HookProcDLL.dll";
static const int hookCount = 2;
HMODULE dllHandle;
std::vector<HHOOK> hooks;
protected:
int CheckHookProc(HOOKPROC proc, int ret);
int CheckHook(HHOOK hook, int ret);
void CleanupHooks(std::vector<HHOOK> hooks, size_t size);
void CleanupLibraries();
public:
///<summary> Constructor, loads hook DLL and will report error. </summary>
HookClass();
HookClass(bool kbd, bool mse);
~HookClass();
};

}
103 changes: 103 additions & 0 deletions HookProcDLL/HookProcDLL/HookProc DLL.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{5A8C2462-C8F7-4CD6-B673-58CFD2C720B5}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>HookProcDLL</RootNamespace>
<ProjectName>HookProcDLL</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>NotSet</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;HOOKPROCDLL_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CallingConvention>StdCall</CallingConvention>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;HOOKPROCDLL_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<None Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="SendKey.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
<CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</CompileAsManaged>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
</PrecompiledHeader>
<CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</CompileAsManaged>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
</PrecompiledHeader>
</ClCompile>
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
Loading

0 comments on commit ea0e4f4

Please sign in to comment.