Giter VIP home page Giter VIP logo

dotnet-ildasm's Introduction

Dot Net IL Disassembler

CircleCI Nuget Nuget License

Description

The dotnet ildasm provides a command-line IL dissassembler. Simply send the assembly path as a parameter and as a result you will get the IL contents of that assembly.

Setup

The project was created as a global CLI tool, therefore you can install with a single command:

dotnet tool install -g dotnet-ildasm

Note that for the command above to work, you need .NET Core SDK 2.1.300 or above installed in your machine.

Syntax

dotnet ildasm <ASSEMBLY_PATH>
dotnet ildasm <ASSEMBLY_PATH> <-o|--output>
dotnet ildasm <ASSEMBLY_PATH> <-i|--item>
dotnet ildasm <-h|--help>

Options

-i
Filter results by method and/or classes to be disassembled.

-o
Define the output file to be created with the assembly's IL.

Examples

Output IL to the command line:

dotnet ildasm myassembly.dll

Filter results by method and/or classes to be disassembled, showing the result in the command line:

dotnet ildasm myassembly.dll -i ClassName
dotnet ildasm myassembly.dll -i ::MethodName
dotnet ildasm myassembly.dll -i ClassName::MethodName

Define the file to be created with the output:

dotnet ildasm myassembly.dll -o disassembledAssembly.il

dotnet-ildasm's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

dotnet-ildasm's Issues

IL Code needs to be indented

Current IL

.class private auto ansi beforefieldinit ConsoleApp1.Program extends System.Object{

.method private hidebysig System.Void ConsoleApp1.Program::Main(System.String[]) cil managed
{
.entrypoint
// Code size 13
.maxstack 8
IL_0000: nop
IL_0001: ldstr "Hello World!"
IL_0006: call System.Void System.Console::WriteLine(System.String)
IL_000b: nop
IL_000c: ret
}// End of method System.Void ConsoleApp1.Program::Main(System.String[])

.method public hidebysig specialname rtspecialname instance System.Void ConsoleApp1.Program::.ctor() cil managed
{
// Code size 8
.maxstack 8
IL_0000: ldarg.0
IL_0001: call System.Void System.Object::.ctor()
IL_0006: nop
IL_0007: ret
}// End of method System.Void ConsoleApp1.Program::.ctor()

} // End of class ConsoleApp1.Program

Expected IL

.class private auto ansi beforefieldinit ConsoleApp1.Program extends System.Object{

	.method private hidebysig System.Void ConsoleApp1.Program::Main(System.String[]) cil managed
	{
		.entrypoint
		// Code size 13
		.maxstack 8
		IL_0000: nop
		IL_0001: ldstr "Hello World!"
		IL_0006: call System.Void System.Console::WriteLine(System.String)
		IL_000b: nop
		IL_000c: ret
	}// End of method System.Void ConsoleApp1.Program::Main(System.String[])

	.method public hidebysig specialname rtspecialname instance System.Void ConsoleApp1.Program::.ctor() cil managed
	{
		// Code size 8
		.maxstack 8
		IL_0000: ldarg.0
		IL_0001: call System.Void System.Object::.ctor()
		IL_0006: nop
		IL_0007: ret
	}// End of method System.Void ConsoleApp1.Program::.ctor()

} // End of class ConsoleApp1.Program

ILDASM - Wrong exit code

I'm using ILDASM to inspect all files in a folder (project build output), and in somes cases i have configuration/text files. In those edge cases i caught a bug, although i received an exit code 0 the process output was "Image is either too small or contains an invalid byte offset or count.\n". According to the process output i was expecting to receive an exit 1.

I'm migrating to this version of ILDASM (before i was using https://docs.microsoft.com/en-us/dotnet/framework/tools/ildasm-exe-il-disassembler) because i couldn't run in Docker container with mono.

I even open an issue on the wrong project site (https://github.com/dotnet/coreclr/issues/18885#issuecomment-404794040), but then i realized this version of ILDASM was manged in a distinct project.

Command example:

dotnet ildasm CannotDisassemble & echo %errorlevel%

Output:

Image is either too small or contains an invalid byte offset or count.
0

CannotDisassemble.zip

Implement some of MS ILDasm Features

Implement keys features from MS IL Dasm:

  • /source Shows original source lines as comments.
  • /raweh Shows exception handling clauses in raw form.
  • /pubonly Disassembles only public types and members.

Also support same syntax, using slashes instead of hyphens.

More information at ILDasm documentation

Wrong IL generated for storing value in a local variable.

Source code

class Program
{
    static void Main(string[] args)
    {
        int add = Add(20, 10);
        int sub = Subtract(20, 10);
        int multiply = Multiply(20, 10);
        int divide = Divide(20, 10);
        // Issue here
        int modulo = Modulo(20, 10);
    }

    static int Add(int i, int j) => i + j;

    static int Subtract(int i, int j) => i - j;

    static int Multiply(int i, int j) => i * j;

    static int Divide(int i, int j) => i / j;

    static int Modulo(int i, int j) => i % j;
}

Steps to reproduce

  1. Compile the above source code into a DLL.
  2. Run dotnet ildasm on the DLL.

Expected IL

IL_0032: stloc.s V_4

Actual IL

IL_0032: stloc.s class V_4

Error
When running ILAsm : MSIL.il(60) : error : syntax error at token 'class' in: IL_0032: stloc.s class V_4
Works well with traditional ILDAsm.

Exported Types needs to be translated from .Net Types to IL Types

Current IL

.method private hidebysig System.Void ConsoleApp1.Program::Main(System.String[]) cil managed
{
.entrypoint
// Code size 13
.maxstack 8
IL_0000: nop
IL_0001: ldstr "Hello World!"
IL_0006: call System.Void System.Console::WriteLine(System.String)
IL_000b: nop
IL_000c: ret
}

Expected IL

.method private hidebysig void ConsoleApp1.Program::Main(string[]) cil managed
{
.entrypoint
// Code size 13
.maxstack 8
IL_0000: nop
IL_0001: ldstr "Hello World!"
IL_0006: call void System.Console::WriteLine(string)
IL_000b: nop
IL_000c: ret
}

Failed to disassemble .Net Framework App

I was executing some tests with ildasm and found an issue. I tried to desassemble a WPF executable (.Net Framework 4.6.2) and it failed due to:

Failed to resolve assembly: 'PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

Then i copied from .NetFramework folder the missinf dll to the output folder of the project and executed again the ildasm, and this time it worked.

Is there any workaround to fix this issue, as ildasm should resolve .NetFramework dlls, as it does for .NetStandard references.

If i use the ildasm version that comes with Microsoft SDK's it workes correctly (for instance Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7.1 Tools).

Sample.zip

Support lookup for nuget packages

Create a switch to allow automatic download of nuget packages.

Need to consider a specific syntax to support package name and version, potentially:

dotnet ildasm packagename/0.1.0 --nuget

or

dotnet ildasm packagename --nuget -v 0.1.0

Consolidate Build and Release Pipelines

Consolidate all builds using a single platform - potentially GitHub Actions.

Context
Currently AppVeyor is being used for windows builds and CircleCI for linux.
Each platform tests for platform-compatibility, but also add the following activities:

  • Windows pipeline: applies git semver and releases the nuget package.
  • Linux: generate code coverage report and submit to codecov.

Add support to params key word

C# Code

public void PublicVoidMethodParams(params string [] parameters)
{
}

Current IL
.method public hidebysig instance void PublicVoidMethodParams(array parameters) cil managed

Expected IL
.method public hidebysig instance void PublicVoidMethodParams(string[] parameters) cil managed

Nested classes do not seem to be supported

While trying to disassemble some assemblies with nested classes, they're not disassembled. ildasm from the .NET framework, and the disassembler from sharplab are able to correctly disassemble the code generated by this C# program:

using System;

namespace Foo {
	class Bar {
		public class FooBar {
			public string SomeMethod() { return "aaaaa"; }
		}

		public FooBar MakeFooBar() {
			return new FooBar();
		}
	}

	class Test {
		public static void Main() {
			var bar = new Bar();
			var fooBar = bar.MakeFooBar();

			Console.WriteLine(fooBar.SomeMethod());
		}
	}
}

In this example, dotnet-ildasm generates calls to FooBar.SomeMethod(), but its definition is nowhere to be found.

netcoreapp5.0 not supported, 3.0 is "out of support"

Attempting to use the current latest release on .NET Core 5.0 gives:

[gitlab@f1b1b25c46f1 test]$ dotnet tool install --tool-path /tmp/ dotnet-ildasm
You can invoke the tool using the following command: dotnet-ildasm
Tool 'dotnet-ildasm' (version '0.12.2') was successfully installed.
[gitlab@f1b1b25c46f1 test]$ /tmp/dotnet-ildasm
It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '3.0.0' was not found.
  - The following frameworks were found:
      5.0.0 at [/usr/share/dotnet/shared/Microsoft.NETCore.App]

You can resolve the problem by installing the specified framework and/or SDK.

The specified framework can be found at:
  - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=3.0.0&arch=x64&rid=centos.7-x64

Taking a look at build.sh, it appears to be building for each version from 2.0 -> 3.0.

Structs are not supported

C# Code

struct Abc
{
}

Current IL

.class private sequential ansi beforefieldinit ConsoleApp1.Abc extends System.ValueType
{
} // End of class ConsoleApp1.Abc

Expected IL

.class private sequential ansi sealed beforefieldinit ConsoleApp1.Abc extends [System.Runtime]System.ValueType
{
  .pack 0
  .size 1
} // end of class ConsoleApp1.Abc

IL Generated has inconsistent Indentation

The generated IL has inconsistent indentation in the following scenarios:

Catch Statements
Expected

    IL_0009: nop
    IL_000a: leave.s       IL_0017
  }
  catch [netstandard]System.Exception
  {
    IL_000c: stloc.0
    IL_000d: nop

Actual

    IL_0009: nop
    IL_000a: leave.s       IL_0017
  }
catch [netstandard]System.Exception
  {
    IL_000c: stloc.0
    IL_000d: nop

Closing Brackets
Expected

.class public ... extends [netstandard]System.Object
{
  .method public hidebysig ...() cil managed
  {
  }
  .method public ...() cil managed
  {
  }
}

Actual

.class public ... extends [netstandard]System.Object
{
  .method public hidebysig ...() cil managed
  {
}
  .method public ...() cil managed
  {
}
}

Breakline between Methods and Classes
Expected

.class public ... extends [netstandard]System.Object
{
  .method public hidebysig ...() cil managed
  {
  }

  .method public ...() cil managed
  {
  }
}

.class private ... extends [netstandard]System.Object
{

Actual

.class public ... extends [netstandard]System.Object
{
  .method public hidebysig ...() cil managed
  {
  }
  .method public ...() cil managed
  {
  }
}
.class private ... extends [netstandard]System.Object
{

Invalid IL for Properties

Current IL
IL_0001: ldfld string dotnet_ildasm.Sample.Classes.PublicClass::<Property1>k__BackingField
Expected IL
IL_0001: ldfld string dotnet_ildasm.Sample.Classes.PublicClass::'<Property1>k__BackingField'

Wrong IL generated for Local init

Source code:

public void UsingTryCatch(int parameter)
{
      try
      {
           Console.WriteLine(parameter);
      }
      catch (Exception e)
      {
          Console.WriteLine(e);
          throw;
      }
}

Expected IL

.locals init (class [System.Runtime]System.Exception V_0)

Actual IL

.locals init([System.Runtime]System.Exception V_0)

dotnet-ildasm throws error as "It was not possible to find any compatible framework version The specified framework 'Microsoft.NETCore.App', version '2.2.0' was not found. - The following frameworks were found: 3.0.0 at [/usr/share/dotnet/shared/Microsoft.NETCore.App]" since we upgraded dotnet version to 2.2xx to 3.0

Since we updated our dotnet version from 2.2.xxx to 3.0.0 we are facing below error while running ./dotnet-ildasm "$dll" command.

It was not possible to find any compatible framework version
The specified framework 'Microsoft.NETCore.App', version '2.2.0' was not found.
  - The following frameworks were found:
      3.0.0 at [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Feels like this command fails with new dotnet version.

Any help with this issue would be appreciated. :)

Extract the public key token actual value from referenced assemblies

Current IL

.assembly extern System.Runtime
{
// .publickeytoken 10110000 111111 1011111 1111111 10001 11010101 1010 111010 // Needs proper formatting
.ver 4:2:0:0
}

Expected IL

.assembly extern System.Runtime
{
  .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A)
  .ver 4:2:0:0
}

External Types should always be preceded by their assembly names

Current IL

.custom instance System.Void System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(System.Int32)

Please notice that the example above is with custom attributes, however this specific issue regards all types. Also, the current IL have other problems that are logged in their own separated issues ( #2 , #3 and #4 )

Expected IL

.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) 

Extract custom attribute values

Current IL

.custom instance System.Void System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(System.Int32)
.custom instance System.Void System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor()
.custom instance System.Void System.Runtime.Versioning.TargetFrameworkAttribute::.ctor(System.String)
.custom instance System.Void System.Reflection.AssemblyCompanyAttribute::.ctor(System.String)
.custom instance System.Void System.Reflection.AssemblyConfigurationAttribute::.ctor(System.String)
.custom instance System.Void System.Reflection.AssemblyDescriptionAttribute::.ctor(System.String)
.custom instance System.Void System.Reflection.AssemblyFileVersionAttribute::.ctor(System.String)
.custom instance System.Void System.Reflection.AssemblyInformationalVersionAttribute::.ctor(System.String)
.custom instance System.Void System.Reflection.AssemblyProductAttribute::.ctor(System.String)
.custom instance System.Void System.Reflection.AssemblyTitleAttribute::.ctor(System.String)

Expected IL

  .custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) 
  .custom instance void [System.Runtime]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78   // ....T..WrapNonEx
                                                                                                                   63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 )       // ceptionThrows.

  .custom instance void [System.Runtime]System.Runtime.Versioning.TargetFrameworkAttribute::.ctor(string) = ( 01 00 18 2E 4E 45 54 43 6F 72 65 41 70 70 2C 56   // ....NETCoreApp,V
                                                                                                              65 72 73 69 6F 6E 3D 76 32 2E 30 01 00 54 0E 14   // ersion=v2.0..T..
                                                                                                              46 72 61 6D 65 77 6F 72 6B 44 69 73 70 6C 61 79   // FrameworkDisplay
                                                                                                              4E 61 6D 65 00 )                                  // Name.
  .custom instance void [System.Runtime]System.Reflection.AssemblyCompanyAttribute::.ctor(string) = ( 01 00 0B 43 6F 6E 73 6F 6C 65 41 70 70 31 00 00 ) // ...ConsoleApp1..
  .custom instance void [System.Runtime]System.Reflection.AssemblyConfigurationAttribute::.ctor(string) = ( 01 00 05 44 65 62 75 67 00 00 )                   // ...Debug..
  .custom instance void [System.Runtime]System.Reflection.AssemblyDescriptionAttribute::.ctor(string) = ( 01 00 13 50 61 63 6B 61 67 65 20 44 65 73 63 72   // ...Package Descr
                                                                                                          69 70 74 69 6F 6E 00 00 )                         // iption..
  .custom instance void [System.Runtime]System.Reflection.AssemblyFileVersionAttribute::.ctor(string) = ( 01 00 07 31 2E 30 2E 30 2E 30 00 00 )             // ...1.0.0.0..
  .custom instance void [System.Runtime]System.Reflection.AssemblyInformationalVersionAttribute::.ctor(string) = ( 01 00 05 31 2E 30 2E 30 00 00 )                   // ...1.0.0..
  .custom instance void [System.Runtime]System.Reflection.AssemblyProductAttribute::.ctor(string) = ( 01 00 0B 43 6F 6E 73 6F 6C 65 41 70 70 31 00 00 ) // ...ConsoleApp1..
  .custom instance void [System.Runtime]System.Reflection.AssemblyTitleAttribute::.ctor(string) = ( 01 00 0B 43 6F 6E 73 6F 6C 65 41 70 70 31 00 00 ) // ...ConsoleApp1..

Extract Assembly Directives

The following assembly directives are not being extracted from the assembly:

  • .imagebase
  • .stackreserve <integer_value>
  • .file alignment
  • .subsystem
  • .corflags

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.