def PopulateFromFileStream(self, fs):
        if (fs is None):
            raise Exception("Invalid File Steam")
        self.EfiTime = EfiTime(decodefs=fs)
        self.AuthInfo = WinCert.Factory(fs)
        self.Payload = None
        self.SigListPayload = None

        self.SetPayload(fs)
示例#2
0
    def PopulateFromFileStream(self, fs):
        if (fs == None):
            raise Exception("Invalid File stream")

        #only populate from file stream those parts that are complete in the file stream
        offset = fs.tell()
        fs.seek(0, 2)
        end = fs.tell()
        fs.seek(offset)

        if ((end - offset) < self.STATIC_STRUCT_SIZE_V1
            ):  # minimum size of the static header data
            raise Exception("Invalid file stream size")

        self.HeaderSignature = fs.read(4).decode()
        if self.HeaderSignature != self.HEADER_SIG_VALUE:
            raise Exception("Incorrect Header Signature")
        self.HeaderVersion = struct.unpack("=B", fs.read(1))[0]
        self.rsvd1 = struct.unpack("=B", fs.read(1))[0]
        self.rsvd2 = struct.unpack("=B", fs.read(1))[0]
        self.rsvd3 = struct.unpack("=B", fs.read(1))[0]

        if (self.HeaderVersion == self.VERSION_V1):
            self.SNTarget = struct.unpack("=Q", fs.read(8))[0]
            self.SessionId = struct.unpack("=I", fs.read(4))[0]
            self.PayloadSize = struct.unpack("=H", fs.read(2))[0]

        elif (self.HeaderVersion == self.VERSION_V2):
            if ((end - offset) <
                    self.STATIC_STRUCT_SIZE_V2):  # minimum size for v2 data
                raise Exception("Invalid V2 file stream size")
            self.SessionId = struct.unpack("=I", fs.read(4))[0]
            self.MfgOffset = struct.unpack("=H", fs.read(2))[0]
            self.ProductOffset = struct.unpack("=H", fs.read(2))[0]
            self.SerialOffset = struct.unpack("=H", fs.read(2))[0]
            self.PayloadSize = struct.unpack("=H", fs.read(2))[0]
            self.PayloadOffset = struct.unpack("=H", fs.read(2))[0]

            if (end - fs.tell() < self.PayloadOffset):
                raise Exception("Packet too small for SmBiosString")

            if ((self.MfgOffset >= self.ProductOffset)
                    or (self.ProductOffset >= self.SerialOffset)
                    or (self.SerialOffset >= self.PayloadOffset)):
                raise Exception("Invalid Offset Structure")

            Temp = fs.tell()
            if Temp != self.MfgOffset:
                raise Exception("Invalid Mfg Offset")
            self.Manufacturer = fs.read(self.ProductOffset - self.MfgOffset -
                                        1).decode()
            Temp = struct.unpack("=B", fs.read(1))[0]
            if Temp != 0:
                raise Exception("Invalid NULL in Mfg")

            Temp = fs.tell()
            if Temp != self.ProductOffset:
                raise Exception("Invalid Product Offset")
            self.ProductName = fs.read(self.SerialOffset - self.ProductOffset -
                                       1).decode()
            Temp = struct.unpack("=B", fs.read(1))[0]
            if Temp != 0:
                raise Exception("Invalid NULL in ProductName")

            Temp = fs.tell()
            if Temp != self.SerialOffset:
                raise Exception("Invalid SerialOffset Offset")
            self.SerialNumber = fs.read(self.PayloadOffset -
                                        self.SerialOffset - 1).decode()
            Temp = struct.unpack("=B", fs.read(1))[0]
            if Temp != 0:
                raise Exception("Invalid NULL in SerialNumber")
        else:
            raise Exception("Invalid header version")

        self.Payload = None
        self._PayloadXml = None
        self.Signature = None

        if ((end - fs.tell()) < self.PayloadSize):
            raise Exception(
                "Invalid file stream size (payload size incorrect)")

        self.Payload = fs.read(self.PayloadSize).decode('utf-8')
        prep = self.Payload
        prep = prep.rstrip('\x00')
        self._PayloadXml = xml.dom.minidom.parseString(prep)

        if ((end - fs.tell()) > 0):
            self.Signature = WinCert.Factory(fs)