77import hashlib
88
99# Anti-error: https://stackoverflow.com/questions/15063936/csv-error-field-larger-than-field-limit-131072
10- csv .field_size_limit (sys .maxsize )
10+ # csv.field_size_limit(sys.maxsize)
1111
1212
1313def cls ():
1414 """Clear console"""
1515 os .system ('cls' if os .name == 'nt' else 'clear' )
1616
17-
1817def numProcs (reportname ):
1918 """Number of created processes by executable in report"""
2019 with open (reportname , "rb" ) as f :
@@ -66,7 +65,6 @@ def sort(leg=True, reportsDir = "./reports/"):
6665 print ("Filename: " , f )
6766 print ("Progress: {0}/{1}. One process files: {2}. Broken: {3}" .format (i , len (dirFiles ), num , broken ))
6867
69-
7068def dataStats (reportsDir = "./reports/" ):
7169 """Statistics about number of reports"""
7270 legMulti = glob .glob (reportsDir + "/leg/*.json" )
@@ -83,7 +81,7 @@ def dataStats(reportsDir = "./reports/"):
8381 print ("""Malicious files:
8482 Total: {0}, One-proc: {1}, Multi-proc: {2}, Broken: {3} """
8583 .format (len (malBroken + malMulti + malOne ), len (malOne ), len (malMulti ), len (malBroken )))
86- print ("Woking samples: {0}" .format (len (malMulti + malOne + legMulti + legOne )))
84+ print ("Working samples: {0}" .format (len (malMulti + malOne + legMulti + legOne )))
8785
8886def parseReport (report , numAPIs = None ):
8987 numProcesses = numProcs (report )
@@ -104,7 +102,6 @@ def parseReport(report, numAPIs=None):
104102 #returns = " ".join(returns)
105103 yield apis #, statuses, returns
106104
107-
108105def collectDataset (saveto = 'data.csv' , reportsDir = "./reports/" , append = False , limitNumAPI = None ):
109106 csvData = [['Malicious' , 'API Calls' ],]#, 'Statuses', 'Returns'],]
110107 csvFile = open (saveto , 'w' )
@@ -132,7 +129,6 @@ def collectDataset(saveto='data.csv', reportsDir = "./reports/", append=False, l
132129 writer .writerows ([["1" , apis ]])#, statuses, returns]])
133130 csvFile .close ()
134131
135-
136132def countProcesses (reportsDir = "./reports/" , printProcNum = 4 , skipLegal = False ):
137133 """Count processes in reports and print reports with provided number of processes
138134 Also write to reports/malprocs.json the malicious files and the number of procs to analyze them manually"""
@@ -180,7 +176,6 @@ def countProcesses(reportsDir = "./reports/", printProcNum = 4, skipLegal=False)
180176 print ("In Malicious reports: {0}" .format (malProcNum ))
181177 print ("Total: {0}" .format ({ k : legalProcNum .get (k , 0 ) + malProcNum .get (k , 0 ) for k in set (legalProcNum ) | set (malProcNum ) }))
182178
183-
184179def hashSortAPI (data , saveto ):
185180 csvData = [['Malicious' , 'API Calls' ],]
186181 saveFile = open (saveto , mode = 'w+' )
0 commit comments