我正在准备一个Delphi模块,它在一个线程中设置一个钩子来记录一个宏:
FHandleRec := SetWindowsHookEx(WH_JOURNALRECORD, FRecordProc, HInstance, 0);
FHandlePlay := SetWindowsHookEx(WH_JOURNALPLAYBACK, FPlayProc, HInstance, 0);
Run Code Online (Sandbox Code Playgroud)
这在WinXP上工作正常,但在Vista/Windows 7上失败了ERROR_ACCESS_DENIED.我在谷歌(这个)中找到了(那个).报价单:
较低权限进程不能:...使用Journal钩子来监视更高权限的进程.
尝试没有成功:
代码示例:
if LogonUser(PWideChar(sAdminUser), PWideChar(sDomain), PWideChar(sPwd),
LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, hToken) then
begin
if not ImpersonateLoggedOnUser(hToken) then
raise Exception.Create('Error impersonating the user');
end;
FHandleRec := SetWindowsHookEx(WH_JOURNALRECORD, FRecordProc, HInstance, 0);
Run Code Online (Sandbox Code Playgroud)
LogonUser并ImpersonateLoggedOnUser执行没有错误.
尝试的其他可能性:
您能否在Visa/Windows 7下显示设置挂钩的代码或建议工作解决方案?
我使用 SetWindowsHookEx 和 WH_CALLWNDPROC 来捕获所有 WndProc 消息 - 它工作正常。我想知道是否有一种方法可以将参数存储在回调函数可以读取和使用的地方。
我假设因为回调函数位于“其他”进程内部,所以与调用 SetWindowsHookEx 的进程没有连接,因此仅将值存储在静态变量中不会有任何好处。
例如:
void Hook(DWORD dwThread, int randomNumber)
{
MagicallyStore(randomNumber);
SetWindowsHookEx(WH_CALLWNDPROC, hookProc, GetModuleHandle(L"WNDProcHooks"), dwThread);
...
...
}
LRESULT CALLBACK hookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
int randomNumber = MagicallyRestore();
DoSomthing(randomNumber);
return CallNextHookEx(0, nCode, wParam, lParam);
}
Run Code Online (Sandbox Code Playgroud)
我已经考虑过让“MagicallyStore”函数将参数写入文件并在“MagicallyRestore”函数中读取一次 - 但必须有更好的方法..
提前致谢 :)
Microsoft不建议使用DirectInput进行键盘和鼠标输入.因此,我编写了一个输入管理器类,它使用SetWindowsHookEx挂钩到WndProc和GetMsg.我认为钩子设置得恰当,但它们看起来是各种问题的原因.
我的WndProc和GetMsg挂钩都不会收到实际WndProc正在接收的任何消息.我的输入管理器永远不会收到它需要的WM_INPUT,WM_ BUTTON,WM_MOUSEWHEEL和WM_KEY*消息.
是什么赋予了?
部分标题:
namespace InputManager
{
class CInputManager
{
HWND m_Window;
HHOOK m_WndProcHook;
HHOOK m_GetMessageHook;
static LRESULT CALLBACK WindowsProcedureHookProcedure(int Code, WPARAM WParameter, LPARAM LParameter);
static LRESULT CALLBACK GetMessageHookProcedure(int Code, WPARAM WParameter, LPARAM LParameter);
static LRESULT CALLBACK MessageHandler(HWND Window, UINT Message, WPARAM wParameter, LPARAM lParameter);
};
}
Run Code Online (Sandbox Code Playgroud)
部分来源:
namespace InputManager
{
bool CInputManager::Initialize(HWND Window)
{
m_Window = Window;
// Hook into the sent messages of the target window to intercept input messages.
m_WndProcHook = SetWindowsHookEx(WH_CALLWNDPROC, &(WindowsProcedureHookProcedure), NULL, GetCurrentThreadId()); …Run Code Online (Sandbox Code Playgroud) 我正在开发一个捕获所有用户交互的项目.MSDN告诉(这个)
SetWindowsHookEx可用于将DLL注入另一个进程.32位DLL无法注入64位进程,64位DLL无法注入32位进程.如果应用程序需要在其他进程中使用钩子,则需要32位应用程序调用SetWindowsHookEx将32位DLL注入32位进程,并且64位应用程序调用SetWindowsHookEx注入64位DLL进入64位进程.
我的问题是,如果构建了一个应用程序会发生什么Any CPU.我是否需要SetWindowsHookEx从构建的DLL 调用Any CPU.
我写了HookLogger_32.exe加载HookFunctions_32.dll(包括x86)和HookLogger_64.exe加载HookFunctions_64.dll(都是x64)设置WH_CBT和WH_MOUSE全局(不是特定的线程).
HookLogger_32.exe,HookLogger_64.exe,HookFunctions_32.dll和HookFunctions_64.dll是用C++编写的.
当我点击构建的.NET应用程序时Any CPU,这些DLL会被注入(通过SetWindowHookEx).Windows操作系统挂起,我必须强行重启我的机器.
当针对x86或x64构建相同的.NET应用程序时,当我在HookLoggers(32位和64位)启动后单击应用程序时,一切正常.
这种未定义行为的任何原因.
我工作的平台是64位机器.
我很有兴趣收集一个我没写过但无法控制的应用程序的使用指标.这是在Windows上运行的应用程序.
我的计划是为鼠标和键盘事件注册一个全局窗口挂钩,并为具有预定标题或其他可识别属性的窗口记录这些事件.
使用这些数据,我希望能够确定用户如何使用相关应用程序.他们点击什么按钮以及什么时候,以及常见的工作流程.等等.
对这个想法的任何想法?是否有第三方产品或库,将有助于该解决方案,也没有要求现有应用程序的修改?
我使用互联网上的源代码创建了一个GLOBAL键盘钩子DLL.最好的部分是它非常出色,除了它涉及到浏览器.
它会接收浏览器中的每个键,除了看起来,当浏览器获得焦点时,它会丢失按下的第一个键.在IE和Firefox中进行了测试,两者似乎都是一样的.
例如,如果我打开IE并开始输入www.,我只回来了.如果浏览器窗口保持清晰,则不会丢失其他密钥.一旦浏览器失去焦点并重新获得焦点,第一个键就会再次丢失.
可能是因为只使用WH_KEYDOWN而不是WH_KEYPRESS/WH_KEYUP?有人可以对此有所了解吗?
谢谢
PS:钩子函数本身如下:DLL发送一个备忘录框和应用程序句柄,DLL将发送消息以及用户消息.
function KeyHookFunc(Code, VirtualKey, KeyStroke: Integer): LRESULT; stdcall;
var
KeyState1: TKeyBoardState;
AryChar: array[0..1] of Char;
Count: Integer;
begin
Result := 0;
if Code = HC_NOREMOVE then Exit;
Result := CallNextHookEx(hKeyHook, Code, VirtualKey, KeyStroke);
{I moved the CallNextHookEx up here but if you want to block
or change any keys then move it back down}
if Code < 0 then
Exit;
if Code = HC_ACTION then
begin
if ((KeyStroke and (1 shl 30)) <> 0) then …Run Code Online (Sandbox Code Playgroud) 我试图从csharp连接到其他窗口.我正在使用SetWindowsHookEx,但没有运气转换它com c ++ tc#.我在这里找到了这个帖子,
但它没有解决.问题是SetWindowsHookEx返回0.它包括我找到的最佳代码samle:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowDrawer
{
public partial class Form1 : Form
{
private delegate int HookProc(int code, IntPtr wParam, IntPtr lParam);
static IntPtr hHook;
IntPtr windowHandle;
uint processHandle;
HookProc PaintHookProcedure;
[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
static extern System.IntPtr FindWindowByCaption(int ZeroOnly, string lpWindowName);
[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SetWindowsHookEx", SetLastError = true)]
static extern IntPtr SetWindowsHookEx(int idHook, …Run Code Online (Sandbox Code Playgroud) 我正在使用VS 2010生成的简单表单,其中包含2个按钮,即启动和停止.使用SetWindowsHookEx启动触发器WH_MOUSE_LL,并停止挂钩.钩子工作正常,我选择"替换"鼠标中键单击双击,我唯一的问题是点击表单的最小化/最大化/关闭按钮,似乎有某种"事件竞赛"之间上面提到的按钮调用的钩子和事件.它反映了这样一个事实:当你按下其中一个按钮时,它会在完成它的动作之前保持"按下"一段时间(例如,形式最小化).当我右键单击表单并选择其中一个操作时,它会立即响应同样的事情,当我停止挂钩并按下上面提到的其中一个按钮时.有没有人遇到过这种行为?
我想在运行时挂钩从加载的DLL调用的函数,我使用了"Windows Via C/C++"一书中的CAPIHook类(通过Install System Wide挂钩完成的DLL注入和通过Modify IAT挂钩)但是这个只有在可执行文件的IAT中存在DLL名称/符号时,代码才有效.(即用于隐式DLL链接)
这是DLL代码:
CAPIHook::CAPIHook(PSTR pszCalleeModName, PSTR pszFuncName, PROC pfnHook) {
// Note: the function can be hooked only if the exporting module
// is already loaded. A solution could be to store the function
// name as a member; then, in the hooked LoadLibrary* handlers, parse
// the list of CAPIHook instances, check if pszCalleeModName
// is the name of the loaded module to hook its export table and
// re-hook the import tables of all …Run Code Online (Sandbox Code Playgroud) 有没有一种简单的方法来挂钩我的代码执行的进程的注册表访问?我知道SetWindowsHookEx和朋友,但它太复杂了......我仍然希望有一种像LD_PRELOAD上一样简单的方法Unix......