Skip to content

Commit

Permalink
add linux support
Browse files Browse the repository at this point in the history
looks like Microsoft fixed `hostfxr_initialize_for_runtime_config`
  • Loading branch information
StackOverflowExcept1on committed Aug 30, 2024
1 parent 2110152 commit 672f029
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 11 deletions.
18 changes: 17 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,23 @@ on:
workflow_dispatch:

jobs:
build:
linux-build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 20

- name: Build project
run: ./_build.sh

- name: Run project
run: ./_run.sh

windows-build:
runs-on: windows-latest

steps:
Expand Down
7 changes: 7 additions & 0 deletions Bootstrapper/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -ex

mkdir -p build && cd build

cmake ..
cmake --build . --config Release
3 changes: 3 additions & 0 deletions DemoApplication/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
set -ex
dotnet publish -c Release -r linux-x64 -p:PublishDir="$(pwd)/dist" --self-contained
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,26 @@ CLI tool that can replace C# methods in .NET Core applications
- Node.js: https://nodejs.org/en/download/
- frida: https://frida.re

### Installation on Windows
### Installation

Open command line and run this script

- `_build.sh` on Linux
- `_build.bat` on Windows

It will build

- Node.js package [net-core-injector](package.json) - DLL-injector written in TypeScript
- [Bootstrapper](Bootstrapper) - helper native library written in C++ to interact with .NET Core runtime
- [DemoApplication](DemoApplication) - test application to demonstrate how it works
- [RuntimePatcher](RuntimePatcher) - code that attaches to [DemoApplication](DemoApplication)

```
_build.bat
```

### Running

This script should produce output like the GIF above

```
_run.bat
```
- `_run.sh` on Linux
- `_run.bat` on Windows

### Internal documentation

Expand All @@ -50,8 +48,8 @@ I did it in [`Bootstrapper/src/library.cpp`](Bootstrapper/src/library.cpp).

[`net-core-injector/src/main.ts`](src/main.ts) injects `Bootstrapper.dll` into C# process and loads custom assembly


The following command runs `DemoApplication.exe` on another thread and injects code.

```
start DemoApplication\dist\DemoApplication.exe
Expand All @@ -64,6 +62,7 @@ RuntimePatcher\dist\RuntimePatcher.dll ^
```

Then the execution happens in this order:

1. get into `DemoApplication.exe` process memory via DLL-injection of `Bootstrapper.dll`
2. call native C++ code
```cpp
Expand All @@ -86,4 +85,4 @@ You can use this to mod games written in C# or to patch any software
### TODO
- Linux support is incomplete due to some issues with the secondary host context in `hostfxr`
- I don't have macOS device so it's supported for now. External contributors are welcome.
3 changes: 3 additions & 0 deletions RuntimePatcher/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
set -ex
dotnet publish -c Release -p:PublishDir="$(pwd)/dist"
16 changes: 16 additions & 0 deletions _build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -ex

npm install

cd Bootstrapper
./build.sh
cd ..

cd DemoApplication
./build.sh
cd ..

cd RuntimePatcher
./build.sh
cd ..
11 changes: 11 additions & 0 deletions _run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -ex

sudo sysctl kernel.yama.ptrace_scope=0
./DemoApplication/dist/DemoApplication &
npm start -- inject \
DemoApplication \
Bootstrapper/build/libBootstrapper.so \
RuntimePatcher/dist/RuntimePatcher.runtimeconfig.json \
RuntimePatcher/dist/RuntimePatcher.dll \
"RuntimePatcher.Main, RuntimePatcher" "InitializePatches"

0 comments on commit 672f029

Please sign in to comment.