parameters: (self)
return_statement: return FileName
docstring: @rtype:  None or str
          @return: Name of the open file, or C{None} if unavailable.
function: def get_filename(self):
          """
          @rtype:  None or str
          @return: Name of the open file, or C{None} if unavailable.
          """
          #
          # XXX BUG
          #
          # This code truncates the first two bytes of the path.
          # It seems to be the expected behavior of NtQueryInformationFile.
          #
          # My guess is it only returns the NT pathname, without the device name.
          # It's like dropping the drive letter in a Win32 pathname.
          #
          # Note that using the "official" GetFileInformationByHandleEx
          # API introduced in Vista doesn't change the results!
          #
          dwBufferSize      = 0x1004
          lpFileInformation = ctypes.create_string_buffer(dwBufferSize)
          try:
              GetFileInformationByHandleEx(self.value,
                                          FILE_INFO_BY_HANDLE_CLASS.FileNameInfo,
                                          lpFileInformation, dwBufferSize)
          except AttributeError:
              from winappdbg.win32.ntdll import NtQueryInformationFile, \
                                FileNameInformation, \
                                FILE_NAME_INFORMATION
              NtQueryInformationFile(self.value,
                                     FileNameInformation,
                                     lpFileInformation,
                                     dwBufferSize)
          FileName = compat.unicode(lpFileInformation.raw[sizeof(DWORD):], 'U16')
          FileName = ctypes.create_unicode_buffer(FileName).value
          if not FileName:
              FileName = None
          elif FileName[1:2] != ':':
              # When the drive letter is missing, we'll assume SYSTEMROOT.
              # Not a good solution but it could be worse.
              import os
              FileName = os.environ['SYSTEMROOT'][:2] + FileName
          return FileName
function_tokens: def get_filename ( self ) : # # XXX BUG # # This code truncates the first two bytes of the path. # It seems to be the expected behavior of NtQueryInformationFile. # # My guess is it only returns the NT pathname, without the device name. # It's like dropping the drive letter in a Win32 pathname. # # Note that using the "official" GetFileInformationByHandleEx # API introduced in Vista doesn't change the results! # dwBufferSize = 0x1004 lpFileInformation = ctypes . create_string_buffer ( dwBufferSize ) try : GetFileInformationByHandleEx ( self . value , FILE_INFO_BY_HANDLE_CLASS . FileNameInfo , lpFileInformation , dwBufferSize ) except AttributeError : from winappdbg . win32 . ntdll import NtQueryInformationFile , FileNameInformation , FILE_NAME_INFORMATION NtQueryInformationFile ( self . value , FileNameInformation , lpFileInformation , dwBufferSize ) FileName = compat . unicode ( lpFileInformation . raw [ sizeof ( DWORD ) : ] , 'U16' ) FileName = ctypes . create_unicode_buffer ( FileName ) . value if not FileName : FileName = None elif FileName [ 1 : 2 ] != ':' : # When the drive letter is missing, we'll assume SYSTEMROOT. # Not a good solution but it could be worse. import os FileName = os . environ [ 'SYSTEMROOT' ] [ : 2 ] + FileName return FileName