kernel32!OpenFile与kernel32! DeleteFile
kernel32!OpenFile与ntdll!NtOpenFile#
kernel32!OpenFile并不是直接调用的ntdll!NtOpenFile,其调用的是ntdll!NtCreateFile。
ntdll!NtOpenFile#
ntdll!NtOpenFile函数并没有声明,如果要调用的话需要GetProcAddress动态获取。
typedef struct _IO_STATUS_BLOCK {
union {
NTSTATUS Status;
PVOID Pointer;
};
ULONG_PTR Information;
} IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
typedef struct _UNICODE_STRING {
USHORT Length;
USHORT MaximumLength;
PWSTR Buffer;
} UNICODE_STRING, *PUNICODE_STRING;
typedef struct _OBJECT_ATTRIBUTES {
ULONG Length;
HANDLE RootDirectory;
PUNICODE_STRING ObjectName;
ULONG Attributes;
PVOID SecurityDescriptor;
PVOID SecurityQualityOfService;
} OBJECT_ATTRIBUTES;
typedef void( __stdcall* RtlInitUnicodeStringA)(PUNICODE_STRING DestinationString, PCWSTR SourceString);
typedef int (__stdcall *NtOpenFileA)(PHANDLE FileHandle, ACCESS_MASK DesiredAccess, OBJECT_ATTRIBUTES* ObjectAttributes, PIO_STATUS_BLOCK IoStatusBlock, ULONG ShareAccess, ULONG OpenOptions);
UNICODE_STRING stFileName = { 0 };
RtlInitUnicodeStringA RtlInitUnicodeString =(RtlInitUnicodeStringA) GetProcAddress(LoadLibrary(TEXT("ntdll.dll")), "RtlInitUnicodeString");
NtOpenFileA NtOpenFile = (NtOpenFileA)GetProcAddress(LoadLibrary(TEXT("ntdll.dll")), "NtOpenFile");
- ntdll!NtOpenFile返回0xC000003B,说明给出的文件的路径错误。
- 注意调用ntdll!NtOpenFile给出的文件名需要加上"\??\"。
- RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)函数在使用时注意其第二个参数为宽字符。
kernel32!DeleteFile与ntdll!NtDeleteFile#
kernel32!DeleteFile底层调用的并不是ntdll!NtDeleteFile,其调用的是ntdll!SetInformationFile(传入FileDispositionInformation/FileDispositionInformationEx参数)
ntdll!NtDeleteFile#
ntdll!NtDeleteFile函数并没有声明,调用的话需要GetProcAddress获得函数地址进行调用
分类:
windows内核编程
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】