def main(): parser = YaffsParser.get_argparser() args = parser.parse_args() #read in and order all of the blocks, by reverse order of sequence number sorted_blocks = YaffsParser.extract_ordered_blocks(args.imagefile, args.chunksize, args.oobsize, args.blocksize, args.tag_offset) objects = YaffsParser.extract_objects(sorted_blocks) current_objects = [o for o in objects if not o.is_deleted] current_file_objects = [] for obj in current_objects: #check the object type from the first header chunk. if len(obj.versions) > 0 and obj.versions[0][0][1].obj_type == 1: current_file_objects.append(obj) print "object_id,name,time_diff,expected,actual" for obj in current_file_objects: missing = get_missing_chunks_by_version(obj) for expected, actual, time_diff, name in missing: if time_diff < 0: pass print "%d\t%s\t%s\t%d\t%d" % (obj.object_id, name, time_diff, expected, actual)
def main(): parser = YaffsParser.get_argparser() parser.add_argument("--fraction", help='The file size of the sampled file as a fraction of the original.', type=float, default=0.01, dest="sample_fraction") args = parser.parse_args() image_size = os.path.getsize(args.imagefile) #We use ceiling so that we always have at least one block to grab, even #if the fraction is 0.000000000001 total_num_blocks = image_size / (args.blocksize * (args.chunksize + args.oobsize)) num_blocks = math.ceil(total_num_blocks * args.sample_fraction) num_blocks = int(num_blocks) blocks = YaffsParser.extract_ordered_blocks(args.imagefile, args.chunksize, args.oobsize, args.blocksize, args.tag_offset) sampled_blocks = random.sample(blocks, num_blocks) root, ext = os.path.splitext(args.imagefile) outfile = "%s_sampled_%s%s" % (root, str(args.sample_fraction).replace('.', "d"), ext) print 'Outfile: %s' % outfile with open(args.imagefile, 'rb') as f: with open(outfile, 'wb') as out: for sblock in sampled_blocks: f.seek(sblock.chunk_pairs[0][1].offset) out.write(f.read((args.chunksize + args.oobsize) * args.blocksize))
def main(): parser = YaffsParser.get_argparser() args = parser.parse_args() #read in and order all of the blocks, by reverse order of sequence number sorted_blocks = YaffsParser.extract_ordered_blocks(args.imagefile, args.chunksize, args.oobsize, args.blocksize, args.tag_offset) objects = YaffsParser.extract_objects(sorted_blocks) current_objects = [o for o in objects if not o.is_deleted] current_file_objects = [] for obj in current_objects: #check the object type from the first header chunk. if len(obj.versions) > 0 and obj.versions[0][0][1].obj_type == 1: current_file_objects.append(obj) print "object_id,name,chunk_id,count" for obj in current_file_objects: count = 0 name = obj.versions[0][0][1].name for id in obj.chunkDict: if id == 0: continue if len(obj.chunkDict[id]) > 1: print "%d\t%s\t%d\t%d" % (obj.object_id, name, id, len(obj.chunkDict[id]))
def extract_files(image, filenames, chunksize, oobsize, blocksize, oob_tag_offset, versions): """ Extracts the most recent version of every file in the filenames list. """ blocks = YaffsParser.extract_ordered_blocks(image, chunksize, oobsize, blocksize, oob_tag_offset) objects = YaffsParser.extract_objects(blocks) destination = os.path.dirname(image) for name in filenames: extract_file(objects, name, destination, versions)
def main(): parser = YaffsParser.get_argparser() args = parser.parse_args() #read in and order all of the blocks sorted_blocks = YaffsParser.extract_ordered_blocks(args.imagefile, args.pagesize, args.oobsize, args.blocksize, tag_offset=args.tag_offset) missing_set = get_missing_block_numbers(sorted_blocks)
def main(): parser = YaffsParser.get_argparser() args = parser.parse_args() blocks = YaffsParser.extract_ordered_blocks(args.imagefile, args.chunksize, args.oobsize, args.blocksize, args.tag_offset) objects = YaffsParser.extract_objects(blocks) tuple_set = set() for object in objects: for version in object.versions: tuple_set.add((object.object_id, version[0][1].name)) for tuple in tuple_set: print tuple
def main(): parser = YaffsParser.get_argparser() args = parser.parse_args() print args.imagefile, args.chunksize, args.oobsize, args.blocksize, args.tag_offset print "Script started: ", datetime.datetime.now() print 'File size: ', os.path.getsize(args.imagefile) #read in and order all of the blocks, by reverse order of sequence number sorted_blocks = YaffsParser.extract_ordered_blocks(args.imagefile, args.chunksize, args.oobsize, args.blocksize, args.tag_offset) nonerased_blocks = [b for b in sorted_blocks if not b.is_erased] print '%d blocks' % len(sorted_blocks) print 'Sequence number range: %d -- %d' \ % (nonerased_blocks[-1].sequence_num, nonerased_blocks[0].sequence_num) print 'Found %d erased blocks.' % (len(sorted_blocks) - len(nonerased_blocks)) #This can happen if the phone is turned off while writing. print 'Found %d blocks with mismatched sequence numbers' \ % len([block for block in sorted_blocks if block.possible_parse_error]) missing_seq_nums = summarize_deleted_blocks.get_missing_block_numbers(sorted_blocks) objects = YaffsParser.extract_objects(sorted_blocks) print 'Found %d objects' % len(objects) print 'Found %d objects with a header.' % len([obj for obj in objects if 0 in obj.chunkDict]) print 'Found %d deleted objects.' % len([obj for obj in objects if obj.is_deleted]) recent_pairs = [] total_pairs_count = 0 for block in sorted_blocks: recent_pairs.extend([(tag, chunk) for tag, chunk in block.chunk_pairs if tag.is_most_recent]) total_pairs_count += len(block.chunk_pairs) print 'Number of Recent chunks: %d' % len(recent_pairs) print 'Total number of chunks: %d' % total_pairs_count print 'Fraction recent: %0.2f' % (float(len(recent_pairs)) / total_pairs_count) last_time = None first_time = None for block in nonerased_blocks: for tag, chunk in block.chunk_pairs: if tag.isHeaderTag: print block.sequence_num last_time = time.ctime(YaffsHeader(chunk).mtime) break if last_time: break for x in xrange(len(nonerased_blocks)-1, 0, -1): block = nonerased_blocks[x] for y in xrange(len(block.chunk_pairs)-1, 0, -1): tag, chunk = block.chunk_pairs[y] if tag.isHeaderTag: print block.sequence_num first_time = time.ctime(YaffsHeader(chunk).mtime) break if first_time: break print 'Oldest object modification: %s' % first_time print 'Newest object modification: %s' % last_time