admin管理员组

文章数量:1194611

I'm learning Boofuzz, and it would be convenient to be able to convert between a boofuzz.Block and an arbitrary custom python object. This is especially the case when encoding. I'm hopeful this example explains what I'm trying to do:

class MyClass:
    def __init__(self, header, data, footer):
        self.header = header
        self.data = data
        self.footer = footer

bf_block = boofuzz.Block('Block-Instance', children=(
    boofuzz.Group('Header', values=['foo', 'bar']),
    boofuzz.RandomData('Data', min_length=1, max_length=20),
    boofuzz.Group('Footer', values=['spam', 'spam', 'spam', 'egg', 'spam'])
))

#How do I tell boofuzz to use this method for encode instead?
def encode_to_override(bf_block):
    #How do I access block members like this?
    class_instance = MyClass(bf_block.header, bf_block.data, bf_block.footer)
    encode(class_instance)

def encode(class_instance):
    #I'll be doing something more complicated than this:
    return bytes(class_instance.header) + bytes(class_instance.data) + bytes(class_instance.footer)

I was able to make the block using the second block of code in this example, and successfully run fuzz(). However, I don't know how to override encode without using a custom block, so it was only encoded using the default method.

本文标签: pythonTrying to learn how encoding works in BoofuzzStack Overflow