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

Impossibility to parse C type #4624

Open
Voxanimus opened this issue May 8, 2024 · 5 comments
Open

Impossibility to parse C type #4624

Voxanimus opened this issue May 8, 2024 · 5 comments
Labels
bug Something is broken

Comments

@Voxanimus
Copy link

Description

For a project I have to add new types.
I add a first types like this:

    tc_ns_client_return = angr.types.parse_types("""
                                typedef struct
                                {
                                    unsigned int code;
                                    unsigned int origin;
                                } TC_NS_ClientReturn;
                            """)
    angr.types.register_types(tc_ns_client_return)

I need to add a second type that look like this:

    tc_ns_client_login = angr.types.parse_types("""
                                typedef struct
                                {
                                    unsigned int method;
                                    unsigned int mdata;
                                } TC_NS_ClientLogin;
                            """)
    angr.types.register_types(tc_ns_client_login)

So a very similar element and for some reason I cannot parse the type. I get the following backtrace:

Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/src/trustdymbex/__main__.py", line 479, in <module>
    main(sys.argv[1])
  File "/src/trustdymbex/__main__.py", line 459, in main
    tcparams.add_tc_params()
  File "/src/trustdymbex/tcparams.py", line 15, in add_tc_params
    tc_ns_client_login = angr.types.parse_types("""
  File "/usr/local/lib/python3.10/dist-packages/angr/sim_type.py", line 1484, in parse_types
    return parse_file(defn, preprocess=preprocess)[1]
  File "/usr/local/lib/python3.10/dist-packages/angr/sim_type.py", line 1502, in parse_file
    node = pycparser.c_parser.CParser().parse(preamble + defn)
  File "/usr/local/lib/python3.10/dist-packages/angr/sim_type.py", line 1570, in parse
    return self.cparser.parse(
  File "/usr/local/lib/python3.10/dist-packages/pycparser/ply/yacc.py", line 331, in parse
    return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
  File "/usr/local/lib/python3.10/dist-packages/pycparser/ply/yacc.py", line 1199, in parseopt_notrack
    tok = call_errorfunc(self.errorfunc, errtoken, self)
  File "/usr/local/lib/python3.10/dist-packages/pycparser/ply/yacc.py", line 193, in call_errorfunc
    r = errorfunc(token)
  File "/usr/local/lib/python3.10/dist-packages/pycparser/c_parser.py", line 1931, in p_error
    self._parse_error(
  File "/usr/local/lib/python3.10/dist-packages/pycparser/plyparser.py", line 67, in _parse_error
    raise ParseError("%s: %s" % (coord, msg))
pycparser.plyparser.ParseError: :60:16: before: <
make: *** [Makefile:20: run-trustdymbex] Error 1

And If I try to replace the second parsing by the exact same as the first one. I get the same error I don't understand what is going on. Either it's a bug in how things are parsed either I made a mistake.

Steps to reproduce the bug

No response

Environment

No response

Additional context

No response

@Voxanimus Voxanimus added bug Something is broken needs-triage Issue has yet to be looked at by a maintainer labels May 8, 2024
@Voxanimus
Copy link
Author

Voxanimus commented May 8, 2024

I figured out that after registering a type the parsing wasn't working anymore but If I add all the types I want to add in the same parse_types then I can register all types at once. Is it suppose to behave like this ?

@rhelmot rhelmot added question Issues that do not require code changes bug Something is broken and removed bug Something is broken needs-triage Issue has yet to be looked at by a maintainer question Issues that do not require code changes labels May 8, 2024
@rhelmot
Copy link
Member

rhelmot commented May 8, 2024

I think this is an angr bug, but I can't reproduce it from the snippets you've posted. Can you post a) the output of python -m angr.misc.bug_report and b) a python file for which running it will cause that crash?

@Voxanimus
Copy link
Author

a)

angr environment report
=============================
Date: 2024-05-14 15:45:21.021396
Running in virtual environment at /home/Voxa/.virtualenvs/hexhive
/home/Voxa/.virtualenvs/hexhive/lib/python3.12/site-packages/angr/misc/bug_report.py:88: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  import pkg_resources  # pylint:disable=import-outside-toplevel
Platform: linux-x86_64
Python version: 3.12.3 (main, Apr 23 2024, 09:16:07) [GCC 13.2.1 20240417]
######## angr #########
Python found it in /home/Voxa/.virtualenvs/hexhive/lib/python3.12/site-packages/angr/__init__.py
Pip version angr 9.2.94
Couldn't find git info
######## ailment #########
Python found it in /home/Voxa/.virtualenvs/hexhive/lib/python3.12/site-packages/ailment/__init__.py
Pip version ailment 9.2.94
Couldn't find git info
######## cle #########
Python found it in /home/Voxa/.virtualenvs/hexhive/lib/python3.12/site-packages/cle/__init__.py
Pip version cle 9.2.94
Couldn't find git info
######## pyvex #########
Python found it in /home/Voxa/.virtualenvs/hexhive/lib/python3.12/site-packages/pyvex/__init__.py
Pip version pyvex 9.2.94
Couldn't find git info
######## claripy #########
Python found it in /home/Voxa/.virtualenvs/hexhive/lib/python3.12/site-packages/claripy/__init__.py
Pip version claripy 9.2.94
Couldn't find git info
######## archinfo #########
Python found it in /home/Voxa/.virtualenvs/hexhive/lib/python3.12/site-packages/archinfo/__init__.py
Pip version archinfo 9.2.94
Couldn't find git info
######## z3 #########
Python found it in /home/Voxa/.virtualenvs/hexhive/lib/python3.12/site-packages/z3/__init__.py
Pip version z3-solver 4.10.2.0
Couldn't find git info
######## unicorn #########
Python found it in /home/Voxa/.virtualenvs/hexhive/lib/python3.12/site-packages/unicorn/__init__.py
Pip version unicorn 2.0.1.post1
Couldn't find git info
######### Native Module Info ##########
angr: <CDLL '/home/Voxa/.virtualenvs/hexhive/lib/python3.12/site-packages/angr/state_plugins/../lib/angr_native.so', handle 5df704c4ec60 at 0x79d547fd8f20>
unicorn: <CDLL '/home/Voxa/.virtualenvs/hexhive/lib/python3.12/site-packages/unicorn/lib/libunicorn.so.2', handle 5df7046362c0 at 0x79d54dad1940>
pyvex: <cffi.api._make_ffi_library.<locals>.FFILibrary object at 0x79d54bc1f770>
z3: <CDLL '/home/Voxa/.virtualenvs/hexhive/lib/python3.12/site-packages/z3/lib/libz3.so', handle 5df7042a9f40 at 0x79d54e0b74d0>

b) I think this is due to the running environment that is a docker. If I try to run the same things outside of it is working well. I don't really know how the docker env is set up.

@rhelmot
Copy link
Member

rhelmot commented May 14, 2024

Can you give me the image name (is it just angr:latest?) and the script to run inside the container?

@Voxanimus
Copy link
Author

the image is a custom one provided by one the people I work with. I am not sure I am allowed to share it.

The script that is run is very few lines:

#!/bin/bash

# Quit on errors
set -ue

export PYTHONPATH=/src
python3 -m trustdymbex $TARGET

trustdymbex is the name of my python program. $TARGET is the binary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken
Projects
None yet
Development

No branches or pull requests

2 participants