Giter Club home page Giter Club logo

dotnetparser's Introduction

DotNetParser

This project allows you to run .NET executables inside of C#. Discord server: http://discord.gg/SeDrYk79W8

Will this execute my .NET Project?

Yes, it will. However, only a limited subset of .NET Features are working.

What is working/implemented?

  • if/while/for statements
  • Console.Write/Writeline
  • Classes
  • Fields
  • sbyte/byte/ushort/short/int/uint/long/ulong/float/double
  • Adding/Subtracting/Multiplying/Dividing/Remainder
  • Bitwise Operations (and, or, xor, not, shift left, shift right)
  • string.Length
  • Loading separate DLLS
  • Actions
  • Basic generic support
  • Really basic reflection
  • Sub-classes
  • Arrays

Building

Set the DotNetParserRunner or TesterKernel project as the startup project in Visual Studio and click on Run.

How to use?

Basics

Setting up

First you need to create an instance of DotNetFile and pass the byte array with the contents of your C# executable. Starting from some .NET core version, the EXE file was made into a stub which just runs dotnet app.dll. You need to use that dll file for it to work.

var fl = new DotNetFile(@"c:\app.dll");

You can access all of the classes from the Types property in the fl variable.

Next, create an instance of DotNetClr. This runs the .NET code.

var clr = new DotNetClr(fl, @"c:\framework\");

C:\framework points to a folder where a basic corlib is made. You can find one under the releases.

Executing

Then you can run the Start method to begin executing the code.

clr.Start();

Marshaling

Calling methods

"CLR" side

You can register an "internal" method which can be called from your application which you want to run.

clr.RegisterCustomInternalMethod("TestsComplete", TestsComplete);
private static void TestsComplete(MethodArgStack[] Stack, ref MethodArgStack returnValue, DotNetMethod method)
{
    Console.WriteLine("All Tests Completed.");
}

Inside of the function, the Stack variable represents all of the parameters. returnValue represents the return value of the internal method. Ignore it if the return type is void.

Application side

To invoke this newly created method, add this code:

TestsComplete();

[MethodImpl(MethodImplOptions.InternalCall)]
public static extern void TestsComplete();

Passing objects from the CLR to the application

"CLR" side

 clr.RegisterCustomInternalMethod("TestsRxObject", TestRxObject);

Now the method:

private static void TestRxObject(MethodArgStack[] Stack, ref MethodArgStack returnValue, DotNetMethod method)
{
  var cctor = m.GetMethod("DotNetparserTester", "TestObject", ".ctor");
  if (cctor == null)
      throw new NullReferenceException();
  var s = new CustomList<MethodArgStack>();
  s.Add(MethodArgStack.String("value"));
  returnValue = clr.CreateObject(cctor, s);
}

First we get the constructor method (normally named .ctor). Then we build the list of parameters and call clr.CreateObject();

Application side

  public class TestObject
    {
        public string TestProperty;

        public TestObject(string prop)
        {
            TestProperty = prop;
        }
    }
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern TestObject TestsRxObject();
var m = TestsRxObject();

dotnetparser's People

Contributors

mishaty avatar giawa avatar

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.