def getModules(): typeName = 'modules' modules = [] for moduleName in config.getSections(typeName, typeName): modules.append(getModule(moduleName)) return modules
def import_modules(): """ Put docstring here """ modules_dict = utils.parser_xml("conf/config.xml", "modules", "config") modules = [] for module in modules_dict: modules.append("modules." + module["name"]) map(__import__, modules)
def parseArguments(args): """ Parses the given arguments. Returns the list of modules and targets to be created and used during the execution. """ global verbose global n i = 0 modules = [] targets = [] writeln("parsing command line arguments...") while (i < len(args)): name, value = args[i] if (name in ("help","h","?","/help","/h","/?")): help() elif (name in ("module", "m")): try: m = importlib.import_module("modules.{0}".format(value)) m = m.Module() m.parseArguments(args) modules.append(m) except ImportError: fatalError("Module {0} cannot be found. Please make sure the module is in folder modules and has the same name (excluding the .py suffix) as the module you are trying to use.".format(value)) elif (name in ("target", "t")): try: t = importlib.import_module("targets.{0}".format(value)) t = t.Target() t.parseArguments(args) targets.append(t) except ImportError: fatalError("Target {0} cannot be found. Please make sure the target is in folder targets and has the same name (excluding the .py suffix) as the target you are trying to use.".format(value)) elif (name in ("verbose", "v")): if (verbose != None): fatalError("Verbosity can only be set once") verbose = True if value else False writeln(" verbosity set to {0}".format(verbose)) elif (name in ("nthreads", "n")): if (n != None): fatalError("Number of threads can only be set once. ") n = int(value) writeln(" number of threads set to {0}".format(n)) else: i += 1 continue args.pop(i) if (verbose == None): verbose = False if (n == None): n = 1 return (modules, targets)
def wire(self, modules, query, model): if not isinstance(query, tuple): position = len(modules) module = model.get_module(position, query, 0, self.input_module.output_name, []) modules.append(module) else: head = query[0] tail = query[1:] arity = len(tail) children = [self.wire(modules, tail_query, model) for tail_query in tail] position = len(modules) module = model.get_module(position, query[0], arity, self.input_module.output_name, children) modules.append(module) return module.output_name
def analyze(input, profile): (fd, filename) = tempfile.mkstemp() engine = PHPEngine() try: tfile = os.fdopen(fd, "wb") tfile.write(input.encode("utf-8")) tfile.close() profileMap = profiles.getProfiles() if profile in profileMap: profile = profileMap[profile] else: return None, [], {}, False stats = dict() taintedSink = [] CFGForest = engine.generateCFG(filename) for i, traversal in enumerate(profile): stats[i] = dict() traversalName = traversal['traversal'] traverser = __import__("Traverser.%s" % traversalName) traverser = traverser.__dict__[traversalName].__dict__[ traversalName]() modules = [] for module in traversal['modules']: temp = importlib.import_module(module[0]) className = getAnalyzerClassName(temp) name = temp.name temp = temp.__dict__[className]() modules.append({'module': name, 'object': temp}) traverser.addVisitor(temp) try: CFGForest = traverser.traverseForest(CFGForest) finally: for x, module in enumerate(modules): stats[i][x] = module['object'].analyzedLines.keys() if "taintedSink" in module['object'].__dict__: taintedSink = module['object'].taintedSink return CFGForest, taintedSink, stats, False except Exception as e: print e return None, [], {}, e finally: os.remove(filename)
def wire(self, modules, query, model): if not isinstance(query, tuple): position = len(modules) module = model.get_module( position, query, 0, self.input_module.output_name, []) modules.append(module) else: head = query[0] tail = query[1:] arity = len(tail) children = [self.wire(modules, tail_query, model) for tail_query in tail] position = len(modules) module = model.get_module( position, query[0], arity, self.input_module.output_name, children) modules.append(module) return module.output_name