当前位置: 首页>>代码示例>>Python>>正文


Python win32file.DeviceIoControl方法代码示例

本文整理汇总了Python中win32file.DeviceIoControl方法的典型用法代码示例。如果您正苦于以下问题:Python win32file.DeviceIoControl方法的具体用法?Python win32file.DeviceIoControl怎么用?Python win32file.DeviceIoControl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在win32file的用法示例。


在下文中一共展示了win32file.DeviceIoControl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ZapMBRGPT

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import DeviceIoControl [as 别名]
def ZapMBRGPT(self, disk_size, sector_size, add1MB):
        self.assert_physical_drive()
        # Implementation borrowed from rufus: https://github.com/pbatard/rufus
        num_sectors_to_clear \
            = (add1MB and 2048 or 0) + self.MAX_SECTORS_TO_CLEAR
        zeroBuf = b'\0' * sector_size
        for i in range(num_sectors_to_clear):
            self.WriteFile(zeroBuf)
        offset = disk_size - self.MAX_SECTORS_TO_CLEAR * sector_size
        win32file.SetFilePointer(self.h, offset, win32con.FILE_BEGIN)
        for i in range(num_sectors_to_clear):
            self.WriteFile(zeroBuf)
        # We need to append paddings as CREATE_DISK structure contains a union.
        param = struct.pack('<IIIHH8s',
                            winioctlcon.PARTITION_STYLE_MBR, 0xdeadbeef,
                            0,0,0,b'abcdefgh')
        win32file.DeviceIoControl(
            self.h, winioctlcon.IOCTL_DISK_CREATE_DISK, param, 0, None) 
开发者ID:mbusb,项目名称:multibootusb,代码行数:20,代码来源:win32.py

示例2: lockPhysicalDrive

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import DeviceIoControl [as 别名]
def lockPhysicalDrive(handle, logfunc=lambda s: None):
    try:
        win32file.DeviceIoControl(
            handle, winioctlcon.FSCTL_ALLOW_EXTENDED_DASD_IO,
            None, 0, None)
    except pywintypes.error as e:
        logfunc('IO boundary checks diabled.')
    for retry in range(20):
        try:
            win32file.DeviceIoControl(handle, winioctlcon.FSCTL_LOCK_VOLUME,
                                      None, 0, None)
            return
        except pywintypes.error as e:
            logfunc( str(e) )
            time.sleep(1)
    raise RuntimeError("Couldn't lock the Volume.") 
开发者ID:mbusb,项目名称:multibootusb,代码行数:18,代码来源:win32.py

示例3: ZapPhysicalDrive

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import DeviceIoControl [as 别名]
def ZapPhysicalDrive(target_drive, get_volume_info_func, log_func):
    with openHandle('\\\\.\\PhysicalDrive%d' % target_drive, True, False,
                    lambda s:sys.stdout.write(s+'\n')) as hDrive:
        hDrive.LockPhysicalDrive()
        geom = hDrive.DiskGeometory()
        for v in get_volume_info_func(target_drive):
            volume_path = '\\\\.\\'+v.DeviceID
            log_func('Dismounting volume ' + volume_path)
            with openHandle(volume_path, False, False) as h:
                x = win32file.DeviceIoControl(
                    h.h, winioctlcon.FSCTL_DISMOUNT_VOLUME, None, None)
                print ('FSCTL_DISMOUNT_VOLUME=>%s' % x)
            x = win32file.DeleteVolumeMountPoint(volume_path+'\\')
            log_func('DeleteVolumeMountPoint=>%s' % x)
        else:
            log_func('No volumes on %s' % target_drive)

        add1MB = False
        hDrive.ZapMBRGPT(geom.disk_size, geom.bytes_per_sector, add1MB) 
开发者ID:mbusb,项目名称:multibootusb,代码行数:21,代码来源:win32.py

示例4: ParseMemoryRuns

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import DeviceIoControl [as 别名]
def ParseMemoryRuns(self):
        self.runs = []

        result = win32file.DeviceIoControl(
            self.fd, INFO_IOCTRL, "", 102400, None)

        fmt_string = "Q" * len(self.FIELDS)
        self.memory_parameters = dict(zip(self.FIELDS, struct.unpack_from(
                    fmt_string, result)))

        self.dtb = self.memory_parameters["CR3"]
        self.kdbg = self.memory_parameters["KDBG"]

        offset = struct.calcsize(fmt_string)

        for x in range(self.memory_parameters["NumberOfRuns"]):
            start, length = struct.unpack_from("QQ", result, x * 16 + offset)
            self.runs.append((start, length)) 
开发者ID:google,项目名称:rekall,代码行数:20,代码来源:winpmem.py

示例5: ParseMemoryRuns

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import DeviceIoControl [as 别名]
def ParseMemoryRuns(self, fhandle):
        # Set acquisition mode. If the driver does not support this mode it will
        # just fall back to the default.
        win32file.DeviceIoControl(
            fhandle, CTRL_IOCTRL,
            struct.pack("I", PMEM_MODE_PTE), 4, None)

        result = win32file.DeviceIoControl(
            fhandle, INFO_IOCTRL, b"", 102400, None)

        fmt_string = "Q" * len(self.FIELDS)
        self.memory_parameters = dict(zip(self.FIELDS, struct.unpack_from(
            fmt_string, result)))

        offset = struct.calcsize(fmt_string)
        for x in range(self.memory_parameters["NumberOfRuns"]):
            start, length = struct.unpack_from("QQ", result, x * 16 + offset)
            self.add_run(start, start, length, self.fhandle_as) 
开发者ID:google,项目名称:rekall,代码行数:20,代码来源:win32.py

示例6: ParseMemoryRuns

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import DeviceIoControl [as 别名]
def ParseMemoryRuns(self):
        self.runs = []

        result = win32file.DeviceIoControl(
            self.fd, INFO_IOCTRL, "", 102400, None)

        fmt_string = "Q" * len(self.FIELDS)
        self.memory_parameters = dict(zip(self.FIELDS, struct.unpack_from(
            fmt_string, result)))

        self.dtb = self.memory_parameters["CR3"]
        self.kdbg = self.memory_parameters["KDBG"]

        offset = struct.calcsize(fmt_string)

        for x in range(self.memory_parameters["NumberOfRuns"]):
            start, length = struct.unpack_from("QQ", result, x * 16 + offset)
            self.runs.append((start, length)) 
开发者ID:SekoiaLab,项目名称:Fastir_Collector,代码行数:20,代码来源:winpmem.py

示例7: DiskGeometory

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import DeviceIoControl [as 别名]
def DiskGeometory(self):
        self.assert_physical_drive()
        o = win32file.DeviceIoControl(
            self.h, winioctlcon.IOCTL_DISK_GET_DRIVE_GEOMETRY_EX,
            None, 256, None)
        return self.geometory_tuple(*struct.unpack('<qiiiiq', o[:32])) 
开发者ID:mbusb,项目名称:multibootusb,代码行数:8,代码来源:win32.py

示例8: findVolumeGuids

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import DeviceIoControl [as 别名]
def findVolumeGuids():
    DiskExtent = collections.namedtuple(
        'DiskExtent', ['DiskNumber', 'StartingOffset', 'ExtentLength'])
    Volume = collections.namedtuple(
        'Volume', ['Guid', 'MediaType', 'DosDevice', 'Extents'])
    found = []
    h, guid = FindFirstVolume()
    while h and guid:
        #print (guid)
        #print (guid, win32file.GetDriveType(guid),
        #       win32file.QueryDosDevice(guid[4:-1]))
        hVolume = win32file.CreateFile(
            guid[:-1], win32con.GENERIC_READ,
            win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE,
            None, win32con.OPEN_EXISTING, win32con.FILE_ATTRIBUTE_NORMAL,  None)
        extents = []
        driveType = win32file.GetDriveType(guid)
        if driveType in [win32con.DRIVE_REMOVABLE, win32con.DRIVE_FIXED]:
            x = win32file.DeviceIoControl(
                hVolume, winioctlcon.IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS,
                None, 512, None)
            instream = io.BytesIO(x)
            numRecords = struct.unpack('<q', instream.read(8))[0]
            fmt = '<qqq'
            sz = struct.calcsize(fmt)
            while 1:
                b = instream.read(sz)
                if len(b) < sz:
                    break
                rec = struct.unpack(fmt, b)
                extents.append( DiskExtent(*rec) )
        vinfo = Volume(guid, driveType, win32file.QueryDosDevice(guid[4:-1]),
                       extents)
        found.append(vinfo)
        guid = FindNextVolume(h)
    return found 
开发者ID:mbusb,项目名称:multibootusb,代码行数:38,代码来源:win32.py

示例9: win_tun_alloc

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import DeviceIoControl [as 别名]
def win_tun_alloc(self, dev, flags):
		TAP_IOCTL_SET_MEDIA_STATUS 	= self.WIN_TAP_CONTROL_CODE(6, 0)
		import pywintypes

		guid = self.WIN_get_device_guid()
		if not guid:
			common.internal_print("Please install OpenVPN's Windows TAP driver (NDIS 6) to use XFLTReaT\r\nhttps://openvpn.net/index.php/open-source/downloads.html", -1)
			sys.exit(-1)

		# create a win32file for manipulating the TUN/TAP interface
		try:
			self.wintun = win32file.CreateFile("\\\\.\\Global\\{0}.tap".format(guid),
				win32file.GENERIC_READ | win32file.GENERIC_WRITE,
				win32file.FILE_SHARE_READ | win32file.FILE_SHARE_WRITE,
				None, win32file.OPEN_EXISTING,
				win32file.FILE_ATTRIBUTE_SYSTEM | win32file.FILE_FLAG_NO_BUFFERING | win32file.FILE_FLAG_OVERLAPPED,
				None)
		except pywintypes.error as e:
			if e.args[0] == 31: # A device attached to the system is not functioning.
				common.internal_print("The TUN device is already in use. Maybe another XFLTReaT is running.", -1)
				sys.exit(-1)	


		# have Windows consider the interface now connected
		win32file.DeviceIoControl(self.wintun, TAP_IOCTL_SET_MEDIA_STATUS, '\x01\x00\x00\x00', 1, None)

		return self.wintun 
开发者ID:earthquake,项目名称:XFLTReaT,代码行数:29,代码来源:interface.py

示例10: GetInfoDeprecated

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import DeviceIoControl [as 别名]
def GetInfoDeprecated(self):
        result = win32file.DeviceIoControl(self.fd, INFO_IOCTRL_DEPRECATED, "",
                                           1024, None)
        fmt_string = "QQl"
        offset = struct.calcsize(fmt_string)

        cr3, kpcr, number_of_runs = struct.unpack_from(fmt_string, result)
        for x in range(number_of_runs):
            start, length = struct.unpack_from("QQ", result, x * 16 + offset)
            print("0x%X\t\t0x%X" % (start, length)) 
开发者ID:google,项目名称:rekall,代码行数:12,代码来源:winpmem.py

示例11: SetMode

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import DeviceIoControl [as 别名]
def SetMode(self):
        if FLAGS.mode == "iospace":
            mode = 0
        elif FLAGS.mode == "physical":
            mode = 1
        elif FLAGS.mode == "pte":
            mode = 2
        elif FLAGS.mode == "pte_pci":
            mode = 3
        else:
            raise RuntimeError("Mode %s not supported" % FLAGS.mode)

        win32file.DeviceIoControl(
            self.fd, CTRL_IOCTRL, struct.pack("I", mode), 0, None) 
开发者ID:google,项目名称:rekall,代码行数:16,代码来源:winpmem.py

示例12: get_physical_drive_size

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import DeviceIoControl [as 别名]
def get_physical_drive_size(drive="\\\\.\\PhysicalDrive0"):
    """Uses IOCTL to get physical drives size"""
    handle = win32file.CreateFile(drive, 0, win32file.FILE_SHARE_READ, None, win32file.OPEN_EXISTING, 0, 0)
    if handle:
        IOCTL_DISK_GET_DRIVE_GEOMETRY = 0x00070000
        info = win32file.DeviceIoControl(handle, IOCTL_DISK_GET_DRIVE_GEOMETRY, '', 24)
        win32file.CloseHandle(handle)
        if info:
            (cyl_lo, cyl_hi, media_type, tps, spt, bps) = struct.unpack('6L', info)
            mediasize = ((cyl_hi << 32) + cyl_lo) * tps * spt * bps
            """print mediasize, 'bytes'
            print mediasize/10**3, 'kbytes'
            print mediasize/10**6, 'Mbytes'
            print mediasize/10**9, 'Gbytes'"""
            return mediasize 
开发者ID:SekoiaLab,项目名称:Fastir_Collector,代码行数:17,代码来源:utils_rawstring.py

示例13: GetInfoDeprecated

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import DeviceIoControl [as 别名]
def GetInfoDeprecated(self):
        result = win32file.DeviceIoControl(self.fd, INFO_IOCTRL_DEPRECATED, "",
                                           1024, None)
        fmt_string = "QQl"
        offset = struct.calcsize(fmt_string)

        cr3, kpcr, number_of_runs = struct.unpack_from(fmt_string, result)
        for x in range(number_of_runs):
            start, length = struct.unpack_from("QQ", result, x * 16 + offset)
            print "0x%X\t\t0x%X" % (start, length) 
开发者ID:SekoiaLab,项目名称:Fastir_Collector,代码行数:12,代码来源:winpmem.py

示例14: SetMode

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import DeviceIoControl [as 别名]
def SetMode(self):
        mode = 1
        win32file.DeviceIoControl(
            self.fd, CTRL_IOCTRL, struct.pack("I", mode), 0, None) 
开发者ID:SekoiaLab,项目名称:Fastir_Collector,代码行数:6,代码来源:winpmem.py

示例15: _sparse_magic

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import DeviceIoControl [as 别名]
def _sparse_magic(handle, length=0):
        win32file.DeviceIoControl(handle, FSCTL_SET_SPARSE, '', 0, None)

        win32file.SetFilePointer(handle, length, win32file.FILE_BEGIN)
        win32file.SetEndOfFile(handle)

        win32file.SetFilePointer(handle, 0, win32file.FILE_BEGIN) 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:9,代码来源:Storage_base.py


注:本文中的win32file.DeviceIoControl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。