-
Notifications
You must be signed in to change notification settings - Fork 28
/
csharp_ini_maker.py
109 lines (79 loc) · 2.43 KB
/
csharp_ini_maker.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
import sys
import argparse
from antlr4 import *
from module_maker.CSharpLexer import CSharpLexer
from module_maker.CSharpParser import CSharpParser
from module_maker.CSharpParserListener import CSharpParserListener
from module_maker.symbol_ini import SymbolINI
OMODULE_TYPES = [
'decrypter',
'dkey',
'executor',
'imports',
'inner_shell',
'output_modules',
'payload_main',
'postmodule',
'premodule',
'runner',
]
IMODULE_TYPES = [
]
MODULE_DIRECTIONS = [
'output',
'input',
]
def cli():
parser = argparse.ArgumentParser()
parser.add_argument('--input-file', '-i',
dest='input_file',
type=str,
required=True,
help='Specify source code file to input')
parser.add_argument('--output-file', '-o',
dest='output_file',
type=str,
required=True,
help='Specify name for output INI file')
args = parser.parse_args()
return args
def gather(args):
input_handle = FileStream(args.input_file)
lexer = CSharpLexer(input_handle)
tokens = CommonTokenStream(lexer)
parser = CSharpParser(tokens)
tree = parser.compilation_unit()
listener = CSharpParserListener()
walker = ParseTreeWalker()
walker.walk(listener, tree)
with open(args.output_file, 'w') as output_handle:
output_handle.write('[vars]\n')
for v in listener.vars:
output_handle.write(v+'\n')
output_handle.write('\n')
output_handle.write('[methods]\n')
for v in listener.methods:
output_handle.write(v+'\n')
output_handle.write('\n')
output_handle.write('[class_decls]\n')
for v in listener.class_decls:
output_handle.write(v+'\n')
output_handle.write('\n')
output_handle.write('[params]\n')
for v in listener.params:
output_handle.write(v+'\n')
output_handle.write('\n')
output_handle.write('[delegates]\n')
for v in listener.delegates:
output_handle.write(v+'\n')
output_handle.write('\n')
output_handle.write('[imports]\n')
for v in listener.imports:
output_handle.write(v+'\n')
output_handle.write('\n')
def main():
args = cli()
gather(args)
if __name__ == '__main__':
cli()
main()