RE4B Challenge 2

Challenge

Link: https://challenges.re/2/

What does this code do?

Optimizing GCC 4.8.2 -m32

<f>:
   0:          mov    eax,DWORD PTR [esp+0x4]
   4:          bswap  eax
   6:          mov    edx,eax
   8:          and    eax,0xf0f0f0f
   d:          and    edx,0xf0f0f0f0
  13:          shr    edx,0x4
  16:          shl    eax,0x4
  19:          or     eax,edx
  1b:          mov    edx,eax
  1d:          and    eax,0x33333333
  22:          and    edx,0xcccccccc
  28:          shr    edx,0x2
  2b:          shl    eax,0x2
  2e:          or     eax,edx
  30:          mov    edx,eax
  32:          and    eax,0x55555555
  37:          and    edx,0xaaaaaaaa
  3d:          add    eax,eax
  3f:          shr    edx,1
  41:          or     eax,edx
  43:          ret

Reslove

这个函数是顺序执行的。主要进行各种计算操作,可以推断出参数为int类型。

使用C重写和汇编是几乎等价的,还会更麻烦一些。所以没有列出C的代码。

Table of Contents