-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrings_main.py
More file actions
executable file
·65 lines (48 loc) · 2.13 KB
/
strings_main.py
File metadata and controls
executable file
·65 lines (48 loc) · 2.13 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
#!/usr/bin/env python3
'''
This script is used to print all the strings in given binary file.
- The strings are extracted using floss.
- Each string get score according to staticly analysis.
- The strings are sorted by their score.
'''
from argparse import ArgumentParser
from strings_extractor import get_strings_from_binary, get_strings_from_output
from feature_extractor import exctract_features_from_binary, extract_features_from_output
from signal import signal, SIGPIPE, SIG_DFL
signal(SIGPIPE, SIG_DFL)
def parse_args():
parser = ArgumentParser()
# one of the following is required
input_group = parser.add_mutually_exclusive_group(required=True)
input_group.add_argument('-ib', '--input-binary',
dest='binary_file', help='the binary file to analyze')
input_group.add_argument('-if', '--input-floss-output',
dest='floss_output', help='the floss output file to analyze')
parser.add_argument('-v', '--verbose', help='print verbose output',
default=False, action='store_true')
parser.add_argument('--no-color', help='print non-colored output',
default=False, action='store_true')
parser.add_argument('--show-scores', help='print scores for each string',
default=False, action='store_true')
args = parser.parse_args()
return args
def main():
args = parse_args()
if args.binary_file:
strings = get_strings_from_binary(args.binary_file)
else:
strings = get_strings_from_output(args.floss_output)
for string in strings:
print_string(string, args.verbose, args.no_color, args.show_scores)
def print_string(string, verbose, no_color, show_scores):
'''
This function prints the given string.
Args:
string (DataString): The string to print.
verbose (bool): If True, print verbose output.
no_color (bool): If True, print non-colored output.
show_scores (bool): If True, print scores for each string.
'''
print(string.format_string(verbose, no_color, show_scores))
if __name__ == '__main__':
main()