SlideShare a Scribd company logo
1 of 30
Topic S
Program Analysis and Transformation
SEG 4110: Advanced Software Design and
Reengineering
SEG4110 - Topic S - Program Analysis 2
Copyright Note
These slides are derived from work by
Bil Tzerpos a faculty member at York University
SEG4110 - Topic S - Program Analysis 3
Program Analysis
Extracting information, in order to present abstractions
of, or answer questions about, a software system
Static Analysis
• Examines the source code
Dynamic Analysis
• Examines the system as it is executing
SEG4110 - Topic S - Program Analysis 4
What are we looking for when performing
program analysis?
Depends on our goals and the system
• In almost any language, we can find out information about variable
usage
• In an OO environment, we can find out which classes use other
classes, what is the inheritance structure, etc.
• We can also find potential blocks of code that can never be executed
in running the program (dead code)
• Typically, the information extracted is in terms of entities and
relationships
—Can be metamodelled in a class diagram
SEG4110 - Topic S - Program Analysis 5
Entities
Entities are individuals that live in the system, and
attributes associated with them.
Some examples:
• Classes, along with information about their superclass,
their scope, and ‘where’ in the code they exist.
• Methods/functions and what their return type or
parameter list is, etc.
• Variables and what their types are, and whether or not
they are static, etc.
SEG4110 - Topic S - Program Analysis 6
Relationships
Relationships are interactions between the entities in the
system
Relationships include
• Classes inheriting from one another.
• Methods in one class calling the methods of another
class, and methods within the same class calling one
another.
• A method referencing an attribute.
SEG4110 - Topic S - Program Analysis 7
Information format for data extracted during
program analysis
Many different formats in use
• Simple but effective: RSF (Rigi Standard Format)
inherit TRIANGLE SHAPE
• TA (Tuple Attribute) is an extension of RSF that includes
a schema
$INSTANCE SHAPE Class
• GXL is a XML-based extension of TA
—Blow-up factor of 10 or more makes it rather
cumbersome
• New formats based on YAML being developed
SEG4110 - Topic S - Program Analysis 8
Representation of extracted information
A fundamental issue in re-engineering
• Provides
—means to generate abstractions
—input to a computational model for analyzing and
reasoning about programs
—means for translation and normalization of programs
SEG4110 - Topic S - Program Analysis 9
Key questions regarding representations of
extracted information
What are the strengths and weaknesses of each
representations of programs?
What levels of abstraction are useful?
SEG4110 - Topic S - Program Analysis 10
Abstract Syntax Trees
A translation of the source text in terms of operands and
operators
Omits superficial details, such as comments, whitespace
All necessary information to generate further
abstractions is maintained
SEG4110 - Topic S - Program Analysis 11
AST production
Four necessary elements to produce an AST:
• Lexical analyzer (turn input strings into tokens)
• Grammar (turn tokens into a parse tree)
• Domain Model (defines the nodes and arcs allowable in
the AST)
• Linker (annotates the AST with global information, e.g.
data types, scoping etc.)
SEG4110 - Topic S - Program Analysis 12
AST example
Input string: 1 + /* two */ 2
Parse Tree:
AST (without
global info) 2
1
+
int
int
Add
1 2
arg1 arg2
SEG4110 - Topic S - Program Analysis 13
Static Analysis
Involves parsing the source code
Usually creates an Abstract Syntax Tree
Borrows heavily from compiler technology
• but stops before code generation
Requires a grammar for the programming language
Can be very difficult to get right
SEG4110 - Topic S - Program Analysis 14
CppETS
CppETS is a benchmark for C++ extractors
A collection of C++ programs that pose various
problems commonly found in parsing and reverse
engineering
Static analysis research tools typically get about 60%
of the problems right
SEG4110 - Topic S - Program Analysis 15
Example program
#include <iostream.h>
class Hello {
public: Hello(); ~Hello();
};
Hello::Hello()
{ cout << "Hello, world.n"; }
Hello::~Hello()
{ cout << "Goodbye, cruel world.n"; }
main() {
Hello h;
return 0;
}
SEG4110 - Topic S - Program Analysis 16
Example Q&A
How many member methods are in the Hello
class?
Where are these member methods used?
Answer: Two, the constructor (Hello::Hello()) and
destructor (Hello::~Hello())
Answer: The constructor is called implicitly when
an instance of the class is created. The destructor
is called implicitly when the execution leaves the
scope of the instance.
SEG4110 - Topic S - Program Analysis 17
Static analysis in IDEs
High-level languages lend themselves better to static analysis
needs
• Rational Software Modeler does this with UML and Java
Unfortunately, most legacy systems are not written in either of
these languages
SEG4110 - Topic S - Program Analysis 18
Static analysis pipeline
Source code Parser Abstract Syntax Tree
Fact base
Fact extractor
Applications
Metrics tool
Visualizer
SEG4110 - Topic S - Program Analysis 19
Dynamic Analysis
Provides information about the run-time behaviour of
software systems, e.g.
• Component interactions
• Event traces
• Concurrent behaviour
• Code coverage
• Memory management
Can be done with a debugger
SEG4110 - Topic S - Program Analysis 20
Instrumentation
Augments the subject program with code that
• transmits events to a monitoring application
• or writes relevant information to an output file
A profiler tool can be used to examine the output file and
extract relevant facts from it
Instrumentation affects the execution speed and storage
space requirements of the system
SEG4110 - Topic S - Program Analysis 21
Instrumentation process
Source code Annotator Annotated program
Instrumented
executable
Compiler
Annotation
script
SEG4110 - Topic S - Program Analysis 22
Dynamic analysis pipeline
Instrumented
executable
CPU Dynamic analysis data
Fact base
Profiler
Applications
Metrics tool
Visualizer
SEG4110 - Topic S - Program Analysis 23
Non-instrumented approach
One can also use debugger log files to obtain dynamic information
• Disadvantage: Limited amount of information provided
• Advantages: Less intrusive, more accurate performance
measurements
SEG4110 - Topic S - Program Analysis 24
Dynamic analysis issues
Ensuring good code coverage is a key concern
A comprehensive test suite is required to ensure that all paths in the
code will be exercised
Results may not generalize to future executions
The size of run-time information is extraordinary large
SEG4110 - Topic S - Program Analysis 25
Summary: Static vs. Dynamic Analysis
Static Analysis
Reasons over all possible
behaviours (general results)
Conservative and sound
Challenge: Choose good
abstractions
Dynamic Analysis
Observes a small number of
behaviours (specific results)
Precise and fast
Challenge: Select representative
test cases
SEG4110 - Topic S - Program Analysis 26
Program Transformation
The act of changing one program into another
• from a source language to a target language
This is possible because of a program’s well-defined structure
• But for validity, we have to be aware of the semantics of each
structure
Used in many areas of software engineering:
• Compiler construction
• Software visualization
• Documentation generation
• Automatic software renovation
SEG4110 - Topic S - Program Analysis 27
Program transformation application
examples
Converting to a new language dialect
Migrating from a procedural language to an object-oriented one,
e.g. C to C++
Adding code comments
Requirement upgrading
• e.g. using 4 digits for years instead of 2 (Y2K)
Structural improvements
• e.g. changing GOTOs to control structures
Pretty printing
SEG4110 - Topic S - Program Analysis 28
Simple program transformation
Modify all arithmetic expressions to reduce the number
of parentheses using the formula: (a+b)*c = a*c + b*c
x := (2+5)*3
becomes
x := 2*3 + 5*3
SEG4110 - Topic S - Program Analysis 29
Two types of transformations
Translation
• Source and target language are different
• Semantics remain the same
Rephrasing
• Source and target language are the same
• Goal is to improve some aspect of the program such as
its understandability or performance
• Semantics might change
SEG4110 - Topic S - Program Analysis 30
Transformation tools
There are many transformation tools
Program-Transformation.org lists 90 of them
• http://www.program-transformation.org/
• TXL is one of the best
Most are based on ‘term rewriting’
• Other solutions use functional programming, lambda
calculus, etc.

More Related Content

Similar to reverse engineering.ppt

LIFT: A Legacy InFormation retrieval Tool
LIFT: A Legacy InFormation retrieval ToolLIFT: A Legacy InFormation retrieval Tool
LIFT: A Legacy InFormation retrieval ToolKellyton Brito
 
Probe Debugging
Probe DebuggingProbe Debugging
Probe DebuggingESUG
 
Bse 3105 lecture 4-software re-engineering
Bse 3105  lecture 4-software re-engineeringBse 3105  lecture 4-software re-engineering
Bse 3105 lecture 4-software re-engineeringAlonzee Tash
 
Software Analytics - Achievements and Challenges
Software Analytics - Achievements and ChallengesSoftware Analytics - Achievements and Challenges
Software Analytics - Achievements and ChallengesTao Xie
 
Pressman ch-11-component-level-design
Pressman ch-11-component-level-designPressman ch-11-component-level-design
Pressman ch-11-component-level-designOliver Cheng
 
CommonKADS design and implementation
CommonKADS design and implementationCommonKADS design and implementation
CommonKADS design and implementationGuus Schreiber
 
Scaling Application on High Performance Computing Clusters and Analysis of th...
Scaling Application on High Performance Computing Clusters and Analysis of th...Scaling Application on High Performance Computing Clusters and Analysis of th...
Scaling Application on High Performance Computing Clusters and Analysis of th...Rusif Eyvazli
 
3 Software Estmation.ppt
3 Software Estmation.ppt3 Software Estmation.ppt
3 Software Estmation.pptSoham De
 
Spm project planning
Spm project planning Spm project planning
Spm project planning Kanchana Devi
 
Triantafyllia Voulibasi
Triantafyllia VoulibasiTriantafyllia Voulibasi
Triantafyllia VoulibasiISSEL
 
Design & Implementation.pptx
Design & Implementation.pptxDesign & Implementation.pptx
Design & Implementation.pptxSalmaItagi2
 
The Magic Of Application Lifecycle Management In Vs Public
The Magic Of Application Lifecycle Management In Vs PublicThe Magic Of Application Lifecycle Management In Vs Public
The Magic Of Application Lifecycle Management In Vs PublicDavid Solivan
 
Software estimation techniques
Software estimation techniquesSoftware estimation techniques
Software estimation techniquesTan Tran
 
Slides4lucid
Slides4lucidSlides4lucid
Slides4lucidroysolay
 

Similar to reverse engineering.ppt (20)

LIFT: A Legacy InFormation retrieval Tool
LIFT: A Legacy InFormation retrieval ToolLIFT: A Legacy InFormation retrieval Tool
LIFT: A Legacy InFormation retrieval Tool
 
Se
SeSe
Se
 
Probe Debugging
Probe DebuggingProbe Debugging
Probe Debugging
 
Bse 3105 lecture 4-software re-engineering
Bse 3105  lecture 4-software re-engineeringBse 3105  lecture 4-software re-engineering
Bse 3105 lecture 4-software re-engineering
 
Software Analytics - Achievements and Challenges
Software Analytics - Achievements and ChallengesSoftware Analytics - Achievements and Challenges
Software Analytics - Achievements and Challenges
 
Pressman ch-11-component-level-design
Pressman ch-11-component-level-designPressman ch-11-component-level-design
Pressman ch-11-component-level-design
 
Software maintenance
Software maintenanceSoftware maintenance
Software maintenance
 
CommonKADS design and implementation
CommonKADS design and implementationCommonKADS design and implementation
CommonKADS design and implementation
 
Scaling Application on High Performance Computing Clusters and Analysis of th...
Scaling Application on High Performance Computing Clusters and Analysis of th...Scaling Application on High Performance Computing Clusters and Analysis of th...
Scaling Application on High Performance Computing Clusters and Analysis of th...
 
3 Software Estmation.ppt
3 Software Estmation.ppt3 Software Estmation.ppt
3 Software Estmation.ppt
 
Msr2021 tutorial-di penta
Msr2021 tutorial-di pentaMsr2021 tutorial-di penta
Msr2021 tutorial-di penta
 
Spm project planning
Spm project planning Spm project planning
Spm project planning
 
lecture_29.pptx
lecture_29.pptxlecture_29.pptx
lecture_29.pptx
 
Triantafyllia Voulibasi
Triantafyllia VoulibasiTriantafyllia Voulibasi
Triantafyllia Voulibasi
 
Design & Implementation.pptx
Design & Implementation.pptxDesign & Implementation.pptx
Design & Implementation.pptx
 
The Magic Of Application Lifecycle Management In Vs Public
The Magic Of Application Lifecycle Management In Vs PublicThe Magic Of Application Lifecycle Management In Vs Public
The Magic Of Application Lifecycle Management In Vs Public
 
Cocomo
CocomoCocomo
Cocomo
 
Software estimation techniques
Software estimation techniquesSoftware estimation techniques
Software estimation techniques
 
DITEC - Software Engineering
DITEC - Software EngineeringDITEC - Software Engineering
DITEC - Software Engineering
 
Slides4lucid
Slides4lucidSlides4lucid
Slides4lucid
 

More from NaglaaFathy42

introduction to web engineering.pptx
introduction to web engineering.pptxintroduction to web engineering.pptx
introduction to web engineering.pptxNaglaaFathy42
 
introduction to web engineering.pdf
introduction to web engineering.pdfintroduction to web engineering.pdf
introduction to web engineering.pdfNaglaaFathy42
 
understanding computers.ppt
understanding computers.pptunderstanding computers.ppt
understanding computers.pptNaglaaFathy42
 
semantic integration.ppt
semantic integration.pptsemantic integration.ppt
semantic integration.pptNaglaaFathy42
 
semantic web tech.ppt
semantic web tech.pptsemantic web tech.ppt
semantic web tech.pptNaglaaFathy42
 
Bioinformatic_Databases_2.ppt
Bioinformatic_Databases_2.pptBioinformatic_Databases_2.ppt
Bioinformatic_Databases_2.pptNaglaaFathy42
 
Lec2_Information Integration.ppt
 Lec2_Information Integration.ppt Lec2_Information Integration.ppt
Lec2_Information Integration.pptNaglaaFathy42
 
ch5-georeferencing.ppt
ch5-georeferencing.pptch5-georeferencing.ppt
ch5-georeferencing.pptNaglaaFathy42
 

More from NaglaaFathy42 (10)

introduction to web engineering.pptx
introduction to web engineering.pptxintroduction to web engineering.pptx
introduction to web engineering.pptx
 
introduction to web engineering.pdf
introduction to web engineering.pdfintroduction to web engineering.pdf
introduction to web engineering.pdf
 
understanding computers.ppt
understanding computers.pptunderstanding computers.ppt
understanding computers.ppt
 
semantic integration.ppt
semantic integration.pptsemantic integration.ppt
semantic integration.ppt
 
semantic web tech.ppt
semantic web tech.pptsemantic web tech.ppt
semantic web tech.ppt
 
Bioinformatic_Databases_2.ppt
Bioinformatic_Databases_2.pptBioinformatic_Databases_2.ppt
Bioinformatic_Databases_2.ppt
 
Lec2_Information Integration.ppt
 Lec2_Information Integration.ppt Lec2_Information Integration.ppt
Lec2_Information Integration.ppt
 
Web Mining .ppt
Web Mining .pptWeb Mining .ppt
Web Mining .ppt
 
ch5-georeferencing.ppt
ch5-georeferencing.pptch5-georeferencing.ppt
ch5-georeferencing.ppt
 
intro to gis
intro to gisintro to gis
intro to gis
 

Recently uploaded

Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
Call Girls In Noida City Center Metro 24/7✡️9711147426✡️ Escorts Service
Call Girls In Noida City Center Metro 24/7✡️9711147426✡️ Escorts ServiceCall Girls In Noida City Center Metro 24/7✡️9711147426✡️ Escorts Service
Call Girls In Noida City Center Metro 24/7✡️9711147426✡️ Escorts Servicejennyeacort
 
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiLow Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiSuhani Kapoor
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfLars Albertsson
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfLars Albertsson
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxStephen266013
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationshipsccctableauusergroup
 
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPramod Kumar Srivastava
 
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130Suhani Kapoor
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptSonatrach
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptxAnupama Kate
 
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...Suhani Kapoor
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingNeil Barnes
 
20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdfHuman37
 
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...shivangimorya083
 
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls DubaiDubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls Dubaihf8803863
 

Recently uploaded (20)

Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Call Girls In Noida City Center Metro 24/7✡️9711147426✡️ Escorts Service
Call Girls In Noida City Center Metro 24/7✡️9711147426✡️ Escorts ServiceCall Girls In Noida City Center Metro 24/7✡️9711147426✡️ Escorts Service
Call Girls In Noida City Center Metro 24/7✡️9711147426✡️ Escorts Service
 
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
 
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiLow Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdf
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdf
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docx
 
E-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptxE-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptx
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships
 
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
 
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx
 
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data Storytelling
 
20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf
 
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
 
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
 
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls DubaiDubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
 
Russian Call Girls Dwarka Sector 15 💓 Delhi 9999965857 @Sabina Modi VVIP MODE...
Russian Call Girls Dwarka Sector 15 💓 Delhi 9999965857 @Sabina Modi VVIP MODE...Russian Call Girls Dwarka Sector 15 💓 Delhi 9999965857 @Sabina Modi VVIP MODE...
Russian Call Girls Dwarka Sector 15 💓 Delhi 9999965857 @Sabina Modi VVIP MODE...
 

reverse engineering.ppt

  • 1. Topic S Program Analysis and Transformation SEG 4110: Advanced Software Design and Reengineering
  • 2. SEG4110 - Topic S - Program Analysis 2 Copyright Note These slides are derived from work by Bil Tzerpos a faculty member at York University
  • 3. SEG4110 - Topic S - Program Analysis 3 Program Analysis Extracting information, in order to present abstractions of, or answer questions about, a software system Static Analysis • Examines the source code Dynamic Analysis • Examines the system as it is executing
  • 4. SEG4110 - Topic S - Program Analysis 4 What are we looking for when performing program analysis? Depends on our goals and the system • In almost any language, we can find out information about variable usage • In an OO environment, we can find out which classes use other classes, what is the inheritance structure, etc. • We can also find potential blocks of code that can never be executed in running the program (dead code) • Typically, the information extracted is in terms of entities and relationships —Can be metamodelled in a class diagram
  • 5. SEG4110 - Topic S - Program Analysis 5 Entities Entities are individuals that live in the system, and attributes associated with them. Some examples: • Classes, along with information about their superclass, their scope, and ‘where’ in the code they exist. • Methods/functions and what their return type or parameter list is, etc. • Variables and what their types are, and whether or not they are static, etc.
  • 6. SEG4110 - Topic S - Program Analysis 6 Relationships Relationships are interactions between the entities in the system Relationships include • Classes inheriting from one another. • Methods in one class calling the methods of another class, and methods within the same class calling one another. • A method referencing an attribute.
  • 7. SEG4110 - Topic S - Program Analysis 7 Information format for data extracted during program analysis Many different formats in use • Simple but effective: RSF (Rigi Standard Format) inherit TRIANGLE SHAPE • TA (Tuple Attribute) is an extension of RSF that includes a schema $INSTANCE SHAPE Class • GXL is a XML-based extension of TA —Blow-up factor of 10 or more makes it rather cumbersome • New formats based on YAML being developed
  • 8. SEG4110 - Topic S - Program Analysis 8 Representation of extracted information A fundamental issue in re-engineering • Provides —means to generate abstractions —input to a computational model for analyzing and reasoning about programs —means for translation and normalization of programs
  • 9. SEG4110 - Topic S - Program Analysis 9 Key questions regarding representations of extracted information What are the strengths and weaknesses of each representations of programs? What levels of abstraction are useful?
  • 10. SEG4110 - Topic S - Program Analysis 10 Abstract Syntax Trees A translation of the source text in terms of operands and operators Omits superficial details, such as comments, whitespace All necessary information to generate further abstractions is maintained
  • 11. SEG4110 - Topic S - Program Analysis 11 AST production Four necessary elements to produce an AST: • Lexical analyzer (turn input strings into tokens) • Grammar (turn tokens into a parse tree) • Domain Model (defines the nodes and arcs allowable in the AST) • Linker (annotates the AST with global information, e.g. data types, scoping etc.)
  • 12. SEG4110 - Topic S - Program Analysis 12 AST example Input string: 1 + /* two */ 2 Parse Tree: AST (without global info) 2 1 + int int Add 1 2 arg1 arg2
  • 13. SEG4110 - Topic S - Program Analysis 13 Static Analysis Involves parsing the source code Usually creates an Abstract Syntax Tree Borrows heavily from compiler technology • but stops before code generation Requires a grammar for the programming language Can be very difficult to get right
  • 14. SEG4110 - Topic S - Program Analysis 14 CppETS CppETS is a benchmark for C++ extractors A collection of C++ programs that pose various problems commonly found in parsing and reverse engineering Static analysis research tools typically get about 60% of the problems right
  • 15. SEG4110 - Topic S - Program Analysis 15 Example program #include <iostream.h> class Hello { public: Hello(); ~Hello(); }; Hello::Hello() { cout << "Hello, world.n"; } Hello::~Hello() { cout << "Goodbye, cruel world.n"; } main() { Hello h; return 0; }
  • 16. SEG4110 - Topic S - Program Analysis 16 Example Q&A How many member methods are in the Hello class? Where are these member methods used? Answer: Two, the constructor (Hello::Hello()) and destructor (Hello::~Hello()) Answer: The constructor is called implicitly when an instance of the class is created. The destructor is called implicitly when the execution leaves the scope of the instance.
  • 17. SEG4110 - Topic S - Program Analysis 17 Static analysis in IDEs High-level languages lend themselves better to static analysis needs • Rational Software Modeler does this with UML and Java Unfortunately, most legacy systems are not written in either of these languages
  • 18. SEG4110 - Topic S - Program Analysis 18 Static analysis pipeline Source code Parser Abstract Syntax Tree Fact base Fact extractor Applications Metrics tool Visualizer
  • 19. SEG4110 - Topic S - Program Analysis 19 Dynamic Analysis Provides information about the run-time behaviour of software systems, e.g. • Component interactions • Event traces • Concurrent behaviour • Code coverage • Memory management Can be done with a debugger
  • 20. SEG4110 - Topic S - Program Analysis 20 Instrumentation Augments the subject program with code that • transmits events to a monitoring application • or writes relevant information to an output file A profiler tool can be used to examine the output file and extract relevant facts from it Instrumentation affects the execution speed and storage space requirements of the system
  • 21. SEG4110 - Topic S - Program Analysis 21 Instrumentation process Source code Annotator Annotated program Instrumented executable Compiler Annotation script
  • 22. SEG4110 - Topic S - Program Analysis 22 Dynamic analysis pipeline Instrumented executable CPU Dynamic analysis data Fact base Profiler Applications Metrics tool Visualizer
  • 23. SEG4110 - Topic S - Program Analysis 23 Non-instrumented approach One can also use debugger log files to obtain dynamic information • Disadvantage: Limited amount of information provided • Advantages: Less intrusive, more accurate performance measurements
  • 24. SEG4110 - Topic S - Program Analysis 24 Dynamic analysis issues Ensuring good code coverage is a key concern A comprehensive test suite is required to ensure that all paths in the code will be exercised Results may not generalize to future executions The size of run-time information is extraordinary large
  • 25. SEG4110 - Topic S - Program Analysis 25 Summary: Static vs. Dynamic Analysis Static Analysis Reasons over all possible behaviours (general results) Conservative and sound Challenge: Choose good abstractions Dynamic Analysis Observes a small number of behaviours (specific results) Precise and fast Challenge: Select representative test cases
  • 26. SEG4110 - Topic S - Program Analysis 26 Program Transformation The act of changing one program into another • from a source language to a target language This is possible because of a program’s well-defined structure • But for validity, we have to be aware of the semantics of each structure Used in many areas of software engineering: • Compiler construction • Software visualization • Documentation generation • Automatic software renovation
  • 27. SEG4110 - Topic S - Program Analysis 27 Program transformation application examples Converting to a new language dialect Migrating from a procedural language to an object-oriented one, e.g. C to C++ Adding code comments Requirement upgrading • e.g. using 4 digits for years instead of 2 (Y2K) Structural improvements • e.g. changing GOTOs to control structures Pretty printing
  • 28. SEG4110 - Topic S - Program Analysis 28 Simple program transformation Modify all arithmetic expressions to reduce the number of parentheses using the formula: (a+b)*c = a*c + b*c x := (2+5)*3 becomes x := 2*3 + 5*3
  • 29. SEG4110 - Topic S - Program Analysis 29 Two types of transformations Translation • Source and target language are different • Semantics remain the same Rephrasing • Source and target language are the same • Goal is to improve some aspect of the program such as its understandability or performance • Semantics might change
  • 30. SEG4110 - Topic S - Program Analysis 30 Transformation tools There are many transformation tools Program-Transformation.org lists 90 of them • http://www.program-transformation.org/ • TXL is one of the best Most are based on ‘term rewriting’ • Other solutions use functional programming, lambda calculus, etc.