Assembly 在程序集中交换两个代码块

Assembly 在程序集中交换两个代码块,assembly,decompiling,ida,Assembly,Decompiling,Ida,我有一个反编译的函数,我想重写它 这个改变似乎很简单——我需要将代码的两大部分相互替换。在C语言中,它只需要剪切和粘贴。但在ASM中,我遇到了一些困难。尽管跳转指令中的地址是相对的(我已经弄明白了),修改后的DLL仍然崩溃,IDA Pro无法解释新代码。我一定是错过了一些与上下文有关的东西。请帮我完成这项任务,因为我在这方面很新 清单如下: push ebp mov ebp, esp sub esp, 20h mov eax, dword ptr _NDFAPI_N

我有一个反编译的函数,我想重写它

这个改变似乎很简单——我需要将代码的两大部分相互替换。在C语言中,它只需要剪切和粘贴。但在ASM中,我遇到了一些困难。尽管跳转指令中的地址是相对的(我已经弄明白了),修改后的DLL仍然崩溃,IDA Pro无法解释新代码。我一定是错过了一些与上下文有关的东西。请帮我完成这项任务,因为我在这方面很新

清单如下:

push    ebp
mov     ebp, esp
sub     esp, 20h
mov     eax, dword ptr _NDFAPI_NULL_THUNK_DATA_DLA-5D1331CCh
xor     eax, ebp
mov     [ebp+var_4], eax
push    ebx
push    esi
push    edi

---------------------------------------------

push    398Eh           ; string_id
push    0C3BEh          ; command_id
mov     ecx, esi        ; this
call    ?AddItemWithStringId@SimpleMenuModel@ui@@QAEXHH@Z ; 
         ui::SimpleMenuModel::AddItemWithStringId(int,int)

push    3990h           ; string_id
push    0C3C0h          ; command_id
mov     ecx, esi        ; this
call    ?AddItemWithStringId@SimpleMenuModel@ui@@QAEXHH@Z ;
         ui::SimpleMenuModel::AddItemWithStringId(int,int) 

push    398Fh           ; string_id
push    0C3BFh          ; command_id
mov     ecx, esi        ; this
call    ?AddItemWithStringId@SimpleMenuModel@ui@@QAEXHH@Z ; 
         ui::SimpleMenuModel::AddItemWithStringId(int,int)

---------------------------------------------

mov     ebx, ecx
call    ?chrome_proxy_header@data_reduction_proxy@@YAPBDXZ ; 

data_reduction_proxy::chrome_proxy_header(void)
push    eax             ; _Ptr
lea     ecx, [ebp+_Keyval] ; this
call    ??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z 

; 

std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string<char,std::char_traits<char>,st

d::allocator<char>>(char const *)
lea     eax, [ebp+_Keyval]
push    eax             ; _Keyval
lea     eax, [ebp+result]
lea     edi, [ebx+3ECh]
push    eax             ; result
mov     ecx, edi        ; this
call    ?find@?$_Tree@V?$_Tmap_traits@V?$basic_string@DU?$char_traits@D@std@@V?

$allocator@D@2@@std@@V12@U?$less@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@V?

$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@std@@@2@

$0A@@std@@@std@@QAE?AV?$_Tree_iterator@V?$_Tree_val@U?$_Tree_simple_types@U?$pair@$$CBV?$basic_string@DU?

$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@std@@@std@@@std@@@2@ABV?$basic_string@DU?$char_traits@D@std@@V?

$allocator@D@2@@2@@Z ; 

std::_Tree<std::_Tmap_traits<std::basic_string<char,std::char_traits<char>,std::allocator<char>>,std::basic_stri

ng<char,std::char_traits<char>,std::allocator<char>>,std::less<std::basic_string<char,std::char_traits<char>,std

::allocator<char>>>,std::allocator<std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char>> 

const,std::basic_string<char,std::char_traits<char>,std::allocator<char>>>>,0>>::find

(std::basic_string<char,std::char_traits<char>,std::allocator<char>> const &)
push    0               ; _Newsize
push    1               ; _Built
lea     ecx, [ebp+_Keyval] ; this
mov     esi, [eax]
call    ?_Tidy@?$basic_string@DU?$char_traits@D@std@@V?

$allocator@D@2@@std@@QAEX_NI@Z ; std::basic_string<char,std::char_traits<char>,std::allocator<char>>::_Tidy

(bool,uint)
cmp     esi, [edi]
jz      short loc_6025D46B
call    ?chrome_proxy_lo_fi_directive@data_reduction_proxy@@YAPBDXZ ; 

data_reduction_proxy::chrome_proxy_lo_fi_directive(void)
push    eax             ; _Ptr
lea     ecx, [esi+28h]  ; this
call    ?compare@?$basic_string@DU?$char_traits@D@std@@V?

$allocator@D@2@@std@@QBEHPBD@Z ; std::basic_string<char,std::char_traits<char>,std::allocator<char>>::compare

(char const *)
test    eax, eax
jnz     short loc_6025D46B
push    3993h           ; string_id
push    0C3C4h          ; command_id
lea     ecx, [ebx+400h] ; this
call    ?AddItemWithStringId@SimpleMenuModel@ui@@QAEXHH@Z ; 
         ui::SimpleMenuModel::AddItemWithStringId(int,int)

.text:6025D46B:                           ; CODE XREF: RenderViewContextMenu::AppendImageItems
(void)
.text:6025D46B                                         ; RenderViewContextMenu::AppendImageItems(void)

push    dword ptr [ebx+3FCh] ; context
call    ?

GetForBrowserContext@DataReductionProxyChromeSettingsFactory@@SAPAVDataReductionProxyChromeSettings@@PAVBrowserC

ontext@content@@@Z ; DataReductionProxyChromeSettingsFactory::GetForBrowserContext(content::BrowserContext *)

pop     ecx
test    eax, eax
jz      short loc_6025D499
lea     ecx, [ebx+0F4h]
push    ecx             ; url
mov     ecx, eax        ; this
call     ?CanUseDataReductionProxy@DataReductionProxySettings@data_reduction_proxy@@QBE_NABVGURL@@@Z ; 

data_reduction_proxy::DataReductionProxySettings::CanUseDataReductionProxy(GURL const &)

test    al, al

jz      short loc_6025D499
push    3992h
push    0C3C3h
jmp     short loc_6025D4A3

.text:6025D499                                         ; RenderViewContextMenu::AppendImageItems(void)

push    3991h           ; string_id
push    0C3C1h          ; command_id

.text:6025D4A3 loc_6025D4A3:                           ; CODE XREF: RenderViewContextMenu::AppendImageItems(void)

lea     esi, [ebx+400h]
mov     ecx, esi        ; this
call    ?AddItemWithStringId@SimpleMenuModel@ui@@QAEXHH@Z ; 
         ui::SimpleMenuModel::AddItemWithStringId(int,int)

---------------------------------------------------------------------------

mov     ecx, [ebp+var_4]
pop     edi
pop     esi
xor     ecx, ebp        ; cookie
pop     ebx
call    @__security_check_cookie@4 ; __security_check_cookie(x)
mov     esp, ebp
pop     ebp
retn
推ebp
电动汽车
副esp,20小时
mov eax、dword ptr、NDFAPI、NULL、THUNK、数据DLA-5D1331CH
xor eax,ebp
mov[ebp+var_4],eax
推ebx
推动esi
推式电子数据交换
---------------------------------------------
推398Eh;字符串id
推0C3BEh;命令id
mov-ecx,esi;这
呼叫AddItemWithStringId@SimpleMenuModel@用户界面@@QAEXHH@Z ; 
ui::SimpleNuModel::AddItemWithStringId(int,int)
推3990h;字符串id
推动0C3C0h;命令id
mov-ecx,esi;这
呼叫AddItemWithStringId@SimpleMenuModel@用户界面@@QAEXHH@Z ;
ui::SimpleNuModel::AddItemWithStringId(int,int)
推398Fh;字符串id
推动0C3BFh;命令id
mov-ecx,esi;这
呼叫AddItemWithStringId@SimpleMenuModel@用户界面@@QAEXHH@Z ; 
ui::SimpleNuModel::AddItemWithStringId(int,int)
---------------------------------------------
mov-ebx,ecx
呼叫?chrome_代理_header@data_reduction_proxy@@YAPBDXZ;
数据缩减代理::chrome代理头(无效)
推动eax_Ptr
lea-ecx[ebp+_-Keyval];这
呼叫??0?$basic_string@DU?$char_traits@D@性病病毒$allocator@D@2@@std@@QAE@PBD@Z
; 
标准::基本字符串::基本字符串(字符常量*)
lea eax,[ebp+\U Keyval]
推动eax_基瓦尔
lea eax,[ebp+结果]
lea电子数据交换[ebx+3ECh]
推动eax;结果
电子数据交换;这
打电话?找@$_Tree@V?$\u Tmap_traits@V?$basic_string@DU?$char_traits@D@性病病毒?
$allocator@D@2@@std@@V12@U?$less@V?$basic_string@DU?$char_traits@D@性病病毒$allocator@D@2@@std@@@2@V?
$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@性病病毒$allocator@D@2@@std@@V12@@std@@@2@
$0A@@std@@@std@@QAE?AV?$\U树_iterator@V?$\u树_val@U?$\u树\u简单_types@U?$pair@$$CBV?$basic_string@DU?
$char_traits@D@性病病毒$allocator@D@2@@std@@V12@@std@@@std@@@std@@@2@ABV?$basic_string@DU?$char_traits@D@性病病毒?
$allocator@D@2@@2@@Z;
std::_树::查找
(标准::基本字符串常量&)
推0_新闻化
推1_建造
lea-ecx[ebp+_-Keyval];这
mov esi,[eax]
呼叫?_Tidy@?$basic_string@DU?$char_traits@D@性病病毒?
$allocator@D@2@@std@@QAEX_NI@Z ; 标准::基本字符串::\u
(布尔,尤因)
cmp esi[edi]
jz短loc_6025D46B
呼叫?chrome\u proxy\u lo\u fi_directive@data_reduction_proxy@@YAPBDXZ;
数据缩减代理::chrome\u proxy\u lo\u fi\u指令(无效)
推动eax_Ptr
lea-ecx[esi+28h];这
呼叫?比较@?$basic_string@DU?$char_traits@D@性病病毒?
$allocator@D@2@@std@@QBEHPBD@Z ; 标准::基本字符串::比较
(字符常量*)
测试eax,eax
jnz short loc_6025D46B
推动3993h;字符串id
推动0C3C4h;命令id
lea ecx,[ebx+400小时];这
呼叫AddItemWithStringId@SimpleMenuModel@用户界面@@QAEXHH@Z ; 
ui::SimpleNuModel::AddItemWithStringId(int,int)
.文本:6025D46B:;代码外部参照:RenderViewContextMenu::AppendImageItems
(无效)
.文本:6025D46B;RenderViewContextMenu::AppendImageItems(无效)
推送dword ptr[ebx+3FCh];上下文
呼叫
GetForBrowserContext@DataReductionProxyChromeSettingsFactory@@SAPAVDataReducementProxyChromeSettings@@PAVBrowserC
ontext@content@@@Z;DataReductionProxyChromeSettingsFactory::GetForBrowserContext(内容::BrowserContext*)
波普ecx
测试eax,eax
jz short loc_6025D499
lea ecx,[ebx+0F4h]
推动ecx;网址
mov-ecx,eax;这
呼叫CanUseDataReductionProxy@DataReductionProxySettings@数据还原代理@QBE\u NABVGURL@@@Z;
数据还原代理::DataReductionProxySettings::CanUseDataReductionProxy(GURL const&)
测试铝,铝
jz short loc_6025D499
推3992h
推动0C3C3h
jmp短loc_6025D4A3
.文本:6025D499;RenderViewContextMenu::AppendImageItems(无效)
推动3991h;字符串id
推0C3C1;命令id
.文本:6025D4A3 loc_6025D4A3:;代码外部参照:RenderViewContextMenu::AppendImageItems(无效)
lea esi,[ebx+400小时]
mov-ecx,esi;这
呼叫AddItemWithStringId@SimpleMenuModel@用户界面@@QAEXHH@Z ; 
ui::SimpleNuModel::AddItemWithStringId(int,int)
---------------------------------------------------------------------------
mov ecx,[ebp+var_4]
流行电子数据交换
波普esi
异或ecx,ebp;曲奇
流行电子束
打电话给"安全检查"_cookie@4 ; __安全检查cookie(x)
电除尘器
流行ebp
翻新

我所做的是将方块从例行程序的末尾移到开头的虚线之间。我说了些什么?

移动代码块后的第一行是:

    mov ebx, ecx
这会将
ecx
中的
This
参数复制到不会被第一次函数调用破坏的寄存器中。您需要将此行移到新代码块上方。
ebx
的此值在整个功能中保持不变

在那之后,你马上需要电话

    lea esi, [ebx+400h]

正如你在评论中提到的。不要从当前位置删除此行,因为它在当前位置仍然需要。

我想我应该在第一条虚线后添加一条“lea esi,[ebx+400h]”指令(作为一个快速的想法)。也许会有用…谢谢。你能告诉我如何让函数体长几个字节吗?这是天秤座