RE4B Challenge 1

2017-10-17

Challenge

Link: https://challenges.re/1/

What does this code do? The function has 4 arguments and it is compiled by GCC for Linux x64 ABI (i.e., arguments are passed in registers).

<f>:
   0:                   mov    r8,rdi
   3:                   push   rbx
   4:                   mov    rdi,rsi
   7:                   mov    rbx,rdx
   a:                   mov    rsi,r8
   d:                   xor    rdx,rdx

begin:
  10:                   lods   rax,QWORD PTR ds:[rsi]
  12:                   div    rbx
  15:                   stos   QWORD PTR es:[rdi],rax
  17:                   loop   begin
  19:                   pop    rbx
  1a:                   mov    rax,rdx
  1d:                   ret

Reslove

四个参数所用寄存器:rdi, rsi, rdx, rcx

  • lods:load data form X to rax
  • stos:store data from rax to X
  • loop:loop until rcx = 0

计算表达式*a2 = *a1 / (a3 * a4)

int function(int *src, int *dest, int div, int times){
    *dest = *src / (div * times);

    return (*scr - *dest);
}