Switch Assembly Language

I am looking at the assembler language code of the switch statement.

I understand how the code works and what are the cases. My question is, how can I identify case names?

Below is the assembler language code, followed by my interpretation. I just need to use the jump table and fill in the case names.

    1 8048420: push %ebp
    2 8048421: mov %esp, $ebp
    3 8048423: mov 0x8(%ebp), %eax       // x
    4 8048426: mov 0xc(%ebp), %edx       // n
    5 8048429: sub $0x32, %edx           // so least value of case is 32
    6 804842c: cmp $0x5, %edx            // max value is 37
    7 804842f: ja 8048448 <switch+0x28>  // if >37, go to default
    8 8048431: jmp *0x80485d0(, %edx, 4)  //THIS RIGHT HERE ?
    9 8048438: shl $0x2, %eax             // CASE A
   10 804843b: jmp 804844b <switch+0x2b>  //break;
   11 804843d: sar $0x2, %eax             //CASE B
   12 8048440: jmp 804844b <switch+0x2b>  //break
   13 8048442: lea (%eax, %eax, 2), %eax  //CASE C
   14 8048445: imul %eax, %eax     
   15 8048448: add $0xa, %eax             //fall through to default
   16 804844b: pop %ebp                   //return
   17 804844c: ret

The transition table created by the gdb command: I do x / 6w 0x80485d0

0x80485d0: 0x08048438 0x08048448 0x08048438 0x0804843d
0x80485e0: 0x08048442 0x08048445

My interpretation:

int result = x;
switch(n) {
case __:
    x = x << 2;
    break;  
case __:
    x = x >> 2
    break;
case __:
    x = 4*x;
    x = x*x
case __: //default
    x += 0xa 
return x;
}

I just don’t understand how to look for a jump table and decide which n values ​​between 32 and 37 fit in which of the blanks.

Any help would be greatly appreciated. Thank.

+3
source share
2 answers

, . n-50 % edx, + 0x11 , 0x80485d0 + %edx * 4. , + 0x18 n == 50 52, switch + 0x28 n == 51, switch + 0x1d, n == 53, switch + 0x22 n == 54 switch + 0x25 n = = 55.

+5

6 , 5 ( 5 , 0x8048448). ( 0x32 0x34) , (0x33) () , (0x35) , (0x36) - , (0x37) - . () , .

switch (n)
{
  case 0x32:
  case 0x34:
    x <<= 2;
    break;
  case 0x35:
    x >>= 2;
    break;
  case 0x36:
    x *= 3;
  case 0x37:
    x *= x;
  //case 0x33:  // not really necessary
  default:
    x += 10;
}
return x;
+1

Source: https://habr.com/ru/post/1771164/


All Articles