Lecture 7
Lecture 7
SE-409
TECHNIQUES USED FOR REVERSE
ENGINEERING
• Fact-finding and information gathering from the source code are the
keys to the Goal/Models/Tools paradigm, which partitions a process
for reverse engineering into three ordered stages: Goals, Models, and
Tools.
• In order to extract information which is not clearly available in source
code, automated analysis techniques are used.
• The well-known analysis techniques that facilitate reverse engineering
are lexical analysis, syntactic analysis, data flow analysis, program
slicing, visualization, etc.
Lexical Analysis
• int
• number
•=
•5
•;
• A pattern defines the structure of tokens. It’s like a rule that the
lexical analyzer uses to recognize lexemes for a particular token type.
Examples of Patterns:
•For a number token, the pattern might be a sequence of digits (e.g., 0-
9).
•For a variable token, the pattern could be a sequence of alphabetic
characters followed by numbers (e.g., abc123).
•For a keyword token, the pattern might simply match exact words like
if, while, or return.
Lexical Analysis (Example 1)
int main()
{
// 2 variables
int a, b;
a = 10;
return 0;
}
Mention All the valid tokens are?
Lexical Analysis (Example 1)
Answer : 'int' 'main' '(' ')' '{' 'int' 'a' ',' 'b' ';‘ 'a' '=' '10' ';' 'return'
'0' ';' '}‘
Above are the valid tokens. Observe that it omitted the comments.
1. a = 10
2. b = 20
3. sum = a + b
Forward slicing
• Starts from a statement or a point in the program and identifies the
statements that are influenced by it. It is useful for understanding
the consequences of a particular statement.
Example
Criteria: S<[3]:sum>
• 1. x = 5
• 2. y = 10
• 3. sum = x + y
• 4. result = sum * 2
• 5. final_result = result - 3
The forward slice starting from sum would
be:
[3]->[4]->[5]
• 3. sum = x + y
• 4. result = sum * 2
• 5. final_result = result - 3
Why Do We Need Slicing?
• Debugging: Focus on parts of program relevant for a bug.