Skip to content

Commit 672f029

Browse files
add linux support
looks like Microsoft fixed `hostfxr_initialize_for_runtime_config`
1 parent 2110152 commit 672f029

File tree

7 files changed

+66
-11
lines changed

7 files changed

+66
-11
lines changed

.github/workflows/ci.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,23 @@ on:
55
workflow_dispatch:
66

77
jobs:
8-
build:
8+
linux-build:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- uses: actions/setup-node@v4
15+
with:
16+
node-version: 20
17+
18+
- name: Build project
19+
run: ./_build.sh
20+
21+
- name: Run project
22+
run: ./_run.sh
23+
24+
windows-build:
925
runs-on: windows-latest
1026

1127
steps:

Bootstrapper/build.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
set -ex
3+
4+
mkdir -p build && cd build
5+
6+
cmake ..
7+
cmake --build . --config Release

DemoApplication/build.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
set -ex
3+
dotnet publish -c Release -r linux-x64 -p:PublishDir="$(pwd)/dist" --self-contained

README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,26 @@ CLI tool that can replace C# methods in .NET Core applications
1515
- Node.js: https://nodejs.org/en/download/
1616
- frida: https://frida.re
1717

18-
### Installation on Windows
18+
### Installation
1919

2020
Open command line and run this script
2121

22+
- `_build.sh` on Linux
23+
- `_build.bat` on Windows
24+
2225
It will build
2326

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

29-
```
30-
_build.bat
31-
```
32-
3332
### Running
3433

3534
This script should produce output like the GIF above
3635

37-
```
38-
_run.bat
39-
```
36+
- `_run.sh` on Linux
37+
- `_run.bat` on Windows
4038

4139
### Internal documentation
4240

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

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

53-
5451
The following command runs `DemoApplication.exe` on another thread and injects code.
52+
5553
```
5654
start DemoApplication\dist\DemoApplication.exe
5755
@@ -64,6 +62,7 @@ RuntimePatcher\dist\RuntimePatcher.dll ^
6462
```
6563

6664
Then the execution happens in this order:
65+
6766
1. get into `DemoApplication.exe` process memory via DLL-injection of `Bootstrapper.dll`
6867
2. call native C++ code
6968
```cpp
@@ -86,4 +85,4 @@ You can use this to mod games written in C# or to patch any software
8685
8786
### TODO
8887
89-
- Linux support is incomplete due to some issues with the secondary host context in `hostfxr`
88+
- I don't have macOS device so it's supported for now. External contributors are welcome.

RuntimePatcher/build.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
set -ex
3+
dotnet publish -c Release -p:PublishDir="$(pwd)/dist"

_build.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
set -ex
3+
4+
npm install
5+
6+
cd Bootstrapper
7+
./build.sh
8+
cd ..
9+
10+
cd DemoApplication
11+
./build.sh
12+
cd ..
13+
14+
cd RuntimePatcher
15+
./build.sh
16+
cd ..

_run.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
set -ex
3+
4+
sudo sysctl kernel.yama.ptrace_scope=0
5+
./DemoApplication/dist/DemoApplication &
6+
npm start -- inject \
7+
DemoApplication \
8+
Bootstrapper/build/libBootstrapper.so \
9+
RuntimePatcher/dist/RuntimePatcher.runtimeconfig.json \
10+
RuntimePatcher/dist/RuntimePatcher.dll \
11+
"RuntimePatcher.Main, RuntimePatcher" "InitializePatches"

0 commit comments

Comments
 (0)