python解释NTFS runlist的代码,,代码如下:#!/us
python解释NTFS runlist的代码,,代码如下:#!/us
代码如下:
#!/usr/bin/python3#http://www.frombyte.com张宇importosimportsysimportrandomimporthashlibimportstructimportzlibimportredefhelp_exit():print("命令格式:")print("python3%s<Filename><Startbytes><StartLCN><StartVCN>:"%sys.argv[0])print("Filename:要解释的包含runlist的文件名称")print("Startbytes:文件中要解释runlist的起始位置")print("StartLCN:runlist开始的参考LCN值,如果是一段完整的runlist,这个值应为0.")print("StartVCN:runlist开始的参考VCN值,如果是一段没有0x20的runlist,这个值多数为0.")print("*返回值:一个二维队列,打印结果。\n")exit()#通过抛出异常判断第一个参数是否是A-Fdefis_num_by_except(s):try:a=int(s,16)if(a>0anda<=16):returnTrueelse:returnFalseexceptValueError:returnFalseiflen(sys.argv)!=5:print("***参数数量或格式错误!")help_exit()ifsys.argv[2].isdigit():spoi=int(sys.argv[2])ifspoi<0:print("***错误,起始字节位置不能取负值")help_exit()else:print("***错误,起始字节位置应为非负整数")help_exit()ifsys.argv[3].isdigit():slcn=int(sys.argv[3])ifslcn<0:print("***错误,起始LCN不能取负值")help_exit()else:print("***错误,起始LCN应为非负整数")help_exit()ifsys.argv[4].isdigit():svcn=int(sys.argv[4])ifsvcn<0:print("***错误,起始VCN不能取负值")help_exit()else:print("***错误,起始VCN应为非负整数")help_exit()defget_i(vl,ilen):q=0foriinrange(0,ilen):q=q|(vl[0][i]<<i*8)#若为负数ifvl[0][ilen-1]>0x80:q=q-(1<<ilen*8)returnqf=open("%s"%sys.argv[1],‘rb‘)f.seek(spoi)data=f.read(1024)v1=1i=0lists=[[0foriinrange(2)]]dellists[0]whileTrue:t=struct.unpack_from(‘B‘,data,i)v1=t[0]ifv1==0:breakv1_p=(v1&0xF0)>>4v1_l=(v1&0xF)if(v1_l>=8)or(v1_p>=8)or(v1_l==0):print("***偏移%d:runlist长度和位置字节有错误!***"%(i+spoi))breaki=i+1if(i+8)>=1024:breakt=struct.unpack_from(‘8s‘,data,i)v1_dl=get_i(t,v1_l)ifv1_dl<0:print("***偏移%d:run片断长度不能为负!***"%(i+spoi))breaki=i+v1_lif(i+8)>=1024:breakt=struct.unpack_from(‘8s‘,data,i)v1_dp=get_i(t,v1_p)slcn=slcn+v1_dplists.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"))foriinlists: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 0
Runlist(共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
本文出自 “张宇(数据恢复)” 博客,请务必保留此出处http://zhangyu.blog.51cto.com/197148/1943606
python解释NTFS runlist的代码
相关内容
- python 多进程中的p.apply_async(),,最近有接触一点怎么
- python Queue/collections.deque,,1.python Q
- Pycharm集成Python编程环境IDE,, Python(英
- python函数 之 提升Python效率之使用循环机制代替递归函
- 入门学习python语言主要用途有哪些?,,python是一门非
- Python语言基础与应用 (P16)上机练习:基本数据类型,
- python 逻辑运算符 () > not > and > or,,针
- 7个Python实战项目代码,让你分分钟晋级大神!,
- Python打包exe程序避坑指南,
- 用 Python 开发 Emoji 表情查找程序,
评论关闭