Python-递归错误不返回字符串变量

时间:2019-03-17 17:51:08

标签: python string recursion path

我正在构建一个Python应用程序,该程序可以搜索具有给定路径的文件并返回它们。

这是代码:

def search(path):
    name = 'filename'
    files = os.listdir(path)
    for filename in files:
        fullname = os.path.join(path, filename)
        if name in fullname and 'rat' not in fullname:
            print(colored('[*] Found: '+fullname+' [*]','blue'))
            return ''+fullname
        elif os.path.isdir(fullname):
            return search(fullname)

当我运行这段代码时:

path = search('output/host/smali/')
code = 'invoke-super {p0, p1}, Lcom/example/rat/activity/MainActivity;->onCreate(Landroid/os/Bundle;)V'
into = 'invoke-static,onCreate'
print(path+' '+code+' '+into)

应用程序启动此异常:

Traceback (most recent call last):
  File "./bane.py", line 48, in <module>
    login(creds[0],creds[1])
  File "./bane.py", line 16, in login
    bane = baneshell(username)
  File "/mnt/c/Users/stecco/Desktop/bane/baneshell.py", line 16, in __init__
    self.start()
  File "/mnt/c/Users/stecco/Desktop/bane/baneshell.py", line 36, in start
    self.execute(command)
  File "/mnt/c/Users/stecco/Desktop/bane/baneshell.py", line 26, in execute
    rat.rat(self.username)
  File "/mnt/c/Users/stecco/Desktop/bane/modules/rat/rat.py", line 13, in __init__
    self.start()
  File "/mnt/c/Users/stecco/Desktop/bane/modules/rat/rat.py", line 18, in start
    self.execute(command)
  File "/mnt/c/Users/stecco/Desktop/bane/modules/rat/rat.py", line 42, in execute
    inject.inject(command.replace('inject',''),self.address,self.port)
  File "/mnt/c/Users/stecco/Desktop/bane/modules/rat/rat_modules/injector.py", line 101, in inject
    injectcode(address,port)
  File "/mnt/c/Users/stecco/Desktop/bane/modules/rat/rat_modules/injector.py", line 75, in injectcode
    print(path+' '+code+' '+into)
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

更新:代码在返回全名变量之前在方法搜索中不打印任何内容

0 个答案:

没有答案