1# Copyright (c) 2017, The MITRE Corporation. All rights reserved.
2# See LICENSE.txt for complete terms.
3
4from mixbox import entities
5from mixbox import fields
6
7import cybox.bindings.code_object as code_binding
8from cybox.common import (ObjectProperties, String, HexBinary, StructuredText,
9        MeasureSource, PlatformSpecification, ExtractedFeatures, DigitalSignatureList)
10
11
12class CodeSegmentXOR(String):
13    _binding = code_binding
14    _binding_class = code_binding.CodeSegmentXORType
15    _namespace = "http://cybox.mitre.org/objects#CodeObject-2"
16
17    xor_pattern = fields.TypedField('xor_pattern')
18
19    def is_plain(self):
20        return super(CodeSegmentXOR, self).is_plain() and not self.xor_pattern
21
22
23class TargetedPlatforms(entities.EntityList):
24    _binding = code_binding
25    _binding_class = code_binding.TargetedPlatformsType
26    _namespace = "http://cybox.mitre.org/objects#CodeObject-2"
27
28    targeted_platform = fields.TypedField("Targeted_Platform", PlatformSpecification, multiple=True)
29
30
31class Code(ObjectProperties):
32    _binding = code_binding
33    _binding_class = code_binding.CodeObjectType
34    _namespace = "http://cybox.mitre.org/objects#CodeObject-2"
35    _XSI_NS = "CodeObj"
36    _XSI_TYPE = "CodeObjectType"
37
38    description = fields.TypedField('Description', StructuredText)
39    type_ = fields.TypedField('Type', String)
40    purpose = fields.TypedField('Purpose', String)
41    code_language = fields.TypedField('Code_Language', String)
42    targeted_platforms = fields.TypedField('Targeted_Platforms', TargetedPlatforms)
43    processor_family = fields.TypedField('Processor_Family', String, multiple=True)
44    discovery_method = fields.TypedField('Discovery_Method', MeasureSource)
45    start_address = fields.TypedField('Start_Address', HexBinary)
46    code_segment = fields.TypedField('Code_Segment', String)
47    code_segment_xor = fields.TypedField('Code_Segment_XOR', CodeSegmentXOR)
48    digital_signatures = fields.TypedField('Digital_Signatures', DigitalSignatureList)
49    extracted_features = fields.TypedField('Extracted_Features', ExtractedFeatures)
50