Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 4 additions & 7 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:

strategy:
matrix:
targetplatform: [x86]
targetplatform: [x64]

runs-on: windows-latest

Expand Down Expand Up @@ -60,6 +60,7 @@ jobs:
uses: actions/setup-dotnet@v5
with:
dotnet-version: '10.x'
architecture: x64

- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@v2.0.0
Expand All @@ -72,9 +73,7 @@ jobs:
dotnet user-secrets --project Daybreak\Daybreak.csproj set ApmUri "${{ secrets.ApmUri }}"

- name: Restore project
run: msbuild $env:Solution_Path /t:Restore /p:Configuration=$env:Configuration /p:RuntimeIdentifier=$env:RuntimeIdentifier --property:SolutionDir=$GITHUB_WORKSPACE
env:
RuntimeIdentifier: win-${{ matrix.targetplatform }}
run: msbuild $env:Solution_Path /t:Restore /p:Configuration=$env:Configuration --property:SolutionDir=$GITHUB_WORKSPACE

- name: Build Daybreak project
run: dotnet build Daybreak -c $env:Configuration --property:SolutionDir=$env:GITHUB_WORKSPACE
Expand All @@ -85,9 +84,7 @@ jobs:
echo "::set-env name=Version::$version"

- name: Create publish launcher files
run: dotnet publish .\Daybreak\Daybreak.csproj -c $env:Configuration -r $env:RuntimeIdentifier --property:SolutionDir=$env:GITHUB_WORKSPACE -p:PublishReadyToRun=true -p:PublishSingleFile=false --self-contained true -o .\Publish
env:
RuntimeIdentifier: win-${{ matrix.targetplatform }}
run: dotnet publish .\Daybreak\Daybreak.csproj -c $env:Configuration --property:SolutionDir=$env:GITHUB_WORKSPACE -p:PublishReadyToRun=true -p:PublishSingleFile=false --self-contained true -o .\Publish

- name: Pack publish files
run: |
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

strategy:
matrix:
targetplatform: [x86]
targetplatform: [x64]

runs-on: windows-latest

Expand All @@ -41,13 +41,12 @@ jobs:
uses: actions/setup-dotnet@v5
with:
dotnet-version: '10.x'
architecture: x86
architecture: x64

- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@v2.0.0

- name: Restore the Wpf application to populate the obj folder
run: msbuild $env:Solution_Path /t:Restore /p:Configuration=$env:Configuration /p:RuntimeIdentifier=$env:RuntimeIdentifier --property:SolutionDir=$env:GITHUB_WORKSPACE
run: msbuild $env:Solution_Path /t:Restore /p:Configuration=$env:Configuration --property:SolutionDir=$env:GITHUB_WORKSPACE
env:
Configuration: Debug
RuntimeIdentifier: win-${{ matrix.targetplatform }}
Configuration: Debug
15 changes: 0 additions & 15 deletions Daybreak.7ZipExtractor/Daybreak.7ZipExtractor.csproj

This file was deleted.

47 changes: 0 additions & 47 deletions Daybreak.7ZipExtractor/Program.cs

This file was deleted.

23 changes: 23 additions & 0 deletions Daybreak.Injector/Daybreak.Injector.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>$(TargetFrameworkVersionWindows)</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Platforms>x86</Platforms>
<SelfContained>true</SelfContained>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
<PublishAot>true</PublishAot>
<StripSymbols>true</StripSymbols>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Reloaded.Assembler" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Daybreak.Shared\Daybreak.Shared.csproj" />
</ItemGroup>

</Project>
138 changes: 138 additions & 0 deletions Daybreak.Injector/ProcessInjector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
using Daybreak.Shared.Models;
using Daybreak.Shared.Utils;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;

namespace Daybreak.Injector;

public static class ProcessInjector
{
public static InjectorResponses.InjectResult InjectWithApi(Process process, string pathToDll)
{
var modulefullpath = Path.GetFullPath(pathToDll);

if (!File.Exists(modulefullpath))
{
Console.WriteLine("Dll to inject not found");
return InjectorResponses.InjectResult.InvalidDllPath;
}

var hKernel32 = NativeMethods.GetModuleHandle("kernel32.dll");
if (hKernel32 == IntPtr.Zero)
{
Console.WriteLine("Unable to get a handle of kernel32.dll");
return InjectorResponses.InjectResult.InvalidKernel32;
}

var hLoadLib = NativeMethods.GetProcAddress(hKernel32, "LoadLibraryW");
if (hLoadLib == IntPtr.Zero)
{
Console.WriteLine("Unable to get the address of LoadLibraryW");
return InjectorResponses.InjectResult.InvalidLoadLibraryW;
}

var hStringBuffer = NativeMethods.VirtualAllocEx(process.Handle, IntPtr.Zero, new IntPtr(2 * (modulefullpath.Length + 1)),
0x3000 /* MEM_COMMIT | MEM_RESERVE */, 0x4 /* PAGE_READWRITE */);
if (hStringBuffer == IntPtr.Zero)
{
Console.WriteLine("Unable to allocate memory for module path");
return InjectorResponses.InjectResult.ModulePathAllocationFailed;
}

WriteWString(process, hStringBuffer, modulefullpath);
if (ReadWString(process, hStringBuffer, 260) != modulefullpath)
{
Console.WriteLine("Module path string is not correct");
return InjectorResponses.InjectResult.DllPathWriteFailed;
}

var hThread = NativeMethods.CreateRemoteThread(process.Handle, IntPtr.Zero, 0, hLoadLib, hStringBuffer, 0, out _);
if (hThread == IntPtr.Zero)
{
Console.WriteLine("Unable to create remote thread");
return InjectorResponses.InjectResult.CreateRemoteThreadFailed;
}

var threadResult = NativeMethods.WaitForSingleObject(hThread, 30000u);
if (threadResult is 0x102 or 0xFFFFFFFF /* WAIT_FAILED */)
{
Console.WriteLine($"Exception occurred while waiting for the remote thread. Result is {threadResult}");
return InjectorResponses.InjectResult.RemoteThreadTimeout;
}

var dllResult = NativeMethods.GetExitCodeThread(hThread, out _);
if (dllResult == 0)
{
Console.WriteLine($"Injected dll returned non-success status code {dllResult}");
return InjectorResponses.InjectResult.DllExitCodeFailed;
}

var memoryFreeResult = NativeMethods.VirtualFreeEx(process.Handle, hStringBuffer, 0, 0x8000 /* MEM_RELEASE */);
if (!memoryFreeResult)
{
Console.WriteLine($"Failed to free dll memory");
}

return memoryFreeResult
? InjectorResponses.InjectResult.Success
: InjectorResponses.InjectResult.MemoryFreeFailed;
}

private static void WriteBytes(Process process, IntPtr address, byte[] data)
{
var size = data.Length;
var buffer = Marshal.AllocHGlobal(size);
Marshal.Copy(data, 0, buffer, size);

NativeMethods.WriteProcessMemory(
process.Handle,
address,
buffer,
size,
out _);

Marshal.FreeHGlobal(buffer);
}

private static void WriteWString(Process process, IntPtr address, string data)
{
WriteBytes(process, address, Encoding.Unicode.GetBytes(data));
}

private static string ReadWString(Process process, IntPtr address, int maxsize, Encoding? encoding = null)
{
encoding ??= Encoding.Unicode;
var rawbytes = ReadBytes(process, address, maxsize);
if (rawbytes.Length == 0)
{
return "";
}

var ret = encoding.GetString(rawbytes);
if (ret.Contains('\0'))
{
ret = ret[..ret.IndexOf('\0')];
}

return ret;
}

private static byte[] ReadBytes(Process process, IntPtr address, int size)
{
var buffer = Marshal.AllocHGlobal(size);

NativeMethods.ReadProcessMemory(process.Handle,
address,
buffer,
size,
out _
);

var ret = new byte[size];
Marshal.Copy(buffer, ret, 0, size);
Marshal.FreeHGlobal(buffer);

return ret;
}
}
Loading
Loading