Search code examples
cassemblyx86-64mach-o

what is this assembly code in C?


I have some assembly code below that I don't really understand. My thoughts are that it is meaningless. Unfortunately I can't provide any more instruction information. What would the output in C be?

0x1000: iretd   
0x1001: cli 
0x1002: in  eax, dx
0x1003: inc byte ptr [rdi]
0x1005: add byte ptr [rax], al
0x1007: add dword ptr [rbx], eax
0x1009: add byte ptr [rax], al
0x100b: add byte ptr [rdx], 0
0x100e: add byte ptr [rax], al

Thanks


Solution

  • The first four bytes (if I did reconstruct them correctly) form 32 bit value 0xFEEDFACF.

    Putting that into google led me to:

    https://gist.github.com/softboysxp/1084476#file-gistfile1-asm-L15

    %define MH_MAGIC_64                 0xfeedfacf
    

    Aren't you by accident disassembling Mach-o x64 executable from Mac OS X as raw machine code, instead of reading meta data of file correctly, and disassembling only code section?

    P.S. in questions like this one, rather include also the source machine code data, so experienced people may check disassembly by targetting different platform, like 32b x86 or 16b real mode code, or completely different CPU, which may help in case you would mistakenly treat machine code with wrong target platform disassembly. I had to first assemble your disassembly to see the raw bytes.