February 2012
Intermediate to advanced
800 pages
23h 55m
English
switch statements are used by programmers (and malware
authors) to make a decision based on a character or integer. For example, backdoors commonly select
from a series of actions using a single byte value. switch
statements are compiled in two common ways: using the if style or using jump tables.
Example 6-20 shows a simple switch statement that uses the variable i. Depending on the value of i, the code under the
corresponding case value will be executed.
Example 6-20. C code for a three-option switch statement
switch(i)
{
case 1:
printf("i = %d", i+1);
break;
case 2:
printf("i = %d", i+2);
break;
case 3:
printf("i = %d", i+3);
break;
default:
break;
}This switch statement has been compiled into the assembly code ...