#!/usr/bin/env python import os, re, string, sys, fnmatch def dirSourceScanner(): path= "." joinedList = [] for files in os.listdir(path): if fnmatch.fnmatch(files, '*.es'): joinedList.extend(files.split()) try: for eachFile in joinedList: fObj = open(eachFile, 'r') incorrect = [] for lines in fObj: lines = lines.strip() incFilter = re.findall('^\w+\s+=\s+', lines) for variables in incFilter: if variables: items = string.replace(variables, ' = ', '') incorrect.extend(items.split()) elif not variables: print '[+]No variables found.' sys.exit(0) elif len(variables) <= 0: print '[+]Incorrect variable declaration not found. Program terminating.' sys.exit(0) fObj.close() except IOError: print 'Exception occurred' try: fObj2 = open(eachFile, 'r') correct = [] for lines in fObj2: lines = lines.strip() incFilter = re.findall('var\ \w+', lines) for variables in incFilter: if variables: items = string.replace(variables, 'var ', '') correct.extend(items.split()) elif not variables: print '[+]No variables found.' sys.exit(0) elif len(variables) <= 0: print '[+]No variable initialization keyword found.' fObj2.close() except IOError: print 'Exception occurred' print '\n[+]Source File : ', eachFile print '[+]Parsing Result :' print '.......................................' diffResult = list(set(incorrect).difference(correct)) if len(diffResult) > 0: print '[+]Probably these are the incorrect variables names list:' for unInit in diffResult: print ' >>', str(unInit) else: print '[+]No variable initialization errors found in this script.\n' def banner(): print '###########################################################' print '[*]Variable Declaration Type Scanner #' print '[*]Author: Sujit Ghosal #' print '###########################################################' def usage(): print '[+]Usage: xylux ~/codesamples $sudo chmod a+x parser.py [For Unix]' print '[+]Usage: xylux ~/codesamples $python parser.py [For Unix]' print '[+]Usage: C:\CodeSamples\python parser.py [For Windows]' def main(): if not len(sys.argv) == 1: banner() usage() sys.exit(0) else: banner() dirSourceScanner() print '\n\n[+]File parsing completed.' if __name__ == "__main__": main()