python解释NTFS runlist的代码
2017-07-01 00:40
337 查看
代码如下:
执行效果如下:
root@zhangyu-VirtualBox:~/NTFS-5# python3 read_runlist.py mft_source.img ***参数数量或格式错误! 命令格式: python3 read_runlist.py <File name> <Start bytes> <Start LCN> <Start VCN>: File name:要解释的包含runlist的文件名称 Start bytes:文件中要解释runlist的起始位置 Start LCN:runlist开始的参考LCN值,如果是一段完整的runlist,这个值应为0. Start VCN:runlist开始的参考VCN值,如果是一段没有0x20的runlist,这个值多数为0. *返回值:一个二维队列,打印结果。
root@zhangyu-VirtualBox:~/NTFS-5# python3 read_runlist.py mft_source.img 5688 0 0Runlist(共18个片断): VCN LCN LEN 0 32212 1 1 157952 2 3 207115 3 6 244046 3 9 122523 1 10 157991 1 11 170296 3 14 40552 5 19 149853 2 21 122721 2 23 141674 1 24 145783 3 27 158109 3 30 145820 1 31 240236 1 32 154081 1 33 166379 3 36 178711 3
#!/usr/bin/python3 #http://www.frombyte.com 张宇 import os import sys import random import hashlib import struct import zlib import re def help_exit(): print(" 命令格式:") print(" python3 %s <File name> <Start bytes> <Start LCN> <Start VCN>:" % sys.argv[0]) print(" File name:要解释的包含runlist的文件名称") print(" Start bytes:文件中要解释runlist的起始位置") print(" Start LCN:runlist开始的参考LCN值,如果是一段完整的runlist,这个值应为0.") print(" Start VCN:runlist开始的参考VCN值,如果是一段没有0x20的runlist,这个值多数为0.") print(" *返回值:一个二维队列,打印结果。\n") exit() #通过抛出异常判断第一个参数是否是A-F def is_num_by_except(s): try: a=int(s,16) if (a>0 and a<=16): return True else: return False except ValueError: return False if len(sys.argv)!= 5 : print(" ***参数数量或格式错误!") help_exit() if sys.argv[2].isdigit(): spoi = int(sys.argv[2]) if spoi<0: print("***错误,起始字节位置不能取负值") help_exit() else: print("***错误,起始字节位置应为非负整数") help_exit() if sys.argv[3].isdigit(): slcn = int(sys.argv[3]) if slcn<0: print("***错误,起始LCN不能取负值") help_exit() else: print("***错误,起始LCN应为非负整数") help_exit() if sys.argv[4].isdigit(): svcn = int(sys.argv[4]) if svcn<0: print("***错误,起始VCN不能取负值") help_exit() else: print("***错误,起始VCN应为非负整数") help_exit() def get_i(vl,ilen): q=0 for i in range(0,ilen): q = q | ( vl[0][i] << i*8 ) #若为负数 if vl[0][ilen-1] > 0x80: q = q - (1 << ilen*8 ) return q f = open("%s"%sys.argv[1],'rb') f.seek(spoi) data = f.read(1024) v1 = 1 i = 0 lists = [[0 for i in range(2)] ] del lists[0] while True: t = struct.unpack_from('B',data,i) v1 = t[0] if v1 == 0: break v1_p = (v1 & 0xF0) >> 4 v1_l = (v1 &0xF) if (v1_l >=8) or (v1_p >=8) or (v1_l == 0): print("***偏移%d:run list长度和位置字节有错误!***"%(i+spoi)) break i = i+1 if (i+8) >= 1024: break t = struct.unpack_from('8s',data,i) v1_dl = get_i(t,v1_l) if v1_dl < 0: print("***偏移%d:run片断长度不能为负!***"%(i+spoi)) break i = i+ v1_l if (i+8) >= 1024: break t = struct.unpack_from('8s',data,i) v1_dp = get_i(t,v1_p) slcn = slcn + v1_dp lists.append([slcn,v1_dl]) i = i + v1_p #print("%x,%x:%x,%x"%(v1_l,v1_p,v1_dl,slcn)) print("Runlist(共%d个片断):"%len(lists)) print("%20s%20s%20s"%("VCN","LCN","LEN")) for i in lists: print("%20d%20d%20d"%(svcn,i[0],i[1])) svcn += i[1] f.close()
执行效果如下:
root@zhangyu-VirtualBox:~/NTFS-5# python3 read_runlist.py mft_source.img ***参数数量或格式错误! 命令格式: python3 read_runlist.py <File name> <Start bytes> <Start LCN> <Start VCN>: File name:要解释的包含runlist的文件名称 Start bytes:文件中要解释runlist的起始位置 Start LCN:runlist开始的参考LCN值,如果是一段完整的runlist,这个值应为0. Start VCN:runlist开始的参考VCN值,如果是一段没有0x20的runlist,这个值多数为0. *返回值:一个二维队列,打印结果。
root@zhangyu-VirtualBox:~/NTFS-5# python3 read_runlist.py mft_source.img 5688 0 0Runlist(共18个片断): VCN LCN LEN 0 32212 1 1 157952 2 3 207115 3 6 244046 3 9 122523 1 10 157991 1 11 170296 3 14 40552 5 19 149853 2 21 122721 2 23 141674 1 24 145783 3 27 158109 3 30 145820 1 31 240236 1 32 154081 1 33 166379 3 36 178711 3
相关文章推荐
- python解释NTFS runlist的代码
- 从数据恢复角度出发 python解释NTFS runlist的代码
- 数据恢复工程师教你用 python解释NTFS runlist的代码
- tf–idf算法解释及其python代码实现(上)
- Python Tensorflow下的Word2Vec代码解释
- 用python写服务器(书上的代码,运行不了,求解释)
- tf–idf算法解释及其python代码实现(下)
- 180122 特征值与特征向量的几何解释与python代码,附matplotlib绘制多边形
- Python Tensorflow下的Word2Vec代码解释
- [置顶] 关于决策树ID3算法,熵,信息增益率的权威解释,稍后奉上python代码
- Python代码是编译执行还是解释执行?
- 关于python代码是编译执行还是解释执行
- python实现的 K-近邻算法代码详细解释
- 180123 PCA主成分分析的原理解释及python代码实现
- twisted之python代码解释
- 自动化测试第一季-selenium + python(环境搭建与基础代码解释)
- [导入]vbscript错误代码及对应解释大全/VBScript 语法错误
- 【转贴】网页媒体播放器代码解释
- jscript错误代码及相应解释大全( 选择自 jmylf 的 Blog )
- python小代码:ElapsedTime