This collection of (mostly unfinished) documents try to explain the inner workings of Project Old Rod. Old Rod is (probably unnecessarily) complex, and I understand that most people probably won't like to sift over my spaghetti code.
The devirtualization process consists of a couple of stages, and are implemented in the OldRod.Pipeline
sub project:
- Locate VM types and constants,
- Parse the injected VM binary stream headers,
- Locate virtualized methods,
- Map constants to VM opcodes and their handlers,
- Disassemble all virtualized methods,
- Also discover any hidden or non-exported functions,
- Analyze the VM code,
- Detect stack layouts,
- Add any non-exported method to the .NET metadata,
- Build AST from disassembled VM code,
- Translate from stack based to a variable based language,
- Perform optimisations on AST level,
- Recompile AST to CIL,
- Convert AST to a "CIL AST",
- Perform type inference and insert missing type conversions,
- Serialize CIL AST to normal CIL,
- Clean up.