39
Extracting Architectural Model from Source Code By: Morteza Zakeri – Mohsen Amirian Advanced Software Engineering Course Iran University of Science and Technology Winter 2017

Extract architecture from_source_code_v1

Embed Size (px)

Citation preview

Page 1: Extract architecture from_source_code_v1

Extracting Architectural Model

from Source Code

By:

Morteza Zakeri – Mohsen AmirianAdvanced Software Engineering CourseIran University of Science and TechnologyWinter 2017

Page 2: Extract architecture from_source_code_v1

Outline

• What is Software Reverse Engineering (SRE)?

• Two Different Dimensions

• Motivation

• SRE Tools

• Modularity Principles

• Extracting Architectural Model Step by Step

• Practical Case Study

• References

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.AmirianPage 2 of 38

Page 3: Extract architecture from_source_code_v1

What is Software Reverse Engineering?

• Software Reverse Engineering (SRE) is the practice of analyzing a software system, either in whole or in part, to extract design and implementationinformation [1].

• [1] Cipresso, T. (2009). Software Reverse Engineering Education, (August), 120.

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.AmirianPage 3 of 38

Page 4: Extract architecture from_source_code_v1

Two Different Dimensions

• Binary Code Reverse Engineering• To obtain source code from executable object.

• Source Code Reverse Engineering• To extract architectural features.

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.AmirianPage 4 of 38

Page 5: Extract architecture from_source_code_v1

Motivation

1. Old software systems are often not documented or very less documentation is available.• Even in the systems where documentation is available

there is no explicit mention of the architecture that the code possesses.

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.AmirianPage 5 of 38

Page 6: Extract architecture from_source_code_v1

Motivation

2. New changes to the system need a knowledge of implicit architecture that the system possess.

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.AmirianPage 6 of 38

Page 7: Extract architecture from_source_code_v1

Motivation

3. Legacy Transformation• It is a tough task to convert a 10,000 line COBOL code

to C/C++ code if the programmer is unaware of the underlying architecture.

• As around 70% of world’s source code is in COBOL and in scientific communities FORTRAN has been the obvious choice [2].

• [2] Ali, M. R. (2005). Why teach reverse engineering? SIGSOFT Softw. Eng. Notes, 30(4), 1–4. https://doi.org/10.1145/1082983.1083004

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.AmirianPage 7 of 38

Page 8: Extract architecture from_source_code_v1

Motivation

4. System evolution• As system evolves , it tends to drift from it’s original

architecture.

• So it is very important to recover or reconstruct the architecture of the system in the spirit that new changes to the system do not affect the existing working model.

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.AmirianPage 8 of 38

Page 9: Extract architecture from_source_code_v1

Motivation

5. Software Testing and Security• Techniques are used to debug and find bugs and

errors.

• Techniques are used to make sure that the system does not have any major vulnerabilities and security flaws.

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.AmirianPage 9 of 38

Page 10: Extract architecture from_source_code_v1

Binary Code Reverse Engineering Tools

• Disassemblers

• Debuggers

• Hex Editors

• PE and Resource Viewer

• Example:• IAD Pro, OllyDBG, WinDBG, etc.

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.AmirianPage 10 of 38

Page 11: Extract architecture from_source_code_v1

Source Code Reverse Engineering Tools

• Calculate some software metrics.• Lines of code (LoC)

• Number of Class, Functions, Statements, etc.

• Visualize source code architecture to optimize software design.

• Sometimes we need higher level of abstraction.• e.g. Component Diagram.

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.AmirianPage 11 of 38

Page 12: Extract architecture from_source_code_v1

Modularity Principles

• Cohesion• Refers to the degree to which the elements of a

module belong together.

• Coupling• The degree of interdependence between software

modules.

• Good Design: High cohesion (↑), loose coupling (↓).

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.AmirianPage 12 of 38

Page 13: Extract architecture from_source_code_v1

Reversing Steps

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.AmirianPage 13 of 38

Page 14: Extract architecture from_source_code_v1

Understand

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.AmirianPage 14 of 38

Page 15: Extract architecture from_source_code_v1

Bunch

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.Amirian

• Bunch is a graph clustering tools.

• As part of Ph.D. thesis in Computer Science at Drexel University.

• By: Brian Mitchell

• Using heuristic searching such as • Genetic Algorithm,

• Hill Climbing,

• …

Page 15 of 38

Page 16: Extract architecture from_source_code_v1

بررسی یک مثال ساده

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.Amirian

. را در نظر بگیریدa, b, c, e, fکالس 5ای مشتمل بر برنامه •

س بهه ما اطالعاتی از تعداد دستیابی های متدهای هر کالدستییک بررسی با •الس برای مثال مشاهده می کنیم که در ک. متدهای کالس دیگر به دست می آوریم

a دو بار متدهای کالسbفراخوانی شده است .

:اطالع را به صورت زیر نشان می دهیمما این •

• a b 2

Page 16 of 38

Page 17: Extract architecture from_source_code_v1

یاستخراج مدل ارتباطی در قالب گراف وابستگی کالس: گام اول

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.AmirianPage 17 of 38

Page 18: Extract architecture from_source_code_v1

یاستخراج مدل ارتباطی در قالب گراف وابستگی کالس: گام اول

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.AmirianPage 18 of 38

Page 19: Extract architecture from_source_code_v1

Bunchبه ورودی Understandتبدیل خروجی : گام دوم

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.Amirian

قرار Bunchدر واقع خروجی گام قبل که گراف وزن دار جهت دار است، ورودی •.می گیرد

Page 19 of 38

Page 20: Extract architecture from_source_code_v1

Bunchبه ورودی Understandتبدیل خروجی : گام دوم

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.AmirianPage 20 of 38

Page 21: Extract architecture from_source_code_v1

خوشه بندی: سومگام

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.AmirianPage 21 of 38

Page 22: Extract architecture from_source_code_v1

Measuring Modularization Quality (MQ)

• Basic MQ

• Inter-connectivity • (i.e., connections between the components of two

distinct clusters)

• Intra-connectivity• (i.e., connections between the components of the

same cluster) [3].

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.AmirianPage 22 of 38

Page 23: Extract architecture from_source_code_v1

Measuring Modularization Quality (MQ)

• Intra-connectivity measurement 𝐴𝑖 of cluster i

consisting of 𝑁𝑖 components and 𝜇𝑖 intra-edge relations as:

• 𝐴𝑖 =𝜇𝑖

𝑁𝑖2

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.AmirianPage 23 of 38

Page 24: Extract architecture from_source_code_v1

Measuring Modularization Quality (MQ)

• Inter-connectivity 𝐸𝑖,𝑗 between clusters i and jconsisting of 𝑁𝑖 and 𝑁𝑗 components, respectively, and with 𝜀𝑖 inter-edge dependencies as:

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.AmirianPage 24 of 38

Page 25: Extract architecture from_source_code_v1

Measuring Modularization Quality (MQ)

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.AmirianPage 25 of 38

Page 26: Extract architecture from_source_code_v1

Measuring Modularization Quality (MQ)

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.AmirianPage 26 of 38

Page 27: Extract architecture from_source_code_v1

The BasicMQ Measurement

• The BasicMQ measurement demonstrates the tradeoff between inter-connectivity and intra-connectivity by rewarding the creation of highly-cohesive clusters, while penalizing the creation of too many inter-edges (k is number of subsystems):

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.AmirianPage 27 of 38

Page 28: Extract architecture from_source_code_v1

The BasicMQ Measurement

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.AmirianPage 28 of 38

Page 29: Extract architecture from_source_code_v1

خوشه بندی: سومگام

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.AmirianPage 29 of 38

Page 30: Extract architecture from_source_code_v1

(Graphvizنمایش در )بندیخوشه : سومگام

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.AmirianPage 30 of 38

Page 31: Extract architecture from_source_code_v1

استخراج طرح معماری: چهارمگام

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.Amirian

• IBM Rational Rose• rationalrose.tlb

• ProgramFiles\Rational\Rose\rationalrose.tlb

Page 31 of 38

Page 32: Extract architecture from_source_code_v1

(Package Viewابزار )معماری استخراج طرح : گام چهارم

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.AmirianPage 32 of 38

Page 33: Extract architecture from_source_code_v1

Rational Roseنمایش در محیط عملیاتی : گام چهارم

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.AmirianPage 33 of 38

Page 34: Extract architecture from_source_code_v1

Rational Roseنمایش در محیط عملیاتی : گام چهارم

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.AmirianPage 34 of 38

Page 35: Extract architecture from_source_code_v1

کارهای آتی

تعمیم برنامه برای استخراج معماری برنامه های ساخت یافته•تبدیل خودکار برنامه های ساخت یافته به شی گرا•بررسی نحوه استخراج سایر نمودارهای طراحی از کد منبع • Visual Paradigm ،Oracleنظیر نمایش در دیگر محیط های مشابه•

Designer و. ...

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.AmirianPage 35 of 38

Page 36: Extract architecture from_source_code_v1

References

• [1] Cipresso, T. (2009). Software Reverse Engineering Education, (August), 120.

• [2] Ali, M. R. (2005). Why teach reverse engineering? SIGSOFT Softw. Eng. Notes, 30(4), 1–4. https://doi.org/10.1145/1082983.1083004

• [3] Mitchell, B. S. (2002). A Heuristic Search Approach to Solving the Software Clustering Problem, (March).

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.AmirianPage 36 of 38

Page 37: Extract architecture from_source_code_v1

Tools

• Understand• https://scitools.com/

• Bunch• https://www.cs.drexel.edu/~spiros/bunch/

• Graphviz• http://www.graphviz.org

• IBM Rational Rose Enterprise• http://www-03.ibm.com/software/products/en/enterprise

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.AmirianPage 37 of 38

Page 38: Extract architecture from_source_code_v1

IUST Tools

• Understand 2 Bunch

• Bunch 2 Rational (Package Viewer)

21 February 2017Extracting Architecture from Source Code -

M.Zakeri, M.AmirianPage 38 of 38

Page 39: Extract architecture from_source_code_v1