1515
1616#define LOG_FILE "{PYLOGFILE}"
1717
18- struct syscall {{
18+ struct conf_syscall {{
1919 char *name;
2020 long callnum;
2121 bool log;
2222 bool block;
2323 char *arg0;
2424 long arg0_long;
2525 int arg0_matchtype;
26+ bool arg0_fdesc;
2627 char *arg1;
2728 long arg1_long;
2829 int arg1_matchtype;
30+ bool arg1_fdesc;
2931 char *arg2;
3032 long arg2_long;
3133 int arg2_matchtype;
34+ bool arg2_fdesc;
3235 char *arg3;
3336 long arg3_long;
3437 int arg3_matchtype;
38+ bool arg3_fdesc;
3539 char *arg4;
3640 long arg4_long;
3741 int arg4_matchtype;
42+ bool arg4_fdesc;
3843 char *arg5;
3944 long arg5_long;
4045 int arg5_matchtype;
46+ bool arg5_fdesc;
4147
42- struct syscall *next;
43- struct syscall *prev;
44- }} syscall_default = {{NULL, -1, false, false, NULL, -1, 0, NULL, -1, 0, NULL, -1, 0, NULL, -1, 0, NULL, -1, 0, NULL, -1, 0, NULL, NULL}};
48+ struct conf_syscall *next;
49+ struct conf_syscall *prev;
50+ }} syscall_default = {{NULL, -1, false, false, NULL, -1, 0, false, NULL, -1, 0, false, NULL, -1, 0, false, NULL, -1, 0, false, NULL, -1, 0, false, NULL, -1, 0, false , NULL, NULL}};
4551
46- typedef struct syscall syscall ;
52+ typedef struct conf_syscall conf_syscall ;
4753
48- syscall *
54+ conf_syscall *
4955get_calls() {{
5056{PYSTRUCTBUILD}
5157return {FIRSTVARNAME};
5258}};
5359"""
5460
5561structbuild_template = {
56- "var_define" : "syscall *{varname} = (struct syscall *) malloc(sizeof(syscall ));\n memcpy({varname}, &syscall_default, sizeof(syscall ));\n " ,
62+ "var_define" : "conf_syscall *{varname} = (struct conf_syscall *) malloc(sizeof(conf_syscall ));\n memcpy({varname}, &syscall_default, sizeof(conf_syscall ));\n " ,
5763 "set_name" : '{varname}->name = (char *) malloc(strlen("{name}")+1);\n strcpy({varname}->name, "{name}");\n {varname}->callnum = {name};\n ' ,
5864 "set_log" : "{varname}->log = {log};\n " ,
5965 "set_block" : "{varname}->block = {block};\n " ,
6066 "set_arg_char" : '{varname}->{argname} = (char *) malloc(strlen("{arg}")+1);\n strcpy({varname}->{argname}, "{arg}");\n ' ,
6167 "set_arg_long" : '{varname}->{argname}_long = {arg};\n ' ,
6268 "set_arg_matchtype" : '{varname}->{argname}_matchtype = {matchtype};\n ' ,
69+ "set_arg_isfdesc" : '{varname}->{argname}_fdesc = {isfdesc};\n ' ,
6370 "set_next" : "{varname}->next = {nextcall};\n " ,
6471 "set_prev" : "{varname}->prev = {prevcall};\n " ,
6572}
6673
6774
75+ class Argument :
76+ content : str = ""
77+ matchtype : str = "full"
78+ isChar : bool = True
79+ isFdesc : bool = False
80+
81+ def __init__ (self , content : str = "" , matchtype : str = "full" , isChar : bool = True , isFdesc : bool = False ):
82+ self .content = content
83+ self .matchtype = matchtype
84+ self .isChar = isChar
85+ self .isFdesc = isFdesc
86+
87+ def build_c_code (self , varname : str , argnum : str ) -> str :
88+ c_code = ""
89+ if self .content != "" and self .isChar :
90+ c_code = c_code + structbuild_template ["set_arg_char" ].format (varname = varname , argname = "arg" + argnum , arg = self .content )
91+ c_code = c_code + structbuild_template ["set_arg_matchtype" ].format (varname = varname , argname = "arg" + argnum , matchtype = 0 if self .matchtype == "full" else - 1 if self .matchtype == "begins" else 1 )
92+ elif self .content != "" and not self .isChar :
93+ c_code = c_code + structbuild_template ["set_arg_long" ].format (varname = varname , argname = "arg" + argnum , arg = self .content )
94+ if self .isFdesc :
95+ c_code = c_code + structbuild_template ["set_arg_isfdesc" ].format (varname = varname , argname = "arg" + argnum , isfdesc = self .isFdesc )
96+ return c_code
97+
98+ @staticmethod
99+ def init_from_dict (parsed : dict ):
100+ arg = Argument ()
101+ if parsed .get ("content" ) is not None :
102+ arg .content = str (parsed .get ("content" ))
103+ if parsed .get ("matchtype" ) is not None :
104+ arg .matchtype = str (parsed .get ("matchtype" ))
105+ if parsed .get ("isChar" ) is not None :
106+ arg .isChar = bool (parsed .get ("isChar" ))
107+ if parsed .get ("isFdesc" ) is not None :
108+ arg .isFdesc = bool (parsed .get ("isFdesc" ))
109+ return arg
110+
68111class Syscall :
69112 name : str
70113 log : bool
71114 block : bool
72- arg0 : str = ""
73- arg0_char : bool = True
74- arg0_matchtype : str = "full"
75- arg1 : str = ""
76- arg1_char : bool = True
77- arg1_matchtype : str = "full"
78- arg2 : str = ""
79- arg2_char : bool = True
80- arg2_matchtype : str = "full"
81- arg3 : str = ""
82- arg3_char : bool = True
83- arg3_matchtype : str = "full"
84- arg4 : str = ""
85- arg4_char : bool = True
86- arg4_matchtype : str = "full"
87- arg5 : str = ""
88- arg5_char : bool = True
89- arg5_matchtype : str = "full"
115+ arg0 : Argument = Argument ()
116+ arg1 : Argument = Argument ()
117+ arg2 : Argument = Argument ()
118+ arg3 : Argument = Argument ()
119+ arg4 : Argument = Argument ()
120+ arg5 : Argument = Argument ()
90121
91122 def __init__ (
92123 self ,
93124 name : str ,
94125 log : bool ,
95126 block : bool ,
96- arg0 : str = "" ,
97- arg0_char : bool = True ,
98- arg0_matchtype : str = "full" ,
99- arg1 : str = "" ,
100- arg1_char : bool = True ,
101- arg1_matchtype : str = "full" ,
102- arg2 : str = "" ,
103- arg2_char : bool = True ,
104- arg2_matchtype : str = "full" ,
105- arg3 : str = "" ,
106- arg3_char : bool = True ,
107- arg3_matchtype : str = "full" ,
108- arg4 : str = "" ,
109- arg4_char : bool = True ,
110- arg4_matchtype : str = "full" ,
111- arg5 : str = "" ,
112- arg5_char : bool = True ,
113- arg5_matchtype : str = "full" ,
127+ arg0 : Argument = Argument (),
128+ arg1 : Argument = Argument (),
129+ arg2 : Argument = Argument (),
130+ arg3 : Argument = Argument (),
131+ arg4 : Argument = Argument (),
132+ arg5 : Argument = Argument (),
114133 ):
115134 self .name = name
116135 self .log = log
117136 self .block = block
118137 self .arg0 = arg0
119- self .arg0_char = arg0_char
120- self .arg0_matchtype = arg0_matchtype
121138 self .arg1 = arg1
122- self .arg1_char = arg1_char
123- self .arg1_matchtype = arg1_matchtype
124139 self .arg2 = arg2
125- self .arg2_char = arg2_char
126- self .arg2_matchtype = arg2_matchtype
127140 self .arg3 = arg3
128- self .arg3_char = arg3_char
129- self .arg3_matchtype = arg3_matchtype
130141 self .arg4 = arg4
131- self .arg4_char = arg4_char
132- self .arg4_matchtype = arg4_matchtype
133142 self .arg5 = arg5
134- self .arg5_char = arg5_char
135- self .arg5_matchtype = arg5_matchtype
143+
136144
137145 def build_c_code (self , varname : str ) -> str :
138146 c_code = structbuild_template ["var_define" ].format (varname = varname )
@@ -145,90 +153,17 @@ def build_c_code(self, varname: str) -> str:
145153 varname = varname , name = "SYS_" + self .name .lower ()
146154 )
147155
148-
149156 c_code = c_code + structbuild_template ["set_log" ].format (
150157 varname = varname , log = str (self .log ).lower ()
151158 )
152159 c_code = c_code + structbuild_template ["set_block" ].format (
153160 varname = varname , block = str (self .block ).lower ()
154161 )
155- if self .arg0 != "" :
156- if self .arg0_char :
157- c_code = c_code + structbuild_template ["set_arg_char" ].format (
158- varname = varname , argname = "arg0" , arg = self .arg0
159- )
160- c_code = c_code + structbuild_template ["set_arg_matchtype" ].format (
161- varname = varname , argname = "arg0" , matchtype = 0 if self .arg0_matchtype == "full" else - 1 if self .arg0_matchtype == "begins" else 1
162- )
163- else :
164- c_code = c_code + structbuild_template ["set_arg_long" ].format (
165- varname = varname , argname = "arg0" , arg = self .arg0
166- )
167- if self .arg1 != "" :
168- if self .arg1_char :
169- c_code = c_code + structbuild_template ["set_arg_char" ].format (
170- varname = varname , argname = "arg1" , arg = self .arg1
171- )
172- c_code = c_code + structbuild_template ["set_arg_matchtype" ].format (
173- varname = varname , argname = "arg1" , matchtype = 0 if self .arg1_matchtype == "full" else - 1 if self .arg1_matchtype == "begins" else 1
174- )
175- else :
176- c_code = c_code + structbuild_template ["set_arg_long" ].format (
177- varname = varname , argname = "arg1" , arg = self .arg1
178- )
179-
180- if self .arg2 != "" :
181- if self .arg2_char :
182- c_code = c_code + structbuild_template ["set_arg_char" ].format (
183- varname = varname , argname = "arg2" , arg = self .arg2
184- )
185- c_code = c_code + structbuild_template ["set_arg_matchtype" ].format (
186- varname = varname , argname = "arg2" , matchtype = 0 if self .arg2_matchtype == "full" else - 1 if self .arg2_matchtype == "begins" else 1
187- )
188- else :
189- c_code = c_code + structbuild_template ["set_arg_long" ].format (
190- varname = varname , argname = "arg2" , arg = self .arg2
191- )
192-
193-
194- if self .arg3 != "" :
195- if self .arg3_char :
196- c_code = c_code + structbuild_template ["set_arg_char" ].format (
197- varname = varname , argname = "arg3" , arg = self .arg3
198- )
199- c_code = c_code + structbuild_template ["set_arg_matchtype" ].format (
200- varname = varname , argname = "arg3" , matchtype = 0 if self .arg3_matchtype == "full" else - 1 if self .arg3_matchtype == "begins" else 1
201- )
202- else :
203- c_code = c_code + structbuild_template ["set_arg_long" ].format (
204- varname = varname , argname = "arg3" , arg = self .arg3
205- )
206-
207- if self .arg4 != "" :
208- if self .arg4_char :
209- c_code = c_code + structbuild_template ["set_arg_char" ].format (
210- varname = varname , argname = "arg4" , arg = self .arg4
211- )
212- c_code = c_code + structbuild_template ["set_arg_matchtype" ].format (
213- varname = varname , argname = "arg4" , matchtype = 0 if self .arg4_matchtype == "full" else - 1 if self .arg4_matchtype == "begins" else 1
214- )
215- else :
216- c_code = c_code + structbuild_template ["set_arg_long" ].format (
217- varname = varname , argname = "arg4" , arg = self .arg4
218- )
219-
220- if self .arg5 != "" :
221- if self .arg5_char :
222- c_code = c_code + structbuild_template ["set_arg_char" ].format (
223- varname = varname , argname = "arg5" , arg = self .arg5
224- )
225- c_code = c_code + structbuild_template ["set_arg_matchtype" ].format (
226- varname = varname , argname = "arg5" , matchtype = 0 if self .arg5_matchtype == "full" else - 1 if self .arg5_matchtype == "begins" else 1
227- )
228- else :
229- c_code = c_code + structbuild_template ["set_arg_long" ].format (
230- varname = varname , argname = "arg5" , arg = self .arg5
231- )
162+ c_code = c_code + self .arg0 .build_c_code (varname , "0" )
163+ c_code = c_code + self .arg1 .build_c_code (varname , "1" )
164+ c_code = c_code + self .arg2 .build_c_code (varname , "2" )
165+ c_code = c_code + self .arg3 .build_c_code (varname , "4" )
166+ c_code = c_code + self .arg4 .build_c_code (varname , "5" )
232167 return c_code
233168
234169 @staticmethod
@@ -240,29 +175,17 @@ def init_from_dict(parsed: dict):
240175 if parsed .get ("block" ) is not None :
241176 call .block = bool (parsed .get ("block" ))
242177 if parsed .get ("arg0" ) is not None :
243- call .arg0 = str (parsed .get ("arg0" ))
244- call .arg0_char = bool (parsed .get ("arg0_char" ))
245- call .arg0_matchtype = str (parsed .get ("arg0_matchtype" ))
178+ call .arg0 = Argument .init_from_dict (parsed ["arg0" ])
246179 if parsed .get ("arg1" ) is not None :
247- call .arg1 = str (parsed .get ("arg1" ))
248- call .arg1_char = bool (parsed .get ("arg1_char" ))
249- call .arg1_matchtype = str (parsed .get ("arg1_matchtype" ))
180+ call .arg1 = Argument .init_from_dict (parsed ["arg1" ])
250181 if parsed .get ("arg2" ) is not None :
251- call .arg2 = str (parsed .get ("arg2" ))
252- call .arg2_char = bool (parsed .get ("arg2_char" ))
253- call .arg2_matchtype = str (parsed .get ("arg2_matchtype" ))
182+ call .arg2 = Argument .init_from_dict (parsed ["arg2" ])
254183 if parsed .get ("arg3" ) is not None :
255- call .arg3 = str (parsed .get ("arg3" ))
256- call .arg3_char = bool (parsed .get ("arg3_char" ))
257- call .arg3_matchtype = str (parsed .get ("arg3_matchtype" ))
184+ call .arg3 = Argument .init_from_dict (parsed ["arg3" ])
258185 if parsed .get ("arg4" ) is not None :
259- call .arg4 = str (parsed .get ("arg4" ))
260- call .arg4_char = bool (parsed .get ("arg4_char" ))
261- call .arg4_matchtype = str (parsed .get ("arg4_matchtype" ))
186+ call .arg4 = Argument .init_from_dict (parsed ["arg4" ])
262187 if parsed .get ("arg5" ) is not None :
263- call .arg5 = str (parsed .get ("arg5" ))
264- call .arg5_char = bool (parsed .get ("arg5_char" ))
265- call .arg5_matchtype = str (parsed .get ("arg5_matchtype" ))
188+ call .arg5 = Argument .init_from_dict (parsed ["arg5" ])
266189 return call
267190
268191
@@ -276,7 +199,7 @@ def __init__(self, log_file: str, syscalls: list[Syscall]):
276199
277200 def build_c_code (self ) -> str :
278201 i : int = len (self .syscalls )
279- c_structs = ""
202+ c_structs : str = ""
280203 for syscall in reversed (self .syscalls ):
281204 c_structs = c_structs + syscall .build_c_code ("call" + str (i ))
282205 i = i - 1
@@ -307,7 +230,6 @@ def build_c_code(self) -> str:
307230 ].format (varname = "call" + str (i ), nextcall = "call" + str (i + 1 ))
308231
309232 c_structs = c_structs + linked_list_setup
310- argtypes : list [str ] = []
311233 c_code = header_template .format (
312234 PYLOGFILE = self .log_file ,
313235 PYSTRUCTBUILD = c_structs ,
0 commit comments