Reverse Engineering Using the C Analyzer

I l @ ve RuBoard

Reverse Engineering Using the C++ Analyzer

Step 1: Create a Project

A C++ Analyzer project contains the information needed to extract a Rose design from source-code files. An analyzer project contains the following information:

  • Caption: Informational description of the project.

  • Directories: List of directories used by the Analyzer. The directories that contain the source code files as well as the directories containing any code used by the source code to be analyzed must be included in the directory list.

  • Extensions: List of file extensions recognized by the analyzer.

  • Files: List of files to be analyzed.

  • Defined Symbols and Undefined Symbols: List of preprocessor symbols and their expansions.

  • Categories: List of packages to which classes and packages may be assigned.

  • Subsystems: List of packages to which components and packages may be assigned.

  • Bases: List of base projects containing information needed to resolve source code references.

  • Type 2 Context: Preprocessor directives needed by context-sensitive source code files.

  • Export Options: List of information that is to be exported either to create or update a Rose model.

Once a project is created, it is saved with a .pjt extension.

CREATING A PROJECT IN THE C++ ANALYZER

graphics/quatranirose_icon.gif
  1. Select the Tools:C++:Reverse Engineering menu choice to start the C++ Analyzer.

  2. Select the File:New menu choice.

The C++ Analyzer Project window is shown in Figure A-8.

Figure A-8. C++ Analyzer Project Window

graphics/afig08.gif

Step 2: Add Project Caption

Just as code is documented for future use, analyzer projects are also documented. Each project should contain a caption. This is typically descriptive information about the project such as its title and purpose. This information may be used by other teams to determine if the project has reuse potential either as a standalone project or as a base project.

ADDING A CAPTION IN THE C++ ANALYZER

graphics/quatranirose_icon.gif
  1. Click the Caption button to make the Caption window visible.

  2. Enter the information in the Caption window.

  3. Click the OK button to close the Caption window.

The Caption window is shown in Figure A-9.

Figure A-9. Caption Window

graphics/afig09.jpg

Step 3: Add Referenced Libraries and Base Projects

The directory list contains a list of directories used by the C++ Analyzer. The directory containing a file to be analyzed must be in the directory list. In addition, the directory for any included file must also be in the directory list.

CREATING THE DIRECTORY LIST IN THE C++ ANALYZER

graphics/quatranirose_icon.gif
  1. Click the Directories button to make the Project Directory List window visible.

  2. Click to select a directory in the Directory Structure file. This will set the directory to the current directory.

  3. Click the Add Current button to add the current directory to the directory list.

  4. Click the Add Subdirs button to add the current directory and its immediate subdirectories to the directory list.

  5. Click the Add Hierarchy button to add the current directory and all its nested subdirectories to the directory list.

The Project Directory List window is shown in Figure A-10.

Figure A-10. Project Directory List Window

graphics/afig10.gif

An analyzer project may use information from another project, called a base project. Typically, base projects contain information about header files for compiler-specific libraries or class libraries on which the program is built. Rather than reanalyze this information in every project that uses these files, a base project is created. The base project may then be used by any other project that needs information about the files in the base project. Base projects are identified in the base project list.

If the Analyzer cannot find a file in the project directory list, it will look for the file in a base project, which are searched in the order in which they appear in the base project list.

ADDING BASE PROJECTS IN THE C++ ANALYZER

graphics/quatranirose_icon.gif
  1. Click the Bases button to make the Base Projects window visible.

  2. Click to navigate through the directory structure until the desired project is visible in the File Name box.

  3. Click to select the project.

  4. Click the Add button to add the base project.

The Base Projects window is shown in Figure A-11.

Figure A-11. Base Projects Window

graphics/afig11.jpg

Step 4: Set the File Type and Analyze the Files

The analyzer categorizes files into three different file typesType 1, Type 2, and Type 3. When a file is added to the file list it is made a Type 1 file. This type of file is syntactically complete and context independent. That is, the file is a list of complete C++ declarations at file scope and either contains all information that it needs or obtains the information from its #include directives. A Type 2 file is syntactically complete but context-dependent; that is, the file is a list of complete C++ declarations at file scope but the file contains symbols whose definitions are provided by the context in which it is included. A Type 3 file is syntactically incomplete. Type 3 files are always processed as they are encountered .

TO CHANGE THE ANALYSIS TYPE IN THE C++ ANALYZER

graphics/quatranirose_icon.gif
  1. Click to select the file in the files list.

  2. Click to select the appropriate type from the Action:Set Type menu.

The C++ Analyzer may process a single file or a group of files. The Analyzer creates and stores analysis information in a data file for each file it processes. This data may be used the next time the file is analyzed. The status of each file is updated in the files list as the file is processed. The status may be

  • Unknown: The file has not been analyzed.

  • Stale Data: There is potentially out-of-date data for the file.

  • Analyzed: Successful analysis. This status is applied to Type 1 and Type 2 source code files only.

  • CodeCycled: Successful analysis, and the file contains annotations that protect existing information in the code from being overwritten. This status is applied to Type 1 and Type 2 source code files only.

  • Excluded: This is a Type 3 file, which is analyzed each time it is encountered in another file.

  • Has Errors: Found errors in the source code file while analyzing it.

  • No Source: Cannot find the file in the file system.

  • Unanalyzed: Cannot find a data file for this file.

ANALYZING FILES IN THE C++ ANALYZER

graphics/quatranirose_icon.gif
  1. Set the Analysis Type for each file to be analyzed.

  2. Click to select the files in the Files list.

  3. Select the Action:Analyze menu choice to analyze the file, or select the Action:CodeCycle menu choice to analyze the file and ensure that the annotations needed for Rose are present.

The analyzer window along with an analysis status is shown in Figure A-12.

Figure A-12. Analyzer Status

graphics/afig12.gif

Step 5: Evaluate the Errors

The Analyzer writes all errors to the Log window. Errors can also be viewed in the files list by double-clicking on the file. Each error should be evaluated as to its severity. Some common errors are

  • Unresolved references: The Analyzer cannot find referenced source files. To resolve this type of error, the directory containing the referenced source file must be added to the directory list.

  • Missing language extensions: Language extensions not recognized by the Analyzer. To resolve this type of error, the language extension must be defined as a symbol.

  • Context-sensitive source files: Code from another directory is referenced but not included in the file. To resolve this type of error, change the file to either a Type 2 or Type 3 file.

The analyzer window, along with the errors encountered during analysis, is shown in Figure A-13.

Figure A-13. Analyzer Errors

graphics/afig13.gif

Step 6: Select Export Options and Export to Rose

The export options specify what elements should be modeled and drawn in the exported file. For example, a class can be modeled and drawn, comments can be added, associations can be modeled and drawn, and dependency relationships can be modeled. If an element is modeled and drawn, it will be visible in the created or updated Rose model. If an element is modeled, it can be drawn within Rose once a Rose model is created or updated. If it is not modeled , then it can never be drawn in Rose.

The C++ Analyzer has multiple export options sets already set up for your use. They are

  • RoundTrip: Export options useful in a round-trip engineering exercise. A file with the extension .red is created.

  • First Look: High-level look at the model. A .mdl file is created.

  • DetailedAnalysis: Detailed look at the model. A .mdl file is created.

You have the option of using one of the preexisting export option sets, modifying one of the preexisting export option sets, or creating your own export option set.

EXPORTING TO ROSE IN THE C++ ANALYZER

graphics/quatranirose_icon.gif
  1. Click to select the files to be exported.

  2. Select the Action:Export to Rose menu choice.

  3. Click the arrow on the Option Set field to make the drop-down menu visible.

  4. Click to select the desired export option set.

  5. Click the OK button or the Overwrite button to export to Rose.

The Export to Rose window is shown in Figure A-14.

Figure A-14. Export to Rose

graphics/afig14.gif

Step 7: Update Rose Model

Once the .red file is created by the Analyzer, it is used to update the Rose model. This will replace elements of the Rose model with elements extracted from the source code. In addition, any elements in the code that are not in the model are added to the model.

UPDATING A ROSE MODEL

graphics/quatranirose_icon.gif
  1. Open the Rose model to be updated.

  2. Select the File:Update menu choice.

  3. Navigate through the directory structure to locate the .red file.

  4. Click to select the .red file.

  5. Click the OK button to close the Update Model From window.

I l @ ve RuBoard


Visual Modeling with Rational Rose 2002 and UML
Visual Modeling with Rational Rose 2002 and UML (3rd Edition)
ISBN: 0201729326
EAN: 2147483647
Year: 2002
Pages: 134

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net