Support for showing if app is 32bit vs 64bit, and support for doing message hooks on both

Added support for message hook viewer to hook both 32 and 64 bit
applications.
Fixed filtering on the msg hook viewer
Added custom filtering on msg hook viewer
Added Process Id targetting on msg hook viewer
Added SetMsgHook.exe command line app as an alternative way of starting
msg hook viewer.
This commit is contained in:
Edward Jakubowski
2014-06-03 06:28:14 -04:00
parent 05748b4582
commit d100d23259
41 changed files with 1232 additions and 72 deletions

View File

@@ -0,0 +1,86 @@
//This function will extract a binary resource.
//
//IDR_SETMH64 BINARY MOVEABLE PURE "..\\SetMsgHook\\bin\\SetMsgHook64.exe"
//IDR_SETMH32 BINARY MOVEABLE PURE "..\\SetMsgHook\\bin\\SetMsgHook32.exe"
#include "stdafx.h"
void ExtractResource(const WORD nID, LPCTSTR szFilename)
{
const HINSTANCE hInstance = (HINSTANCE)pData->g_hInstance;//GetModuleHandle(NULL);
HRSRC hResource = FindResource(hInstance, MAKEINTRESOURCE(nID), _T("BINARY"));// _ASSERTE(hResource);
if (hResource == NULL) // no resource found.
{
//MessageBoxA(0, "error, no resource found", "error", 0);
printf("error, resource %d not found\n", nID);
return;
}
HGLOBAL hFileResource = LoadResource(hInstance, hResource);// _ASSERTE(hFileResource);
LPVOID lpFile = LockResource(hFileResource);
DWORD dwSize = SizeofResource(hInstance, hResource);
// Open the file and filemap
HANDLE hFile = CreateFile(szFilename, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
HANDLE hFilemap = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, dwSize, NULL);
// Get a pointer to write to
LPVOID lpBaseAddress = MapViewOfFile(hFilemap, FILE_MAP_WRITE, 0, 0, 0);
// Write the file
CopyMemory(lpBaseAddress, lpFile, dwSize);
// Unmap the file and close the handles
UnmapViewOfFile(lpBaseAddress);
CloseHandle(hFilemap);
CloseHandle(hFile);
}
void RunResource(const WORD nID, LPWSTR params)
{
TCHAR tmpFilename[500];
TCHAR tmpPath[500];
GetTempPath(500, tmpPath);
if (GetTempFileName(tmpPath, _T(""), 0, tmpFilename) == 0)
{
MessageBox(0,_T("Error getting temp file name"), _T("Error"), 0);
return;
}
ExtractResource(nID, tmpFilename);
//MessageBox(0, tmpFilename, _T("tmp file2"), 0);
STARTUPINFO si;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
PROCESS_INFORMATION pi;
ZeroMemory( &pi, sizeof(pi) );
si.wShowWindow = SW_MINIMIZE;
// Start the child process.
if(!CreateProcess(tmpFilename, // No module name (use command line)
params, // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi )) // Pointer to PROCESS_INFORMATION structure
{
MessageBox(0, _T("CreateProcess failed"), _T("error"), 0);
printf( "CreateProcess failed (%d).\n", GetLastError() );
return;
}
//MessageBox(0, tmpFilename, _T("tmp file3"), 0);
// Wait until child process exits.
//WaitForSingleObject( pi.hProcess, INFINITE );
// Close process and thread handles.
//CloseHandle( pi.hProcess );
//CloseHandle( pi.hThread );
}