HookZwWriteFile(
IN HANDLE FileHandle,
IN HANDLE Event OPTIONAL,
IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
IN PVOID ApcContext OPTIONAL,
OUT PIO_STATUS_BLOCK IoStatusBlock,
IN PVOID Buffer,
IN ULONG Length,
IN PLARGE_INTEGER ByteOffset OPTIONAL,
IN PULONG Key OPTIONAL
)
{
if (TurnOnFileMon==1)//如果功能开启的话
{
PDEVICE_EXTENSION deviceExtension;//设备扩展
char ansiProcessName[PROCNAMELEN];
UNICODE_STRING *volumeDosName;
WCHAR DelFullName[1024];
PCWSTR WriteFileName;
PFILE_OBJECT fileobj;
FILE_INFORMATION_CLASS FileInformationClass = FileNameInformation ;
if ( FileHandle != NULL)
{
NTSTATUS nts = STATUS_UNSUCCESSFUL;
//得到进程路径和进程名
UNICODE_STRING UniProcessPath,volumeDosName;
ANSI_STRING AnsiProcessPath,ansiProcessName1;
ANSI_STRING ansipath,apathpre;
UNICODE_STRING unipath,upathpre;
PCWSTR ProcessPath = GetCurrentProcessFileName();//进程路径
RtlInitUnicodeString(&UniProcessPath,ProcessPath);
RtlUnicodeStringToAnsiString(&AnsiProcessPath,&UniProcessPath,TRUE);
GetProcessName(ansiProcessName); //进程名
RtlInitAnsiString(&ansiProcessName1,ansiProcessName);
KdPrint(("%s(%s)修改文件 \r\n",ansiProcessName,AnsiProcessPath.Buffer));
ObReferenceObjectByHandle(FileHandle,GENERIC_READ,NULL,KernelMode,&fileobj,NULL);
WriteFileName=fileobj->FileName.Buffer;
RtlInitUnicodeString(&unipath,WriteFileName);
RtlUnicodeStringToAnsiString(&ansipath,&unipath,TRUE);
//KdPrint(("%s(%s)修改文件 %s\r\n",ansiProcessName,AnsiProcessPath.Buffer,ansipath.Buffer));
IoVolumeDeviceToDosName(fileobj->DeviceObject, &volumeDosName );
RtlInitUnicodeString(&upathpre,volumeDosName.Buffer);
RtlUnicodeStringToAnsiString(&apathpre,&upathpre,TRUE);
KdPrint(("%s(%s)修改文件 %s(%s) \r\n",ansiProcessName,AnsiProcessPath.Buffer,apathpre.Buffer,ansipath.Buffer));
ExFreePool(volumeDosName.Buffer);
ObDereferenceObject(fileobj);
RtlFreeAnsiString(&apathpre);
RtlFreeAnsiString(&ansipath);
RtlFreeAnsiString(&AnsiProcessPath);
}
}
return RealZwWriteFile(
FileHandle,
Event OPTIONAL,
ApcRoutine OPTIONAL,
ApcContext OPTIONAL,
IoStatusBlock,
Buffer,
Length,
ByteOffset OPTIONAL,
Key OPTIONAL
);
}
不用IoVolumeDeviceToDosName的话都很正常,加上就会蓝屏。
分析dump文件,错误指向ObDereferenceObject(fileobj) 这一行,可是我找不到明显的错误,特来求助。自己弄了几天了,实在没能找到原因......水平是太菜了。。。
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!