-
Notifications
You must be signed in to change notification settings - Fork 39
/
mt_read.py
executable file
·155 lines (120 loc) · 3.63 KB
/
mt_read.py
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
import sys
from bstruct_defs import *
def dump_hcc_content(filename):
try:
fp = open(filename, "rb")
except OSError as e:
print(
"[ERROR] '%s' raised when tried to read the file '%s'"
% (e.strerror, filename)
)
sys.exit(1)
buf = fp.read(HccHeader._size)
obj = HccHeader(buf)
assert obj.magic == 501
print(obj)
while True:
buf = fp.read(HccTable._size)
obj = HccTable(buf)
# Quite crude, but seems to work
if obj.off == obj.size == 0:
break
print(obj)
was = fp.tell()
fp.seek(obj.off)
buf = fp.read(HccRecordHeader._size)
obj = HccRecordHeader(buf)
assert obj.magic == 0x81
print(obj)
for i in range(obj.rows):
buf = fp.read(HccRecord._size)
obj = HccRecord(buf)
assert obj.separator & 0x00088884 == 0x00088884
print(obj)
# Skip the eventual trailing bytes
extra1 = (obj.separator >> 28) & 15
extra2 = (obj.separator >> 24) & 15
extra3 = (obj.separator >> 20) & 15
fp.seek(extra1 + extra2 + extra3, 1)
fp.seek(was)
def dump_srv_content(filename):
try:
fp = open(filename, "rb")
except OSError as e:
print(
"[ERROR] '%s' raised when tried to read the file '%s'"
% (e.strerror, filename)
)
sys.exit(1)
buf = fp.read(SrvHeader._size)
obj = SrvHeader(buf)
print(obj)
while True:
buf = fp.read(SrvRecord._size)
if len(buf) != SrvRecord._size:
break
obj = SrvRecord(buf)
print(obj)
def dump_content(filename, offset, strucc):
"""
Dump the content of the file "filename" starting from offset and using the
BStruct subclass pointed by strucc
"""
try:
fp = open(filename, "rb")
except OSError as e:
print(
"[ERROR] '%s' raised when tried to read the file '%s'"
% (e.strerror, filename)
)
sys.exit(1)
fp.seek(offset)
while True:
buf = fp.read(strucc._size)
if len(buf) != strucc._size:
break
obj = strucc(buf)
print(obj)
if __name__ == "__main__":
# Parse the arguments
argumentParser = argparse.ArgumentParser(add_help=False)
argumentParser.add_argument(
"-i",
"--input-file",
action="store",
dest="inputFile",
help="input file",
required=True,
)
argumentParser.add_argument(
"-t",
"--input-type",
action="store",
dest="inputType",
help="input type",
required=True,
)
argumentParser.add_argument(
"-h", "--help", action="help", help="Show this help message and exit"
)
args = argumentParser.parse_args()
if args.inputType == "sel":
# There's a 4-byte magic preceding the data
dump_content(args.inputFile, 4, SymbolSel)
elif args.inputType == "ticksraw":
dump_content(args.inputFile, 0, TicksRaw)
elif args.inputType == "symbolsraw":
dump_content(args.inputFile, 0, SymbolsRaw)
elif args.inputType == "symgroups":
dump_content(args.inputFile, 0, Symgroups)
elif args.inputType == "fxt-header":
dump_content(args.inputFile, 0, FxtHeader)
elif args.inputType == "srv":
dump_srv_content(args.inputFile)
elif args.inputType == "hcc-header":
dump_hcc_content(args.inputFile)
else:
print("Invalid type {}!".format(args.inputType))