-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexplore.py
More file actions
executable file
·93 lines (70 loc) · 2.22 KB
/
explore.py
File metadata and controls
executable file
·93 lines (70 loc) · 2.22 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#! /usr/bin/python
from datetime import datetime
from utils import get_map
from objects import BigDir, BootBlock
import sys
import cmd
if len(sys.argv) != 2:
print("Usage: explore <device>")
exit(1)
fd = open(sys.argv[1], "rb")
fd.seek(0xc00)
bb = BootBlock.from_buffer_copy(fd.read(0x200))
fd.seek(0)
fs_map = get_map(fd)
# fs_map.disc_record.show()
root_fragment = fs_map.disc_record.root >> 8
root_locations = fs_map.find_fragment(root_fragment, fs_map.disc_record.root_size)
fd.seek((root_locations[0])[0])
root = BigDir(fd.read(fs_map.disc_record.root_size))
csd = root
path = [root]
csd.show()
class Shell(cmd.Cmd):
intro = ''
prompt = '$> '
def do_dir(self, arg):
'Change into the specified directory.'
global csd
dirent = csd.find(arg.encode('latin-1'))
if not dirent:
print("Not found.")
return
if not dirent.is_directory():
print("Not a directory.")
return
location = fs_map.find_fragment(dirent.ind_disc_addr >> 8, dirent.length)[0]
fd.seek(location[0])
csd = BigDir(fd.read(dirent.length))
path.append(csd)
def do_up(self, arg):
'Change into the parent directory.'
global csd
global path
if len(path) > 1:
path = path[:-1]
csd = path[-1]
def do_cat(self, arg):
'List the contents of the current directory'
csd.show()
def do_zone(self, arg):
'Show info about a zone'
zone = int(arg)
print("Zone: {} - {} to {}".format(zone, *fs_map.zone_range(zone)))
print("Header: {:02x} {:02x} {:02x} {:02x}".format(*fs_map.zone_header(zone)))
fs_map.show_zone(zone, True)
print("Zone check (calclated): {:02x}".format(fs_map.calc_zone_check(zone)))
def do_quit(self, arg):
'Exits the exploerer.'
return True
def do_EOF(self, arg):
return True
def postcmd(self, stop, line):
path_str = ''
for item in path:
if path_str != '':
path_str += '.'
path_str += item.name.decode('latin-1')
self.prompt = path_str + "> "
return cmd.Cmd.postcmd(self, stop, line)
Shell().cmdloop()