簡體   English   中英

該程序集的等效C代碼是什么?

[英]What is the equivalent C code for this assembly?

add    0x4025c0(,%rcx,4),%edx

因此,我正在嘗試將這段匯編代碼轉換為實際的C表達式,有人可以幫助我嗎? 謝謝!

更新:該代碼實際上是此匯編程序的一部分:

   0x00000000004010fe <+0>:     push   %rbx
   0x00000000004010ff <+1>:     mov    %rdi,%rbx
   0x0000000000401102 <+4>:     callq  0x401341 <string_length>
   0x0000000000401107 <+9>:     cmp    $0x6,%eax
   0x000000000040110a <+12>:    je     0x401111 <phase_5+19>
   0x000000000040110c <+14>:    callq  0x4015bf <explode_bomb>
   0x0000000000401111 <+19>:    mov    $0x0,%eax
   0x0000000000401116 <+24>:    mov    $0x0,%edx
   0x000000000040111b <+29>:    movzbl (%rbx,%rax,1),%ecx
   0x000000000040111f <+33>:    and    $0xf,%ecx
   0x0000000000401122 <+36>:    add    0x4025c0(,%rcx,4),%edx
   0x0000000000401129 <+43>:    add    $0x1,%rax
   0x000000000040112d <+47>:    cmp    $0x6,%rax
   0x0000000000401131 <+51>:    jne    0x40111b <phase_5+29>
   0x0000000000401133 <+53>:    cmp    $0x33,%edx
   0x0000000000401136 <+56>:    je     0x40113d <phase_5+63>
   0x0000000000401138 <+58>:    callq  0x4015bf <explode_bomb>
   0x000000000040113d <+63>:    pop    %rbx
   0x000000000040113e <+64>:    xchg   %ax,%ax
   0x0000000000401140 <+66>:    retq
add    0x4025c0(,%rcx,4),%edx

手段

%edx += *(0x4025c0 + %rcx*4);

%rcx是x64 asm中的寄存器。 這里0x4025c0是基地址。 * 4表示數組元素的大小為4字節(32位)。 所以可以翻譯成

%edx += *(uint32_t)0x4025c0[%rcx];

整個代碼段執行以下操作:

void check(char *str)
{
    const uint32_t *subTable = 0x4025c0;

    if (strlen(str) == 6)
    {
        uint32_t j = 0;
        for (int i = 0; i < 6; i++)
            j += subTable[str[i]];
        if (j == 0x33)
            return;
    }
    call explode_bomb;
}

替換表存儲在地址0x4025c0中。 僅當輸入的長度為6並且其替換數的總和為0x33時,它才會通過檢查。

簡單地用C表示它就像edx += ((uint32_t *)0x4025c0)[rcx]; 但是,如果沒有更多的上下文信息,就很難知道它的用途。

通常,括號應采用以下形式:

displacement(base register, offset register, scalar multiplier)  

擴展為

[base register + displacement + offset register * scalar multiplier].

所以,

0x4025c0(,%rcx,4)

是,

(0x4025C0 + value at RCX * 4)

ADD    (0x4025C0 + value at RCX x 4), %edx

應該意味着

edx += (0x4025C0 + ((*rcx)*4));

這意味着執行該指令后,例如,如果RCX值為100(0x64),則EDX將保持值0x4025C0 + 0x190

參考: https//en.wikibooks.org/wiki/X86_Assembly/GAS_Syntax

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM