HyperDbg Debugger
Loading...
Searching...
No Matches
test-case-generator Namespace Reference

Functions

 S ()
 
 STATEMENT ()
 
 CALL_FUNC_STATEMENT ()
 
 ASSIGN_STATEMENT ()
 
 IF_STATEMENT ()
 
 ELSIF_STATEMENT ()
 
 ELSIF_STATEMENTP ()
 
 ELSE_STATEMENT ()
 
 END_OF_IF ()
 
 WHILE_STATEMENT ()
 
 DO_WHILE_STATEMENT ()
 
 FOR_STATEMENT ()
 
 SIMPLE_ASSIGNMENT ()
 
 SIMPLE_ASSIGNMENTP ()
 
 INC_DEC ()
 
 INC_DECP ()
 
 INCP ()
 
 DECP ()
 
 BOOLEAN_EXPRESSION ()
 
 EXPRESSION ()
 
 E0P ()
 
 E1 ()
 
 E1P ()
 
 E2 ()
 
 E2P ()
 
 E3 ()
 
 E3P ()
 
 E4 ()
 
 E4P ()
 
 E5 ()
 
 E5P ()
 
 E6 ()
 
 E6P ()
 
 E7 ()
 
 E7P ()
 
 E8 ()
 
 E8P ()
 
 E9 ()
 
 E9P ()
 
 E10 ()
 
 E12 ()
 
 E13 ()
 
 L_VALUE ()
 
 NULL ()
 
 tohex (val, nbits)
 
 evaluate (s)
 

Variables

int depth = 0
 
int MAX_DEPTH = 20
 
 f = open('script-test-cases.txt', 'w')
 
int counter = 1
 
int initCounter = counter
 
 sentence = FOR_STATEMENT()
 
 res = sentence
 
 val = evaluate(sentence)
 

Function Documentation

◆ ASSIGN_STATEMENT()

test-case-generator.ASSIGN_STATEMENT ( )
68def ASSIGN_STATEMENT():
69 global depth
70 depth+=1
71 res = L_VALUE() + ' = ' + EXPRESSION() + ' ' + NULL()
72 depth-=1
73 return res
74
75
STATEMENT2 VARIABLE_TYPE1 VARIABLE_TYPE2 L_VALUE
Definition Grammar.txt:76

◆ BOOLEAN_EXPRESSION()

test-case-generator.BOOLEAN_EXPRESSION ( )
200def BOOLEAN_EXPRESSION():
201 res = ''
202 return res
203
204

◆ CALL_FUNC_STATEMENT()

test-case-generator.CALL_FUNC_STATEMENT ( )
64def CALL_FUNC_STATEMENT():
65 res = ''
66 return res
67

◆ DECP()

test-case-generator.DECP ( )
192def DECP():
193 res = ''
194 return res
195

◆ DO_WHILE_STATEMENT()

test-case-generator.DO_WHILE_STATEMENT ( )
132def DO_WHILE_STATEMENT():
133 global depth
134 depth+=1
135 res = 'do {' + S() + '} while ( ' + BOOLEAN_EXPRESSION() + ') ;'
136 depth-=1
137 return res
138
ThreeOpFunc1 interlocked_compare_exchange ThreeOpFunc2 event_inject_error_code memcpy TwoOpFunc1 ed eb eq interlocked_exchange interlocked_exchange_add TwoOpFunc2 spinlock_lock_custom_wait event_inject OneOpFunc1 poi db dd dw dq neg hi low not check_address disassemble_len disassemble_len32 disassemble_len64 interlocked_increment interlocked_decrement reference physical_to_virtual virtual_to_physical OneOpFunc2 print formats event_enable event_disable event_clear test_statement spinlock_lock spinlock_unlock event_sc OneOpFunc3 strlen TwoOpFunc3 strcmp ThreeOpFunc3 memcmp strncmp ThreeOpFunc4 wcsncmp OneOpFunc4 wcslen TwoOpFunc4 wcscmp ZeroOpFunc1 pause flush event_trace_step event_trace_step_in event_trace_step_out event_trace_instrumentation_step event_trace_instrumentation_step_in VarArgFunc1 printf OperatorsTwoOperand or xor and asr asl add sub mul div mod gt lt egt elt equal neq OperatorsOneOperand inc dec reference dereference SemantiRules start_of_if jmp jz jnz jmp_to_end_and_jzcompleted end_of_if start_of_while end_of_while vargstart mov start_of_do_while start_of_do_while_commands end_of_do_while start_of_for for_inc_dec start_of_for_ommands end_of_if ignore_lvalue push pop call ret Registers rax eax ax ah al rcx ecx cx ch cl rdx edx dx dh dl rbx ebx bx bh bl rsp esp sp spl rbp ebp bp bpl rsi esi si sil rdi edi di dil r8 r8d r8w r8h r8l r9 r9d r9w r9h r9l r10 r10d r10w r10h r10l r11 r11d r11w r11h r11l r12 r12d r12w r12h r12l r13 r13d r13w r13h r13l r14 r14d r14w r14h r14l r15 r15d r15w r15h r15l ds es fs gs cs ss rflags eflags flags cf pf af zf sf tf if df of iopl nt rf vm ac vif vip id rip eip ip idtr ldtr gdtr tr cr0 cr2 cr3 cr4 cr8 dr0 dr1 dr2 dr3 dr6 dr7 PseudoRegisters pid tid pname core proc thread peb teb ip buffer context event_tag event_id event_stage date time S STATEMENT S S
Definition Grammar.txt:51

◆ E0P()

test-case-generator.E0P ( )
212def E0P():
213 r = random.randrange(2)
214
215 global depth
216 depth += 1
217 if depth>=MAX_DEPTH:
218 r = 1
219
220 if r==0:
221 res = ' | ' + E1() + E0P()
222 depth-=1
223 return res
224 elif r==1:
225 res = ''
226 depth-=1
227 return res
228
229

◆ E1()

test-case-generator.E1 ( )
230def E1():
231 global depth
232 depth+=1
233 res = E2() + E1P()
234 depth-=1
235 return res
236

◆ E10()

test-case-generator.E10 ( )
449def E10():
450 global depth
451 depth+=1
452 res = E12()
453 depth-=1
454 return res
455
456
457

◆ E12()

test-case-generator.E12 ( )
458def E12():
459 r=random.randrange(0,8)
460
461 global depth
462 depth += 1
463 if depth>=MAX_DEPTH:
464 r = 1
465
466
467 if r==0:
468 res = '(' + EXPRESSION() + ')'
469 depth-=1
470 return res
471 elif r==1:
472 ri = random.randrange(0,20)
473 res = str(hex(ri)) # hex
474 depth-=1
475 return res
476 elif r==2:
477 ri = random.randrange(0,20)
478 res = '0n' + str(ri) # decimal
479 depth-=1
480 return res
481 elif r==3:
482 ri = random.randrange(0,20)
483 res = str(oct(ri)) # octal
484 depth-=1
485 return res
486 elif r==4:
487 ri = random.randrange(0,20)
488 res = '0y' + str(bin(ri))[2:] # binary
489 depth-=1
490 return res
491 elif r==5:
492 res = '-' + E12() + E13()
493 depth-=1
494 return res
495 elif r==6:
496 res = '+' + E12() + E13()
497 depth-=1
498 return res
499 elif r==7:
500 res = '~' + E12() + E13()
501 depth-=1
502 return res
503 elif r==8:
504 res = '@rax' # register
505 depth-=1
506 return res
507 elif r==9:
508 res = 'x' # id
509 depth-=1
510 return res
511 elif r==10:
512 res = 'pid' # sample pseudo register, can be added more options later
513 depth-=1
514 return res
515

◆ E13()

test-case-generator.E13 ( )
516def E13():
517 res = ''
518 return res
519

◆ E1P()

test-case-generator.E1P ( )
237def E1P():
238 r=random.randrange(2)
239
240 global depth
241 depth += 1
242 if depth>=MAX_DEPTH:
243 r = 1
244
245 if r==0:
246 res = ' ^ ' + E2() + E1P()
247 depth-=1
248 return res
249 elif r==1:
250 res = ''
251 depth-=1
252 return res
253

◆ E2()

test-case-generator.E2 ( )
254def E2():
255 global depth
256 depth+=1
257 res = E3() + E2P()
258 depth-=1
259 return res
260

◆ E2P()

test-case-generator.E2P ( )
261def E2P():
262 r=random.randrange(2)
263
264 global depth
265 depth += 1
266 if depth>=MAX_DEPTH:
267 r = 1
268
269 if r==0:
270 res = ' & ' + E3() + E2P()
271 depth-=1
272 return res
273 elif r==1:
274 res = ''
275 depth-=1
276 return res
277

◆ E3()

test-case-generator.E3 ( )
278def E3():
279 global depth
280 depth+=1
281 res = E4() + E3P()
282 depth-=1
283 return res
284

◆ E3P()

test-case-generator.E3P ( )
285def E3P():
286 r=random.randrange(2)
287
288 global depth
289 depth += 1
290 if depth>=MAX_DEPTH:
291 r = 1
292
293 if r==0:
294 res = ' >> ' + E4() + E3P()
295 depth-=1
296 return res
297 elif r==1:
298 res = ''
299 depth-=1
300 return res
301

◆ E4()

test-case-generator.E4 ( )
302def E4():
303 global depth
304 depth+=1
305 res = E5() + E4P()
306 depth-=1
307 return res
308

◆ E4P()

test-case-generator.E4P ( )
309def E4P():
310 r=random.randrange(2)
311
312 global depth
313 depth += 1
314 if depth>=MAX_DEPTH:
315 r = 1
316
317 if r==0:
318 res = ' << ' + E5() + E4P()
319 depth-=1
320 return res
321 elif r==1:
322 res = ''
323 depth-=1
324 return res
325

◆ E5()

test-case-generator.E5 ( )
326def E5():
327 global depth
328 depth+=1
329 res = E6() + E5P()
330 depth-=1
331 return res
332

◆ E5P()

test-case-generator.E5P ( )
333def E5P():
334 r=random.randrange(2)
335
336 global depth
337 depth += 1
338 if depth>=MAX_DEPTH:
339 r = 1
340
341 if r==0:
342 res = ' + ' + E6() + E5P()
343 depth-=1
344 return res
345 elif r==1:
346 res = ''
347 depth-=1
348 return res
349
350

◆ E6()

test-case-generator.E6 ( )
351def E6():
352 global depth
353 depth+=1
354 res = E7() + E6P()
355 depth-=1
356 return res
357

◆ E6P()

test-case-generator.E6P ( )
358def E6P():
359 r=random.randrange(2)
360
361 global depth
362 depth += 1
363 if depth>=MAX_DEPTH:
364 r = 1
365
366 if r==0:
367 res = ' - ' + E7() + E6P()
368 depth-=1
369 return res
370 elif r==1:
371 res = ''
372 depth-=1
373 return res
374

◆ E7()

test-case-generator.E7 ( )
375def E7():
376 global depth
377 depth+=1
378 res = E8() + E7P()
379 depth-=1
380 return res
381

◆ E7P()

test-case-generator.E7P ( )
382def E7P():
383 r=random.randrange(2)
384
385 global depth
386 depth += 1
387 if depth>=MAX_DEPTH:
388 r = 1
389
390 if r==0:
391 res = ' * ' + E8() + E7P()
392 depth-=1
393 return res
394 elif r==1:
395 res = ''
396 depth-=1
397 return res
398
399

◆ E8()

test-case-generator.E8 ( )
400def E8():
401 global depth
402 depth+=1
403 res = E9() + E8P()
404 depth-=1
405 return res
406

◆ E8P()

test-case-generator.E8P ( )
407def E8P():
408 r=random.randrange(2)
409
410 global depth
411 depth += 1
412 if depth>=MAX_DEPTH:
413 r = 1
414
415 if r==0:
416 res = ' / ' + E9() + E8P()
417 depth-=1
418 return res
419 elif r==1:
420 res = ''
421 depth-=1
422 return res
423
424

◆ E9()

test-case-generator.E9 ( )
425def E9():
426 global depth
427 depth+=1
428 res = E10() + E9P()
429 depth-=1
430 return res
431

◆ E9P()

test-case-generator.E9P ( )
432def E9P():
433 r=random.randrange(2)
434
435 global depth
436 depth += 1
437 if depth>=MAX_DEPTH:
438 r = 1
439
440 if r==0:
441 res = ' % ' + E10() + E9P()
442 depth-=1
443 return res
444 elif r==1:
445 res = ''
446 depth-=1
447 return res
448

◆ ELSE_STATEMENT()

test-case-generator.ELSE_STATEMENT ( )
104def ELSE_STATEMENT():
105 r=random.randrange(2)
106
107 global depth
108 depth += 1
109 if depth>=MAX_DEPTH:
110 r = 1
111
112 if r==0:
113 res = 'else {' + S() + '}'
114 depth-=1
115 return res
116 elif r==1:
117 res = ''
118 depth-=1
119 return res
120

◆ ELSIF_STATEMENT()

test-case-generator.ELSIF_STATEMENT ( )
83def ELSIF_STATEMENT():
84 r=random.randrange(2)
85
86 global depth
87 depth += 1
88 if depth>=MAX_DEPTH:
89 r = 1
90
91 if r==0:
92 res = 'elsif (' + BOOLEAN_EXPRESSION() + ') {' + S() + '}' + ELSIF_STATEMENT()
93 depth-=1
94 return res
95 elif r==1:
96 res = ELSIF_STATEMENTP()
97 depth-=1
98 return res
99

◆ ELSIF_STATEMENTP()

test-case-generator.ELSIF_STATEMENTP ( )
100def ELSIF_STATEMENTP():
101 res = ''
102 return res
103

◆ END_OF_IF()

test-case-generator.END_OF_IF ( )
121def END_OF_IF():
122 res = ''
123 return res
124

◆ evaluate()

test-case-generator.evaluate ( s)
537def evaluate(s):
538 s2 = s.replace('0n','').replace('0y','0b').replace('/','//')
539 v = '$error$'
540
541 try:
542 v = eval(s2)
543 v = tohex(v, 64)
544 v = v.replace('0x', '')
545 except:
546 pass
547 return v
548
549
550'''
551if __name__ == '__main__':
552# global depth
553
554 f = open('script-test-cases.txt', 'w')
555 counter = 1
556
557 initCounter = counter
558 while counter-initCounter<1000:
559 depth = 0
560 sentence = EXPRESSION()
561 if len(sentence)<=150:
562 res = 'x = ' + sentence + '; test_statement(x);'
563 val = evaluate(sentence)
564 if type(val)=='int' and not(abs(val)<=65536):
565 continue
566 f.write(str(counter)+'\n')
567 f.write(res+'\n')
568 f.write(str(val)+'\n')
569 f.write('$end$'+'\n')
570 print(counter)
571 print(res)
572 print(val)
573 print()
574 counter+=1
575
576 f.close()
577'''

◆ EXPRESSION()

test-case-generator.EXPRESSION ( )
205def EXPRESSION():
206 global depth
207 depth+=1
208 res = E1() + E0P()
209 depth-=1
210 return res
211

◆ FOR_STATEMENT()

test-case-generator.FOR_STATEMENT ( )
139def FOR_STATEMENT():
140 global depth
141 depth+=1
142 res = 'for (' + SIMPLE_ASSIGNMENT() + '; ' + BOOLEAN_EXPRESSION() + ';' + INC_DEC() + ') { ' + S() + '}'
143 depth-=1
144 return res
145

◆ IF_STATEMENT()

test-case-generator.IF_STATEMENT ( )
76def IF_STATEMENT():
77 global depth
78 depth+=1
79 res = 'if (' + BOOLEAN_EXPRESSION() +') {' + S() + '}' + ELSIF_STATEMENT() + ELSE_STATEMENT() + END_OF_IF()
80 depth-=1
81 return res
82

◆ INC_DEC()

test-case-generator.INC_DEC ( )
167def INC_DEC():
168 global depth
169 depth+=1
170 res = L_VALUE() + INC_DECP()
171 depth-=1
172 return res
173

◆ INC_DECP()

test-case-generator.INC_DECP ( )
174def INC_DECP():
175 global depth
176 depth+=1
177 res = '++' + INCP()
178 depth-=1
179 return res
180

◆ INCP()

test-case-generator.INCP ( )
188def INCP():
189 res = ''
190 return res
191

◆ L_VALUE()

test-case-generator.L_VALUE ( )
520def L_VALUE():
521 r = random.randrange(2)
522
523 if r==0:
524 res = 'x' # id
525 return res
526 elif r==1:
527 res = '@rax' # register
528 return res
529

◆ NULL()

test-case-generator.NULL ( )
530def NULL():
531 res = ''
532 return res
533

◆ S()

test-case-generator.S ( )
7def S():
8 r = random.randrange(2)
9
10
11 global depth
12 depth += 1
13 if depth>=MAX_DEPTH:
14 r = 1
15
16 if r==0:
17 res = STATEMENT() + ' ' + S()
18 depth -= 1
19 return res
20 elif r==1:
21 res = ''
22 depth -= 1
23 return res
24

◆ SIMPLE_ASSIGNMENT()

test-case-generator.SIMPLE_ASSIGNMENT ( )
146def SIMPLE_ASSIGNMENT():
147 r=random.randrange(2)
148
149 global depth
150 depth += 1
151 if depth>=MAX_DEPTH:
152 r = 1
153
154 if r==0:
155 res = L_VALUE() + '= ' + EXPRESSION() + SIMPLE_ASSIGNMENTP()
156 depth-=1
157 return res
158 elif r==1:
159 res = ''
160 depth-=1
161 return res
162

◆ SIMPLE_ASSIGNMENTP()

test-case-generator.SIMPLE_ASSIGNMENTP ( )
163def SIMPLE_ASSIGNMENTP():
164 res = ''
165 return res
166

◆ STATEMENT()

test-case-generator.STATEMENT ( )
25def STATEMENT():
26 r = random.randrange(8)
27
28 global depth
29 depth += 1
30
31 if r==0:
32 res = IF_STATEMENT()
33 depth -= 1
34 return res
35 elif r==1:
36 res = WHILE_STATEMENT()
37 depth -= 1
38 return res
39 elif r==2:
40 res = DO_WHILE_STATEMENT()
41 depth-=1
42 return res
43 elif r==3:
44 res = FOR_STATEMENT()
45 depth-=1
46 return res
47 elif r== 4:
48 res = ASSIGN_STATEMENT() + ";"
49 depth-=1
50 return res
51 elif r== 5:
52 res = CALL_FUNC_STATEMENT() + ";"
53 depth-=1
54 return res
55 elif r== 6:
56 res = "break ;"
57 depth-=1
58 return res
59 elif r== 7:
60 res = "continue ;"
61 depth-=1
62 return res
63

◆ tohex()

test-case-generator.tohex ( val,
nbits )
534def tohex(val, nbits):
535 return hex((val + (1 << nbits)) % (1 << nbits))
536

◆ WHILE_STATEMENT()

test-case-generator.WHILE_STATEMENT ( )
125def WHILE_STATEMENT():
126 global depth
127 depth+=1
128 res = 'while (' + BOOLEAN_EXPRESSION() + ') { ' + S() + ' }'
129 depth-=1
130 return res
131

Variable Documentation

◆ counter

int test-case-generator.counter = 1

◆ depth

int test-case-generator.depth = 0

◆ f

test-case-generator.f = open('script-test-cases.txt', 'w')

◆ initCounter

int test-case-generator.initCounter = counter

◆ MAX_DEPTH

int test-case-generator.MAX_DEPTH = 20

◆ res

test-case-generator.res = sentence

◆ sentence

test-case-generator.sentence = FOR_STATEMENT()

◆ val

test-case-generator.val = evaluate(sentence)