File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ # Generate some sample CMD scripts to aid with debugging.
2+
3+ import random
4+ import sys
5+
6+ # Number of functions to generate.
7+ NUM_FUNCTIONS = 30
8+
9+ # Maximum number of LoC to generate.
10+ MAX_LENGTH = 100
11+
12+ # Probability for any line of code to be a call to a random function.
13+ CALL_PROBABILITY = 0.05
14+
15+ # Probability for any function to not terminate with "exit /b 0", which
16+ # results in a "nested" link in cmd-call-graph
17+ NESTED_PROBABILITY = 0.01
18+
19+ functions = [u"function{}" .format (i ) for i in range (NUM_FUNCTIONS )]
20+
21+ code = [u"@echo off" , u"call :function0" , u"exit /b 0" ]
22+
23+ for function in functions :
24+ code .append (":{}" .format (function ))
25+ loc = random .randint (1 , MAX_LENGTH )
26+
27+ for i in range (loc ):
28+ if random .random () < CALL_PROBABILITY :
29+ target = random .choice (functions )
30+ code .append (u" call :{}" .format (target ))
31+ else :
32+ code .append (u" ; some code goes here." )
33+
34+ if random .random () > NESTED_PROBABILITY :
35+ code .append (u"exit /b 0" )
36+
37+ if len (sys .argv ) > 1 :
38+ with open (sys .argv [1 ], "w" ) as f :
39+ f .write (u"\n " .join (code ))
40+ else :
41+ print (u"\n " .join (code ))
You can’t perform that action at this time.
0 commit comments