Beispiel #1
0
class File(DefinedObject):
    _XSI_TYPE = "FileObjectType"
    
    def __init__(self):
        self.is_packed = None
        self.file_name = None
        self.file_path = None
        self.device_path = None
        self.full_path = None
        self.file_extension = None
        self.size_in_bytes = None
        self.magic_number = None
        self.file_format = None
        self.hashes = None

        # Not supported yet:
        # - Digital_Signatures
        # - Modified_Time
        # - Accessed_Time
        # - Created_Time
        # - File_Attributes_List
        # - Permissions
        # - User_Owner
        # - Packer_List
        # - Peak_Entropy
        # - Sym_Links
        # - Extracted_Features
        # - Byte Runs

    @property
    def file_name(self):
        return self._file_name

    @file_name.setter
    def file_name(self, value):
        if value is not None and not isinstance(value, String):
            value = String(value)
        self._file_name = value

    @property
    def file_path(self):
        return self._file_path

    @file_path.setter
    def file_path(self, value):
        if value is not None and not isinstance(value, FilePath):
            value = FilePath(value)
        self._file_path = value

    def add_hash(self, hash_):
        if not self.hashes:
            self.hashes = HashList()
        self.hashes.add(hash_)

    def to_obj(self):
        file_obj = file_binding.FileObjectType()
        file_obj.set_anyAttributes_({'xsi:type' : 'FileObj:FileObjectType'})

        if self.is_packed is not None:
            file_obj.set_is_packed(self.is_packed)
        if self.file_name is not None:
            file_obj.set_File_Name(self.file_name.to_obj())
        if self.file_path is not None:
            file_obj.set_File_Path(self.file_path.to_obj())
        if self.device_path is not None:
            file_obj.set_Device_Path(self.device_path.to_obj())
        if self.full_path is not None:
            file_obj.set_Full_Path(self.full_path.to_obj())
        if self.file_extension is not None:
            file_obj.set_File_Extension(self.file_extension.to_obj())
        if self.size_in_bytes is not None:
            file_obj.set_Size_In_Bytes(self.size_in_bytes.to_obj())
        if self.magic_number is not None:
            file_obj.set_Magic_Number(self.magic_number.to_obj())
        if self.file_format is not None:
            file_obj.set_File_Format(self.file_format.to_obj())
        if self.hashes is not None:
            file_obj.set_Hashes(self.hashes.to_obj())

        return file_obj

    def to_dict(self):
        file_dict = {}

        if self.is_packed is not None:
            file_dict['is_packed'] = self.is_packed,
        if self.file_name is not None:
            file_dict['file_name'] = self.file_name.to_dict()
        if self.file_path is not None:
            file_dict['file_path'] = self.file_path.to_dict()
        if self.device_path is not None:
            file_dict['device_path'] = self.device_path.to_dict()
        if self.full_path is not None:
            file_dict['full_path'] = self.full_path.to_dict()
        if self.file_extension is not None:
            file_dict['file_extension'] = self.file_extension.to_dict()
        if self.size_in_bytes is not None:
            file_dict['size_in_bytes'] = self.size_in_bytes.to_dict()
        if self.magic_number is not None:
            file_dict['magic_number'] = self.magic_number.to_dict()
        if self.file_format is not None:
            file_dict['file_format'] = self.file_format.to_dict()
        if self.hashes is not None:
            file_dict['hashes'] = self.hashes.to_dict()
        file_dict['xsi_type'] = self._XSI_TYPE

        return file_dict

    @staticmethod
    def from_obj(file_obj):
        if not file_obj:
            return None

        file_ = File()

        file_.is_packed = file_obj.get_is_packed()
        file_.file_name = String.from_obj(file_obj.get_File_Name())
        file_.file_path = FilePath.from_obj(file_obj.get_File_Path())
        file_.device_path = String.from_obj(file_obj.get_Device_Path())
        file_.full_path = String.from_obj(file_obj.get_Full_Path())
        file_.file_extension = String.from_obj(file_obj.get_File_Extension())
        file_.size_in_bytes = UnsignedLong.from_obj(file_obj.get_Size_In_Bytes())
        file_.magic_number = HexBinary.from_obj(file_obj.get_Magic_Number())
        file_.file_format = String.from_obj(file_obj.get_File_Format())
        file_.hashes = HashList.from_obj(file_obj.get_Hashes())

        return file_

    @staticmethod
    def from_dict(file_dict):
        if not file_dict:
            return None

        file_ = File()

        file_.is_packed = file_dict.get('is_packed')
        file_.file_name = String.from_dict(file_dict.get('file_name'))
        file_.file_path = FilePath.from_dict(file_dict.get('file_path'))
        file_.device_path = String.from_dict(file_dict.get('device_path'))
        file_.full_path = String.from_dict(file_dict.get('full_path'))
        file_.file_extension = String.from_dict(file_dict.get('file_extension'))
        file_.size_in_bytes = UnsignedLong.from_dict(file_dict.get('size_in_bytes'))
        file_.magic_number = HexBinary.from_dict(file_dict.get('magic_number'))
        file_.file_format = String.from_dict(file_dict.get('file_format'))
        file_.hashes = HashList.from_dict(file_dict.get('hashes'))

        return file_