Introduction
This book on metadata tables is a heady cocktail of the esoteric and mysterious details pertaining to the internals of an executable file, which gets created by the compiler of any. net product.
It is an intricate book, which wowould appear formidable to those uninitiated to the world of C #. it is replete with programs written using the C # language, and is predicated on the presumption that you possess adequate knowledge of this language.
In. net World, when the compiler processes the source code, it creates an il file. this Il file is inherently capable of comprehening object types. it is equipped with instructions that do the following: Create and initialize objects, call methods, raise and catch exceptions, etc. this Il file is thereafter converted into an executable or a DLL file, I. e. PE file, after the compiler has firmly embedded the metadata information in it. it is the repository of information that relates to the types and the methods that have been employed in the file.
Earlier, Microsoft had extended its original DOS format and had ininitialized ated the PE file format in order to buttress the execution of files on the Windows platform. however, with the introduction. net, Microsoft remolded its PE file format and instituted a header to store the metadata information. specifically, one of the structures in the optional Header has been used for the CLR header.
Metadata is a key component that casts a significant shadow on. NET architecture. it renders the runtime with vital information about assemblies, classes, methods and scores of other significant details. thus, metadata represents data, which is exacting, comprehensive, and most importantly, language-independent. this results in a common format for exposing the information contained in a file or an assembly, thereby introducing flexibility and code sharing between applications that use disparate versions. finally, the Metadata facilitates remote method callin. net Framework.
Our book on 'metadata tables 'delineates how the metadata is laid out after being read into memory from a PE file. the metadata is stored in either tables or streams. there are five streams in all. one of the streams comprises of tables that store the relevant data. the remaining four are string, blob, userstring and guid. there exists an awesome amount of interdependence between these streams.
All metadata is stored internally in the form of tables. there exist about 43 assorted table types in the realm of metadata, each of which stores specific information. for instance, all the types are stored in one table, all the methods are stored in another table, all the parameters are stored in yet another table, and so on. each table is assigned one bit in one of the metadata fields. contingent upon the status of this bit field, the presence of a special table can be ascertained.
Every table has been assigned a name and a number. the table that is assigned the number 0 is known as 'module', while the table that is assigned the number 1 is called typeref, and so on. moreover, Microsoft has extensively utilized the features of coded indexes to enhance efficiency and to restrict the byte-consumption, thereby avoiding dissipation of memory space.
The captivating feature of this book is its remarkably simplistic approach. firstly, we get you well acquainted with the PE file format, where we introduce you to the relevant details of the file. then, we focus our attention on the metadata header.
Next, we plough our way ahead, scrutinizing every metadata table meticulously, one at a time. on certain occasions, we have replicated some portions of the Code, in order to facilitate versions of understanding. further, to expound every table, miniature snippets of code have been provided, using either IL or the C # language. an independent chapter has been authorized Ted to the topic of Blob signatures, since they unravel an altogether unique class of information.
At times, we have undertaken discursive diversions at crucial junctures to explain specific concepts, which may not be directly related to the main topic. this has been done to provide a holistic panorama of. NET architecture.
Tables have been drawn and screen shots have been provided to reinforce the assumptions and to restrict strate the concepts that have been proffered.
Finally, since no cross-connections cocould be established between these tables while holding ing each of them, we chose to dedicate the last chapter to the display of all the linkages and to provide values to the data stored in the table.
Although we are aware that there is scope for extensive enhancement to make this book exhaustive, we chose to wrap it up at this stage. this is because we hope that by the time you reach the end of this book, you wocould have developed a penchant for metadata tables and wocould be in a position to lead e the subject further by yourself.
In addition to the samples, Microsoft has also offered a program called metainfo, which provides a dump of the metadata. another program utility that can be used is the discycler, known as the ildasm. these two utilities can be used to verify and validate the output of our program.
We take immense pleasure in proclaiming the fact that we are the pioneers in employing the C # language while writing our metadata program. we are convinced that even the tools have not been written in C #. since our primary focus has been on the task of discerning the tables and their contents, the chores of alignment and the formatting have taken a back seat.
In order to serve up all this information to you, we have scrutinized the web in its entirety, and have extracted meaningful inputs from it. further, we have probed the unfathomable depths of the 'uncomplicated 'technical documentation provided by Microsoft.
Towards the latter part of this book, we have inspected the intricacies of each and every bit, and have investigated all the formatting issues. once more, a program written in C # comports itself like the ildasm utility, providing substantial information about every table and its field attributes.
In conclusion, we reiterate that this is a path-breaking book, which delves into the internals of. NET architecture, which is a virgin territory. we hope that you enjoy your journey into this exotic domain and put the knowledge gained from this book to good use. we are confident that this book will pave the way to sculpt you into an aficionado of. NET architecture. we wish you good luck and Happy reading!
Minimum requirements
The software requirements to successfully run all the programs in this book are
• Operating System-Windows 2000, Windows XP
• Visual Studio. NET or. NET Framework SDK
• UltraEdit-32 (can be downloaded from http://www.download.com)
Acknowledgements
I wish to thank a number of people who gave me their support, new ideas and inspiration while writing this book.
First and foremost, thanksManish Jain, BPB publications for publishing the book.
Special thanks to my co-authors,AkashAndSonal, Who have put in their very best in the work assigned to them as without them and their efforts the book wowould have never seen the light of day.
ThanksTanuja Sodhi, An ex-naval officer from the first batch of lady officers and an MBA from jbims for editing the book. She is presently freelancing as a creative writer.
Thanks to my cover designers,Altaf hemaniAndKishore rohra,For designing the cover.
ThanksManish PurohitFor putting in all the time he had to verify the Code with the explanations and then giving the book a good look and feel.
ToShivanand Shetty, Who made it simple for me and my co-authors to come up with the book. He has always been a source of inspiration and encouragement.
A long list of friends need a mention here for their patience and cooperation on this book while it was being written.
-Vijay mukhi