0

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

Michael Petch
  • 46,082
  • 8
  • 107
  • 198

2 Answers2

16

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.

Ped7g
  • 16,236
  • 3
  • 26
  • 63
  • Funnily enough, that binary **MAY** be product of pure C/C++ source (even simple "hello world" example may be source) after all... but the particular bytes you disassembled can't be created by C language construct in source (except defining them as `const uint8_t* data { 0xCF, 0xFA, ...};`), these are fixed meta data defined by target platform, linker, and executable binary specification, outside of C language source scope. – Ped7g Nov 09 '17 at 14:38
  • 1
    This SO answer has ore details on the magic header itself. https://stackoverflow.com/questions/27669766/how-to-read-mach-o-header-from-object-file – Michael Petch Nov 09 '17 at 15:04
3

iretd is "return from interrupt", cli is "clear interrupt flag" which means disable all maskable interrupts. The C language does not understand the concept of an interrupt, so it is unlikely that this was compiled from C. In fact, this isn't a single complete fragment of code.

Also add byte ptr [rdx], 0 is adding 0 to a value which doesn't make sense to me unless it is the result of an unoptimised compilation or the result of disassembling something that isn't code.

JeremyP
  • 84,577
  • 15
  • 123
  • 161