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)]
請參閱文件以取得更多範例。