C#中的WIN32 API覆盖(特别是CreateFile) [英] WIN32 API override (Specifically CreateFile) in C#

查看:123
本文介绍了C#中的WIN32 API覆盖(特别是CreateFile)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我希望有人可以提供帮助.我一直在寻找一种方法来拦截特定进程名称对CreateFile的所有调用,并将该调用强制为共享只读模式.我知道大多数程序都会出于某种原因锁定文件.我也知道该程序仅从文件中读取,不需要锁定.我计划以只读方式打开文件,并将文件锁定为只读.

我发现了许多不同的方法,大多数(即使不是全部)都已过时,或者我只是无法让它们正确地覆盖该调用.
尽管不胜感激,但我不需要完整的源代码,也不需要任何帮助.我只需要向正确的方向轻推即可!

感谢您提供的任何帮助!

注意:虽然我要覆盖的函数名称是CreateFile,但它实际上将打开一个现有文件,而不是创建一个新文件.

Hello, I''m hoping someone might be able to help out. I''ve been looking for a few days now for a way to intercept all calls to CreateFile for a specific process name, and force that call to be in shared read only mode. I am aware that most programs lock a file for a reason. I am also aware that the program only reads from the file, and does not need to be locked. I plan on opening the file with read only and locking the file to read only.

I have found many different methods, most if not all being outdated, or I just could not get them to properly override the call.

While it would be very appreciated, I don''t need complete source code, and I''m not asking for any hand holding. I just need a nudge in the proper direction!

Thank you for any help you can offer!

NOTE: While the name of the function I want to override is CreateFile, it will actually open an existing file instead of creating a new one.

推荐答案

Hello,

您看过WinApi Hooks吗?

本文使用CreateFile演示api挂钩:D

EasyHook-Windows API挂钩的重新发明 [
Hello,

Have you looked at WinApi Hooks?

This article uses CreateFile to demonstrate api hooking :D

EasyHook - The reinvention of Windows API hooking[^]

Valery.


那根本没有道理.如果进程正在创建文件,则无法以只读模式打开该文件.我的意思是,您希望将文件设置为互斥写模式,以便其他任何应用都无法写入该文件.
That makes no sense at all. If a process is creating the file, it CAN''T be opened in read-only mode. What I think you mean is that you want to set the file to exclusive-write mode so no other apps can write to it.


这篇关于C#中的WIN32 API覆盖(特别是CreateFile)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆