This problem will give you a chance to reverse engineer a switch statement from
ID: 3889443 • Letter: T
Question
This problem will give you a chance to reverse engineer a switch statement from machine code. In the following procedure, the body of the switch statement has been removed:
The disassembled machine code for the procedure is shown below. Recall parameter x is passed in register %rdi and parameter n is passed in register %rsi. The jump table resides in a different area of memory. We can see from the mov at address 0x040065e that the jump table begins at address 0x0400798. Using the gdb debugger, we can examine the ten 8-byte words of memory comprising the jump table with the command x/10x 0x400798. gdb prints the following:
Explanation / Answer
long switch_prob(long x, long n)
{
long result = n;
switch(x){
case 60: result = n*8; break;
case 62: result = n*8; break;
case 63: result = n;
result >>= 0x3;
break;
case 64: result = n;
result <<= 0x4;
result -= n;
n = result;
n *= n;
result = n + 75;
break;
case 65: n *= n;
result = n + 75;
break;
default: result = n + 75;
}
return result;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.