本工具從最初版的跳轉分布圖只為了更直觀地分析反匯編代碼的分支結構,第三版開始對直觀圖進行逆向分支代碼的輸出,第四版對分支輸出策略的一些探索,第五版結合之前的探索進行改進。第六版在現在功能的基礎上進行增強,利用第六版(一)的基本功能-直譯,第六版(二)對條件分支增加條件判斷翻譯,以及改進在函數調用處附帶備選參數參考。
第六版(三)將(一)和(二)組合在一起進行逆向代碼輸出。
第六版(四),在(三)的基礎上增加對原子操作指令的逆向以及c++函數的逆向。
本篇是(五),對待c風格的函數符號調用的翻譯,通過導入c風格符號的函數原型來參考分析。
上一篇在介紹對待 c++風格的函數符號調用的情況,提到了c風格的函數符號沒有太多的原型信息可供參考,但是它唯一不被重載,參數約定使用標準的約定,所以用古老(老土)的辦法就好了。就是導入c風格符號的函數原型(主要是符號名和參數序列)。
有外部的是參考信息,就可以對函數調用配用相應的寄存器和存儲單元。我并不想讓機器去試圖臆意猜測一個不知道原型的函數參數序列,因為過猶不及,而且不嚴謹,機器猜測誤導坑更加大。試想一下,一個c風格的函數,你可以單從函數被調用前的準備參數的工作流就能分辨出是foo(double, int)還是foo(int, double)嗎?我是不能做到這種超人的程序了,我必須要通過外部信息來指導機器進行分析工作。
下面貼上機器逆向出來的代碼:


CA::Transaction::add_root {// 0 pushq %rbp// 1 rbp = rsp;// 4 pushq %r14// 6 pushq %rbx// 7 rbx = rsi;// 10 r14 = rdi;// 13 rdi = & CA::Transaction::roots_lock;// 20 call OSSpinLockLock(CA::Transaction::roots_lock);// 25 rdi = CA::Transaction::roots;// 32 testq %rdi, %rdi// 35if (!) { // 32 (0 != rdi)// 37 edi = 0;// 39 esi = 0;// 41 edx = 0;// 43 ecx = 0;// 45 r8d = 0;// 48 r9d = 0;// 51 callx_hash_table_new_(0, 0, 0, 0, 0, 0);// 56 rdi = rax;// 59 CA::Transaction::roots = rdi;} // 66// 66 rsi = rbx;// 69 rdx = rbx;// 72 callx_hash_table_insert((x_hash_table*)rax, (uintptr_t)esi, (uintptr_t)edx);// 77 testb %al, %al// 79if (!) { // 77 (0 == al)// 81 lock// 82 OSAtomicIncrement32((volatile int32_t*)&rbx->_0);// 84 testb $0x10, 0x84(%r14)// 92if (!) { // 84 (0 == (0x10 & r14->_84))// 94 rax = (int64_t)(int32_t&)r14->_8;// 98 testq %rax, %rax// 101if () { // 98 (0 > rax)// gen jmp 113goto _f113;// 103 cmpl $0x0, 0xa8(%rbx,%rax,4)} // 111else if () { // 103 ((int32_t&)((uint32_t*)&rbx->_a8)[rax] != 0x0)// gen jmp 124goto _f124;}else { // 111 next_f113: // from 101} // 113// 113 rdi = rbx;// 116 rsi = r14;// 119 call((CA::Layer*)rbx)->thread_flags_((CA::Transaction*)r14);_f124: // from 111} // 124} // 124// 124 rdi = & CA::Transaction::roots_lock;// 131 popq %rbx// 132 popq %r14// 134 popq %rbp// 135 retreturn; // jmp 0x1041ecb2a; symbol stub for: OSSpinLockUnlock// 140 rbx = rax;// 143 rdi = & CA::Transaction::roots_lock;// 150 call OSSpinLockUnlock(CA::Transaction::roots_lock);// 155 rdi = rbx;// 158 call _Unwind_Resume;// 163 nop/***** * global variables * */// 13 extern ent_off__0x5146c; leaq 0x51458(%rip), %rdi; CA::Transaction::roots_lock // 25 extern ent_off__0x51464; movq 0x51444(%rip), %rdi; CA::Transaction::roots // 59 extern ent_off__0x51464; movq %rdi, 0x51422(%rip); CA::Transaction::roots // 124 extern ent_off__0x5146c; leaq 0x513e9(%rip), %rdi; CA::Transaction::roots_lock // 143 extern ent_off__0x5146c; leaq 0x513d6(%rip), %rdi; CA::Transaction::roots_lock }
?


CA::Transaction::run_deferred_visibility_layer_calls {// 0 pushq %rbp// 1 rbp = rsp;// 4 pushq %r15// 6 pushq %r14// 8 pushq %rbx// 9 pushq %rax// 10 r14 = rdi;// 13 rbx = r14->_78;// 17 testq %rbx, %rbx// 20if (!) { // 17 (0 == rbx)_b22: // from 81// 22 r15 = rbx->_0;// 25 testq %r15, %r15// 28if (!) { // 25 (0 == r15)// 30 rdi = r15;// 33 call((CA::Layer*)r15)->call_did_become_visible();// 38 eax = 0xffffffff;// 43 lock// 44 OSAtomicAdd32(eax, (volatile int32_t*)&r15->_0);// 48 cmpl $0x1, %eax// 51if (!) { // 48 (eax != 0x1)// 53 rdi = r15;// 56 call((CA::Layer*)r15)->~Layer();// 61 edi = 0xb;// 66 rsi = r15;// 69 callx_mem_dealloc_bucket(0xb, (void*)r15);} // 74} // 74// 74 rbx = rbx->_8;// 78 testq %rbx, %rbx// 81if () // 78 (0 != rbx)goto _b22;// 83 rdi = r14->_78;// 87 callx_list_free((x_list*)r14->_78);// 92 r14->_78 = 0x0;} // 100// 100 rsp = rsp + 0x8;// 104 popq %rbx// 105 popq %r14// 107 popq %r15// 109 popq %rbp// 110 ret return; // 111 nop }
?