ccrawl
1.0.0
| 地位: | 开发中 |
| 地点: | https://github.com/bdcht/ccrawl |
| 版本: | 1.x |
| 文档: | http://ccrawl.readthedocs.io/en/latest/index.html |
Ccrawl 使用 clang 构建与各种 C/C++ 数据结构(结构、联合、类、枚举、typedef、原型和宏)相关的数据库,它允许通过查询该数据库的特定属性(包括属性)来识别数据类型和常量/宏与结构/类内存布局相关。
基本上它允许例如
然后,Ccrawl 允许以多种格式输出找到的结构:当然是 C/C++,还有 ctypes 或 amoco。 C++ 类的 ctypes 输出对应于内存中的实例(对象)布局,包括可能由多个父(可能是虚拟)类产生的所有虚拟表指针(或 VTT)。
最后,Ccrawl 允许计算有关库 API 的各种统计信息,并允许计算任何给定类型的依赖关系图,例如(请参阅tests/samples/xxx/graph.h):

用户文档和 API 可以在 http://ccrawl.readthedocs.io/en/latest/index.html 找到
考虑文件示例/simple.h中的以下 C 结构
结构体S{
字符c;
整数 n;
联盟{
无符号字符x[2];
无符号短 s;
} 你;
char (*PtrCharArrayOf3[2])[3];
无效(*pfunc)(int,int);
};
首先,收集本地数据库中的结构定义:
$ ccrawl -l test.db -g 'test0' 收集样本/simple.h [100%] 简单.h [ 2] -------------------------------------------------- ------------------ 正在保存数据库...[2]
然后,可以将完整结构翻译为 ctypes
$ ccrawl -l test.db show -r -f ctypes 'struct S'
struct_S = 类型('struct_S',(结构,),{})
union_b0eccf67 = 类型('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(无, c_int, c_int)))]
或者只是计算字段偏移量
$ ccrawl -l test.db info 'struct S' 标识符:结构S 类:cStruct 来源:simple.h 标签: 测试0 尺寸:40 偏移量 : [(0, 1), (4, 4), (8, 2), (16, 16), (32, 8)]
现在让我们处理一个更棘手的 C++ 示例:
$ ccrawl -l test.db 收集 -a --cxx 样本/shahar.cpp [100%] 沙哈尔.cpp [ 18] -------------------------------------------------- ------------------ 正在保存数据库... [ 18]
我们可以显示类的完整(递归)定义:
$ ccrawl -l test.db show -r 'class Child'
祖父母类{
民众:
虚拟无效grandparent_foo();
int 祖父母数据;
};
类 Parent1 :虚拟公共祖父母 {
民众:
虚拟无效parent1_foo();
intparent1_data;
};
类 Parent2 :虚拟公共祖父母 {
民众:
虚拟无效parent2_foo();
intparent2_data;
};
子类:公共Parent1,公共Parent2 {
民众:
虚拟无效child_foo();
int 子数据;
};
及其ctypes内存布局:
$ ccrawl -l test.db show -f ctypes 'class Child'
struct___layout$Child = 类型('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$祖父母", c_void_p),
(“祖父母数据”,c_int)]
请参阅文档以获取更多示例。