跟踪哪个进程打开了特定文件

发布于 2024-07-07 10:02:18 字数 199 浏览 12 评论 0原文

在 Windows 的内核模式中,我能够拦截和监视在特定磁盘上执行的几乎所有操作。 当出于任何目的打开文件时,我会收到一个事件。

现在我想追踪哪个应用程序打开了它。 我认为这应该是可能的,但不知道如何。

我正在使用 Windows Win32 API 中的标准文件管理功能。

提前致谢。

/罗伯特

From kernel mode in Windows I'm able to intercept and monitor virtually all actions performed on a particular disk. When a file is opened for any purpose I get an event.

Now I want to trace which application that opened it. I think this should be possible but don't know how.

I'm using the standard file management functions in Windows Win32 API.

Thanks in advance.

/Robert

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

稀香 2024-07-14 10:02:18

Sysinternals Filemon(免费)可以做到这一点,而且更好的是他们描述了如何他们做到了:

对于Windows 9x驱动,心脏
FileMon 的内容在虚拟设备中
驱动程序,Filevxd.vxd。 它是动态的
已加载,并在初始化时
通过安装文件系统过滤器
VxD服务,
IFSMGR_InstallFileSystemApiHook,到
将其自身插入到调用链中
所有文件系统请求。 在 Windows 上
NT FileMon 的核心是文件
创建和的系统驱动程序
将过滤器设备对象附加到
目标文件系统设备对象所以
FileMon 将看到所有 IRP 并
FastIO 请求针对驱动器。
当 FileMon 看到打开的文件时,创建或
千钧一发,它更新了内部
充当映射的哈希表
内部文件句柄和文件之间
路径名称。 每当看到来电时
基于句柄的,它会查找
哈希表中的句柄获取
用于显示的全名。 如果一个
基于句柄的访问引用文件
在 FileMon 启动之前打开,FileMon
将无法在其中找到映射
哈希表并且将简单地呈现
而是使用句柄的值。

-亚当

Sysinternals Filemon (free) does this, and better yet they describe how they did it:

For the Windows 9x driver, the heart
of FileMon is in the virtual device
driver, Filevxd.vxd. It is dynamically
loaded, and in its initialization it
installs a file system filter via the
VxD service,
IFSMGR_InstallFileSystemApiHook, to
insert itself onto the call chain of
all file system requests. On Windows
NT the heart of FileMon is a file
system driver that creates and
attaches filter device objects to
target file system device objects so
that FileMon will see all IRPs and
FastIO requests directed at drives.
When FileMon sees an open, create or
close call, it updates an internal
hash table that serves as the mapping
between internal file handles and file
path names. Whenever it sees calls
that are handle based, it looks up the
handle in the hash table to obtain the
full name for display. If a
handle-based access references a file
opened before FileMon started, FileMon
will fail to find the mapping in its
hash table and will simply present the
handle's value instead.

-Adam

许久 2024-07-14 10:02:18

Sysinternals 在执行和解释方面做得非常好,旧版本的一些源代码仍然可用 这里,并且代码有详细记录(恕我直言)。 这也可能是一个好的开始。

Sysinternals did a so good job at doing it and explaining it, that some source code of old version are still available here for instance, and the code is well documented (imho). It could be a good start as well.

丢了幸福的猪 2024-07-14 10:02:18

我会使用 Sysinternals 的“handle.exe”应用程序。

或者,您实际上正在尝试以编程方式执行此操作吗?

I would use the "handle.exe" app from Sysinternals.

Or, are you actually trying to do this programmactically?

み零 2024-07-14 10:02:18

只需使用 Win32 N.API 从文件句柄获取 pid。
这是15年来的常见问题解答...

Just use Win32 N.API to get the pid from the File handle.
It's a FAQ for 15 years...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文