0

我正在用 Python 进行这个模糊测试,但我有一些问题。当我编译这段代码时,我有下一个错误:

Traceback (most recent call last): 
  File "vm_main.py", line 33, in <module> 
    import main 
  File "/tmp/vmuser_tgqlkfrnov/main.py", line 44 
    return fuzzit 
SyntaxError: 'return' outside function

我可以给点建议吗?

这是我的代码:

import array

import random

import math

content = """
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Phasellus sollicitudin condimentum libero,
sit amet ultrices lacus faucibus nec.
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Cum sociis natoque penatibus et magnis dis parturient montes,
nascetur ridiculus mus. Cras nulla nisi, accumsan gravida commodo et,
venenatis dignissim quam. Mauris rutrum ullamcorper consectetur.
Nunc luctus dui eu libero fringilla tempor. Integer vitae libero purus.
Fusce est dui, suscipit mollis pellentesque vel, cursus sed sapien.
Duis quam nibh, dictum ut dictum eget, ultrices in tortor.
In hac habitasse platea dictumst. Morbi et leo enim.
Aenean ipsum ipsum, laoreet vel cursus a, tincidunt ultrices augue.
Aliquam ac erat eget nunc lacinia imperdiet vel id nulla."""


def fuzzit(content):

    buf = bytearray(content)
    strlst = list()

    for j in range(numwrites):
        rbyte = random.randrange(256)
        rn = random.randrange(len(buf))
        buf[rn] = "%c" %(rbyte)
        strlst[i] = array.tostring(buf)
fuzzed = strlst[:]
return fuzzit

谢谢!!!

4

2 回答 2

2

Python 使用缩进设置它的结构而不是花括号。您return需要缩进以与您的for陈述保持一致。

从外观上看,您似乎正试图fuzzit在 .py 中返回该方法?这在 python 中是不可能的,你想做什么?

于 2012-08-21T08:35:28.800 回答
1

我不确定你是否理解 Fredrik 关于缩进的理解。看起来你的 strlst 是你想要返回的。尝试这个

for j in range(numwrites):
    rbyte = random.randrange(256)
    rn = random.randrange(len(buf))
    buf[rn] = "%c" %(rbyte)
    strlst[i] = array.tostring(buf)
return strlst[:]
于 2012-08-21T13:17:00.847 回答