From b030831991aa7cc697dfc73feb2535a799fb5b8c Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 19 Oct 2020 10:39:12 -0400 Subject: [PATCH] Add project files. --- chromewphook.cpp | 15 ++++ chromewphook.sln | 31 +++++++ chromewphook.vcxproj | 159 +++++++++++++++++++++++++++++++++++ chromewphook.vcxproj.filters | 19 +++++ hooks.cpp | 30 +++++++ hooks.h | 11 +++ 6 files changed, 265 insertions(+) create mode 100644 chromewphook.cpp create mode 100644 chromewphook.sln create mode 100644 chromewphook.vcxproj create mode 100644 chromewphook.vcxproj.filters create mode 100644 hooks.cpp create mode 100644 hooks.h diff --git a/chromewphook.cpp b/chromewphook.cpp new file mode 100644 index 0000000..53cdb56 --- /dev/null +++ b/chromewphook.cpp @@ -0,0 +1,15 @@ +#include +#include +#include +#include "hooks.h" + +int main() +{ + std::cout << "hello" << std::endl; + std::cout << FindWindow("Chrome_WidgetWin_1", NULL) << std::endl; + if (!hooks::setup()) + std::cout << "hooking returned false" << std::endl; + while (!GetAsyncKeyState(VK_F10)) + std::this_thread::sleep_for(std::chrono::milliseconds(20)); + std::cout << "done" << std::endl; +} \ No newline at end of file diff --git a/chromewphook.sln b/chromewphook.sln new file mode 100644 index 0000000..e076b0d --- /dev/null +++ b/chromewphook.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29926.136 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "chromewphook", "chromewphook.vcxproj", "{FB66946B-C5A1-4314-AF40-3F0F31979AF9}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FB66946B-C5A1-4314-AF40-3F0F31979AF9}.Debug|x64.ActiveCfg = Debug|x64 + {FB66946B-C5A1-4314-AF40-3F0F31979AF9}.Debug|x64.Build.0 = Debug|x64 + {FB66946B-C5A1-4314-AF40-3F0F31979AF9}.Debug|x86.ActiveCfg = Debug|Win32 + {FB66946B-C5A1-4314-AF40-3F0F31979AF9}.Debug|x86.Build.0 = Debug|Win32 + {FB66946B-C5A1-4314-AF40-3F0F31979AF9}.Release|x64.ActiveCfg = Release|x64 + {FB66946B-C5A1-4314-AF40-3F0F31979AF9}.Release|x64.Build.0 = Release|x64 + {FB66946B-C5A1-4314-AF40-3F0F31979AF9}.Release|x86.ActiveCfg = Release|Win32 + {FB66946B-C5A1-4314-AF40-3F0F31979AF9}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {DA3E707A-FF44-43C6-A4CF-EEA71B229680} + EndGlobalSection +EndGlobal diff --git a/chromewphook.vcxproj b/chromewphook.vcxproj new file mode 100644 index 0000000..4006ed9 --- /dev/null +++ b/chromewphook.vcxproj @@ -0,0 +1,159 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {FB66946B-C5A1-4314-AF40-3F0F31979AF9} + Win32Proj + chromewphook + 10.0 + + + + Application + true + v142 + MultiByte + + + Application + false + v142 + true + MultiByte + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/chromewphook.vcxproj.filters b/chromewphook.vcxproj.filters new file mode 100644 index 0000000..8e329fc --- /dev/null +++ b/chromewphook.vcxproj.filters @@ -0,0 +1,19 @@ + + + + + + hooks + + + + + {07a9d87f-bc27-4401-b54a-0cf2aa88443d} + + + + + hooks + + + \ No newline at end of file diff --git a/hooks.cpp b/hooks.cpp new file mode 100644 index 0000000..738b3ff --- /dev/null +++ b/hooks.cpp @@ -0,0 +1,30 @@ +#include "hooks.h" + +WNDPROC oWndProc = nullptr; + + +//https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/ms633573(v=vs.85) +LRESULT CALLBACK hooks::hkWndProc(HWND handle, UINT message, WPARAM wParam, LPARAM lParam) +{ + static bool block = false; + if (GetAsyncKeyState(VK_F9) & 0x1) + block = !block; + if (block) + return 1; + return CallWindowProcA(oWndProc, handle, message, wParam, lParam); +} + +bool hooks::setup() +{ + //https://stackoverflow.com/questions/19705797/find-the-window-handle-for-a-chrome-browser + oWndProc = (WNDPROC)(SetWindowLongPtr(FindWindow("Chrome_WidgetWin_1", NULL), GWLP_WNDPROC, (LONG)hkWndProc)); + if (!oWndProc) + return false; + return true; +} + +bool hooks::destroy() +{ + SetWindowLongPtr(FindWindow("Chrome_WidgetWin_1", NULL), GWLP_WNDPROC, (LONG)oWndProc); + return true; +} \ No newline at end of file diff --git a/hooks.h b/hooks.h new file mode 100644 index 0000000..f767196 --- /dev/null +++ b/hooks.h @@ -0,0 +1,11 @@ +#pragma once +#include +#include + +namespace hooks +{ + //https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/ms633573(v=vs.85) + LRESULT CALLBACK hkWndProc(HWND handle, UINT message, WPARAM wParam, LPARAM lParam); + bool setup(); + bool destroy(); +} \ No newline at end of file