Beispiel #1
0
def _decode_type_tool_object_setting(data):
    fp = io.BytesIO(data)
    ver, xx, xy, yx, yy, tx, ty, txt_ver, descr1_ver = read_fmt("H 6d H I", fp)

    # This decoder needs to be updated if we have new formats.
    if ver != 1 or txt_ver != 50 or descr1_ver != 16:
        warnings.warn("Ignoring type setting tagged block due to old versions")
        return data

    try:
        text_data = decode_descriptor(None, fp)
    except UnknownOSType as e:
        warnings.warn("Ignoring type setting tagged block (%s)" % e)
        return data

    warp_ver, descr2_ver = read_fmt("H I", fp)
    if warp_ver != 1 or descr2_ver != 16:
        warnings.warn("Ignoring type setting tagged block due to old versions")
        return data

    try:
        warp_data = decode_descriptor(None, fp)
    except UnknownOSType as e:
        warnings.warn("Ignoring type setting tagged block (%s)" % e)
        return data

    left, top, right, bottom = read_fmt("4i", fp)   # wrong info in specs...
    return TypeToolObjectSetting(
        ver, xx, xy, yx, yy, tx, ty, txt_ver, descr1_ver, text_data,
        warp_ver, descr2_ver, warp_data, left, top, right, bottom
    )
Beispiel #2
0
def _decode_type_tool_object_setting(data):
    fp = io.BytesIO(data)
    ver, xx, xy, yx, yy, tx, ty, txt_ver, desc_ver1 = read_fmt("H 6Q H I", fp)

    # This decoder needs to be updated if we have new formats.
    if ver != 1 or txt_ver != 50 or desc_ver1 != 16:
        warnings.warn("Ignoring type setting tagged block due to old versions")
        return data

    try:
        text_data = decode_descriptor(None, fp)
    except UnknownOSType as e:
        warnings.warn("Ignoring type setting tagged block (%s)" % e)
        return data

    # XXX: Until Engine Data is parsed properly, the following cannot be parsed.
    # The end of the engine data dictates where this starts.
    return TypeToolObjectSetting(ver, xx, xy, yx, yy, tx, ty, txt_ver,
                                 desc_ver1, text_data)

    warp_ver, desc_ver2 = read_fmt("H I", fp)
    if warp_ver != 1 or desc_ver2 != 16:
        warnings.warn("Ignoring type setting tagged block due to old versions")
        return

    try:
        warp_data = decode_descriptor(None, fp)
    except UnknownOSType as e:
        warnings.warn("Ignoring type setting tagged block (%s)" % e)
        return

    left, top, right, bottom = read_fmt("4Q", fp)
    return TypeToolObjectSetting(ver, xx, xy, yx, yy, tx, ty, txt_ver,
                                 desc_ver1, text_data, warp_ver, desc_ver2,
                                 warp_data, left, top, right, bottom)
Beispiel #3
0
def _decode_type_tool_object_setting(data):
    fp = io.BytesIO(data)
    ver, xx, xy, yx, yy, tx, ty, txt_ver, desc_ver1 = read_fmt("H 6Q H I", fp)

    # This decoder needs to be updated if we have new formats.
    if ver != 1 or txt_ver != 50 or desc_ver1 != 16:
        warnings.warn("Ignoring type setting tagged block due to old versions")
        return

    try:
        text_data = decode_descriptor(None, fp)
    except UnknownOSType as e:
        warnings.warn("Ignoring type setting tagged block (%s)" % e)
        return

    # XXX: Until Engine Data is parsed properly, the following cannot be parsed.
    # The end of the engine data dictates where this starts.
    return TypeToolObjectSetting(ver, xx, xy, yx, yy, tx, ty, txt_ver, desc_ver1, text_data)

    warp_ver, desc_ver2 = read_fmt("H I", fp)
    if warp_ver != 1 or desc_ver2 != 16:
        warnings.warn("Ignoring type setting tagged block due to old versions")
        return

    try:
        warp_data = decode_descriptor(None, fp)
    except UnknownOSType as e:
        warnings.warn("Ignoring type setting tagged block (%s)" % e)
        return

    left, top, right, bottom = read_fmt("4Q", fp)
    return TypeToolObjectSetting(ver, xx, xy, yx, yy, tx, ty, txt_ver, desc_ver1,
                                 text_data, warp_ver, desc_ver2, warp_data,
                                 left, top, right, bottom)
Beispiel #4
0
def _decode_type_tool_object_setting(data):
    fp = io.BytesIO(data)
    ver, xx, xy, yx, yy, tx, ty, txt_ver, descr1_ver = read_fmt("H 6d H I", fp)

    # This decoder needs to be updated if we have new formats.
    if ver != 1 or txt_ver != 50 or descr1_ver != 16:
        warnings.warn("Ignoring type setting tagged block due to old versions")
        return data

    try:
        text_data = decode_descriptor(None, fp)
    except UnknownOSType as e:
        warnings.warn("Ignoring type setting tagged block (%s)" % e)
        return data

    warp_ver, descr2_ver = read_fmt("H I", fp)
    if warp_ver != 1 or descr2_ver != 16:
        warnings.warn("Ignoring type setting tagged block due to old versions")
        return data

    try:
        warp_data = decode_descriptor(None, fp)
    except UnknownOSType as e:
        warnings.warn("Ignoring type setting tagged block (%s)" % e)
        return data

    left, top, right, bottom = read_fmt("4i", fp)   # wrong info in specs...
    return TypeToolObjectSetting(
        ver, xx, xy, yx, yy, tx, ty, txt_ver, descr1_ver, text_data,
        warp_ver, descr2_ver, warp_data, left, top, right, bottom
    )
Beispiel #5
0
def _decode_metadata(data):
    fp = io.BytesIO(data)
    items_count = read_fmt("I", fp)[0]
    items = []

    for x in range(items_count):
        sig = fp.read(4)
        if sig != b'8BIM':
            warnings.warn("Invalid signature in metadata item (%s)" % sig)

        key, copy_on_sheet, data_length = read_fmt("4s ? 3x I", fp)

        data = fp.read(data_length)
        if data_length < 4 + 12:
            # descr_version is 4 bytes, descriptor is at least 12 bytes,
            # so data can't be a descriptor.
            descr_ver = None
        else:
            # try load data as a descriptor
            fp2 = io.BytesIO(data)
            descr_ver = read_fmt("I", fp2)[0]
            try:
                data = decode_descriptor(None, fp2)
            except UnknownOSType as e:
                # FIXME: can it fail with other exceptions?
                descr_ver = None
                warnings.warn("Can't decode metadata item (%s)" % e)

        items.append(MetadataItem(key, copy_on_sheet, descr_ver, data))

    return items
Beispiel #6
0
def _decode_metadata(data):
    fp = io.BytesIO(data)
    items_count = read_fmt("I", fp)[0]
    items = []

    for x in range(items_count):
        sig = fp.read(4)
        if sig != b"8BIM":
            raise Error("Invalid signature in metadata item (%r)" % sig)

        key, copy_on_sheet, data_length = read_fmt("4s ? 3x I", fp)

        data = fp.read(data_length)
        if data_length < 4 + 12:
            # descr_version is 4 bytes, descriptor is at least 12 bytes,
            # so data can't be a descriptor.
            descr_ver = None
        else:
            # try load data as a descriptor
            fp2 = io.BytesIO(data)
            descr_ver = read_fmt("I", fp2)[0]
            try:
                data = decode_descriptor(None, fp2)
            except UnknownOSType as e:
                # FIXME: can it fail with other exceptions?
                descr_ver = None
                warnings.warn("Can't decode metadata item (%s)" % e)

        items.append(MetadataItem(key, copy_on_sheet, descr_ver, data))

    return items
Beispiel #7
0
def _decode_soco(data):
    fp = io.BytesIO(data)
    version = read_fmt("I", fp)
    try:
        data = decode_descriptor(None, fp)
        return SolidColorSettings(version, data)
    except UnknownOSType as e:
        warnings.warn("Ignoring solid color tagged block (%s)" % e)
Beispiel #8
0
def _decode_soco(data):
    fp = io.BytesIO(data)
    version = read_fmt("I", fp)
    try:
        data = decode_descriptor(None, fp)
        return SolidColorSettings(version, data)
    except UnknownOSType as e:
        warnings.warn("Ignoring solid color tagged block (%s)" % e)
Beispiel #9
0
def _decode_layer_comps(data):
    fp = io.BytesIO(data)
    version = read_fmt("I", fp)[0]

    try:
        return LayerComps(version, decode_descriptor(None, fp))
    except UnknownOSType as e:
        warnings.warn("Ignoring image resource %s" % e)
        return data
Beispiel #10
0
def _decode_layer_comps(data):
    fp = io.BytesIO(data)
    version = read_fmt("I", fp)[0]

    try:
        return LayerComps(version, decode_descriptor(None, fp))
    except UnknownOSType as e:
        warnings.warn("Ignoring image resource %s" % e)
        return data
Beispiel #11
0
def _decode_path_selection_state(data):
    fp = io.BytesIO(data)
    version = read_fmt("I", fp)[0]

    try:
        return PathSelectionState(version, decode_descriptor(None, fp))
    except UnknownOSType as e:
        warnings.warn("Ignoring image resource %s" % e)
        return data
Beispiel #12
0
def _decode_extd(data, **kwargs):
    fp = io.BytesIO(data)
    version = read_fmt("I", fp)[0]
    try:
        data = decode_descriptor(None, fp)
        return ExportData(version, data)
    except UnknownOSType as e:
        warnings.warn("Ignoring extd tagged block (%s)" % e)
        return data
Beispiel #13
0
def _decode_path_selection_state(data):
    fp = io.BytesIO(data)
    version = read_fmt("I", fp)[0]

    try:
        return PathSelectionState(version, decode_descriptor(None, fp))
    except UnknownOSType as e:
        warnings.warn("Ignoring image resource %s" % e)
        return data
Beispiel #14
0
def _decode_color_lookup(data, **kwargs):
    fp = io.BytesIO(data)
    version, descriptor_version = read_fmt("H I", fp)

    try:
        return ColorLookup(version, descriptor_version,
                           decode_descriptor(None, fp))
    except UnknownOSType as e:
        warnings.warn("Ignoring tagged block %s" % e)
        return data
Beispiel #15
0
def _decode_descriptor_resource(data, kls):
    if isinstance(data, bytes):
        fp = io.BytesIO(data)
    version = read_fmt("I", fp)[0]

    try:
        return kls(version, decode_descriptor(None, fp))
    except UnknownOSType as e:
        warnings.warn("Ignoring image resource %s" % e)
        return data
Beispiel #16
0
def _decode_descriptor_block(data, kls):
    if len(data) == 0:
        warnings.warn("Empty descriptor")
        return data
    try:
        fp = io.BytesIO(data)
        version = read_fmt("I", fp)[0]
        return kls(version, decode_descriptor(None, fp))
    except UnknownOSType as e:
        warnings.warn("Ignoring tagged block %s" % e)
        return data
Beispiel #17
0
def _decode_type_tool_object_setting(data, **kwargs):
    fp = io.BytesIO(data)
    ver, xx, xy, yx, yy, tx, ty, txt_ver, descr1_ver = read_fmt(
        "H 6d H I", fp)

    # This decoder needs to be updated if we have new formats.
    if ver != 1 or txt_ver != 50 or descr1_ver != 16:
        warnings.warn(
            "Ignoring type setting tagged block due to old versions")
        return data

    try:
        text_data = decode_descriptor(None, fp)
    except UnknownOSType as e:
        warnings.warn("Ignoring type setting tagged block (%s)" % e)
        return data

    # Decode EngineData here.
    for index in range(len(text_data.items)):
        item = text_data.items[index]
        if item[0] == b'EngineData':
            text_data.items[index] = (
                b'EngineData', engine_data.decode(item[1].value))

    warp_ver, descr2_ver = read_fmt("H I", fp)
    if warp_ver != 1 or descr2_ver != 16:
        warnings.warn(
            "Ignoring type setting tagged block due to old versions")
        return data

    try:
        warp_data = decode_descriptor(None, fp)
    except UnknownOSType as e:
        warnings.warn("Ignoring type setting tagged block (%s)" % e)
        return data

    left, top, right, bottom = read_fmt("4i", fp)   # wrong info in specs...
    return TypeToolObjectSetting(
        ver, xx, xy, yx, yy, tx, ty, txt_ver, descr1_ver, text_data,
        warp_ver, descr2_ver, warp_data, left, top, right, bottom
    )
Beispiel #18
0
def _decode_type_tool_object_setting(data):
    fp = io.BytesIO(data)
    ver, xx, xy, yx, yy, tx, ty, txt_ver, descr1_ver = read_fmt("H 6d H I", fp)

    # This decoder needs to be updated if we have new formats.
    if ver != 1 or txt_ver != 50 or descr1_ver != 16:
        warnings.warn("Ignoring type setting tagged block due to old versions")
        return data

    try:
        #print("new type tool")
        text_data = decode_descriptor(None, fp)
        # check for engineData
        list = text_data.items
        #for i in range(len(list)):
        #if list[i][0] == OSType.ENGINE_DATA:
        #list[i][1] = paresr(list[i][1].value)
        #print (list[i][1])
        #print("text_data",text_data.items)
    except UnknownOSType as e:
        warnings.warn("Ignoring type setting tagged block (%s)" % e)
        return data

    warp_ver, descr2_ver = read_fmt("H I", fp)
    if warp_ver != 1 or descr2_ver != 16:
        warnings.warn("Ignoring type setting tagged block due to old versions")
        return data

    try:
        warp_data = decode_descriptor(None, fp)

    except UnknownOSType as e:
        warnings.warn("Ignoring type setting tagged block (%s)" % e)
        return data

    left, top, right, bottom = read_fmt("4i", fp)  # wrong info in specs...
    return TypeToolObjectSetting(ver, xx, xy, yx, yy, tx, ty, txt_ver,
                                 descr1_ver, text_data, warp_ver, descr2_ver,
                                 warp_data, left, top, right, bottom)
Beispiel #19
0
def _decode_placed_layer(data, **kwargs):
    fp = io.BytesIO(data)
    type_, version = read_fmt("2I", fp)
    if version != 3:
        warnings.warn("Unsupported placed layer version %s" % (version))
        return data
    uuid = read_pascal_string(fp, "ascii")
    page, total_pages, anti_alias, layer_type = read_fmt("4I", fp)
    transformation = read_fmt("8d", fp)
    warp_version, warp_desc_version = read_fmt("2I", fp)
    descriptor = decode_descriptor(None, fp)
    warp = WarpInformation(warp_version, warp_desc_version, descriptor)
    return PlacedLayerObsolete(type_, version, uuid, page, total_pages,
                               anti_alias, layer_type, transformation, warp)
Beispiel #20
0
def decode_object_based(effects, **kwargs):
    """
    Reads and decodes info about object-based layer effects.
    """
    fp = io.BytesIO(effects)

    version, descriptor_version = read_fmt("II", fp)
    try:
        descriptor = decode_descriptor(None, fp)
    except UnknownOSType as e:
        warnings.warn("Ignoring object-based layer effects tagged block (%s)" % e)
        return effects

    return ObjectBasedEffects(version, descriptor_version, descriptor)
Beispiel #21
0
def decode_object_based(effects):
    """
    Reads and decodes info about object-based layer effects.
    """
    fp = io.BytesIO(effects)

    version, descriptor_version = read_fmt("II", fp)
    try:
        descriptor = decode_descriptor(None, fp)
    except UnknownOSType as e:
        warnings.warn("Ignoring object-based layer effects tagged block (%s)" % e)
        return effects

    return ObjectBasedEffects(version, descriptor_version, descriptor)
Beispiel #22
0
def _decode_vector_stroke_data(data, **kwargs):
    fp = io.BytesIO(data)
    version = read_fmt("I", fp)[0]

    if version != 16:
        warnings.warn("Invalid vstk version %s" % (version))
        return data

    try:
        data = decode_descriptor(None, fp)
        return VectorStrokeSetting(version, data)
    except UnknownOSType as e:
        warnings.warn("Ignoring vstk tagged block (%s)" % e)
        return data
Beispiel #23
0
def decode(data):
    """
    Reads and decodes info about linked layers.

    These are embedded files (embedded smart objects). But Adobe calls
    them "linked layers", so we'll follow that nomenclature. Note that
    non-embedded smart objects are not included here.
    """
    fp = io.BytesIO(data)
    layers = []
    while True:
        start = fp.tell()
        length_buf = fp.read(8)
        if not length_buf:
            break   # end of file
        length = struct.unpack(str('>Q'), length_buf)[0]
        liFD, version = read_fmt('4s I', fp)
        if liFD != b'liFD':
            warnings.warn('unknown layer type')
            break
        unique_id = read_pascal_string(fp, 'ascii')
        filename = read_unicode_string(fp)
        filetype, creator, filelength, have_file_open_descriptor = read_fmt('4s 4s Q B', fp)
        filetype = str(filetype)
        if have_file_open_descriptor:
            # Does not seem to contain any useful information
            undocumented_integer = read_fmt("I", fp)
            file_open_descriptor = decode_descriptor(None, fp)
        else:
            file_open_descriptor = None
        decoded = fp.read(filelength)
        # Undocumented extra field
        if version == 5:
            uuid = read_unicode_string(fp)
        else:
            uuid = None
        layers.append(
            LinkedLayer(version, unique_id, filename, filetype, file_open_descriptor,
                        creator, decoded, uuid)
        )
        # Gobble up anything that we don't know how to decode
        expected_position = start + 8 + length      # first 8 bytes contained the length
        if expected_position != fp.tell():
            warnings.warn('skipping over undocumented additional fields')
            fp.read(expected_position - fp.tell())
        # Each layer is padded to start and end at 4-byte boundary
        pad = -fp.tell() % 4
        fp.read(pad)
    return LinkedLayerCollection(layers)
Beispiel #24
0
def decode(data):
    """
    Reads and decodes info about linked layers.

    These are embedded files (embedded smart objects). But Adobe calls
    them "linked layers", so we'll follow that nomenclature. Note that
    non-embedded smart objects are not included here.
    """
    fp = io.BytesIO(data)
    layers = []
    while True:
        start = fp.tell()
        length_buf = fp.read(8)
        if not length_buf:
            break  # end of file
        length = struct.unpack(str('>Q'), length_buf)[0]
        liFD, version = read_fmt('4s I', fp)
        if liFD != b'liFD':
            warnings.warn('unknown layer type')
            break
        unique_id = read_pascal_string(fp, 'ascii')
        filename = read_unicode_string(fp)
        filetype, creator, filelength, have_file_open_descriptor = read_fmt(
            '4s 4s Q B', fp)
        filetype = str(filetype)
        if have_file_open_descriptor:
            # Does not seem to contain any useful information
            undocumented_integer = read_fmt("I", fp)
            file_open_descriptor = decode_descriptor(None, fp)
        else:
            file_open_descriptor = None
        decoded = fp.read(filelength)
        # Undocumented extra field
        if version == 5:
            uuid = read_unicode_string(fp)
        else:
            uuid = None
        layers.append(
            LinkedLayer(version, unique_id, filename, filetype,
                        file_open_descriptor, creator, decoded, uuid))
        # Gobble up anything that we don't know how to decode
        expected_position = start + 8 + length  # first 8 bytes contained the length
        if expected_position != fp.tell():
            warnings.warn('skipping over undocumented additional fields')
            fp.read(expected_position - fp.tell())
        # Each layer is padded to start and end at 4-byte boundary
        pad = -fp.tell() % 4
        fp.read(pad)
    return LinkedLayerCollection(layers)
Beispiel #25
0
def _decode_vector_origination_data(data, **kwargs):
    fp = io.BytesIO(data)
    ver, descr_ver = read_fmt("II", fp)

    if ver != 1 and descr_ver != 16:
        warnings.warn("Invalid vmsk version %s %s" % (ver, descr_ver))
        return data

    try:
        vector_origination_data = decode_descriptor(None, fp)
    except UnknownOSType as e:
        warnings.warn("Ignoring vector origination tagged block (%s)" % e)
        return data

    return VectorOriginationData(ver, descr_ver, vector_origination_data)
Beispiel #26
0
def _decode_vector_stroke_content_data(data, **kwargs):
    fp = io.BytesIO(data)
    key, version = read_fmt("II", fp)

    if version != 16:
        warnings.warn("Invalid vscg version %s" % (version))
        return data

    try:
        descriptor = decode_descriptor(None, fp)
    except UnknownOSType as e:
        warnings.warn("Ignoring vscg tagged block (%s)" % e)
        return data

    return VectorStrokeContentSetting(key, version, descriptor)
Beispiel #27
0
def _decode_vector_origination_data(data):
    fp = io.BytesIO(data)
    ver, descr_ver = read_fmt("II", fp)

    # This decoder needs to be updated if we have new formats.
    if ver != 1 and descr_ver != 16:
        warnings.warn("Ignoring vector origination tagged block due to unsupported versions %s %s" % (ver, descr_ver))
        return data

    try:
        vector_origination_data = decode_descriptor(None, fp)
    except UnknownOSType as e:
        warnings.warn("Ignoring vector origination tagged block (%s)" % e)
        return data

    return VectorOriginationData(ver, descr_ver, vector_origination_data)
Beispiel #28
0
def _decode_vector_origination_data(data):
    fp = io.BytesIO(data)
    ver, descr_ver = read_fmt("II", fp)

    # This decoder needs to be updated if we have new formats.
    if ver != 1 and descr_ver != 16:
        warnings.warn("Ignoring vector origination tagged block due to unsupported versions %s %s" % (ver, descr_ver))
        return data

    try:
        vector_origination_data = decode_descriptor(None, fp)
    except UnknownOSType as e:
        warnings.warn("Ignoring vector origination tagged block (%s)" % e)
        return data

    return VectorOriginationData(ver, descr_ver, vector_origination_data)
Beispiel #29
0
def _decode_timeline(data):
    fp = io.BytesIO(data)
    version = read_fmt("I", fp)[0]
    return decode_descriptor(None, fp)
Beispiel #30
0
def _decode_placed_layer(data):
    fp = io.BytesIO(data)
    type, version, descriptorVersion = read_fmt("4s I I", fp)
    descriptor = decode_descriptor(None, fp)
    return descriptor.items
Beispiel #31
0
def _decode_soco(data):
    fp = io.BytesIO(data)
    version = read_fmt("I", fp)
    data = decode_descriptor(fp.read())
    return SolidColorSettings(version, data)
Beispiel #32
0
def _decode_placed_layer(data):
    fp = io.BytesIO(data)
    type, version, descriptorVersion = read_fmt("4s I I", fp)
    descriptor = decode_descriptor(None, fp)
    return descriptor.items