-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
executable file
·85 lines (59 loc) · 2.86 KB
/
run.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
#!/usr/bin/env python3
import argparse
import logging
import pprint
from vbincarver.parser import FileParser
from vbincarver.formatter import HexFormatter, SummaryFormatter
from vbincarver.config import FormatConfig
def main():
parser = argparse.ArgumentParser()
parser.add_argument( '-f', '--format', action='store',
help='Name of the format to analyze.' )
parser.add_argument(
'-o', '--out-file', action='store', default='output.html',
help='Path to the HTML output file to create.' )
mutex_verbose = parser.add_mutually_exclusive_group()
mutex_verbose.add_argument( '-v', '--verbose', action='store_true' )
mutex_verbose.add_argument(
'-vv', '--extra-verbose', action='store_true' )
parser.add_argument( 'parse_file', action='store',
help='Path to the file to dissect.' )
args = parser.parse_args()
log_level = logging.INFO
if args.verbose or args.extra_verbose:
log_level = logging.DEBUG
logging.basicConfig( level=log_level )
logger = logging.getLogger( 'main' )
if not args.extra_verbose:
storage_logger = logging.getLogger( 'storage' )
storage_logger.setLevel( level=logging.INFO )
chunk_logger = logging.getLogger( 'chunk' )
chunk_logger.setLevel( level=logging.INFO )
parser_logger = logging.getLogger( 'parser.parse.byte' )
parser_logger.setLevel( level=logging.INFO )
parser_logger = logging.getLogger( 'parser.add' )
parser_logger.setLevel( level=logging.INFO )
parser_logger = logging.getLogger( 'parser.select' )
parser_logger.setLevel( level=logging.INFO )
parser_logger = logging.getLogger( 'parser.repeats' )
parser_logger.setLevel( level=logging.INFO )
logger.debug( 'starting...' )
format_data = FormatConfig( args.parse_file, args.format )
with open( args.out_file, 'w' ) as out_file:
with open( args.parse_file, 'rb' ) as parse_file:
file_parser = FileParser( parse_file.read(), format_data )
out_file.write( '<!DOCTYPE html>\n<html>\n<head>\n' )
out_file.write( '<link rel="stylesheet" href="hex.css" />\n' )
out_file.write( '<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>\n' )
out_file.write( '<script src="hex.js"></script>\n' )
out_file.write( '</head>\n<body>\n' )
file_parser.parse()
formatter = HexFormatter( out_file, file_parser )
formatter.write_layout()
#printer = pprint.PrettyPrinter()
#printer.pprint( file_parser.buffer )
formatter = SummaryFormatter( out_file, file_parser )
formatter.write_layout()
out_file.write( '</body></html>' )
if '__main__' == __name__:
main()