3

How to translate code assembly to C?? I am very poor in assembly code. EG:

mov     dword ptr [ebp+data], 612E2F47h
mov     dword ptr [ebp+data+4], 5B2A451Ch
mov     dword ptr [ebp+data+8], 6E6B5E18h
mov     dword ptr [ebp+data+0Ch], 5C121F67h
mov     dword ptr [ebp+data+10h], 0D5E2223h
mov     dword ptr [ebp+data+14h], 5E0A5F1Dh
mov     word ptr [ebp+data+18h], 858h
mov     word ptr [ebp+data+1Ah], 0h
xor     eax, eax                
loc_4012B2:                             
add     [ebp+eax+data], al      
inc     eax                     
cmp     eax, 1Ah                
jl      short loc_4012B2
3
  • 2
    -2 down vote favorite?? stackoverflow.com/questions/32675326/translate-assembly-to-c
    – 0xec
    Sep 21, 2015 at 14:48
  • 7
    Reverse engineering isn't about converting assembly to C, it's about understanding what's going on. Sep 21, 2015 at 15:25
  • These days it is possible to ask ChatGPT or related models to explain and translate these instructions to C or even to Python. The result here is "G00d J0b guys, k33p 1t up!\x1a\x1b" :-)
    – Guntram
    Mar 21 at 14:21

1 Answer 1

14

Here is exact answer to you question.

  1. Go to http://www.tutorialspoint.com/compile_assembly_online.php

  2. Doubleclick on main.asm in upper-left corner of the screen

  3. Copy your snippet to the text window. You'll need to add definition of data and make some tweaks, my resulting assembly code is

    section     .text
    global main
    main:
    
    xor ebp,ebp
    
    mov      dword [ebp+data], 0x612E2F47
    mov      dword [ebp+data+4], 0x5B2A451C
    mov      dword [ebp+data+8], 0x6E6B5E18
    mov      dword [ebp+data+0Ch], 0x5C121F67
    mov      dword [ebp+data+10h], 0x0D5E2223
    mov      dword [ebp+data+14h], 0x5E0A5F1D 
    mov      dword [ebp+data+18h], 0x858
    mov      dword [ebp+data+1Ah], 0x0
    xor     eax, eax                
    loc_4012B2:                             
    add     [ebp+eax+data], al      
    inc     eax                     
    cmp     eax, 1Ah                
    jl      short loc_4012B2
    nop
    nop
    
    
    section     .data
    
    data    db 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0
    
  4. Press compile button

  5. Go to project menu, download the project, extract demo file from the archive

  6. Go to retdec decompiler site

  7. Select executable input file and upload your binary file there

  8. Press decompile

  9. See results

I wouldn't say that results of this translation to C code are too much understandable. In addition I'd like to note that learning 6 assembly commands is much less time consuming process.

1

Not the answer you're looking for? Browse other questions tagged or ask your own question.