@@ -0,0 +1,1362 @@
+#!/usr/bin/env python%0Aimport sys%0Aimport shutil%0Aimport os%0A%0A%22%22%22%0AThis tool extract blocks from a possible corrupted file in the order given %0Aby the block_order_file. The layout of the block_order_file is the following:%0Aoffset-size%0A657457152-3145728%0A150994944-3145728%0A355467264-3145728%0A%22%22%22%0A%0A# TODO: improve with flags%0A%0Achunk_folder=%22./chunks%22%0Atry:%0A    shutil.rmtree(chunk_folder)%0Aexcept:%0A    pass%0A    %0Aos.mkdir(chunk_folder)%0A%0A%0Aif len(sys.argv) %3C 3:%0A    print %22Usage: %25s %3Ccorrupted-file%3E %3Cblock-order-file%3E%22 %25 (sys.argv%5B0%5D)%0A    sys.exit(1)%0A%0Acorrupted_file=sys.argv%5B1%5D%0Ablock_order_file=sys.argv%5B2%5D%0A%0Alines = %5Bline.rstrip('%5Cn') for line in open(block_order_file)%5D%0Achunks=%5B%5D%0Afor line in lines:%0A    tokens=line.split(%22-%22)%0A    offset,size=int(tokens%5B0%5D),int(tokens%5B1%5D)%0A    chunks.append((offset,size))%0A%0A#chunks=%5B(0,3),(9,0.1),(3,3),(6,3)%5D%0An=len(chunks)%0Acorrupted_index=zip(range(n),chunks)%0Asource_index=zip(range(n),sorted(chunks))          %0Asource_index_map = dict(%5B(x%5B1%5D,x%5B0%5D) for x in source_index%5D)%0Ac=0%0Afor i,r in corrupted_index:%0A    chunk_fn=os.path.join(chunk_folder, str(source_index_map%5Br%5D+1))%0A    print %22read corrupted file from offset=%25d size_bytes=%25d -%3E save as chunk index=%2503d%22 %25 (c,r%5B1%5D,source_index_map%5Br%5D+1) %0A    cmd=%22dd if=%25s of=%25s bs=%25d count=1 skip=%25d iflag=skip_bytes%22 %25 (corrupted_file,chunk_fn,r%5B1%5D,c) %0A    print cmd%0A    os.system(cmd)%0A    c += r%5B1%5D%0A

add block_extractor.py tool