Download presentation
Presentation is loading. Please wait.
1
Authors: Khaled Abdelsalam Mohamed Amr Kamel
Reverse Engineering State and Strategy Design Patterns using Static Code Analysis Authors: Khaled Abdelsalam Mohamed Amr Kamel
2
Software Development Continuous changes Bug fixing New features
Requirements/Technological
3
Software Development Development team can also change
New team members may need to learn from scratch Hard to know every implementation detail
4
Software Development Development team can also change
New team members may need to learn from scratch Documentation becomes vital Tedious to keep updated
5
Software Development There have been many techniques to ease legacy code insight and understanding
6
Legacy/Undocumented code
Design patterns have specific intentions Leads to understanding the usage of different parts of the software
7
Legacy/Undocumented code
How can we extract design patterns from software? Decorator Strategy Observer State
8
The techniques Analysis type Search Methodology
How to map the software properties Search Methodology How to search those properties
9
The techniques Analysis type:
Structural analysis: Recovers Class relationships, method signatures, compositions etc. Proxy, Decorator, Adapter etc.
10
The techniques Analysis type:
Structural analysis: Recovers Class relationships, method signatures, compositions etc. Proxy, Decorator, Adapter etc. Behavioral analysis: Recovers the components actions of the software. Iterator, State, Observer etc.
11
The techniques Analysis type:
Structural analysis: Recovers Class relationships, method signatures, compositions etc. Proxy, Decorator, Adapter etc. Behavioral analysis: Recovers the components actions of the software. Iterator, State, Observer etc. Semantic analysis: Supplements both. Uses naming conventions.
12
The techniques Search Methodology:
Database queries: Code is mapped with metadata structures
13
The techniques Search Methodology:
Database queries: Code is mapped with metadata structures Constraint Resolver: Code Is mapped with addition of constraints and roles
14
The techniques Search Methodology:
Database queries: Code is mapped with metadata structures Constraint Resolver: Code Is mapped with addition of constraints and roles XPG formalism and parsing: Source code mapped as a visual language
15
The techniques Search Methodology:
Database queries: Code is mapped with metadata structures Constraint Resolver: Code Is mapped with addition of constraints and roles XPG formalism and parsing: Source code mapped as a visual language Code UML structures used to derive metrics. Found metrics compared against the expected metrics of a given Design Pattern
16
The techniques Static Analysis Dynamic Analysis
Process to analyze code by deriving information from the source code Dynamic Analysis Derive information from running software Static Analysis -> Can be done in incomplete code
17
The techniques Static Analysis
Process to analyze code by deriving information from the source code
18
The techniques Static Analysis Dynamic Analysis
Process to analyze code by deriving information from the source code Dynamic Analysis Derive information from running software
19
The techniques Static Analysis Dynamic Analysis
Process to analyze code by deriving information from the source code Dynamic Analysis Derive information from running software Static Analysis -> Can be done in incomplete code
20
The approach Use Static code analysis to find design patterns
Program dependency Control dependency Data dependency
21
The approach The code is mapped as a graph
Design patterns graphs are matched to code generated graph
22
The approach The Joern Platform was modified to also save class hierarchy Graph data persisted with Neo4j Gremlin to query the data Joern
23
The approach - Steps 1. Load source code
24
The approach - Steps 1. Load source code 2. Code property graph Joern
25
The approach - Steps Joern 1. Load source code 2. Code property graph
3. Save graph in Neo4j DB Joern
26
4. Add Design Patterns Attributes
The approach - Steps 1. Load source code 2. Code property graph 3. Save graph in Neo4j DB 4. Add Design Patterns Attributes Joern
27
4. Add Design Patterns Attributes
The approach - Steps 1. Load source code 2. Code property graph 3. Save graph in Neo4j DB 4. Add Design Patterns Attributes 5. Select Design Pattern Joern
28
The approach - Steps Joern 1. Load source code 2. Code property graph
3. Save graph in Neo4j DB 4. Add Design Patterns Attributes 5. Select Design Pattern 6. Load Design Pattern Matching Queries Joern
29
The approach - Steps Joern 1. Load source code 2. Code property graph
3. Save graph in Neo4j DB 4. Add Design Patterns Attributes 5. Select Design Pattern 6. Load Design Pattern Matching Queries 7. Run Queries Joern
30
The approach - Steps Joern 1. Load source code 2. Code property graph
3. Save graph in Neo4j DB 4. Add Design Patterns Attributes 5. Select Design Pattern 6. Load Design Pattern Matching Queries 7. Run Queries 8. Display Graph Matching Patterns results Joern
31
The approach State and Strategy design patterns issue
Similar structure Different behavior
32
State and Strategy design patterns issue
Similar structure Different behavior vs
33
State and Strategy design patterns issue
34
Metadata graph enrichment
Methods to Classes Link between classes and their methods (Joern misses)
35
Metadata graph enrichment
Methods to Classes Link between classes and their methods (Joern misses) Inheritance Adds the relation between Super class and their subclasses
36
Metadata graph enrichment
Methods to Classes Link between classes and their methods (Joern misses) Inheritance Adds the relation between Super class and their subclasses Abstract (Virtual) Methods With body No body
37
Metadata graph enrichment
Class Aggregates Class
38
Metadata graph enrichment
Class Aggregates Class Link between classes aggregating other classes Method Creates Class Link between a method and the class of the object it instantiates
39
Metadata graph enrichment
Class Aggregates Class Link between classes aggregating other classes Method Creates Class Link between a method and the class of the object it instantiates Method Overrides Method Link between methods overriding each other
40
Metadata graph enrichment
Class Aggregates Class Link between classes aggregating other classes Method Creates Class Link between a method and the class of the object it instantiates Method Overrides Method Link between methods overriding each other Method Calls Method Link between a caller method and the method called
41
Solving the State and Strategy issue
Step 1 Find State and Strategy candidates Step 2 Differentiate State and Strategy candidates
42
Differentiating State and Strategy candidates
Loop each pattern candidate Find class aggregations variables (let’s call it X) Use find methods M that use variables X Check if methods M includes subclasses from pattern candidates If c is truth then the candidate is a State design Check if methods from c includes client method from pattern candidates If f is true then the candidate is a strategy
43
Authors Conclusion Successfully use Code Property Graph to map Design patterns Able to differentiate Strategy and State Uses only static analysis As future work Make catalogue of all relationships and properties of design patterns Support multiple graph pattern variants
44
Paper critique Abstract and Introduction
Deviated from the described a Approach Focus in the Strategy/State No mention of qualitative/quantitative study
45
My Conclusion Needs to evaluate the approach Practical idea Constrain
Test on well know good code (e.g, Linux Kernel on Github) Practical idea Constrain Needs well written code that uses design pattern
46
References https://refactoring.guru/design-patterns/strategy
Kniesel, Gunter and Binun, Alexander, "Standing on the shoulders of giants- a data fusion approach to design pattern detection," in Program Comprehension, ICPC'09. IEEE 17th International Conference on, T. A. Ghaleb, "The role of open source software in program analysis for reverse engineering," 2016 2nd International Conference on Open Source Software Computing (OSSCOM), Beirut, 2016, pp doi: /OSSCOM G. Costagliola and G. Polese, "Extended positional grammars," Proceeding IEEE International Symposium on Visual Languages, Seattle, WA, 2000, pp doi: /VL
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.