Hi !
I need a help with the following problem in Windows XP with Service Pack 2
and all updates:
My function NativeSetFileAttributes works fine with Native .exe (to execute
in BootExecute registry…),
but dont work inside .sys device-driver.
I debug the program and the error is in “RtlDosPathNameToNtPathName_U”. But
the error is only in the .sys. Native .exe works fine.
I try replace all “Nt*” API function names to “Zw*” API function names and
the error is the same.
I try change start mode device-driver to automatic, boot, system, etc and
dont work too.
What the error in this function ? Or exist another way to change file
attributes inside Kernel Mode ?
Thank you
void __stdcall NativeSetFileAttributes( short *FileName, DWORD attributes )
{
UNICODE_STRING uniString;
OBJECT_ATTRIBUTES obj;
IO_STATUS_BLOCK io;
NTSTATUS Status;
HANDLE Handle;
if ( RtlDosPathNameToNtPathName_U( FileName, &uniString, NULL, NULL ) )
{
InitializeObjectAttributes( &obj, &uniString, OBJ_CASE_INSENSITIVE,
NULL, NULL );
Status = NtOpenFile( &Handle,
FILE_WRITE_ATTRIBUTES,
&obj, &io,
0,
FILE_NON_DIRECTORY_FILE );
if ( NT_SUCCESS( Status ) )
{
FILE_BASIC_INFORMATION info = { 0 };
info.FileAttributes = attributes | FILE_ATTRIBUTE_NORMAL;
Status = NtSetInformationFile( Handle, &io, &info, sizeof(
info ), FileBasicInformation );
NtClose( Handle );
}
}
}