Skip to content

WIP: C Exports, C# Exports and Fixing CI Workflows #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 28 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
fdc0da3
Set 'nightly' toolchain as default.
Sewer56 Feb 21, 2024
539b664
Improved: Now runs tests on Linux/Wine
Sewer56 Feb 23, 2024
bbfe38a
Added: VSCode Shortcuts
Sewer56 Feb 22, 2024
c2e8f6f
Added: Workaround for zero sized write issue on Wine
Sewer56 Feb 23, 2024
801e0cc
Removed: Unused lock from earlier code revision
Sewer56 Feb 23, 2024
1e2d1ac
Fix: Redundant Return in Code Style
Sewer56 Feb 23, 2024
4b7afe9
VSCode: Don't prompt for which errors/warnings to show when running t…
Sewer56 Feb 23, 2024
fa8f7e9
Added: Support for suspended processes
Sewer56 Feb 23, 2024
b5195c6
Fix: Windows 10+ Detection
Sewer56 Feb 23, 2024
acea5a0
Removed: Unused 'IcedError' Import
Sewer56 Feb 23, 2024
c13f005
Fix: Pass 1 byte param correctly, and null parameter.
Sewer56 Feb 23, 2024
f82423d
Added: Disclaimer on Wine Bug #56362
Sewer56 Feb 23, 2024
02cbdfe
x86: Skip call to flush_instruction_cache
Sewer56 Feb 24, 2024
d8027c5
Changed: Enable all features in rust-analyzer
Sewer56 Feb 24, 2024
67cbd82
Added: C Exports for Library
Sewer56 Feb 24, 2024
34fe92c
Added: Generate C# exports for library
Sewer56 Feb 24, 2024
335856f
Update & Fix CI Workflows
Sewer56 Feb 25, 2024
67df032
.NET: DllImportResolver should be internal
Sewer56 Feb 25, 2024
d1dc1a3
.NET: Forgot to comment out nuget-icon.png
Sewer56 Feb 25, 2024
dc08711
Fix: CI by allowing `buffer::*` to be unused conditionally.
Sewer56 Feb 25, 2024
95cd08f
CI: Add missing i686 Rust Target
Sewer56 Feb 25, 2024
6062e35
CI: Try Installing Wine into the Image
Sewer56 Feb 25, 2024
af352ba
Fixed: c-exports should imply 'syringe' since it depends on 'syringe'
Sewer56 Feb 25, 2024
243e097
CI: Build C libs without RPC feature (unused).
Sewer56 Feb 25, 2024
6b90a9a
Remove: Redundant double DllImportResolver
Sewer56 Feb 25, 2024
cfa231d
Bugfix: We shlould be checking Process, not OS Architecture to find w…
Sewer56 Feb 28, 2024
e831138
Merge branch 'add-c-exports' of https://github.com/Sewer56/dll-syring…
Sewer56 Feb 28, 2024
878d473
Removed WINE Notice: No Longer Valid/Bug Fixed
Sewer56 Mar 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
target = ['i686-pc-windows-msvc','x86_64-pc-windows-msvc']
264 changes: 212 additions & 52 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ name: CI

on:
push:
branches: [ master ]
branches: [ master,add-c-exports ]
pull_request:
branches: [ master ]
workflow_dispatch:

env:
CARGO_TERM_COLOR: always
Expand All @@ -17,83 +18,242 @@ jobs:
strategy:
fail-fast: false
matrix:
toolchain: ["nightly"]
os: ["windows-latest"]
target: ["x86_64-pc-windows-msvc", "i686-pc-windows-msvc"]
include:
- target: x86_64-pc-windows-msvc
target32: i686-pc-windows-msvc
steps:
- uses: actions/checkout@v2
- name: Install latest rust ${{ matrix.toolchain }} for ${{ matrix.target }}
uses: actions-rs/toolchain@v1
- uses: actions/checkout@v4

- name: Install Nightly Rust
uses: dtolnay/rust-toolchain@nightly
with:
target: ${{ matrix.target }}
toolchain: ${{ matrix.toolchain }}
override: true

- name: Install latest rust ${{ matrix.toolchain }} for x86 version of target
if: matrix.target32
uses: actions-rs/toolchain@v1
with:
target: ${{ matrix.target32 }}
toolchain: ${{ matrix.toolchain }}
override: true

- name: Build
targets: ${{ matrix.target }}

# We need this because we also text x64-to-x86 injection.
- name: Add i686 Rust Target
run: rustup target add i686-pc-windows-msvc --toolchain nightly

- name: Can Build
run: cargo build --target ${{ matrix.target }}

- name: Build test target
run: cargo build --target ${{ matrix.target }} --manifest-path "tests/helpers/test_target/Cargo.toml" --all-targets
- name: Build test payload
run: cargo build --target ${{ matrix.target }} --manifest-path "tests/helpers/test_payload/Cargo.toml" --all-targets
- name: Can Build test target
run: cargo build --target ${{ matrix.target }} --manifest-path "tests/helpers/test_target/Cargo.toml"
- name: Can Build test payload
run: cargo build --target ${{ matrix.target }} --manifest-path "tests/helpers/test_payload/Cargo.toml"

- name: Test
run: cargo test --target ${{ matrix.target }} --all-targets --all-features -- --nocapture
run: cargo test --target ${{ matrix.target }} --all-features -- --nocapture

- name: Build (default features)
run: cargo build --target ${{ matrix.target }} --all-targets
- name: Build (no features)
run: cargo build --target ${{ matrix.target }} --no-default-features --all-targets
- name: Build (feature syringe)
run: cargo build --target ${{ matrix.target }} --features syringe --all-targets
- name: Build (feature rpc)
run: cargo build --target ${{ matrix.target }} --features rpc --all-targets
- name: Can Build (no features)
run: cargo build --target ${{ matrix.target }} --no-default-features
- name: Can Build (feature syringe)
run: cargo build --target ${{ matrix.target }} --no-default-features --features syringe
- name: Can Build (feature rpc)
run: cargo build --target ${{ matrix.target }} --no-default-features --features rpc

test-on-wine:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

# Install Rust nightly toolchain
- name: Install Nightly Rust
uses: dtolnay/rust-toolchain@nightly

# Add Windows MSVC targets
- name: Add Rust targets
run: |
rustup target add x86_64-pc-windows-msvc --toolchain nightly
rustup target add i686-pc-windows-msvc --toolchain nightly

# Install cargo-xwin
- name: Install cargo-xwin
run: cargo install cargo-xwin

# We can't use 'cross' due to using xwin, so we have to manually install Wine
- name: Install Wine
run: |
sudo apt-get install ppa-purge && sudo ppa-purge -y ppa:ubuntu-toolchain-r/test
sudo dpkg --add-architecture i386
sudo mkdir -pm755 /etc/apt/keyrings && sudo wget -O /etc/apt/keyrings/winehq-archive.key https://dl.winehq.org/wine-builds/winehq.key
sudo wget -NP /etc/apt/sources.list.d/ https://dl.winehq.org/wine-builds/ubuntu/dists/jammy/winehq-jammy.sources
sudo apt-get update
sudo apt install --install-recommends winehq-stable

# Run tests with Wine
- name: Run tests on Wine
run: ./scripts/test-wine.ps1
shell: pwsh

build-c-libs:
strategy:
matrix:
include:
- os: windows-latest
target: x86_64-pc-windows-msvc
use_cross: false
features: "c-exports,into-x86-from-x64"
- os: windows-latest
target: i686-pc-windows-msvc
use_cross: false
features: "c-exports"
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- id: build-libs
uses: Reloaded-Project/reloaded-project-configurations-rust/.github/actions/build-c-library@v1 # upgrade if needed
with:
target: ${{ matrix.target }}
use_pgo: false
use_cross: ${{ matrix.use_cross }}
features: ${{ matrix.features }}
no_default_features: true

build-c-headers:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Generate C++ bindings
uses: Reloaded-Project/reloaded-project-configurations-rust/.github/actions/generate-bindings@v1
with:
config_file: cbindgen_cpp.toml
header_file: bindings_cpp.hpp

- name: Generate C bindings
uses: Reloaded-Project/reloaded-project-configurations-rust/.github/actions/generate-bindings@v1
with:
config_file: cbindgen_c.toml
header_file: bindings_c.h

build-dotnet-library:
needs: build-c-libs
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Build and Package .NET Library
uses: Reloaded-Project/reloaded-project-configurations-rust/.github/actions/build-dotnet-library@dotnet-bindings
with:
targets: 'x86_64-pc-windows-msvc,i686-pc-windows-msvc'

documentation:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["windows-latest"]
steps:
- uses: actions/checkout@v2
- name: Install latest nightly
uses: actions-rs/toolchain@v1
- uses: actions/checkout@v4
with:
profile: minimal
toolchain: nightly
override: true
submodules: recursive

- name: Install Nightly Rust
uses: dtolnay/rust-toolchain@nightly

# Add Windows MSVC targets
- name: Add Rust targets
run: |
rustup target add x86_64-pc-windows-msvc --toolchain nightly
rustup target add i686-pc-windows-msvc --toolchain nightly

- name: Generate documentation
run: cargo doc --all-features
run: cargo +nightly doc --all-features
- name: Install cargo-deadlinks
run: cargo install cargo-deadlinks
run: cargo +nightly install cargo-deadlinks
- name: Check dead links in doc
run: cargo deadlinks
run: cargo +nightly deadlinks

clippy:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["windows-latest"]
steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Nightly Rust
uses: dtolnay/rust-toolchain@nightly
with:
components: clippy

- uses: giraffate/clippy-action@v1
with:
toolchain: nightly
components: clippy
override: true
- uses: actions-rs/clippy-check@v1
reporter: 'github-pr-review'
github_token: ${{ secrets.GITHUB_TOKEN }}

publish-crate:
permissions:
contents: write

needs: [test,build-c-libs,build-c-headers,test-on-wine,build-dotnet-library]
# Publish only on tags
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: ↙️ Download Artifacts
uses: actions/download-artifact@v4
with:
path: artifacts

- name: Upload to NuGet
shell: pwsh
run: |
$items = Get-ChildItem -Path "artifacts/**.nupkg" -Recurse
Foreach ($item in $items)
{
Write-Host "Pushing $item"
dotnet nuget push "$item" -k "${{ secrets.NUGET_KEY }}" -s "https://api.nuget.org/v3/index.json" --skip-duplicate
}

$items = Get-ChildItem -Path "artifacts/**.snupkg" -Recurse
Foreach ($item in $items)
{
Write-Host "Pushing Symbol Package $item"
dotnet nuget push "$item" -k "${{ secrets.NUGET_KEY }}" -s "https://api.nuget.org/v3/index.json" --skip-duplicate
}

- name: Compress Artifacts
shell: bash
run: |
dir="artifacts"
if [ ! -d "$dir" ]; then
echo "Directory $dir does not exist. No artifacts found."
exit 0
fi

for subdir in "$dir"/*; do
if [ -d "$subdir" ]; then
base=$(basename "$subdir")
zip -r "$dir/$base.zip" "$subdir"
rm -r "$subdir"
fi
done
ls -A ./artifacts

- name: GitHub Release Artifacts
uses: softprops/action-gh-release@v1
with:
files: |
artifacts/*


- name: Publish to crates.io
uses: Reloaded-Project/reloaded-project-configurations-rust/.github/actions/publish-crate@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features
token: ${{ secrets.CRATES_IO_TOKEN }}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
/target
Cargo.lock
.vscode
12 changes: 12 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"rust-analyzer.checkOnSave.command": "clippy",
"[rust]": {
"editor.formatOnSave": true
},
"rust-analyzer.linkedProjects": [
"Cargo.toml",
"tests/helpers/test_payload/Cargo.toml",
"tests/helpers/test_target/Cargo.toml",
],
"rust-analyzer.cargo.features": "all"
}
23 changes: 23 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Test on Windows",
"type": "shell",
"command": "pwsh ./scripts/test.ps1",
"problemMatcher": []
},
{
"label": "Clean",
"type": "shell",
"command": "pwsh ./scripts/clean.ps1",
"problemMatcher": []
},
{
"label": "Test on Wine (See Readme)",
"type": "shell",
"command": "pwsh ./scripts/test-wine.ps1",
"problemMatcher": []
},
]
}
20 changes: 20 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ iced-x86 = { version = "1.19", features = ["std", "code_asm"], default-features
bincode = { version = "1.3", default-features = false, optional = true }
serde = { version = "1.0", default-features = false, optional = true }

# C# Bindings
[build-dependencies]
csbindgen = "1.9.0"

[target.'cfg(target_arch = "x86")'.dependencies]

[target.'cfg(target_arch = "x86_64")'.dependencies]
Expand All @@ -50,7 +54,23 @@ payload-utils = ["bincode", "serde"]
syringe = ["iced-x86"]
full = ["into-x86-from-x64", "rpc", "process-memory", "payload-utils"]
doc-cfg = ["full"]
c-exports = ["syringe"]

[package.metadata.docs.rs]
targets = ["x86_64-pc-windows-msvc", "i686-pc-windows-msvc"]
features = ["doc-cfg"]

# Profile Build
[profile.profile]
inherits = "release"
debug = true
codegen-units = 1
lto = true
strip = false # No stripping!!

# Optimized Release Build
[profile.release]
codegen-units = 1
lto = true
strip = true # Automatically strip symbols from the binary.
panic = "abort"
Loading