lovetrojan
驱动牛犊
驱动牛犊
  • 注册日期2007-04-09
  • 最后登录2007-08-29
  • 粉丝0
  • 关注0
  • 积分180分
  • 威望19点
  • 贡献值0点
  • 好评度18点
  • 原创分1分
  • 专家分0分
阅读:2982回复:0

ZwCreateFile VS IoCreateFile

楼主#
更多 发布于:2007-08-25 19:20
2007/2/9

Apart from their obvious name difference and number of parameters, do YOU know what the difference between them?
 
Well, obviously, ZwCreateFile calls IoCreateFile at some point in it's life, but there is a less obvious differences as well:
 
ZwCreateFile is used by kernel mode drivers to create their file, and intenally this cals IoCreateFile. But a little less known fact is that ZwCreateFile will make the create in kernel mode while IoCreateFile will not override the mode that you are in.
 
What does that mean? Well, if you are in the context of the user process, and you try to use IoCreateFile, and don't specify any override flags, the call will fail with 0xC0000005. The reason is that IoCreateFile is checking the parameters, figurs out that he is in a usermode context, but that the create is a kernel mode call, so he sees a discrepancy, and will fail.
 
You can also specify the extra parameter: IO_NO_PARAMETER_CHECKING, and that should override the calls mean streak ;)
 
Another little difference is that you could (if you were a bad person) hook the ZwCreateFile, and replace it with your own, directly in the kernel service table, but the other one would be a bit more difficult ;) It's an export of our true friend: Nt Kernel, better known as ntoskrnl.exe.
 
Oh well, now remember that ZwCreate is usually the safer bet ;)
养马专业户!
游客

返回顶部