You are previewing .NET IL Assembler.
O'Reilly logo
.NET IL Assembler

Book Description

"

Advanced .NET IL Assembler is a comprehensive drill-down into the inner workings of the .NET Framework. Acknowledged runtime expert and Microsoft insider Serge Lidin steps through the internal structures and operations that take place when .NET code is executed, showing how the syntax and grammar of the coding language is broken down into low-level units that can be expressed through the ILAsm language that runs behind the scenes in .NET.

By reading this book you will develop the skills you need to write tighter, faster, .NET code; to debug complex error handling situations; and to oversee multi-language and multi-platform projects with confidence.

"

Table of Contents

  1. Cover
  2. Title
  3. Copyright
  4. Dedication
  5. Contents at a Glance
  6. Contents
  7. About the Author
  8. About the Technical Reviewer
  9. Acknowledgments
  10. Introduction
  11. Chapter 1: Simple Sample
    1. Basics of the Common Language Runtime
    2. Simple Sample: The Code
      1. Program Header
      2. Class Declaration
      3. Field Declaration
      4. Method Declaration
      5. Global Items
      6. Mapped Fields
      7. Data Declaration
      8. Value Type As Placeholder
      9. Calling Unmanaged Code
    3. Forward Declaration of Classes
    4. Summary
  12. Chapter 2: Enhancing the Code
    1. Compacting the Code
    2. Protecting the Code
    3. Summary
  13. Chapter 3: Making the Coding Easier
    1. Aliasing
    2. Compilation Control Directives
    3. Referencing the Current Class and Its Relatives
    4. Summary
  14. Chapter 4: The Structure of a ManagedExecutable File
    1. PE/COFF Headers
      1. MS-DOS Header/Stub and PE Signature
      2. COFF Header
      3. PE Header
      4. Section Headers
    2. Common Language Runtime Header
      1. Header Structure
      2. Flags Field
      3. EntryPointToken Field
      4. VTableFixups Field
      5. StrongNameSignature Field
      6. Relocation Section
      7. Text Section
      8. Data Sections
      9. Data Constants
      10. V-Table
      11. Unmanaged Export Table
      12. Thread Local Storage
      13. Resources
      14. Unmanaged Resources
      15. Managed Resources
    3. Summary
      1. Phase 1: Initialization
      2. Phase 2: Source Code Parsing
      3. Phase 3: Image Generation
      4. Phase 4: Completion
  15. Chapter 5: Metadata Tables Organization
    1. What Is Metadata?
    2. Heaps and Tables
      1. Heaps
      2. General Metadata Header
      3. Metadata Table Streams
    3. RIDs and Tokens
      1. RIDs
      2. Tokens
    4. Coded Tokens
    5. Metadata Validation
    6. Summary
  16. Chapter 6: Modules and Assemblies
    1. What Is an Assembly?
    2. Private and Shared Assemblies
    3. Application Domains As Logical Units of Execution
    4. Manifest
    5. Assembly Metadata Table and Declaration
    6. AssemblyRef Metadata Table and Declaration
      1. Autodetection of Referenced Assemblies
    7. The Loader in Search of Assemblies
    8. Module Metadata Table and Declaration
    9. ModuleRef Metadata Table and Declaration
    10. File Metadata Table and Declaration
    11. Managed Resource Metadata and Declaration
    12. ExportedType Metadata Table and Declaration
    13. Order of Manifest Declarations in ILAsm
    14. Single-Module and Multimodule Assemblies
    15. Summary of Metadata Validity Rules
      1. Assembly Table Validity Rules
      2. AssemblyRef Table Validity Rules
      3. Module Table Validity Rules
      4. ModuleRef Table Validity Rules
      5. File Table Validity Rules
      6. ManifestResource Table Validity Rules
      7. ExportedType Table Validity Rules
  17. Chapter 7: Namespaces and Classes
    1. Class Metadata
      1. TypeDef Metadata Table
      2. TypeRef Metadata Table
      3. InterfaceImpl Metadata Table
      4. NestedClass Metadata Table
      5. ClassLayout Metadata Table
    2. Namespace and Full Class Name
      1. ILAsm Naming Conventions
      2. Namespaces
      3. Full Class Names
    3. Class Attributes
      1. Flags
      2. Class Visibility and Friend Assemblies
      3. Class References
      4. Parent of the Type
      5. Interface Implementations
      6. Class Layout Information
    4. Interfaces
    5. Value Types
      1. Boxed and Unboxed Values
      2. Instance Members of Value Types
      3. Derivation of Value Types
    6. Enumerations
    7. Delegates
    8. Nested Types
    9. Class Augmentation
    10. Summary of the Metadata Validity Rules
      1. TypeDef Table Validity Rules
      2. Enumeration-Specific Validity Rules
      3. TypeRef Table Validity Rules
      4. InterfaceImpl Table Validity Rules
      5. NestedClass Table Validity Rules
      6. ClassLayout Table Validity Rules
  18. Chapter 8: Primitive Types and Signatures
    1. Primitive Types in the Common Language Runtime
      1. Primitive Data Types
      2. Data Pointer Types
      3. Function Pointer Types
      4. Vectors and Arrays
      5. Modifiers
      6. Native Types
      7. Variant Types
    2. Representing Classes in Signatures
    3. Signatures
      1. Calling Conventions
      2. Field Signatures
      3. Method and Property Signatures
      4. MemberRef Signatures
      5. Indirect Call Signatures
      6. Local Variables Signatures
      7. Type Specifications
    4. Summary of Signature Validity Rules
  19. Chapter 9: Fields and Data Constants
    1. Field Metadata
      1. Defining a Field
      2. Referencing a Field
    2. Instance and Static Fields
    3. Default Values
    4. Mapped Fields
    5. Data Constants Declaration
    6. Explicit Layouts and Union Declaration
    7. Global Fields
    8. Constructors vs. Data Constants
    9. Summary of Metadata Validity Rules
      1. Field Table Validity Rules
      2. FieldLayout Table Validity Rules
      3. FieldRVA Table Validity Rules
      4. FieldMarshal Table Validity Rules
      5. Constant Table Validity Rules
      6. MemberRef Table Validity Rules
  20. Chapter 10: Methods
    1. Method Metadata
      1. Method Table Record Entries
      2. Method Flags
      3. Method Name
      4. Method Implementation Flags
      5. Method Parameters
      6. Referencing the Methods
      7. Method Implementation Metadata
    2. Static, Instance, Virtual Methods
    3. Explicit Method Overriding
    4. Method Overriding and Accessibility
    5. Method Header Attributes
    6. Local Variables
    7. Class Constructors
      1. Class Constructors and the beforefieldinit Flag
      2. Module Constructors
    8. Instance Constructors
    9. Instance Finalizers
    10. Variable Argument Lists
    11. Method Overloading
    12. Global Methods
    13. Summary of Metadata Validity Rules
      1. Method Table Validity Rules
      2. Param Table Validity Rules
      3. MethodImpl Table Validity Rules
  21. Chapter 11: Generic Types
    1. Generic Type Metadata
      1. GenericParam Metadata Table
      2. GenericParamConstraint Metadata Table
      3. TypeSpec Metadata Table
    2. Constraint Flags
    3. Defining Generic Types in ILAsm
    4. Addressing the Type Parameters
    5. Generic Type Instantiations
    6. Defining Generic Types: Inheritance, Implementation, Constraints
    7. Defining Generic Types: Cyclic Dependencies
    8. The Members of Generic Types
      1. Virtual Methods in Generic Types
    9. Nested Generic Types
    10. Summary of the Metadata Validity Rules
  22. Chapter 12: Generic Methods
    1. Generic Method Metadata
      1. MethodSpec Metadata Table
    2. Signatures of Generic Methods
    3. Defining Generic Methods in ILAsm
    4. Calling Generic Methods
    5. Overriding Virtual Generic Methods
    6. Summary of the Metadata Validity Rules
  23. Chapter 13: IL Instructions
    1. Long-Parameter and Short-Parameter Instructions
    2. Labels and Flow Control Instructions
      1. Unconditional Branching Instructions
      2. Conditional Branching Instructions
      3. Comparative Branching Instructions
      4. The switch Instruction
      5. The break Instruction
      6. Managed EH Block Exiting Instructions
      7. EH Block Ending Instructions
      8. The ret Instruction
    3. Arithmetical Instructions
      1. Stack Manipulation
      2. Constant Loading
      3. Indirect Loading
      4. Indirect Storing
      5. Arithmetical Operations
      6. Overflow Arithmetical Operations
      7. Bitwise Operations
      8. Shift Operations
      9. Conversion Operations
      10. Overflow Conversion Operations
      11. Logical Condition Check Instructions
      12. Block Operations
    4. Addressing Arguments and Local Variables
      1. Method Argument Loading
      2. Method Argument Address Loading
      3. Method Argument Storing
      4. Method Argument List
      5. Local Variable Loading
      6. Local Variable Reference Loading
      7. Local Variable Storing
      8. Local Block Allocation
      9. Prefix Instructions
    5. Addressing Fields
    6. Calling Methods
      1. Direct Calls
      2. Indirect Calls
      3. Tail Calls
      4. Constrained Virtual Calls
    7. Addressing Classes and Value Types
    8. Vector Instructions
      1. Vector Creation
      2. Element Address Loading
      3. Element Loading
      4. Element Storing
    9. Code Verifiability
  24. Chapter 14: Managed Exception Handling
    1. EH Clause Internal Representation
    2. Types of EH Clauses
    3. Label Form of EH Clause Declaration
    4. Scope Form of EH Clause Declaration
    5. Processing the Exceptions
    6. Exception Types
      1. Loader Exceptions
      2. JIT Compiler Exceptions
      3. Execution Engine Exceptions
      4. Interoperability Services Exceptions
      5. Subclassing the Exceptions
      6. Unmanaged Exception Mapping
    7. Summary of EH Clause Structuring Rules
  25. Chapter 15: Events and Properties
    1. Events and Delegates
    2. Event Metadata
      1. The Event Table
      2. The EventMap Table
      3. The MethodSemantics Table
    3. Event Declaration
    4. Property Metadata
      1. The Property Table
      2. The PropertyMap Table
    5. Property Declaration
    6. Summary of Metadata Validity Rules
      1. Event Table Validity Rules
      2. EventMap Table Validity Rules
      3. Property Table Validity Rules
      4. PropertyMap Table Validity Rules
      5. MethodSemantics Table Validity Rules
  26. Chapter 16: Custom Attributes
    1. Concept of a Custom Attribute
    2. CustomAttribute Metadata Table
    3. Custom Attribute Value Encoding
    4. Verbal Description of Custom Attribute Value
    5. Custom Attribute Declaration
    6. Classification of Custom Attributes
      1. Execution Engine and JIT Compiler
      2. Interoperation Subsystem
      3. Security
      4. Remoting Subsystem
      5. Visual Studio Debugger
      6. Assembly Linker
      7. Common Language Specification (CLS) Compliance
      8. Pseudocustom Attributes
    7. Summary of Metadata Validity Rules
  27. Chapter 17: Security Attributes
    1. Declarative Security
    2. Declarative Actions
    3. Security Permissions
      1. Access Permissions
      2. Identity Permissions
      3. Custom Permissions
      4. Permission Sets
    4. Changes in Declarative Security in v4.0
    5. Declarative Security Metadata
    6. Permission Set Blob Encoding
    7. Security Attribute Declaration
    8. Summary of Metadata Validity Rules
  28. Chapter 18: Managed and Unmanaged Code Interoperation
    1. Thunks and Wrappers
      1. P/Invoke Thunks
      2. Implementation Map Metadata
      3. IJW Thunks
      4. COM Callable Wrappers
      5. Runtime Callable Wrappers
    2. Data Marshaling
      1. Blittable Types
      2. In/Out Parameters
      3. String Marshaling
      4. Object Marshaling
      5. More Object Marshaling
      6. Array Marshaling
      7. Delegate Marshaling
    3. Interoperation with Windows Runtime
    4. Providing Managed Methods as Callbacks for Unmanaged Code
    5. Managed Methods as Unmanaged Exports
      1. Export Table Group
    6. Summary
  29. Chapter 19: Multilanguage Projects
    1. IL Disassembler
    2. Principles of Round-Tripping
    3. Creative Round-Tripping
    4. Using Class Augmentation
    5. Module Linking Through Round-Tripping
    6. ASMMETA: Resolving Circular Dependencies
    7. IL Inlining in High-Level Languages
    8. Compiling in Debug Mode
    9. Summary
  30. Appendix A: ILAsm Grammar Reference
    1. Lexical Tokens
      1. Auxiliary Lexical Tokens
    2. Data Type Nonterminals
    3. Identifier Nonterminals
    4. Class Referencing
    5. Module-Level Declarations
    6. Compilation Control Directives
    7. Module Parameter Declaration
      1. V-Table Fixup Table Declaration
    8. Manifest Declarations
    9. Managed Types in Signatures
    10. Native Types in Marshaling Signatures
    11. Method and Field Referencing
    12. Class Declaration
      1. Generic Type Parameters Declaration
      2. Class Body Declarations
    13. Field Declaration
    14. Method Declaration
      1. Method Body Declarations
      2. External Source Directives
      3. Managed Exception Handling Directives
      4. IL Instructions
    15. Event Declaration
    16. Property Declaration
    17. Constant Declarations
    18. Custom Attribute Declarations
      1. Verbal Description of Custom Attribute Initialization Blob
    19. Security Declarations
    20. Aliasing of Types, Methods, Fields, and Custom Attributes
    21. Data Declaration
  31. Appendix B: Metadata Tables Reference
  32. Appendix C: IL Instruction Set Reference
  33. Appendix D: IL Assembler and Disassembler Command-Line Options
    1. IL Assembler
    2. IL Disassembler
      1. Output Redirection Options
      2. ILAsm Code-Formatting Options (PE Files Only)
      3. File Output Options (PE Files Only)
      4. File or Console Output Options (PE Files Only)
      5. Metadata Summary Option
  34. Appendix E: Offline Verification Tool Reference
    1. Error Codes and Messages
  35. Index