clang-based search engine for C/C++ data structures, classes, prototypes & macros
.. image:: http://readthedocs.org/projects/ccrawl/badge/?version=latest :target: http://ccrawl.readthedocs.io/en/latest/?badge=latest :alt: Documentation Status
.. image:: https://badge.fury.io/py/ccrawl.svg :target: https://badge.fury.io/py/ccrawl
+-----------+--------------------------------------------------+ | Status: | Under Development | +-----------+--------------------------------------------------+ | Location: | https://github.com/bdcht/ccrawl | +-----------+--------------------------------------------------+ | Version: | 1.x | +-----------+--------------------------------------------------+ | Doc: | http://ccrawl.readthedocs.io/en/latest/index.html| +-----------+--------------------------------------------------+
Ccrawl uses clang_ to build a database related to various C/C++ data structures (struct, union, class, enum, typedef, prototypes and macros) which allows to identify data types and constants/macros by querying this database for specific properties, including properties related to the struct/class memory layout.
Basically it allows for example to
Ccrawl then allows to output found structures in many formats: C/C++ of course, but also ctypes_, or amoco_. The ctypes_ output of a C++ class corresponds to an instance (object) layout in memory, including all virtual table pointers (or VTT) that result from possibly multiple parent (possibly virtual) classes.
Finally, Ccrawl allows to compute various statistics about a library API, and allows to compute the dependency graph of any given type like for example (see tests/samples/xxx/graph.h):
.. image:: https://github.com/bdcht/ccrawl/blob/release/doc/g.png :width: 800
User documentation and API can be found at
http://ccrawl.readthedocs.io/en/latest/index.html
Consider the following C struct from file samples/simple.h ::
struct S { char c; int n; union { unsigned char x[2]; unsigned short s; } u; char (*PtrCharArrayOf3[2])[3]; void (*pfunc)(int, int); };
First, collect the structure definition in a local database::
saving database... [ 2]
Then, its possible to translate the full structure in ctypes_ ::
$ ccrawl -l test.db show -r -f ctypes 'struct S' struct_S = type('struct_S',(Structure,),{}) union_b0eccf67 = type('union_b0eccf67',(Union,),{}) union_b0eccf67.fields = [("x", c_ubyte*2), ("s", c_ushort)]
struct_S.anonymous = ("u",) struct_S.fields = [("c", c_byte), ("n", c_int), ("u", union_b0eccf67), ("PtrCharArrayOf3", POINTER(c_byte*3)*2), ("pfunc", POINTER(CFUNCTYPE(None, c_int, c_int)))]
Or simply to compute the fields offsets ::
$ ccrawl -l test.db info 'struct S' identifier: struct S class : cStruct source : simple.h tag : test0 size : 40 offsets : [(0, 1), (4, 4), (8, 2), (16, 16), (32, 8)]
Now let's deal with a more tricky C++ example::
saving database... [ 18]
We can show a full (recursive) definition of a class::
$ ccrawl -l test.db show -r 'class Child' class Grandparent { public: virtual void grandparent_foo(); int grandparent_data; };
class Parent1 : virtual public Grandparent { public: virtual void parent1_foo(); int parent1_data; }; class Parent2 : virtual public Grandparent { public: virtual void parent2_foo(); int parent2_data; };
class Child : public Parent1, public Parent2 { public: virtual void child_foo(); int child_data; };
And its ctypes_ memory layout::
$ ccrawl -l test.db show -f ctypes 'class Child' struct___layout$Child = type('struct___layout$Child',(Structure,),{})
struct___layout$Child.fields = [("__vptr$Parent1", c_void_p), ("parent1_data", c_int), ("__vptr$Parent2", c_void_p), ("parent2_data", c_int), ("child_data", c_int), ("__vptr$Grandparent", c_void_p), ("grandparent_data", c_int)]
See the documentation for more examples.
v1.10
_
v1.9
_
v1.8
_
v1.7
_
v1.6
_
v1.5
_
v1.4
_
v1.3
_
.. _clang: https://pypi.org/project/clang/ .. _ctypes: https://docs.python.org/3.7/library/ctypes.html .. _amoco: https://github.com/bdcht/amoco .. _v1.10: https://github.com/bdcht/ccrawl/releases/tag/v1.10 .. _v1.9: https://github.com/bdcht/ccrawl/releases/tag/v1.9 .. _v1.8: https://github.com/bdcht/ccrawl/releases/tag/v1.8 .. _v1.7: https://github.com/bdcht/ccrawl/releases/tag/v1.7 .. _v1.6: https://github.com/bdcht/ccrawl/releases/tag/v1.6 .. _v1.5: https://github.com/bdcht/ccrawl/releases/tag/v1.5 .. _v1.4: https://github.com/bdcht/ccrawl/releases/tag/v1.4 .. _v1.3: https://github.com/bdcht/ccrawl/releases/tag/v1.3