自制反汇编逆向分析工具 迭代第六版本 (五)
本工具從最初版的跳轉(zhuǎn)分布圖只為了更直觀地分析反匯編代碼的分支結(jié)構(gòu),第三版開(kāi)始對(duì)直觀圖進(jìn)行逆向分支代碼的輸出,第四版對(duì)分支輸出策略的一些探索,第五版結(jié)合之前的探索進(jìn)行改進(jìn)。第六版在現(xiàn)在功能的基礎(chǔ)上進(jìn)行增強(qiáng),利用第六版(一)的基本功能-直譯,第六版(二)對(duì)條件分支增加條件判斷翻譯,以及改進(jìn)在函數(shù)調(diào)用處附帶備選參數(shù)參考。
第六版(三)將(一)和(二)組合在一起進(jìn)行逆向代碼輸出。
第六版(四),在(三)的基礎(chǔ)上增加對(duì)原子操作指令的逆向以及c++函數(shù)的逆向。
本篇是(五),對(duì)待c風(fēng)格的函數(shù)符號(hào)調(diào)用的翻譯,通過(guò)導(dǎo)入c風(fēng)格符號(hào)的函數(shù)原型來(lái)參考分析。
上一篇在介紹對(duì)待 c++風(fēng)格的函數(shù)符號(hào)調(diào)用的情況,提到了c風(fēng)格的函數(shù)符號(hào)沒(méi)有太多的原型信息可供參考,但是它唯一不被重載,參數(shù)約定使用標(biāo)準(zhǔn)的約定,所以用古老(老土)的辦法就好了。就是導(dǎo)入c風(fēng)格符號(hào)的函數(shù)原型(主要是符號(hào)名和參數(shù)序列)。
有外部的是參考信息,就可以對(duì)函數(shù)調(diào)用配用相應(yīng)的寄存器和存儲(chǔ)單元。我并不想讓機(jī)器去試圖臆意猜測(cè)一個(gè)不知道原型的函數(shù)參數(shù)序列,因?yàn)檫^(guò)猶不及,而且不嚴(yán)謹(jǐn),機(jī)器猜測(cè)誤導(dǎo)坑更加大。試想一下,一個(gè)c風(fēng)格的函數(shù),你可以單從函數(shù)被調(diào)用前的準(zhǔn)備參數(shù)的工作流就能分辨出是foo(double, int)還是foo(int, double)嗎?我是不能做到這種超人的程序了,我必須要通過(guò)外部信息來(lái)指導(dǎo)機(jī)器進(jìn)行分析工作。
下面貼上機(jī)器逆向出來(lái)的代碼:
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::add_root?
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 } CA::Transaction::run_deferred_visibility_layer_calls?
轉(zhuǎn)載于:https://www.cnblogs.com/bbqzsl/p/5512642.html
總結(jié)
以上是生活随笔為你收集整理的自制反汇编逆向分析工具 迭代第六版本 (五)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: bzoj 4517: [Sdoi2016
- 下一篇: [HDOJ2586]How far aw