Klairovoyance

September, 2012. Compiler Laboratory

Program for .NET UI editing. Capable of viewing a program’s GUI outside Visual Studio. Features a finely abstracted code structure for simple addition and definition of GUI components for source analysis and GUI reconstruction. This is done by working on .res files of forms.

The objective:

To facilitate GUI previewing of VB.NET applications independent of the Microsoft Visual Studio IDE by reverse engineering information obtained by analysis of Visual Studio generated designer files and information extraction from .resx files.

Large scale .Net projects take excessively longer processing time for Visual Studio to prepare the IDE. Situation may require only a visual preview or analysis of certain forms in a solution/project/single form. Construction of an external GUI renderer based on VS generated designer files would prove to be a highly efficient means of achieving the same.

Flow of operation:

A general investigation into script generated from user specified GUI information designed from within the VS IDE yields the following details, each respective to 3 files for each Form in a solution/project space:

  • .vb File
  • .vb.designer File
  • .resx File

.vb File

This file contains a one-is-to-one dump of only the user entered source code for events with respect to components being addresses as seen from within the VS IDE.

vb.designer File

This file contains the IDE generated code for GUI specifications from user specified information in the VS WYSIWYG GUI designer. The information is stored in .NET compliant source code describing procedures to create components during runtime. The source code in the “InitializeComponent()” section needs to be selectively parsed out by the Klairvoyance Scanner and a subsequent text specifying details relevant to our objective is generated for processing by the Klairvoyance  Renderer.

.resx File

This file contains embedded Meta data in the program. Data pertaining to bulk text stored in textbox related components, Images of various formats stored in image storing components like picturebox or image containers like Form backgrounds and background properties of components having support for the same, encoded in ByteArray, base64 .

Components

Steps up to actual GUI rendering are done using 2 individual components, namely:

  • Klairvoyance Scanner
  • Klairvoyance Renderer

Klairvoyance Scanner

This component is programmed in C++ with the help of Bison and Flex. The scanner looks through the above mentioned Files of relevance and generates a separate file with purely relevant information in a condensed format. This file, called the Klairvoyance Descriptor File, extension: “.KD” is later used as the prime script for GUI rendering in the Klairvoyance Renderer.

Klairvoyance Renderer

This component is programmed in vb.net. It mimics a minimalistic IDE for GUI examination, an extension of which could also serve as a GUI editor. Klairvoyance Renderer is triggered after Klairvoyance Scanner completes generating the .KD files. The .KD files are processed in a procedural manner and components are generated during runtime, their properties being set with respect to details in the .KD file. The components are generated and modified in a hierarchical fashion right up to the Form itself. The resulting form will be in absolute resemblance to the actual Binary Files built in VS.

Order of Events:

Sample Lexical investigation

The following considers a simple “About” Form for a sample investigation into derivation of Grammar exclusively pertaining to GUI elements of a Solution/Project. A few elemental properties have been enlisted.

Relevant extract From About.vb.DesignerObservations:

  • All details prior to the InitializeComponent() section is irrelevant to our objective.
  • Lines of code prior to the first occurrence of a quote specify enumeration of controls. The general grammatical format being: Me.<objectname> = new <Component definition path>. This can be expressed in Bison by:

This defines a basic grammar for detecting enumerating statements in the .vb.designer file. Later, in combination with flex, Klairvoyance Scanner generates appropriate text in accordance with custom rules for generating the .KD file which is later used by Klairvoyance Renderer as a generating Script.

Merits/Limitations

Primary merits of this project would be a resulting super fast GUI previewer, even when tested against Visual Studio, an extension of which could also be made to work as a GUI editor. This would also feature a program with an extremely small size on disk and memory footprint.

Limitations would be knowledge blindness of custom components, External ActiveX components, Imported WinForm components and undocumented .Net components, the latter of which could be specified based on simple extension to the current/general parser at hand. This knowledge blindness would lead to the inability of the program to perform extraction of GUI related code on imported components. This however, can be overcome by constructing an abstract plugin framework beneath the render bench in Klairvoyance Renderer, which takes into consideration dynamically defined .KD files. This would require the design and implementation of a third component to automate the creation of dynamic .KD files. This is an unplanned feature and will not be implemented owing to a slightly increased complexity in Klairovoyance’s general architecture