Exemplo n.º 1
0
def parse_experiment(file_name):
    experiment_data = session.read_artifact(file_name, binary=True)
    experiment_data = ensure_string(experiment_data)

    cut = 0
    result = [[]]
    while len(result[0]) == 0:
        result = ExperimentFileParser.parse_partial(experiment_data)
        experiment_data = experiment_data[1:]
        cut += 1

    (basename, _) = path.splitext(file_name)

    with session.open_artifact(basename + '.txt', 'w') as output:
        for p in result[0]:
            pprint(p, output)

    unparsed_bytes = result[1]

    if len(unparsed_bytes) > 0:
        logging.warning(
            'Unparsed bytes in experiment file {} ({} bytes)'.format(
                file_name, len(unparsed_bytes)))
        session.write_artifact(basename + '.unparsed',
                               content=result[1],
                               binary=True)

    logging.info("Parsed experiment file {}: Result entries: {}".format(
        file_name, len(result[0])))
Exemplo n.º 2
0
def decode_photo(file_name, output_file_name=None):
    (basename, _) = path.splitext(file_name)
    jpg_file_name = output_file_name or (basename + '.jpg')

    with session.open_artifact(file_name, 'rb') as raw_file:
        with open(session.expand_artifact_path(jpg_file_name), 'wb') as jpg_file:
            raw_file.seek(4, SEEK_SET)
            
            while True:
                chunk = raw_file.read(512)
                if chunk == '':
                    break

                jpg_file.write(chunk[0:512 - 6])
Exemplo n.º 3
0
def save_memory_files():
    memory_frames = only_type(session.all_frames, response_frames.MemoryContent
                              )  # type: List[response_frames.MemoryContent]

    packs = defaultdict(list)

    for frame in memory_frames:
        packs[frame.correlation_id].append(frame)

    for cid in packs.keys():
        chunks = sorted(packs[cid], key=lambda f: f.seq())
        chunks = unique_seqs(chunks)

        with session.open_artifact('memory_content_{}'.format(cid), 'wb') as f:
            for c in chunks:
                f.write(ensure_string(c.content))
Exemplo n.º 4
0
def write_file_from_description(file_path, description):
    missing_chunk_ids = description['MissingChunks']
    error_chunk_ids = description['ErrorChunks']
    downloaded_chunks = description['ChunkFrames']

    missing_file_name = file_path + '.missing'

    if len(missing_chunk_ids) > 0:
        session.write_artifact(missing_file_name,
                               ', '.join(map(str, missing_chunk_ids)))
    else:
        if session.has_artifact(missing_file_name):
            logging.warning(
                'Removing obsolete missing file {}'.format(missing_file_name))
            session.remove_artifact(missing_file_name)

    if len(error_chunk_ids) > 0:
        session.write_artifact(file_path + '.error',
                               ', '.join(map(str, error_chunk_ids)))

    (base_name, ext) = path.splitext(file_path)

    is_jpg = ext == '.jpg'

    if is_jpg:
        jpg_file_name = base_name + '.jpg'
        file_path = base_name + '.raw'
    else:
        jpg_file_name = None

    with session.open_artifact(file_path, 'wb') as f:
        for chunk in downloaded_chunks:
            f.write(ensure_string(chunk.response))

    if is_jpg:
        just_responses = []

        for f in description['ChunkFrames']:
            just_responses.append(f.response)

        RemoteFileTools.save_photo(session.expand_artifact_path(jpg_file_name),
                                   just_responses)
Exemplo n.º 5
0
def save_frames_list():
    with session.open_artifact('downlink_frames.txt', 'w') as f:
        for frame in session.all_frames:
            pprint(frame, f)
Exemplo n.º 6
0
def dump_scrubbing_status(correlation_id):
    file_name = 'memory_content_{}'.format(correlation_id)
    out_file_name = 'scrubbing_{}.txt'.format(correlation_id)

    def dump_program(scrubber_offset, output):
        (offset, count,
         corrected) = unpack_binary_file(file_name,
                                         '<LLL',
                                         from_byte=scrubber_offset + 16)
        (time_counter, ) = unpack_binary_file(file_name,
                                              '<Q',
                                              from_byte=scrubber_offset - 16)

        output.write('\tOffset: {}\n'.format(offset))
        output.write('\tCount: {}\n'.format(count))
        output.write('\tCorrected: {}\n'.format(corrected))
        output.write('\tTime counter: {}ms\n'.format(time_counter))

    def dump_bootloader(output):
        (count, copies,
         mcu) = unpack_binary_file(file_name,
                                   '<LLL',
                                   from_byte=BOOTLOADER_SCRUBBER + 12)
        (time_counter, ) = unpack_binary_file(
            file_name, '<Q', from_byte=BOOTLOADER_SCRUBBER_COUNTER)
        output.write('Bootloader scrubbing:\n')
        output.write('\tIterations count: {}\n'.format(count))
        output.write('\tCopies corrected: {}\n'.format(copies))
        output.write('\tMCU pages corrected: {}\n'.format(mcu))
        output.write('\tTime counter: {}ms\n'.format(time_counter))

    def dump_safe_mode(output):
        (count, copies,
         eeprom) = unpack_binary_file(file_name,
                                      '<LLL',
                                      from_byte=SAFE_MODE_SCRUBBER + 12)
        (time_counter, ) = unpack_binary_file(
            file_name, '<Q', from_byte=SAFE_MODE_SCRUBBER_COUNTER)
        output.write('Safe mode scrubbing:\n')
        output.write('\tIterations count: {}\n'.format(count))
        output.write('\tCopies corrected: {}\n'.format(copies))
        output.write('\tEEPROM pages corrected: {}\n'.format(eeprom))
        output.write('\tTime counter: {}ms\n'.format(time_counter))

    def dump_boot_settings(output):
        (time_counter, ) = unpack_binary_file(
            file_name, '<Q', from_byte=BOOT_SETTINGS_SCRUBBER_COUNTER)
        output.write('Boot settings scrubbing:\n')
        output.write('\tTime counter: {}ms\n'.format(time_counter))

    with session.open_artifact(out_file_name, 'w') as f:
        (iterations_count, ) = unpack_binary_file(file_name,
                                                  '<L',
                                                  from_byte=ITERATIONS_COUNT)
        f.write('Iterations count: {}\n'.format(iterations_count))

        f.write('\n')
        f.write('Primary slots scrubbing:\n')
        dump_program(PRIMARY_SLOTS_SCRUBBER, f)

        f.write('\n')
        f.write('Secondary slots scrubbing:\n')
        dump_program(SECONDARY_SLOTS_SCRUBBER, f)

        f.write('\n')
        dump_bootloader(f)

        f.write('\n')
        dump_safe_mode(f)

        f.write('\n')
        dump_boot_settings(f)