C语言在用户模式使用NT函数
来源:互联网 发布:高性能网络编程 编辑:程序博客网 时间:2024/06/14 12:34
C语言要使用NT函数并不像使用库函数那么简单,下面介绍一下使用方法,以NtSetInformationFile为例:
#include <windows.h>#include <stdio.h>//因为NtSetInformationFile方法要用到FILE_INFORMATION_CLASS的值,所以这里全部枚举出来//当然你也可以直接使用1,2,3,这样值代替,只是这样定义以后在后面使用更接近使用一般函数一些。typedef enum _FILE_INFORMATION_CLASS { FileDirectoryInformation = 1, FileFullDirectoryInformation, FileBothDirectoryInformation, FileBasicInformation, FileStandardInformation, FileInternalInformation, FileEaInformation, FileAccessInformation, FileNameInformation, FileRenameInformation, FileLinkInformation, FileNamesInformation, FileDispositionInformation, FilePositionInformation, FileFullEaInformation, FileModeInformation, FileAlignmentInformation, FileAllInformation, FileAllocationInformation, FileEndOfFileInformation, FileAlternateNameInformation, FileStreamInformation, FilePipeInformation, FilePipeLocalInformation, FilePipeRemoteInformation, FileMailslotQueryInformation, FileMailslotSetInformation, FileCompressionInformation, FileObjectIdInformation, FileCompletionInformation, FileMoveClusterInformation, FileQuotaInformation, FileReparsePointInformation, FileNetworkOpenInformation, FileAttributeTagInformation, FileTrackingInformation, FileIdBothDirectoryInformation, FileIdFullDirectoryInformation, FileValidDataLengthInformation, FileShortNameInformation, FileIoCompletionNotificationInformation, FileIoStatusBlockRangeInformation, FileIoPriorityHintInformation, FileSfioReserveInformation, FileSfioVolumeInformation, FileHardLinkInformation, FileProcessIdsUsingFileInformation, FileNormalizedNameInformation, FileNetworkPhysicalNameInformation, FileIdGlobalTxDirectoryInformation, FileIsRemoteDeviceInformation, FileAttributeCacheInformation, FileNumaNodeInformation, FileStandardLinkInformation, FileRemoteProtocolInformation, FileMaximumInformation} FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS;typedef struct _IO_STATUS_BLOCK { union { NTSTATUS Status; PVOID Pointer; }; ULONG_PTR Information;} IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;typedef struct _FILE_DISPOSITION_INFORMATION { BOOLEAN DeleteFile;} FILE_DISPOSITION_INFORMATION, *PFILE_DISPOSITION_INFORMATION;//声明一个与NtSetInformationFile一样的方法,这些方法参数可以参考MSDNtypedef NTSTATUS(__stdcall *NtSetInformationFile)( HANDLE FileHandle, PIO_STATUS_BLOCK IoStatusBlock, PVOID FileInformation, ULONG Length, FILE_INFORMATION_CLASS FileInformationClass );int main(){ FILE_DISPOSITION_INFORMATION fi = { 1 }; IO_STATUS_BLOCK bs = { 0 }; //想要删除文件,必须要有delete权限,即STANDARD_RIGHTS_ALL,DELETE //HANDLE hfile = CreateFileA("c:\\Hello.txt", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); HANDLE hfile = CreateFileA("c:\\Hello.txt", STANDARD_RIGHTS_ALL, 0, NULL, OPEN_EXISTING, 0, NULL); //HANDLE hfile = CreateFileA("c:\\Hello.txt", DELETE, 0, NULL, OPEN_EXISTING, 0, NULL); if (hfile == INVALID_HANDLE_VALUE) { printf("open file failed !"); } //获取NtSetInformationFile NtSetInformationFile ntSetInformationFile; ntSetInformationFile = (NtSetInformationFile)GetProcAddress(LoadLibrary(L"ntdll.dll"), "NtSetInformationFile"); //使用NtSetInformationFile,参数如果本地没有,就自己声明定义就自己填上,方法和NtSetInformationFile是一样的 ntSetInformationFile(hfile, &bs, &fi, 1, FileDispositionInformation);//handle要有删除权限 CloseHandle(hfile); getchar(); return 0;}
阅读全文
0 0
- C语言在用户模式使用NT函数
- C语言函数使用
- C语言函数指针模式
- C语言中系统函数在linux下的使用
- 在c语言中函数的定义与使用
- C语言结构体指针在函数调用中的使用
- C语言 如何在函数中使用指针?
- C语言函数使用笔记
- C语言snprintf函数使用
- C语言qsort函数使用
- C语言inline函数使用
- C语言 strtok函数使用
- C语言 select函数使用
- C语言 select函数使用
- C语言 strtok函数使用
- C语言函数使用小试牛
- C语言之函数使用
- 第5章 在保护模式中调用C语言函数
- 基于最新版soot-infoflow-android绘制android应用函数调用图
- 磁盘挂载信息:/etc/fstab
- 9.4训练日志
- matlab 绘图,设置label字体,插入公式
- GetSystemInfo函数实验
- C语言在用户模式使用NT函数
- 2127-树-堆结构练习——合并果子之哈夫曼树(优先队列实现)
- hexo+github搭建博客跳坑
- WebRTC协议栈视图结构
- excel导入
- 智慧北京(2017.09.01)
- 内联式css样式,直接写在现有的HTML标签中
- 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)
- 你所不知道的Unity功能和背后的原理(一)