Skip to content

Common Intermediate Language (CIL) assembler available as a library, based on Mono assembler.

License

Notifications You must be signed in to change notification settings

stephen-riley/Mobius.ILasm

 
 

Repository files navigation

BigCow.Mobius.ILasm

This repo is a fork of Mobius.ILasm. It's been reconfigured to be a net5.0 package that builds without warnings. For background and usage, please keep reading.

Build and test NuGet Downloads Stars License


Mobius.ILasm

Common Intermediate Language (CIL) assembler available as a library and command-line tool (like ilasm). It is based on a CIL assembler code taken out from the Mono runtime, including the CIL parser autogenerated by the Jay tool (which in turn was a C# port of a Berkeley Yacc parser for Java).

Current refactorings include:

  • main class Driver usage change
  • using MemoryStream instead of files directly
  • error reporting
  • initial unit tests
  • CLI runner extracted and command line parsing
  • logger abstraction
  • minor renaming

This is part of Mobius project - experimental .NET runtime running on .NET Core.

Library

Definitely the most useful use case, as it is the first available .NET library that you can use to assemble textual CIL files.

Currently it targets .NET Standard 2.0 and is also available as Mobius.ILasm NuGet package.

Example usage

// Read some CIL code
var cil = File.ReadAllText(@"./trivial/helloworldconsole.il");

var logger = new Logger();
var driver = new Driver(logger, Driver.Target.Dll, showParser: false, debuggingInfo: false, showTokens: false);

// Assemble
using var memoryStream = new MemoryStream();
driver.Assemble(new [] { cil }, memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);

// Load assembled binary stream into AsemblyLoadContext and execute
var assemblyContext = new AssemblyLoadContext(null);
var assembly = assemblyContext.LoadFromStream(memoryStream);
var entryPoint = assembly.EntryPoint;
var result = entryPoint?.Invoke(null, new object[] { new string[] { } });

Note: Due to the early stage of development, and some legacy code improvements, the available API is subject to change in future versions.

Command line tool

Typical usage is just to assembly a spefied il file:

> `mobius.ilasm.cil -I helloworld.il`

which will produce helloworld.dll that you can execute by dotnet command (if your provide hellologger.runtimeconfig.json). Additionaly, for Windows, you can produce EXE file that will be self-executable.

All options available:

InputFile* (-I)             IL file to be parsed
OutputFile (-O)
Target (-T)                 [Default='Dll']
                            Dll
                            Exe
NoAutoInherit (-nai)
Debug (-D)                  [Default='False']
ShowParser (-sp)            [Default='False']
ShowTokens (-st)            [Default='False']
StrongKeyFile (-S)          Strongname using the specified key file
StrongKeyContainer (-Str)   Strongname using the specified key container

About

Common Intermediate Language (CIL) assembler available as a library, based on Mono assembler.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 99.9%
  • Other 0.1%