c++ string 源碼分析

菜雞的我當醬油去了ctf,re的第一題就把我整懵了
ida警告
Unexpected entries in the PLT stub.
The file might have been modified after linking.
大致就是PLT 被修改了
解決方法我能想到的有二:
一:修復PLT表//本菜雞不會
二:直接動調//莽就完事了


跟到源碼裏
使用了一堆0x20大小的棧空間//我剛開始以爲是數組
跟到函數裏
有個basic_string 的構造函數和析構函數
那這些0x20大小的棧空間是string?
實驗了一下,的確的string, 那麼string是怎麼存,於是今天研究一下string源碼
//環境VC6.0++ 下 sizeof(string) 0x10      vs2010下(string) 0x20 研究一下vc6.0++的源碼
#include<string>
using namespce std;           //這行必須加不然找不到string,也就是string在std這個命名空間裏
int main()
{
    string a;
    cin >> a;
    getchar();
    return 0;
}

string == basic_string< char ,char_traits<char>, allocator<char> >
模板類哦,開始不快樂了,變量辣麼多
template<class _E,
    class _Tr = char_traits<_E>,
    class _A = allocator<_E> >
    class basic_string {
public:
    static const size_type npos;                         // static 不佔本空間,算是全局變量,加了const變成靜態
    _A allocator;
    _E *_Ptr;
    size_type _Len, _Res;

算了,直接調試吧,本菜雞就是莽
在棧上分配空間



根據結果
string 是這樣一個結構
全局變量一個int

{
    int 未知;
    char*  字符串真實地址;
    int  length;
    int Res(未知);
}
所以根據這個結構,a.length的效率賊高,64位系統肯定要變化,至少指針長度不同,至於裏面的函數,就不去分析了

網上搜索的時候看到一個網站,應該還行http://www.cplusplus.com/reference/string/string/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章