Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken after upgrading to Python 3.8 #1092

Closed
htfy96 opened this issue Nov 16, 2019 · 0 comments · Fixed by #1093
Closed

Broken after upgrading to Python 3.8 #1092

htfy96 opened this issue Nov 16, 2019 · 0 comments · Fixed by #1093

Comments

@htfy96
Copy link
Contributor

htfy96 commented Nov 16, 2019

Version: 0.1.1.dev192

Possibly related to changes to AST in 3.8

See also: pallets/werkzeug#1551
Their fix is to change ast.Module to ast.parse: https://github.com/pallets/werkzeug/pull/1552/files

tests/test_worklist.py:46: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests/test_worklist.py:29: in get_simplified_ircfg
    machine = Machine(cont.arch)
.env/lib/python3.8/site-packages/miasm/analysis/machine.py:126: in __init__
    from miasm.arch.x86 import jit
.env/lib/python3.8/site-packages/miasm/arch/x86/jit.py:5: in <module>
    from miasm.arch.x86.sem import ir_x86_16, ir_x86_32, ir_x86_64
.env/lib/python3.8/site-packages/miasm/arch/x86/sem.py:429: in <module>
    def xchg(arg1, arg2):
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <miasm.core.sembuilder.SemBuilder object at 0x7ff32d7d8ca0>, func = <function xchg at 0x7ff32d7e1e50>

    def parse(self, func):
        """Function decorator, returning a correct method from a pseudo-Python
        one"""
    
        # Get the function AST
        parsed = ast.parse(inspect.getsource(func))
        fc_ast = parsed.body[0]
        argument_names = [get_arg_name(name) for name in fc_ast.args.args]
    
        # Init local cache
        self._local_ctx = {}
    
        # Translate (blocks[0][0] is the current instr)
        blocks, body = self._parse_body(fc_ast.body, argument_names)
    
        # Build the new function
        fc_ast.args.args[0:0] = [
            gen_arg('ir', ast.Param()),
            gen_arg('instr', ast.Param())
        ]
        cur_instr = blocks[0][0]
        if len(blocks[-1][0]) == 0:
            ## Last block can be empty
            blocks.pop()
        other_blocks = blocks[1:]
        body.append(ast.Return(value=ast.Tuple(elts=[ast.List(elts=cur_instr,
                                                              ctx=ast.Load()),
                                                     ast.List(elts=other_blocks,
                                                              ctx=ast.Load())],
                                               ctx=ast.Load())))
    
        ret = ast.Module([ast.FunctionDef(name=fc_ast.name,
                                          args=fc_ast.args,
                                          body=body,
                                          decorator_list=[])])
    
        # To display the generated function, use codegen.to_source
        # codegen: https://github.com/andreif/codegen
    
        # Compile according to the context
        fixed = ast.fix_missing_locations(ret)
>       codeobj = compile(fixed, '<string>', 'exec')
E       TypeError: required field "type_ignores" missing from Module

.env/lib/python3.8/site-packages/miasm/core/sembuilder.py:349: TypeError
htfy96 added a commit to htfy96/miasm that referenced this issue Nov 16, 2019
Python3.8 changes the signature of ast.Module by adding a
ignore_comment field which breaks this project. ast.parse("")
is a dirty but more compatible way to make it work in both
Python 3.8 and <3.8.

Fixed cea-sec#1092
w4kfu pushed a commit to w4kfu/miasm that referenced this issue Jun 16, 2020
Python3.8 changes the signature of ast.Module by adding a
ignore_comment field which breaks this project. ast.parse("")
is a dirty but more compatible way to make it work in both
Python 3.8 and <3.8.

Fixed cea-sec#1092
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant