Example #1
0
import ast
import astor
import inspect

if __name__ == "__main__":
    triangle_source = inspect.getsource(triangle)
    triangle_source

if __package__ is None or __package__ == "":
    from fuzzingbook_utils import print_content
else:
    from .fuzzingbook_utils import print_content

if __name__ == "__main__":
    print_content(triangle_source, '.py')

if __name__ == "__main__":
    triangle_ast = ast.parse(triangle_source)

if __name__ == "__main__":
    print(astor.dump_tree(triangle_ast))

if __package__ is None or __package__ == "":
    from fuzzingbook_utils import rich_output
else:
    from .fuzzingbook_utils import rich_output

if __name__ == "__main__":
    if rich_output():
        import showast
Example #2
0
if __name__ == "__main__":
    cgi_decode_traced("a+b")
    print(coverage)

import inspect

if __name__ == "__main__":
    cgi_decode_code = inspect.getsource(cgi_decode)

if __package__ is None or __package__ == "":
    from fuzzingbook_utils import print_content, print_file
else:
    from .fuzzingbook_utils import print_content, print_file

if __name__ == "__main__":
    print_content(cgi_decode_code[:300] + "...", ".py")

if __name__ == "__main__":
    cgi_decode_lines = [""] + cgi_decode_code.splitlines()

if __name__ == "__main__":
    cgi_decode_lines[1]

if __name__ == "__main__":
    cgi_decode_lines[9:13]

if __name__ == "__main__":
    cgi_decode_lines[15]

if __name__ == "__main__":
    covered_lines = set(coverage)
import astor

if __package__ is None or __package__ == "":
    from fuzzingbook_utils import print_content
else:
    from .fuzzingbook_utils import print_content


if __name__ == "__main__":
    source = inspect.getsource(cgi_decode)
    node = ast.parse(source)
    BranchTransformer().visit(node)

    # Make sure the line numbers are ok before printing
    node = ast.fix_missing_locations(node)
    print_content(astor.to_source(node), '.py')


def create_instrumented_function(f):
    source = inspect.getsource(f)
    node = ast.parse(source)
    node = BranchTransformer().visit(node)

    # Make sure the line numbers are ok so that it compiles
    node = ast.fix_missing_locations(node)

    # Compile and add the instrumented function to the current module
    current_module = sys.modules[__name__]
    code = compile(node, filename="<ast>", mode="exec")
    exec(code, current_module.__dict__)
Example #4
0
import ast
import inspect
import astor

if __name__ == "__main__":
    my_sqrt_source = inspect.getsource(my_sqrt)
    my_sqrt_source

if __package__ is None or __package__ == "":
    from fuzzingbook_utils import print_content
else:
    from .fuzzingbook_utils import print_content

if __name__ == "__main__":
    print_content(my_sqrt_source, '.py')

if __name__ == "__main__":
    my_sqrt_ast = ast.parse(my_sqrt_source)

if __name__ == "__main__":
    print(astor.dump_tree(my_sqrt_ast))

if __package__ is None or __package__ == "":
    from fuzzingbook_utils import rich_output
else:
    from .fuzzingbook_utils import rich_output

if __name__ == "__main__":
    if rich_output():
        import showast