{"id":20152270,"url":"https://github.com/winscripter/ilsourceparser","last_synced_at":"2025-04-09T21:21:11.132Z","repository":{"id":249865466,"uuid":"832785918","full_name":"winscripter/ilsourceparser","owner":"winscripter","description":"Provides functionality for parsing ECMA-335 Microsoft Intermediate Language (IL) syntax to a syntax tree.","archived":false,"fork":false,"pushed_at":"2024-08-14T19:55:54.000Z","size":336,"stargazers_count":5,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-22T12:35:20.755Z","etag":null,"topics":["ast","cil","common-intermediate-language","csharp","dotnet","ecma335","il","intermediate-language","msil","netcore","parser","pe","syntax"],"latest_commit_sha":null,"homepage":"https://nuget.org/packages/ILSourceParser","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/winscripter.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-23T18:12:58.000Z","updated_at":"2025-03-16T18:09:34.000Z","dependencies_parsed_at":"2024-08-14T21:54:14.679Z","dependency_job_id":null,"html_url":"https://github.com/winscripter/ilsourceparser","commit_stats":null,"previous_names":["winscripter/ilsourceparser"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winscripter%2Filsourceparser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winscripter%2Filsourceparser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winscripter%2Filsourceparser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winscripter%2Filsourceparser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/winscripter","download_url":"https://codeload.github.com/winscripter/ilsourceparser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248112366,"owners_count":21049646,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ast","cil","common-intermediate-language","csharp","dotnet","ecma335","il","intermediate-language","msil","netcore","parser","pe","syntax"],"created_at":"2024-11-13T23:10:26.655Z","updated_at":"2025-04-09T21:21:11.113Z","avatar_url":"https://github.com/winscripter.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ILSourceParser\nThis library for .NET provides functionality to parse IL source code. If you're not aware, Microsoft Intermediate Language (IL or CIL, formerly known as MSIL) is\nwhat the .NET application typically consists of. C#, Visual Basic, F#, and other well-known official .NET languages compile to IL bytecode. However,\nIL actually has its syntax as well. ILSourceParser parses the IL syntax into syntax nodes, making it easier to analyze IL.\n\nILSourceParser aims to be the comprehensive parser for Microsoft Intermediate Language for .NET. Supports:\n - Leading and trailing trivia\n - Detecting line/column where a syntax error occurs\n - Source file specification\n - Asynchronous parsing\n - Parsing the following types:\n   - Method parameters:\n     - \u0026#91;out\u0026#93;, \u0026#91;opt\u0026#93; and \u0026#91;in\u0026#93; prefixes\n     - Marshalling (IL `marshal()` function)\n     - Optional parameter names\n   - Method Locals:\n     - Supports `.locals` and `.locals init` directives in methods\n   - Type parsing:\n     - Optional assembly reference, such as `[System.Runtime]`\n     - Generic type references\n     - Generic parameter references like `!T` or !!T`\n     - Nested generic type references (e.g. generic type reference passed to parameter of generic type passed to parameter of generic type and so on)\n   - Attributes:\n     - Custom attributes\n     - Anonymous custom attributes (e.g. with byte data omitted)\n   - Comments:\n     - Inline and multiline comments\n   - Directives:\n     - Most if not all IL directives are supported, such as `.assembly`, `.property`, `.file`, `.file alignment`, `.hash algorithm`, `.permissionset`, `.imagebase`, `.event`, `.custom`, `.pack`, `.size`, `.field`, `.module`, `.line`, and more\n   - And more\n\nThis library does not rely on any existing project and is not a port from another language, so chances are there could be some issues with this library. If\nyou encounter one, please create a new issue post about it!\n\nThe known issue is that ILSourceParser might not be the fastest thing in the world, because it took nearly 1 second to analyze a 200-line of code IL file. Maybe\nit just needs some additional JIT warming, although there could be a different reason - parsing IL is generally harder than parsing C#, mostly because IL has almost 300\ninstructions, and we have to do over 300 checks when parsing method body to parse one instruction.\n\nAvailable on NuGet: https://nuget.org/packages/ILSourceParser\n\n### Example\n```cs\nvar syntaxTree = ILSyntaxTree.ParseText(@\".assembly MyAssembly { }\");\nvar root = syntaxTree.GetRoot();\nforeach (SyntaxNode node in root.DescendantNodes)\n{\n    // do something with node\n}\n```\nILSourceParser is generally really similar to [Roslyn](https://github.com/dotnet/roslyn), even though it doesn't rely on it at all.\n\nA more complex example here:\n```cs\nusing ILSourceParser;\nusing ILSourceParser.Syntax;\nusing ILSourceParser.Syntax.Instructions;\nusing Sprache;\n\nstring input = @\".assembly MyAssembly\n{\n    .ver 1:2:3:4\n}\n.assembly extern System.Runtime\n{\n}\n.assembly extern System.Console\n{\n}\n\n// My Cool Application !\n\n.imagebase 0x00400000\n.line 123\n\n.class public sequential auto ansi beforefieldinit MyValueType extends [System.Runtime]System.ValueType\n{\n    .field private static initonly string s_myString\n\n    .method public static hidebysig void .cctor() cil managed\n    {\n        ldstr \"\"Hello, World!\"\"\n        stsfld string MyValueType::s_myString\n    }\n    \n    .method public static void PrintText() cil managed\n    {\n        .maxstack 8\n        \n        ldsfld string MyValueType::s_myString\n        call void [System.Console]System.Console::WriteLine(string)\n        \n        ret\n    }\n}\";\nvar syntaxRoot = ILSyntaxTree.ParseText(input).GetRoot();\n\nforeach (var descendant in syntaxRoot.DescendantNodes)\n{\n    switch (descendant)\n    {\n        case AssemblyDeclarationSyntax asm:\n            Console.WriteLine($\"Assembly {asm.AssemblyName}, is external: {asm.IsExtern}\");\n            break;\n        case BaseCommentSyntax comment:\n            if (comment is InlineCommentSyntax inline)\n            {\n                Console.WriteLine($\"Inline comment, text: {inline.CommentText}\");\n            }\n            else if (comment is MultilineCommentSyntax multiline)\n            {\n                Console.WriteLine($\"Multiline comment, text: {multiline.CommentText}\");\n            }\n            break;\n        case ImageBaseDirectiveSyntax imageBase:\n            Console.WriteLine($\"Image base {imageBase.ImageBase}\");\n            break;\n        case LineDirectiveSyntax line:\n            Console.WriteLine($\"Line {line.Line}\");\n            break;\n        case ClassDeclarationSyntax @class:\n            string flags = string.Join(\", \", @class.Flags);\n            Console.WriteLine($\"Class named {@class.Name}; flags: {flags}\");\n            break;\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwinscripter%2Filsourceparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwinscripter%2Filsourceparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwinscripter%2Filsourceparser/lists"}