Exemplo n.º 1
0
 def create(self, raw_data):
     """convert segments data into a segments objects by using SegmentFactory.
     """
     try:
         segments = []
         raw_data_segments_lst = self._parse_segments(raw_data)
         for raw_seg in raw_data_segments_lst:
             seg_type = '{:0b}'.format(raw_seg[cs.SEGMENT_TYPE_DWORD_LOCATION]).zfill(32)[cs.SEGMENT_TYPE_START: cs.
                                                                                          SEGMENT_TYPE_END]
             seg_type = hex(int(seg_type, 2))
             seg_type_for_create = SegmentCreator.get_seg_type_for_register_segments(seg_type)
             seg = SegmentFactory.create(seg_type_for_create, raw_seg)
             seg.resource_type = seg_type
             segments.append(seg)
     except Exception as e:
         raise Exception("Failed to create segments with error: {0}".format(e))
     return segments
Exemplo n.º 2
0
        """get the reference segment data.
        """
        return self.raw_data

    def get_type(self):
        """get the reference segment type.
        """
        return cs.RESOURCE_DUMP_SEGMENT_TYPE_REFERENCE

    def get_parsed_data(self):
        """get dictionary of parsed segment data.
        """
        # dw_data = self.get_data()
        # self._parsed_data['Segment Type'] = "{0} ({1})".format("Reference Segment",
        #                                                  str(hex(int('{:0b}'.format(dw_data[0]).zfill(32)[16:32], 2))))
        # offset = cs.SEGMENTS_HEADER_SIZE_IN_DW
        #
        # if len(dw_data) > cs.SEGMENTS_HEADER_SIZE_IN_DW:
        #     self._parsed_data['reference_segment'] = str(hex(int('{:0b}'.format(dw_data[offset]).zfill(32)[16:32], 2)))
        #     offset += 1
        #     self._parsed_data['index1'] = str(hex(int('{:0b}'.format(dw_data[offset]).zfill(32)[0:32], 2)))
        #     offset += 1
        #     self._parsed_data['index2'] = str(hex(int('{:0b}'.format(dw_data[offset]).zfill(32)[0:32], 2)))
        #     offset += 1
        #     self._parsed_data['num_of_obj1'] = str(hex(int('{:0b}'.format(dw_data[offset]).zfill(32)[0:16], 2)))
        #     self._parsed_data['num_of_obj2'] = str(hex(int('{:0b}'.format(dw_data[offset]).zfill(32)[16:32], 2)))
        return self._parsed_data


SegmentFactory.register(cs.RESOURCE_DUMP_SEGMENT_TYPE_REFERENCE, RefSegment)
Exemplo n.º 3
0
# Created on:      14-Aug-2019 10:11:57 AM
# Original author: talve
#
#######################################################
from segments.Segment import Segment
from segments.SegmentFactory import SegmentFactory
from utils import constants


class ErrorSegment(Segment):
    """this class is responsible for holding error segment data.
    """
    def __init__(self, data):
        """initialize the class by setting the class data.
        """
        self.raw_data = data

    def get_data(self):
        """get the general segment data.
        """
        return self.raw_data

    def get_type(self):
        """get the general segment type.
        """
        return constants.RESOURCE_DUMP_SEGMENT_TYPE_ERROR


SegmentFactory.register(constants.RESOURCE_DUMP_SEGMENT_TYPE_ERROR,
                        ErrorSegment)
Exemplo n.º 4
0
# Created on:      14-Aug-2019 10:11:57 AM
# Original author: talve
#
#######################################################
from segments.Segment import Segment
from segments.SegmentFactory import SegmentFactory
from utils import constants


class TerminateSegment(Segment):
    """this class is responsible for holding Terminate segment data.
    """
    def __init__(self, data):
        """initialize the class by setting the class data.
        """
        self.raw_data = data

    def get_data(self):
        """get the general segment data.
        """
        return self.raw_data

    def get_type(self):
        """get the general segment type.
        """
        return constants.RESOURCE_DUMP_SEGMENT_TYPE_TERMINATE


SegmentFactory.register(constants.RESOURCE_DUMP_SEGMENT_TYPE_TERMINATE,
                        TerminateSegment)
Exemplo n.º 5
0
# Created on:      14-Aug-2019 10:11:57 AM
# Original author: talve
#
#######################################################
from segments.Segment import Segment
from segments.SegmentFactory import SegmentFactory
from utils import constants


class CommandSegment(Segment):
    """this class is responsible for holding command segment data.
    """
    def __init__(self, data):
        """initialize the class by setting the class data.
        """
        self.raw_data = data

    def get_data(self):
        """get the general segment data.
        """
        return self.raw_data

    def get_type(self):
        """get the general segment type.
        """
        return constants.RESOURCE_DUMP_SEGMENT_TYPE_COMMAND


SegmentFactory.register(constants.RESOURCE_DUMP_SEGMENT_TYPE_COMMAND,
                        CommandSegment)
Exemplo n.º 6
0
# Generated by Enterprise Architect
# Created on:      14-Aug-2019 10:11:57 AM
# Original author: talve
#
#######################################################
from segments.Segment import Segment
from segments.SegmentFactory import SegmentFactory
from utils import constants


class InfoSegment(Segment):
    """this class is responsible for holding info segment data.
    """
    def __init__(self, data):
        """initialize the class by setting the class data.
        """
        self.raw_data = data

    def get_data(self):
        """get the general segment data.
        """
        return self.raw_data

    def get_type(self):
        """get the general segment type.
        """
        return constants.RESOURCE_DUMP_SEGMENT_TYPE_INFO


SegmentFactory.register(constants.RESOURCE_DUMP_SEGMENT_TYPE_INFO, InfoSegment)
Exemplo n.º 7
0
        """
        return self.raw_data

    def get_type(self):
        """get the general segment type.
        """
        return cs.RESOURCE_DUMP_SEGMENT_TYPE_NOTICE

    def get_parsed_data(self):
        """get dictionary of parsed segment data.
        """
        dw_data = self.get_data()
        # self._parsed_data['Segment Type'] = "{0} ({1})".format("Notice Segment", str(
        #     hex(int('{:0b}'.format(dw_data[0]).zfill(32)[16:32], 2))))

        offset = cs.SEGMENTS_HEADER_SIZE_IN_DW
        if len(dw_data) > cs.SEGMENTS_HEADER_SIZE_IN_DW:
            # self._parsed_data['syndrome_id'] = str(hex(int('{:0b}'.format(dw_data[offset]).zfill(32)[16:32], 2)))
            try:
                self._parsed_data['notice msg'] = MenuRecord.bin_list_to_ascii(
                    dw_data[cs.ERROR_SEGMENT_NOTICE_MSG_START:cs.
                            ERROR_SEGMENT_NOTICE_MSG_END])
            except:
                # in case that the bin is not an ascii we will not display the notice msg
                pass

        return self._parsed_data


SegmentFactory.register(cs.RESOURCE_DUMP_SEGMENT_TYPE_NOTICE, NoticeSegment)
Exemplo n.º 8
0
                    .format(dump_type))

            if num_of_objs_1 == "all" and not match_rec.supports_all_num_of_obj1:
                raise DumpNotSupported(
                    "Dump type: {0} does not support 'all' as numOfObj1 attribute"
                    .format(dump_type))

            if num_of_objs_2 == "all" and not match_rec.supports_all_num_of_obj2:
                raise DumpNotSupported(
                    "Dump type: {0} does not support 'all' as numOfObj2 attribute"
                    .format(dump_type))

            if num_of_objs_1 == "active" and not match_rec.supports_active_num_of_obj1:
                raise DumpNotSupported(
                    "Dump type: {0} does not support 'active' as numOfObj1 attribute"
                    .format(dump_type))

            if num_of_objs_2 == "active" and not match_rec.supports_active_num_of_obj2:
                raise DumpNotSupported(
                    "Dump type: {0} does not support 'active' as numOfObj2 attribute"
                    .format(dump_type))

        except DumpNotSupported as e:
            print(e)
            return False

        return True


SegmentFactory.register(cs.RESOURCE_DUMP_SEGMENT_TYPE_MENU, MenuSegment)
Exemplo n.º 9
0
# Original author: talve
#
#######################################################
from segments.Segment import Segment
from segments.SegmentFactory import SegmentFactory
from utils import constants


class ResourceSegment(Segment):
    """this class is responsible for holding Resource segment data.
    """
    def __init__(self, data):
        """initialize the class by setting the class data.
        """
        self.raw_data = data
        self.resource_type = constants.RESOURCE_DUMP_SEGMENT_TYPE_RESOURCE

    def get_data(self):
        """get the general segment data.
        """
        return self.raw_data

    def get_type(self):
        """get the general segment type.
        """
        return self.resource_type


SegmentFactory.register(constants.RESOURCE_DUMP_SEGMENT_TYPE_RESOURCE,
                        ResourceSegment)