Ejemplo n.º 1
0
def dump(path):
    for path in args.paths:
        for filename in glob(path): #$'/Users/remco/Downloads/documents-export-2014-05-13/NOCD.SI'):
            with open(filename, 'rb') as f:
                logger.info ("Dumping {0}.".format(filename))

                riff = RIFF(f)
                for subchunk in riff.subchunks():
                    logger.info (subchunk)
Ejemplo n.º 2
0
def dump(path):
    for path in args.paths:
        for filename in glob(
                path
        ):  #$'/Users/remco/Downloads/documents-export-2014-05-13/NOCD.SI'):
            with open(filename, 'rb') as f:
                logger.info("Dumping {0}.".format(filename))

                riff = RIFF(f)
                for subchunk in riff.subchunks():
                    logger.info(subchunk)
Ejemplo n.º 3
0
def extract(path, dest):
    for path in args.paths:
        for filename in glob(
                path
        ):  #$'/Users/remco/Downloads/documents-export-2014-05-13/NOCD.SI'):
            # extract
            import os
            with open(filename, 'rb') as f:
                logger.info("Extracting {0}.".format(filename))
                try:
                    os.mkdir(os.path.join(dest, os.path.basename(filename)))
                except OSError as exc:
                    pass

                riff = RIFF(f)

                d = {}
                d2 = {}

                subchunk_iter = riff.subchunks()
                for subchunk in subchunk_iter:
                    #logger.info (subchunk)
                    if isinstance(subchunk, MxOb):
                        d[subchunk.id] = subchunk

                    if isinstance(subchunk, MxCh):
                        if not subchunk.id in d2:
                            d2[subchunk.id] = []
                        d2[subchunk.id].append(subchunk)

                for b in d.keys():
                    print(b)
                    mxob = d[b]
                    print(mxob)
                    if mxob.s1 == 4:
                        #wav
                        x = d2[b][0]

                        # portions thanks to LIME
                        try:
                            import binascii
                            #logger.info(binascii.hexlify(x.data[0:40]))
                            #logger.info(binascii.hexlify(x.data[18:20]))
                            data = StringIO(x.data[14:])
                            data.read(4)
                            bitrate1 = struct.unpack('<H', data.read(2))[0]
                            data.read(2)
                            bitrate2 = struct.unpack('<H', data.read(2))[0]
                            data.read(2)
                            idk = struct.unpack('<H', data.read(2))[0]
                            bits = struct.unpack('<H', data.read(2))[0]
                            logger.info(
                                "Audio format might be %dHz or %dHz, with %d bits\n"
                                % (bitrate1, bitrate2, bits))
                        except Exception as exc:
                            logger.error(exc)

                        import os
                        logger.info("Exporting wav to " + os.path.join(
                            dest, os.path.basename(filename), "{0}_{1}.wav".
                            format(str(mxob.id), os.path.basename(mxob.s3))))

                        import wave
                        w = wave.open(
                            os.path.join(
                                dest, os.path.basename(filename),
                                "{0}_{1}.wav".format(str(mxob.id),
                                                     os.path.basename(
                                                         mxob.s3))), 'wb')
                        w.setnchannels(1)
                        w.setframerate(int(bitrate1))
                        w.setsampwidth(int(bits) / 8)

                        for x in d2[b][1:]:
                            w.writeframesraw(x.data[14:])

                        w.close()
                    elif mxob.s1 == 10:
                        #f.write("BM")
                        # bitmap meta data
                        x = d2[b][0]
                        """
                        000080020000c4000000010008000000000000ea0100130b0000130b00000000000000000000ff00ff0000008000008000000080800080000000800080008080000080808000
                        000080020000c4000000010008000000000000ea0100130b0000130b00000000000000000000ff00ff0000008000008000000080800080000000800080008080000080808000
                        00003900000013000000010008000000000074040000130b0000130b00000000000000000000ff00ff0000008000008000000080800080000000800080008080000080808000
                        """
                        data = StringIO(x.data[14:])

                        import binascii
                        print(binascii.hexlify(x.data[14:]))
                        # http://en.wikipedia.org/wiki/BMP_file_format
                        header_size = struct.unpack('<L', data.read(4))[0]
                        width = struct.unpack('<L', data.read(4))[0]
                        height = struct.unpack('<L', data.read(4))[0]
                        number_of_color_planes = struct.unpack(
                            '<H', data.read(2))[0]
                        number_of_bits_per_pixel = struct.unpack(
                            '<H', data.read(2))[0]
                        compression = struct.unpack('<L', data.read(4))[0]
                        image_size = struct.unpack('<L', data.read(4))[0]
                        hor_res = struct.unpack('<L', data.read(4))[0]
                        vert_res = struct.unpack('<L', data.read(4))[0]
                        colors_in_palette = struct.unpack('<L',
                                                          data.read(4))[0]
                        important_colors = struct.unpack('<L', data.read(4))[0]

                        logger.info(
                            "Header size {0} Width {1} Height {2} nofcp {3} nobpp {4} com {5} size {6} hor {7} vert {8} pal {9} impo {10}"
                            .format(header_size, width, height,
                                    number_of_color_planes,
                                    number_of_bits_per_pixel, image_size,
                                    compression, hor_res, vert_res,
                                    colors_in_palette, important_colors))

                        import os
                        logger.info("Exporting wav to " + os.path.join(
                            dest, os.path.basename(filename), "{0}_{1}.bmp".
                            format(str(mxob.id), os.path.basename(mxob.s3))))

                        import os
                        with open(
                                os.path.join(
                                    dest, os.path.basename(filename),
                                    "{0}_{1}.bmp".format(
                                        str(mxob.id),
                                        os.path.basename(mxob.s3))),
                                'wb') as f:
                            f.write(b'BM')
                            # size
                            f.write(b'\00\00\00\00')
                            f.write(b'\00\00')
                            f.write(b'\00\00')
                            f.write(struct.pack('<L', len(d2[b][0].data[14:])))
                            for x in d2[b]:
                                f.write(x.data[14:])
                    elif mxob.s1 == 4:
                        import os
                        x = d2[b][0]
                        data = StringIO(x.data[14:])
                        with open(
                                os.path.join(
                                    dest, os.path.basename(filename),
                                    "{0}_{1}.unknown".format(
                                        str(mxob.id),
                                        os.path.basename(mxob.s3))),
                                'wb') as f:
                            for x in d2[b]:
                                f.write(x.data[14:])
                    elif mxob.s1 == 6:
                        import os
                        x = d2[b][0]
                        data = StringIO(x.data[14:])
                        with open(
                                os.path.join(
                                    dest, os.path.basename(filename),
                                    "{0}_{1}.unknown".format(
                                        str(mxob.id),
                                        os.path.basename(mxob.s3))),
                                'wb') as f:
                            for x in d2[b]:
                                f.write(x.data[14:])
                        pass
                    elif mxob.s1 == 8:
                        import os
                        x = d2[b][0]
                        data = StringIO(x.data[14:])
                        with open(
                                os.path.join(
                                    dest, os.path.basename(filename),
                                    "{0}_{1}.unknown".format(
                                        str(mxob.id),
                                        os.path.basename(mxob.s3))),
                                'wb') as f:
                            for x in d2[b]:
                                f.write(x.data[14:])
                        pass
                    elif mxob.s1 == 7:
                        pass
                    elif mxob.s1 == 11:
                        import os
                        x = d2[b][0]
                        data = StringIO(x.data[14:])
                        with open(
                                os.path.join(
                                    dest, os.path.basename(filename),
                                    "{0}_{1}.unknown".format(
                                        str(mxob.id),
                                        os.path.basename(mxob.s3))),
                                'wb') as f:
                            for x in d2[b]:
                                f.write(x.data[14:])
                        pass
                    else:
                        import os
                        x = d2[b][0]
                        data = StringIO(x.data[14:])
                        with open(
                                os.path.join(
                                    dest, os.path.basename(filename),
                                    "{0}_{1}.unknown".format(
                                        str(mxob.id),
                                        os.path.basename(mxob.s3))),
                                'wb') as f:
                            for x in d2[b]:
                                f.write(x.data[14:])
                        pass

                print("<<<<", str(mxob))
Ejemplo n.º 4
0
def extract(path, dest):
    for path in args.paths:
        for filename in glob(path): #$'/Users/remco/Downloads/documents-export-2014-05-13/NOCD.SI'):
            # extract
            import os
            with open(filename, 'rb') as f:
                logger.info ("Extracting {0}.".format(filename))
                try:
                    os.mkdir(os.path.join(dest, os.path.basename(filename)))
                except OSError as exc:
                    pass

                riff = RIFF(f)

                d = {}
                d2 = {}

                subchunk_iter = riff.subchunks()
                for subchunk in subchunk_iter:
                    #logger.info (subchunk)
                    if isinstance(subchunk, MxOb):
                        d[subchunk.id]=subchunk

                    if isinstance(subchunk, MxCh):
                        if not subchunk.id in d2:
                            d2[subchunk.id] = []
                        d2[subchunk.id].append(subchunk)

                for b in d.keys():
                    print (b)
                    mxob = d[b] 
                    print (mxob)
                    if mxob.s1==4:
                        #wav
                        x = d2[b][0]

                        # portions thanks to LIME
                        try:
                            import binascii
                            #logger.info(binascii.hexlify(x.data[0:40]))
                            #logger.info(binascii.hexlify(x.data[18:20]))
                            data = StringIO(x.data[14:])
                            data.read(4)
                            bitrate1 = struct.unpack('<H', data.read(2))[0]
                            data.read(2)
                            bitrate2 = struct.unpack('<H', data.read(2))[0]
                            data.read(2)
                            idk = struct.unpack('<H', data.read(2))[0]
                            bits = struct.unpack('<H', data.read(2))[0]
                            logger.info ("Audio format might be %dHz or %dHz, with %d bits\n" % ( bitrate1, bitrate2, bits))
                        except Exception as exc:
                            logger.error(exc)
                        
                        import os
                        logger.info("Exporting wav to " + os.path.join(dest, os.path.basename(filename), "{0}_{1}.wav".format(str(mxob.id), os.path.basename(mxob.s3))))

                        import wave
                        w = wave.open(os.path.join(dest, os.path.basename(filename), "{0}_{1}.wav".format(str(mxob.id), os.path.basename(mxob.s3))), 'wb')
                        w.setnchannels(1)
                        w.setframerate(int(bitrate1))
                        w.setsampwidth(int(bits) / 8)

                        for x in d2[b][1:]:
                            w.writeframesraw(x.data[14:])

                        w.close()
                    elif mxob.s1==10:
                        #f.write("BM")
                        # bitmap meta data
                        x = d2[b][0]
                        """
                        000080020000c4000000010008000000000000ea0100130b0000130b00000000000000000000ff00ff0000008000008000000080800080000000800080008080000080808000
                        000080020000c4000000010008000000000000ea0100130b0000130b00000000000000000000ff00ff0000008000008000000080800080000000800080008080000080808000
                        00003900000013000000010008000000000074040000130b0000130b00000000000000000000ff00ff0000008000008000000080800080000000800080008080000080808000
                        """
                        data = StringIO(x.data[14:])

                        import binascii
                        print (binascii.hexlify(x.data[14:]))
                        # http://en.wikipedia.org/wiki/BMP_file_format
                        header_size = struct.unpack('<L', data.read(4))[0]
                        width = struct.unpack('<L', data.read(4))[0]
                        height = struct.unpack('<L', data.read(4))[0]
                        number_of_color_planes = struct.unpack('<H', data.read(2))[0]
                        number_of_bits_per_pixel = struct.unpack('<H', data.read(2))[0]
                        compression = struct.unpack('<L', data.read(4))[0]
                        image_size = struct.unpack('<L', data.read(4))[0]
                        hor_res = struct.unpack('<L', data.read(4))[0]
                        vert_res = struct.unpack('<L', data.read(4))[0]
                        colors_in_palette = struct.unpack('<L', data.read(4))[0]
                        important_colors = struct.unpack('<L', data.read(4))[0]

                        logger.info ("Header size {0} Width {1} Height {2} nofcp {3} nobpp {4} com {5} size {6} hor {7} vert {8} pal {9} impo {10}"
                                    .format(header_size, width, height, number_of_color_planes, number_of_bits_per_pixel, image_size, compression, hor_res, vert_res, colors_in_palette, important_colors))

                        import os
                        logger.info("Exporting wav to " + os.path.join(dest, os.path.basename(filename), "{0}_{1}.bmp".format(str(mxob.id), os.path.basename(mxob.s3))))

                        import os
                        with open(os.path.join(dest, os.path.basename(filename), "{0}_{1}.bmp".format(str(mxob.id), os.path.basename(mxob.s3))), 'wb') as f:
                            f.write(b'BM')
                            # size
                            f.write(b'\00\00\00\00')
                            f.write(b'\00\00')
                            f.write(b'\00\00')
                            f.write(struct.pack('<L', len(d2[b][0].data[14:])))
                            for x in d2[b]:
                                f.write(x.data[14:])
                    elif mxob.s1==4:
                        import os
                        x = d2[b][0]
                        data = StringIO(x.data[14:])
                        with open(os.path.join(dest, os.path.basename(filename), "{0}_{1}.unknown".format(str(mxob.id), os.path.basename(mxob.s3))), 'wb') as f:
                            for x in d2[b]:
                                f.write(x.data[14:])
                    elif mxob.s1==6:
                        import os
                        x = d2[b][0]
                        data = StringIO(x.data[14:])
                        with open(os.path.join(dest, os.path.basename(filename), "{0}_{1}.unknown".format(str(mxob.id), os.path.basename(mxob.s3))), 'wb') as f:
                            for x in d2[b]:
                                f.write(x.data[14:])
                        pass
                    elif mxob.s1==8:
                        import os
                        x = d2[b][0]
                        data = StringIO(x.data[14:])
                        with open(os.path.join(dest, os.path.basename(filename), "{0}_{1}.unknown".format(str(mxob.id), os.path.basename(mxob.s3))), 'wb') as f:
                            for x in d2[b]:
                                f.write(x.data[14:])
                        pass
                    elif mxob.s1==7:
                        pass
                    elif mxob.s1==11:
                        import os
                        x = d2[b][0]
                        data = StringIO(x.data[14:])
                        with open(os.path.join(dest, os.path.basename(filename), "{0}_{1}.unknown".format(str(mxob.id), os.path.basename(mxob.s3))), 'wb') as f:
                            for x in d2[b]:
                                f.write(x.data[14:])
                        pass
                    else:
                        import os
                        x = d2[b][0]
                        data = StringIO(x.data[14:])
                        with open(os.path.join(dest, os.path.basename(filename), "{0}_{1}.unknown".format(str(mxob.id), os.path.basename(mxob.s3))), 'wb') as f:
                            for x in d2[b]:
                                f.write(x.data[14:])
                        pass

                print ("<<<<", str(mxob))