GithubHelp home page GithubHelp logo

notcarlton / csinternalsample Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cxcubehd/csinternalsample

0.0 0.0 0.0 26 KB

A sample that shows the usage of internal C# clients.

License: Other

C++ 60.23% C# 33.92% CMake 5.84%

csinternalsample's Introduction

CsInternalSample

This sample uses the power of C# and .NET NativeAOT to create an injectable client.

Since I didn't find a known way to execute code in C# when injected, I had to make this client depended from another C++ DLL (which gets injected first). This C++ DLL then loads our C# DLL and calls the Load_ function which we exported as _Load_CsInternalClient.

[UnmanagedCallersOnly(EntryPoint = "_Load_CsInternalClient", CallConvs = new[] { typeof(CallConvStdcall) })]
internal static void Load_()
{
    ...
}

Building

Make sure to clone this repo using the --recursive flag:

git clone --recursive https://github.com/CXCubeHD/CsInternalSample

You can create the NativeAOT C# DLL (CsInternalClient) using:

dotnet publish -r win-x64 -c Release

If it doesn't say Generating compatible native code. To optimize for size or speed, visit https://aka.ms/OptimizeNativeAOT then you probably did something wrong.

The compiled DLL should appear at this location: .\CsInternalClient\bin\Release\net7.0-windows10.0.22621.0\win-x64\native

Then tell the C++ DLL where our DLL is located by editing this file: .\CsInternalLoader\src\CsInternalLoader-impl\config\config.cc

// TODO: Enter the path of your CsInternalClient DLL
inline chr::wstr CsInternalClientPath =
	L"PATH TO NativeAOT C# DLL";

If you are trying to inject those DLLs into an UWP app then make sure they both have the required file permissions.

Lastly compile the C++ DLL (CsInternalLoader) using CMake.


That's it now you can inject it!

License

The license can be found under LICENSE.md.

Please note that currently the license is very strict so please make sure to read it.

Changes License to MIT

csinternalsample's People

Contributors

cxcubehd 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.