Example #1
0
    def parseDirectoryControlResponse(self, deviceID: int, completionID: int,
                                      ioStatus: int,
                                      stream: BytesIO) -> DeviceIOResponsePDU:
        minorFunction = self.minorFunctionsForParsingResponse.pop(
            completionID, None)

        if minorFunction is None:
            return DeviceIOResponsePDU(None, deviceID, completionID, ioStatus,
                                       stream.read())
        elif minorFunction == MinorFunction.IRP_MN_NOTIFY_CHANGE_DIRECTORY:
            return DeviceIOResponsePDU(None, deviceID, completionID, ioStatus,
                                       stream.read())

        informationClass = self.informationClassForParsingResponse.pop(
            completionID)

        length = Uint32LE.unpack(stream)
        responseData = stream.read(length)
        endByte = stream.read(1)

        fileInformation = self.fileInformationParsers[informationClass](
            responseData)

        return DeviceQueryDirectoryResponsePDU(deviceID, completionID,
                                               ioStatus, informationClass,
                                               fileInformation, endByte)
Example #2
0
 def parseDeviceIOResponse(self, stream: BytesIO) -> DeviceIOResponsePDU:
     """
     Starts after the rdpdr header.
     """
     deviceId = Uint32LE.unpack(stream)
     completionId = Uint32LE.unpack(stream)
     ioStatus = Uint32LE.unpack(stream)
     payload = stream.read()
     return DeviceIOResponsePDU(deviceId, completionId, ioStatus, payload=payload)
Example #3
0
    def parseDeviceIOResponse(self, stream: BytesIO) -> DeviceIOResponsePDU:
        deviceID = Uint32LE.unpack(stream)
        completionID = Uint32LE.unpack(stream)
        ioStatus = Uint32LE.unpack(stream)

        majorFunction = self.majorFunctionsForParsingResponse.pop(completionID, None)

        if majorFunction in self.ioResponseParsers:
            return self.ioResponseParsers[majorFunction](deviceID, completionID, ioStatus, stream)
        else:
            # If for some reason, we don't know this completionID, we also return a raw response PDU (because majorFunction is None).
            payload = stream.read()
            return DeviceIOResponsePDU(majorFunction, deviceID, completionID, ioStatus, payload)