Exetools  

Go Back   Exetools > General > Source Code

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 11-07-2023, 12:12
vic4key's Avatar
vic4key vic4key is offline
Family
 
Join Date: Apr 2010
Posts: 62
Rept. Given: 5
Rept. Rcvd 24 Times in 10 Posts
Thanks Given: 62
Thanks Rcvd at 98 Times in 23 Posts
vic4key Reputation: 24
Talking C++ Hooking - Write Less Do More

With this library, you can set up function hooking easily and write less code.
It supports both Inline hooking & IAT hooking on both 32-bit & 64-bit.

Eg. To hook/un-hook a function with the Inline Hooking technique, you only need to write codes as the following
Code:
#include "cpp-hooking/hooking.h"

// Define the hooking function
int WINAPI hkMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType)
{
  lpText = L"INL Hooked";
  return INLHookingManager::instance().invoke<int>(MessageBoxW, hWnd, lpText, lpCaption, uType);
}

// Perform hooking
INLHookingManager::instance().hook(MessageBoxW, hkMessageBoxW);

// Perform un-hooking
INLHookingManager::instance().unhook(MessageBoxW);
Eg. To hook/un-hook a function with the IAT Hooking technique, you only need to write codes as the following
Code:
#include "cpp-hooking/hooking.h"

// Define the hooking entry
#define Entry_MessageBoxW { "cpp-hooking.exe"s, "user32.dll"s, "MessageBoxW"s }

// Define the hooking function
int WINAPI hkMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType)
{
  lpText = L"IAT Hooked";
  return IATHookingManager::instance().invoke<int>(Entry_MessageBoxW, hWnd, lpText, lpCaption, uType);
}

// Perform hooking
IATHookingManager::instance().hook(Entry_MessageBoxW, hkMessageBoxW);

// Perform un-hooking
IATHookingManager::instance().unhook(Entry_MessageBoxW);
The repository @ https://github.com/vic4key/cpp-hooking.git

Follow me on GitHub @ https://github.com/vic4key

Regards,
Vic P.

Last edited by vic4key; 11-07-2023 at 15:26. Reason: forum auto remove unexpected chars when submitting the post
Reply With Quote
The Following 4 Users Gave Reputation+1 to vic4key For This Useful Post:
ahmadmansoor (11-07-2023), blue_devil (11-07-2023), chants (11-12-2023), MarcElBichon (11-07-2023)
The Following 13 Users Say Thank You to vic4key For This Useful Post:
ahmadmansoor (11-07-2023), astroid (11-09-2023), besoeso (11-08-2023), blue_devil (11-07-2023), canopus (01-12-2024), chants (11-12-2023), darkBLACK (11-09-2023), Dr.FarFar (04-14-2024), NoneForce (11-07-2023), pnta (11-12-2023), WillyTerra (11-19-2023), wilson bibe (11-07-2023), zhongtiany (11-07-2023)
  #2  
Old 11-07-2023, 14:26
wilson bibe wilson bibe is offline
VIP
 
Join Date: Nov 2012
Posts: 499
Rept. Given: 491
Rept. Rcvd 439 Times in 180 Posts
Thanks Given: 920
Thanks Rcvd at 178 Times in 113 Posts
wilson bibe Reputation: 400-499 wilson bibe Reputation: 400-499 wilson bibe Reputation: 400-499 wilson bibe Reputation: 400-499 wilson bibe Reputation: 400-499
Hello, is it possible for someone publish the compiled version of this tool? Thanks in advance
Reply With Quote
  #3  
Old 11-07-2023, 14:32
blue_devil's Avatar
blue_devil blue_devil is offline
Family
 
Join Date: Dec 2011
Location: Observable Universe
Posts: 343
Rept. Given: 78
Rept. Rcvd 51 Times in 24 Posts
Thanks Given: 342
Thanks Rcvd at 496 Times in 168 Posts
blue_devil Reputation: 52
Hello vic4key, you have an awesome repo. Once, I have created a thread for sharing our socials (not only twitter&instagram but github&gitlab or other similar accounts)
Socials

If you want you can share your socials on this thread.

Regards
Reply With Quote
The Following User Says Thank You to blue_devil For This Useful Post:
vic4key (11-07-2023)
  #4  
Old 11-07-2023, 14:37
blue_devil's Avatar
blue_devil blue_devil is offline
Family
 
Join Date: Dec 2011
Location: Observable Universe
Posts: 343
Rept. Given: 78
Rept. Rcvd 51 Times in 24 Posts
Thanks Given: 342
Thanks Rcvd at 496 Times in 168 Posts
blue_devil Reputation: 52
Quote:
Originally Posted by wilson bibe View Post
Hello, is it possible for someone publish the compiled version of this tool? Thanks in advance
But @wilson, this repo is only contains header files. You create a project and add this header files to you solution; and then start hooking-unhooking! You do not need a compiled version of it! Am I right @vic4key?
Reply With Quote
The Following User Says Thank You to blue_devil For This Useful Post:
vic4key (11-07-2023)
  #5  
Old 11-07-2023, 15:10
vic4key's Avatar
vic4key vic4key is offline
Family
 
Join Date: Apr 2010
Posts: 62
Rept. Given: 5
Rept. Rcvd 24 Times in 10 Posts
Thanks Given: 62
Thanks Rcvd at 98 Times in 23 Posts
vic4key Reputation: 24
Quote:
Originally Posted by blue_devil View Post
But @wilson, this repo is only contains header files. You create a project and add this header files to you solution; and then start hooking-unhooking! You do not need a compiled version of it! Am I right @vic4key?
Yes. You're right. But these header files required Vutils library as its hooking backend.
And install Vutils library is very easy and quick, just checkout/download and double-click to run 2 batch file .cmd inside `Vutils\tools` folder to complete.

Refer to https://github.com/vic4key/Vutils#installation
Reply With Quote
The Following User Says Thank You to vic4key For This Useful Post:
ahmadmansoor (11-08-2023)
  #6  
Old 11-07-2023, 16:50
sendersu sendersu is offline
VIP
 
Join Date: Oct 2010
Posts: 1,126
Rept. Given: 334
Rept. Rcvd 228 Times in 119 Posts
Thanks Given: 265
Thanks Rcvd at 538 Times in 299 Posts
sendersu Reputation: 200-299 sendersu Reputation: 200-299 sendersu Reputation: 200-299
batch files have got some hardcoded pathes
in my case VS is installed into other path,
is it possible to deduce it from the env the real install pathes?

SET VU_VSDEV=%ProgramFiles(x86)%\Microsoft Visual Studio\%VU_VSVER%\%%L\Common7\Tools\VsDevCmd.bat
Reply With Quote
The Following User Says Thank You to sendersu For This Useful Post:
vic4key (11-07-2023)
  #7  
Old 11-07-2023, 18:02
vic4key's Avatar
vic4key vic4key is offline
Family
 
Join Date: Apr 2010
Posts: 62
Rept. Given: 5
Rept. Rcvd 24 Times in 10 Posts
Thanks Given: 62
Thanks Rcvd at 98 Times in 23 Posts
vic4key Reputation: 24
Can you gimme the path in your case?
Thanks for feedback. I will check and update the script to make it more common.
Reply With Quote
  #8  
Old 11-07-2023, 19:18
sendersu sendersu is offline
VIP
 
Join Date: Oct 2010
Posts: 1,126
Rept. Given: 334
Rept. Rcvd 228 Times in 119 Posts
Thanks Given: 265
Thanks Rcvd at 538 Times in 299 Posts
sendersu Reputation: 200-299 sendersu Reputation: 200-299 sendersu Reputation: 200-299
well, I mean it might be any
in my case it is D:\dev\vs2019
Reply With Quote
The Following User Says Thank You to sendersu For This Useful Post:
vic4key (11-07-2023)
  #9  
Old 11-12-2023, 09:17
chants chants is offline
VIP
 
Join Date: Jul 2016
Posts: 805
Rept. Given: 42
Rept. Rcvd 50 Times in 31 Posts
Thanks Given: 715
Thanks Rcvd at 1,113 Times in 514 Posts
chants Reputation: 51
Yes and VS2022 is no longer x86 with an x64 IDE. One reason I like CMake is not just it's portability but that it has all the strategies to detect all different compilers even on Windows to build with. Providing a CMakeLists.txt in projects is very convenient to make it easy for anyone to configure and build.
Reply With Quote
  #10  
Old 11-14-2023, 14:25
vic4key's Avatar
vic4key vic4key is offline
Family
 
Join Date: Apr 2010
Posts: 62
Rept. Given: 5
Rept. Rcvd 24 Times in 10 Posts
Thanks Given: 62
Thanks Rcvd at 98 Times in 23 Posts
vic4key Reputation: 24
Quote:
Originally Posted by chants View Post
Yes and VS2022 is no longer x86 with an x64 IDE. One reason I like CMake is not just it's portability but that it has all the strategies to detect all different compilers even on Windows to build with. Providing a CMakeLists.txt in projects is very convenient to make it easy for anyone to configure and build.
Actually, I'm not a fan of CMake. CMake is portability, but it needs too many steps to finish, and only build for a specified arch at once (cannot generate for both Win & x64, or maybe I don't know how to do that).

I targeted only using for Win32/x64/MinGW. So, I wrote a batch file to build all at once (x86, x64, MT/MTd, MD/MDd). And then, just one-click to finish. I believe it much easier and simpler than CMake.

BTW, I will update the batch file to fix the bug when I get free time.
Reply With Quote
  #11  
Old 11-15-2023, 02:38
chants chants is offline
VIP
 
Join Date: Jul 2016
Posts: 805
Rept. Given: 42
Rept. Rcvd 50 Times in 31 Posts
Thanks Given: 715
Thanks Rcvd at 1,113 Times in 514 Posts
chants Reputation: 51
Yes if you are targetting a specific set of architectures and compilers would not argue it is more efficient to use simpler build methods.

But if you want to write something with library quality usefulness then being independent of these things is important. Different configurations should require different builds if being totally generic.

You are likely locked into the Microsoft ecosystem. But at this day and age that is rather niche. Professional programmers can go cross architecture and cross platform and cross compiler quite readily.

Getting off topic though, for this project which is very Windows specific, of course CMake is overkill. But there are still several of C compilers on Windows, MSVC isn't the only possibility.

The main point is these batch file type issues are completely solved by modern build tools. Whereas making a project that can be shared and built without any issues isn't so easy with custom build processes.
Reply With Quote
  #12  
Old 11-15-2023, 03:43
sendersu sendersu is offline
VIP
 
Join Date: Oct 2010
Posts: 1,126
Rept. Given: 334
Rept. Rcvd 228 Times in 119 Posts
Thanks Given: 265
Thanks Rcvd at 538 Times in 299 Posts
sendersu Reputation: 200-299 sendersu Reputation: 200-299 sendersu Reputation: 200-299
so how to instruct cmake to use clang/gcc and not msvc?
in this specific case
Reply With Quote
  #13  
Old 11-15-2023, 04:18
chants chants is offline
VIP
 
Join Date: Jul 2016
Posts: 805
Rept. Given: 42
Rept. Rcvd 50 Times in 31 Posts
Thanks Given: 715
Thanks Rcvd at 1,113 Times in 514 Posts
chants Reputation: 51
I mean I suppose using Ninja is best in this case and something along the lines of:

Quote:
cmake -B build -S . -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files/LLVM/bin/clang.exe" -DCMAKE_C_COMPILER:FILEPATH="C:/Program Files/LLVM/bin/clang.exe" -DCMAKE_LINKER:FILEPATH="C:/Program Files/LLVM/bin/lld-link.exe" -G"Ninja" -DCMAKE_EXPORT_COMPILE_COMMANDS=1
Reply With Quote
The Following User Says Thank You to chants For This Useful Post:
sendersu (11-15-2023)
  #14  
Old 11-15-2023, 11:48
vic4key's Avatar
vic4key vic4key is offline
Family
 
Join Date: Apr 2010
Posts: 62
Rept. Given: 5
Rept. Rcvd 24 Times in 10 Posts
Thanks Given: 62
Thanks Rcvd at 98 Times in 23 Posts
vic4key Reputation: 24
Quote:
cross architecture and cross platform and cross compiler quite readily.
@chants Absolutely, I got it. In this case, I will use CMake for sure.

Quote:
Getting off topic though, for this project which is very Windows specific, of course CMake is overkill. But there are still several of C compilers on Windows, MSVC isn't the only possibility.
@chants My library is only targeting to MSVC & MinGW compilerr. I did not test and check for other compilers. I mentioned at https://github.com/vic4key/Vutils#information
Reply With Quote
  #15  
Old 01-06-2024, 10:12
tianmuxia tianmuxia is offline
Guest
 
Join Date: Jan 2024
Posts: 1
Rept. Given: 0
Rept. Rcvd 0 Times in 0 Posts
Thanks Given: 0
Thanks Rcvd at 0 Times in 0 Posts
tianmuxia Reputation: 0
maybe minhook is more useful for unknow functions?
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On



All times are GMT +8. The time now is 20:46.


Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX, chessgod101
( 1998 - 2024 )