Hi, i have a piece of code in assembler, and i do not understand the switch statement in it.  This is an assigment, i did two of those pieces of code, but this one i can not figure out, i can not see even what is asking me in the switch command.  Any help will be really appreciate, here is the piece of code in assemble, if anyone can translate to C, i will really appreciate:

08048b7b <phase_3>:
8048b7b: 55                  push  %ebp
8048b7c: 89 e5                mov    %esp,%ebp
8048b7e: 83 ec 24            sub    $0x24,%esp
8048b81: 8d 45 f8            lea    0xfffffff8(%ebp),%eax
8048b84: 50                  push  %eax
8048b85: 8d 45 f7            lea    0xfffffff7(%ebp),%eax
8048b88: 50                  push  %eax
8048b89: 8d 45 fc            lea    0xfffffffc(%ebp),%eax
8048b8c: 50                  push  %eax
8048b8d: 68 26 97 04 08      push  $0x8049726
8048b92: ff 75 08            pushl  0x8(%ebp)
8048b95: e8 de fc ff ff      call  8048878 <sscanf@plt>
8048b9a: 83 c4 20            add    $0x20,%esp
8048b9d: 83 f8 02            cmp    $0x2,%eax
8048ba0: 7f 05                jg    8048ba7 <phase_3+0x2c>
8048ba2: e8 99 08 00 00      call  8049440 <explode_bomb>
8048ba7: 83 7d fc 07          cmpl  $0x7,0xfffffffc(%ebp)
8048bab: 0f 87 bd 00 00 00    ja    8048c6e <phase_3+0xf3>
8048bb1: 8b 45 fc            mov    0xfffffffc(%ebp),%eax
8048bb4: ff 24 85 30 97 04 08 jmp    *0x8049730(,%eax,4)
8048bbb: 81 7d f8 37 01 00 00 cmpl  $0x137,0xfffffff8(%ebp)
8048bc2: 0f 84 af 00 00 00    je    8048c77 <phase_3+0xfc>
8048bc8: e8 73 08 00 00      call  8049440 <explode_bomb>
8048bcd: b0 69                mov    $0x69,%al
8048bcf: e9 a5 00 00 00      jmp    8048c79 <phase_3+0xfe>
8048bd4: 81 7d f8 7d 01 00 00 cmpl  $0x17d,0xfffffff8(%ebp)
8048bdb: 0f 84 96 00 00 00    je    8048c77 <phase_3+0xfc>
8048be1: e8 5a 08 00 00      call  8049440 <explode_bomb>
8048be6: b0 69                mov    $0x69,%al
8048be8: e9 8c 00 00 00      jmp    8048c79 <phase_3+0xfe>
8048bed: 81 7d f8 20 03 00 00 cmpl  $0x320,0xfffffff8(%ebp)
8048bf4: 75 04                jne    8048bfa <phase_3+0x7f>
8048bf6: b0 77                mov    $0x77,%al
8048bf8: eb 7f                jmp    8048c79 <phase_3+0xfe>
8048bfa: e8 41 08 00 00      call  8049440 <explode_bomb>
8048bff: b0 77                mov    $0x77,%al
8048c01: eb 76                jmp    8048c79 <phase_3+0xfe>
8048c03: 81 7d f8 9f 02 00 00 cmpl  $0x29f,0xfffffff8(%ebp)
8048c0a: 75 04                jne    8048c10 <phase_3+0x95>
8048c0c: b0 75                mov    $0x75,%al
8048c0e: eb 69                jmp    8048c79 <phase_3+0xfe>
8048c10: e8 2b 08 00 00      call  8049440 <explode_bomb>
8048c15: b0 75                mov    $0x75,%al
8048c17: eb 60                jmp    8048c79 <phase_3+0xfe>
8048c19: 83 7d f8 35          cmpl  $0x35,0xfffffff8(%ebp)
8048c1d: 75 04                jne    8048c23 <phase_3+0xa8>
8048c1f: b0 61                mov    $0x61,%al
8048c21: eb 56                jmp    8048c79 <phase_3+0xfe>
8048c23: e8 18 08 00 00      call  8049440 <explode_bomb>
8048c28: b0 61                mov    $0x61,%al
8048c2a: eb 4d                jmp    8048c79 <phase_3+0xfe>
8048c2c: 81 7d f8 ac 03 00 00 cmpl  $0x3ac,0xfffffff8(%ebp)
8048c33: 75 04                jne    8048c39 <phase_3+0xbe>
8048c35: b0 7a                mov    $0x7a,%al
8048c37: eb 40                jmp    8048c79 <phase_3+0xfe>
8048c39: e8 02 08 00 00      call  8049440 <explode_bomb>
8048c3e: b0 7a                mov    $0x7a,%al
8048c40: eb 37                jmp    8048c79 <phase_3+0xfe>
8048c42: 81 7d f8 bd 03 00 00 cmpl  $0x3bd,0xfffffff8(%ebp)
8048c49: 75 04                jne    8048c4f <phase_3+0xd4>
8048c4b: b0 70                mov    $0x70,%al
8048c4d: eb 2a                jmp    8048c79 <phase_3+0xfe>
8048c4f: e8 ec 07 00 00      call  8049440 <explode_bomb>
8048c54: b0 70                mov    $0x70,%al
8048c56: eb 21                jmp    8048c79 <phase_3+0xfe>
8048c58: 81 7d f8 80 03 00 00 cmpl  $0x380,0xfffffff8(%ebp)
8048c5f: 75 04                jne    8048c65 <phase_3+0xea>
8048c61: b0 6d                mov    $0x6d,%al
8048c63: eb 14                jmp    8048c79 <phase_3+0xfe>
8048c65: e8 d6 07 00 00      call  8049440 <explode_bomb>
8048c6a: b0 6d                mov    $0x6d,%al
8048c6c: eb 0b                jmp    8048c79 <phase_3+0xfe>
8048c6e: e8 cd 07 00 00      call  8049440 <explode_bomb>
8048c73: b0 72                mov    $0x72,%al
8048c75: eb 02                jmp    8048c79 <phase_3+0xfe>
8048c77: b0 69                mov    $0x69,%al
8048c79: 3a 45 f7            cmp    0xfffffff7(%ebp),%al
8048c7c: 74 05                je    8048c83 <phase_3+0x108>
8048c7e: e8 bd 07 00 00      call  8049440 <explode_bomb>
8048c83: c9                  leave 
8048c84: c3                  ret 
Posted on 2007-05-02 23:19:44 by rbulus
Ick, AT&T style assembly.
Ick, disassembly dump - we tend to not be very happy about those here.
Ick, homework assignment?

A couple of pieces of advice, though: convert the 0xFFFFFFxx to signed isntead of unsigned numbers, and give them names.
Give phase_3+xx unique names, and insert those labels.
Graph it visually.

What is this an assignment for, and are you just given the disassembly listings, or executables?
Posted on 2007-05-03 03:47:17 by f0dder
Thanks for the help, i have done two phases, this is the phase number three.  I just can not figure out.  This is a homework name BombLab, it has 6 phases, it gave you the exe and the c code, but you can not do anything with the c code, the idea is to use gbd for everything.  I was asking for a little help when i can work it after it.

Thanks
Posted on 2007-05-03 11:15:15 by rbulus
hm, sounds like a weird assignment. Get a better disassembler, especially if there's debug info present in the exe.
Posted on 2007-05-03 17:54:11 by f0dder
you didn't give the table at 0x8049730, nor did you give string at 0x8049726 - nevertheless i foresaw it.

does your C code look like this:

phase3 (char *inputbuff)
{
dword X1,X2;
byte X3,Y;

if (sscanf(inputbuff,"%u %u %u",&X1,&X3,&X2) <= 2) explode_bomb();

if (X1<=7) {
switch (X1) {
/*
table at 0x8049730 should be
dd 0x8048bbb,0x8048bd4,0x8048bed,0x8048c03
dd 0x8048c19,0x8048c2c,0x8048c42,0x8048c58
*/

case 0:
if (X2==311) Y=105;
else { explode_bomb(); Y=105; }
break;
case 1:
if (X2==381) Y=105;
else { explode_bomb(); Y=105; }
break;
case 2:
if (X2==800) Y=119;
else { explode_bomb(); Y=119; }
break;
case 3:
if (X2==671) Y=117;
else { explode_bomb(); Y=117; }
break;
case 4:
if (X2==53) Y=97;
else { explode_bomb(); Y=97; }
break;
case 5:
if (X2==940) Y=122;
else { explode_bomb(); Y=122; }
break;
case 6:
if (X2==957) Y=112;
else { explode_bomb(); Y=112; }
break;
case 7:
if (X2==896) Y=109;
else { explode_bomb(); Y=109; }
break;
default:
Y=114;
}
}

if (Y!=X3) explode_bomb();

}
Posted on 2007-05-03 19:18:04 by drizz
Thanks a lot, this C code works fine, the only the input is %d %c %d, it is giving in the line:

8048b8d:  68 26 97 04 08          push  $0x8049726

But thanks again a lot.

Posted on 2007-05-04 13:54:33 by rbulus