-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse-ntfs.py
More file actions
71 lines (63 loc) · 2.39 KB
/
parse-ntfs.py
File metadata and controls
71 lines (63 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import sys
import NTFS.Bytes as Bytes
from NTFS.NTFSDrive import NTFSDrive
from NTFS.Win32FileReader import Win32FileReader
KILOBYTES = 2**10
MEGABYTES = 2**20
GIGABYTES = 2**30
if len(sys.argv) < 2:
raise RuntimeError('Missing command line argument: py main.py "drivename"')
driveName = sys.argv[1]
driveReader = Win32FileReader(driveName)
drive = NTFSDrive(driveName, driveReader)
print('Opened NTFS drive "%s"' % driveName)
config = drive.config()
bytesPerSector = config.bytesPerSector
sectorsPerCluster = config.sectorsPerCluster
totalSize = config.totalSectors * config.bytesPerSector
print('Bytes per sector: %d' % bytesPerSector)
print('Sectors per cluster: %d' % sectorsPerCluster)
print('Total size: %.2fGb (%d)' % (float(totalSize) / GIGABYTES, totalSize))
cd = drive.root()
while True:
print('')
try:
input = raw_input('%s>' % cd.fullname()).split()
argv = input[1:]
argc = len(argv)
cmd = input[0]
if cmd == 'exit':
if argc != 0:
raise IOError('This command excepted %d parameters, received %d.' % (0, argc))
break
elif cmd == 'dir':
if argc != 0:
raise IOError('This command excepted %d parameters, received %d.' % (0, argc))
cd.children().dump()
elif cmd == 'cd':
if argc != 1:
raise IOError('This command excepted %d parameters, received %d.' % (1, argc))
pathElements = argv[0].replace('/', '\\').split('\\')
cdNew = cd
for pathElement in pathElements:
if pathElement == '..':
cdNew = cdNew.parent()
elif pathElement != '.':
cdNew = cdNew.child(pathElement)
if not cdNew:
raise IOError('This path does not exist.')
if not cdNew.isDir():
content = cdNew.content()
if content:
Bytes.dump(content, maxLines = 100)
else:
for attr in cdNew.attributes():
print(attr)
raise IOError('This path is not a directory.')
cd = cdNew
else:
raise IOError('This command does not exist.')
except IOError as io:
print('Invalid input: %s' % io)
#except Exception as exception:
# print(exception)