-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
64 lines (52 loc) · 1.56 KB
/
main.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
#!/usr/bin/env python
# encoding: utf-8
"""
@author: w-devin
@contact: [email protected]
@file: main.py
@time: 10/24/2020 01:50
@desc:
"""
import os
import sys
import click
from constant import NULL_STRING
from malware_detector.detector import Detector
from malware_detector.constant import *
from malware_detector.log_printer import *
detector = Detector()
def res_handler(res):
if not res:
return False
bingo(res)
return True
@click.command()
@click.option('-f', '--file2scan', type=click.STRING, default=NULL_STRING)
@click.option('-d', '--dir2scan', type=click.STRING, default=NULL_STRING)
@click.option('-p', '--payload', type=click.STRING, default=NULL_STRING)
def run(file2scan, dir2scan, payload):
if file2scan:
if os.path.isfile(file2scan):
res = detector.detect(file2scan)
res_handler(res)
else:
error('input a file with -f')
if dir2scan:
if os.path.isdir(dir2scan):
info('scan dir: {}'.format(dir2scan))
for root, dirs, files in os.walk(dir2scan):
for filename in files:
file2scan = os.path.join(root, filename)
if os.path.isfile(file2scan):
res = detector.detect(file2scan)
res_handler(res)
else:
error('input a dir with -d')
if payload:
res = detector.detect(payload, PAYLOAD)
res_handler(res)
if __name__ == '__main__':
if len(sys.argv) <= 1:
error('--help to get help message')
exit()
run()