Guest User

Untitled

a guest
Nov 30th, 2020
198
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from ctypes import *
  2. CreateFileW = windll.kernel32.CreateFileW
  3. SetFileInformationByHandle = windll.kernel32.SetFileInformationByHandle
  4. GetFinalPathNameByHandleW = windll.kernel32.GetFinalPathNameByHandleW
  5. GetLastError = windll.kernel32.GetLastError
  6. BUFSIZE=1024
  7. Path = create_unicode_buffer(BUFSIZE)
  8. hFile = CreateFileW(c_wchar_p('tempfile'), 0xC0010000, 7, 0, 1, 0x80, 0)
  9. VOLUME_NAME_DOS = 0
  10. FILE_NAME_NORMALIZED = 0
  11. fResult = GetFinalPathNameByHandleW(hFile, Path, BUFSIZE, FILE_NAME_NORMALIZED|VOLUME_NAME_DOS)
  12. print('fResult=' + str(fResult) + '\nPath=' + Path.value)
  13. FileDispositionInfo = 4
  14. class FILE_DISPOSITION_INFO(Structure):
  15.     _fields_ = [("DeleteFile", c_bool)]
  16. fdi = FILE_DISPOSITION_INFO()
  17. fdi.DeleteFile = True
  18. fResult = SetFileInformationByHandle(hFile, FileDispositionInfo, byref(fdi), sizeof(FILE_DISPOSITION_INFO))
  19. fResult = GetFinalPathNameByHandleW(hFile, Path, BUFSIZE, FILE_NAME_NORMALIZED|VOLUME_NAME_DOS)
  20. err = GetLastError()
  21. print(fResult, err)
  22.  
RAW Paste Data