Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The last jump type is the indirect jump, which is often used for switch statements in the real world. Switch statements are a special case

The last jump type is the indirect jump, which is often used for switch statements in the real world.
Switch statements are a special case of if-statements that use only numbers to determine where the control flow will go.
Here is an example:
switch(number):
0: jmp do_thing_0
1: jmp do_thing_1
2: jmp do_thing_2
default: jmp do_default_thing
The switch in this example is working on `number`, which can either be 0,1, or 2.
In the case that `number` is not one of those numbers, the default triggers.
You can consider this a reduced else-if type structure.
In x86, you are already used to using numbers, so it should be no suprise that you can make if statements based on something being an exact number.
In addition, if you know the range of the numbers, a switch statement works very well.
Take for instance the existence of a jump table.
A jump table is a contiguous section of memory that holds addresses of places to jump.
In the above example, the jump table could look like:
[0x1337]= address of do_thing_0
[0x1337+0x8]= address of do_thing_1
[0x1337+0x10]= address of do_thing_2
[0x1337+0x18]= address of do_default_thing
Using the jump table, we can greatly reduce the amount of cmps we use.
Now all we need to check is if `number` is greater than 2.
If it is, always do:
jmp [0x1337+0x18]
Otherwise:
jmp [jump_table_address + number *8]
Using the above knowledge, implement the following logic:
if rdi is 0:
jmp 0x40305b
else if rdi is 1:
jmp 0x4030ef
else if rdi is 2:
jmp 0x4031c1
else if rdi is 3:
jmp 0x403258
else:
jmp 0x40333d
Please do the above with the following constraints:
Assume rdi will NOT be negative
Use no more than 1 cmp instruction
Use no more than 3 jumps (of any variant)
We will provide you with the number to 'switch' on in rdi.
We will provide you with a jump table base address in rsi.
Here is an example table:
[0x4040ad]=0x40305b (addrs will change)
[0x4040b5]=0x4030ef
[0x4040bd]=0x4031c1
[0x4040c5]=0x403258
[0x4040cd]=0x40333d

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle RMAN For Absolute Beginners

Authors: Darl Kuhn

1st Edition

1484207637, 9781484207635

More Books

Students also viewed these Databases questions

Question

Are you double jointed in any way?

Answered: 1 week ago

Question

find the length of the curve y=e2xln4xln8

Answered: 1 week ago