首页
社区
课程
招聘
[求助]修改SSDT获取当前操作的文件名,代码有些问题,调式输出的时候是乱码:
发表于: 2007-9-7 11:24 5708

[求助]修改SSDT获取当前操作的文件名,代码有些问题,调式输出的时候是乱码:

2007-9-7 11:24
5708
.386
.model flat, stdcall
option casemap:none

;**************************************************************************************************
include w2k\ntstatus.inc
include w2k\ntddk.inc
include w2k\ntoskrnl.inc
includelib ntoskrnl.lib
include Strings.mac

;**************************************************************************************************
.data?
dwOldSetInformationFile   dd            ?
dwAddr              dd            ?
dwFileName        ANSI_STRING <?>
.const
CCOUNTED_UNICODE_STRING "\\Device\\Asm", g_usDeviceName, 4
CCOUNTED_UNICODE_STRING "\\??\\AsmFile", g_usSymbolicLinkName, 4
CCOUNTED_UNICODE_STRING "ZwSetInformationFile", g_ApiAddr, 4 ;wSetInformationFile
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;这个新函数打印出当前操作的文件名,但是却是乱码,不知道为啥
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.code
NewSetInformationFile  proc hfile:HANDLE,iosb:IO_STATUS_BLOCK,psi:FILE_NAME_INFORMATION,FileInformationLength,FileInformationClass
pushad
      invoke RtlUnicodeStringToAnsiString, addr dwFileName,addr psi.FileName,TRUE
        invoke DbgPrint, $CTA0("\nFileName: %s\n"),addr dwFileName.Buffer  ;打印出来的文件名是乱码
        
popad        
      ret
NewSetInformationFile     endp
;**************************************************************************************************
_SetSSDT        proc
      pushad
      mov eax, KeServiceDescriptorTable ;导出符号获得数组的基地址
      mov esi, [eax]
      mov esi, [esi]
      invoke MmGetSystemRoutineAddress,addr g_ApiAddr ;取ZwSetInformationFile地址
      inc eax
      movzx ecx,byte ptr[eax]
      sal ecx,2    ;取ZwSetInformationFile服务ID号               
      add esi,ecx
      mov dwAddr,esi
      mov edi,dword ptr[esi]
      mov dwOldSetInformationFile,edi
      mov edi,offset NewSetInformationFile ;获得新函数地址
      cli
      mov dword ptr[esi],edi
      sti
      popad
      mov eax, STATUS_SUCCESS
      ret

_SetSSDT     endp
;**************************************************************************************************                                
DispatchCreateClose proc pDeviceObject:PDEVICE_OBJECT, pIrp:PIRP

             mov eax, pIrp
             assume eax:ptr _IRP
             mov [eax].IoStatus.Status, STATUS_SUCCESS
             and [eax].IoStatus.Information, 0
             assume eax:nothing
             invoke  IoCompleteRequest, pIrp, IO_NO_INCREMENT
             mov eax, STATUS_SUCCESS
             ret

DispatchCreateClose endp
;**************************************************************************************************
;此分派过程在ControlService调用时调用
;**************************************************************************************************
DriverUnload        proc pDriverObject:PDRIVER_OBJECT

             pushad
             mov esi,dwAddr
             mov eax,dwOldSetInformationFile ;正常的ZwSetInformationFile函数地址保存到eax。
             cli
             mov dword ptr[esi],eax ;恢复SSDT
             sti
             invoke IoDeleteSymbolicLink, addr g_usSymbolicLinkName
             mov eax,pDriverObject
             invoke IoDeleteDevice, (DRIVER_OBJECT PTR [eax]).DeviceObject              
             popad

             ret

DriverUnload endp
;**************************************************************************************************
DriverEntry         proc pDriverObject:PDRIVER_OBJECT, pusRegistryPath:PUNICODE_STRING
local status:NTSTATUS
local pDeviceObject:PDEVICE_OBJECT

             mov status, STATUS_DEVICE_CONFIGURATION_ERROR
                    invoke IoCreateDevice, pDriverObject, 0, addr g_usDeviceName, FILE_DEVICE_UNKNOWN, 0, FALSE, addr pDeviceObject
             .if eax == STATUS_SUCCESS
                 invoke IoCreateSymbolicLink, addr g_usSymbolicLinkName, addr g_usDeviceName
                 .if eax == STATUS_SUCCESS
                     mov eax, pDriverObject
                     assume eax:ptr DRIVER_OBJECT
                     mov [eax].DriverUnload,offset DriverUnload ;分派过程,ring3下调用ControlService时此过程被调用,恢复SSDT
                     mov [eax].MajorFunction[IRP_MJ_CREATE*(sizeof PVOID)],offset DispatchCreateClose
                     mov [eax].MajorFunction[IRP_MJ_CLOSE*(sizeof PVOID)],offset DispatchCreateClose
           
                     assume eax:nothing
                     invoke _SetSSDT
            
                     mov status, STATUS_SUCCESS
                 .else
                  invoke IoDeleteDevice, pDeviceObject
                 .endif
             .endif
             mov eax, status

             ret

DriverEntry         endp
end DriverEntry

调式了好多遍的,但是psi.FileName老显示不出正确的文件名来 

[课程]FART 脱壳王!加量不加价!FART作者讲授!

收藏
免费 0
支持
分享
最新回复 (4)
雪    币: 209
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
不要转换为ANSI
直接打印UNICODE看看
2007-9-7 14:27
0
雪    币: 796
活跃值: (370)
能力值: ( LV9,RANK:380 )
在线值:
发帖
回帖
粉丝
3
直接打印UNICODE也为乱码
2007-9-7 17:57
0
雪    币: 325
活跃值: (97)
能力值: ( LV13,RANK:530 )
在线值:
发帖
回帖
粉丝
4
ZwSetInformationFile
The ZwSetInformationFile routine changes various kinds of information about a file object.

NTSTATUS
  ZwSetInformationFile(
    IN HANDLE  FileHandle,
    OUT PIO_STATUS_BLOCK  IoStatusBlock,
    IN PVOID  FileInformation,
    IN ULONG  Length,
    IN FILE_INFORMATION_CLASS  FileInformationClass
    );

Parameters
FileHandle
Handle to the file object. This handle is created by a successful call to ZwCreateFile or ZwOpenFile.
IoStatusBlock
Pointer to an IO_STATUS_BLOCK structure that receives the final completion status and information about the requested operation. The Information member receives the number of bytes set on the file.
FileInformation
Pointer to a buffer that contains the information to set for the file. The particular structure in this buffer is determined by the FileInformationClass parameter. Setting any member of the structure to zero tells ZwSetInformationFile to leave the current information about the file for that member unchanged.
Length
The size, in bytes, of the FileInformation buffer.
FileInformationClass
The type of information, supplied in the buffer pointed to by FileInformation, to set for the file. Device and intermediate drivers can specify any of the following values.FileInformationClass Value Meaning
FileBasicInformation Change the information that is supplied in a FILE_BASIC_INFORMATION structure. The caller must have opened the file with the FILE_WRITE_ATTRIBUTES flag set in the DesiredAccess parameter.
FileDispositionInformation Usually, sets the DeleteFile member of a FILE_DISPOSITION_INFORMATION to TRUE, so the file can be deleted when ZwClose is called to release the last open handle to the file object. The caller must have opened the file with the DELETE flag set in the DesiredAccess parameter.
FileEndOfFileInformation Change the current end-of-file information, supplied in a FILE_END_OF_FILE_INFORMATION structure. The operation can either truncate or extend the file. The caller must have opened the file with the FILE_WRITE_DATA flag set in the DesiredAccess parameter.
FileIoPriorityHintInformation Change the current default IRP priority hint for the file handle. The new value is supplied in a FILE_IO_PRIORITY_HINT_INFORMATION structure.
Note  This structure must be 8-byte aligned.

FilePositionInformation Change the current file information, which is stored in a FILE_POSITION_INFORMATION structure.
FileShortNameInformation Change the current short file name, which is supplied in a FILE_NAME_INFORMATION structure. The file must be on an NTFS volume, and the caller must have opened the file with the DesiredAccess DELETE flag set in the DesiredAccess parameter.
FileValidDataLengthInformation Change the current valid data length for the file, which is supplied in a FILE_VALID_DATA_LENGTH_INFORMATION structure. The file must be on an NTFS volume, and the caller must have opened the file with the FILE_WRITE_DATA flag set in the DesiredAccess parameter. Nonadministrators and remote users must have the SeManageVolumePrivilege privilege.


Return Value
ZwSetInformationFile returns STATUS_SUCCESS or an appropriate error status.

Headers
Declared in ntddk.h. Include ntddk.h.

Comments
ZwSetInformationFile changes information about a file. It ignores any member of a FILE_XXX_INFORMATION structure that is not supported by a particular device or file system.

If you set FileInformationClass to FileDispositionInformation, you can subsequently pass FileHandle to ZwClose but not to any other ZwXxxFile routine. Because FileDispositionInformation causes the file to be marked for deletion, it is a programming error to attempt any subsequent operation on the handle other than closing it.

If you set FileInformationClass to FilePositionInformation, and the preceding call to ZwCreateFile included the FILE_NO_INTERMEDIATE_BUFFERING flag in the CreateOptions parameter, certain restrictions on the CurrentByteOffset member of the FILE_POSITION_INFORMATION structure are enforced. For more information, see ZwCreateFile.

If you set FileInformationClass to FileEndOfFileInformation, and the EndOfFile member of FILE_END_OF_FILE_INFORMATION specifies an offset beyond the current end-of-file mark, ZwSetInformationFile extends the file and pads the extension with zeros.

For more information about working with files, see Using Files in a Driver.

Callers of ZwSetInformationFile must be running at IRQL = PASSIVE_LEVEL and with APCs enabled.

See Also
FILE_BASIC_INFORMATION, FILE_DISPOSITION_INFORMATION, FILE_END_OF_FILE_INFORMATION, FILE_NAME_INFORMATION, FILE_POSITION_INFORMATION, FILE_VALID_DATA_LENGTH_INFORMATION, ZwCreateFile, ZwQueryInformationFile

© 2007 Microsoft Corporation
Send feedback on this topic
Built on January 24, 2007

Build machine: CAPEBUILD
See Also
FILE_BASIC_INFORMATION, FILE_DISPOSITION_INFORMATION, FILE_END_OF_FILE_INFORMATION, FILE_NAME_INFORMATION, FILE_POSITION_INFORMATION, FILE_VALID_DATA_LENGTH_INFORMATION, ZwCreateFile, ZwQueryInformationFile

你怎么保证传进来的一定是 FileShortNameInformation struct??
2007-9-8 21:08
0
雪    币: 66
活跃值: (16)
能力值: ( LV8,RANK:130 )
在线值:
发帖
回帖
粉丝
5
ObReferenceObjectByHandle(hFile)
ObQueryObjectString
2007-9-8 21:30
0
游客
登录 | 注册 方可回帖
返回
//