Пример #1
0
    def __init__(self, **kwargs):
        '''Initializes an Olecf Tag'''

        # These next lists are used for quickly jumping around
        # the DIFAT, FAT, miniFAT, and directory sectors without
        # having to follow chains in the FAT or DIFAT.

        # A list of the DIFAT sector numbers IN ORDER.
        # If none exist, this list will be empty.
        # This excludes the array of 109 DIFAT entries in the header.
        self.difat_sectors = []

        # A list of the FAT sector numbers IN ORDER.
        self.fat_sectors = []

        # A list of the miniFAT sector numbers IN ORDER.
        self.minifat_sectors = []

        # A list of the directory sector numbers IN ORDER.
        self.dir_sectors = []

        # A list of the names of each directory entry IN ORDER
        self.dir_names = []

        # A quick reference to the number of bytes in a sector
        self.sector_size = 512

        Tag.__init__(self, **kwargs)
Пример #2
0
    def __init__(self, **kwargs):
        self.sigkey  = kwargs.get('sigkey',  self.sigkey)
        self.authkey = kwargs.get('authkey', self.authkey)
        self.xboxkey = kwargs.get('xboxkey', self.xboxkey)
        self.data_start = kwargs.get('data_start', self.data_start)
        self.data_end = kwargs.get('data_end', self.data_end)
        self.sigkey   = kwargs.get('sigkey',   self.sigkey)

        Tag.__init__(self, **kwargs)
Пример #3
0
    def __init__(self, *args, **kwargs):
        Tag.__init__(self, *args, **kwargs)
        self.map_pointer_converter = MapPointerConverter((0, 0, 0xFFffFFff))
        self.setup_defs()

        try:
            rsrc_tags = self.data.tags
        except Exception:
            rsrc_tags = ()
        self.tag_path_indices = {rsrc_tags[i].tag.path.lower(): i
                                 for i in range(len(rsrc_tags))}
Пример #4
0
    def serialize(self, **kwargs):
        '''
        Overload of the supyr serialization function that retroactively adds
        a CRC to the tag.
        '''
        head = self.data.blam_header
        filepath = kwargs.get('filepath', self.filepath)
        buffer = kwargs.get('buffer', None)

        # Run the normal serialization.
        result = Tag.serialize(self, **kwargs)

        # If there is neither a buffer or filepath just return the result.
        if (buffer is None) and (not filepath):
            return result

        # Prefer to use the buffer as that is how Tag.serialize does it.
        f = buffer
        if buffer is None:
            f = Path(filepath).open('rb+')

        # Calculate the crc from after the header to the end.
        crc = calc_halo_crc32(f, offset=head.get_desc('SIZE'))
        # Write the crc to the offset of the checksum value in the header.
        # The way we retrieve this offset from supyr is insane.
        attr_index = head.get_desc('NAME_MAP')['checksum']
        f.seek(head.get_desc('ATTR_OFFS')[attr_index])
        f.write(crc.to_bytes(4, byteorder='big', signed=False))
        # Flush the stream.
        f.flush()
        # Only close if it is a file. Because the only case where we own
        # this buffer is if there was no buffer kwarg.
        if not buffer:
            f.close()

        # Update the tag object so it won't have to be deserialized again.
        head.checksum = crc
        return result
Пример #5
0
    def serialize(self, **kwargs):
        '''Writes this tag to the set path like normal, but makes
        sure to calculate and set the checksums before doing so.'''
        try:
            if self.is_powerpc:
                FieldType.force_big()
            if self.is_xbox:
                #calculate the xbox checksum
                self.xbox_sign()
            else:
                #calculate the pc/ce checksum
                footer = self.data.gametype_footer
                footer.crc_32 = self.calc_crc32(None, CE_CRC32_OFF)

                footer.hybrid_settings = BytearrayBuffer()
                self.data.gametype_settings.serialize(buffer=footer.\
                                                      hybrid_settings)

                footer.crc_32_ce = self.calc_crc32(None, PC_CRC32_OFF)
            return Tag.serialize(self, **kwargs)
        finally:
            if self.is_powerpc:
                FieldType.force_normal()
Пример #6
0
 def __init__(self, **kwargs):
     kwargs.setdefault('zero_fill', False)
     Tag.__init__(self, **kwargs)
Пример #7
0
 def serialize(self, **kwargs):
     self.xbox_sign()
     return Tag.serialize(self, **kwargs)
Пример #8
0
 def serialize(self, *args, **kwargs):
     if kwargs.get("calc_checksums", True):
         for chunk in self.data.chunks:
             self.calculate_chunk_checksum(chunk)
     Tag.serialize(self, *args, **kwargs)
Пример #9
0
 def parse(self, *args, **kwargs):
     Tag.parse(self, *args, **kwargs)
     try:
         self._orig_tag_count = len(self.data.tags)
     except Exception:
         self._orig_tag_count = 0
Пример #10
0
 def __init__(self, **kwargs):
     self.calc_pointers = False
     Tag.__init__(self, **kwargs)