mirror of
https://github.com/tiennm99/time-mocker.git
synced 2026-10-12 02:14:20 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fc1ba194d1 | ||
|
|
46c13d0533 | ||
|
|
06e195c5a2 |
No files matched your search
Vendored
+4
-21
@@ -10,7 +10,7 @@ permissions:
|
||||
|
||||
jobs:
|
||||
build-and-release:
|
||||
runs-on: windows-2025-vs2026
|
||||
runs-on: windows-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
@@ -21,30 +21,13 @@ jobs:
|
||||
with:
|
||||
dotnet-version: 10.x
|
||||
|
||||
- name: Build Hook DLL (x86)
|
||||
run: dotnet build TimeMocker.Hook\TimeMocker.Hook.csproj -c Release -p:Platform=x86
|
||||
|
||||
- name: Build Hook DLL (x64)
|
||||
run: dotnet build TimeMocker.Hook\TimeMocker.Hook.csproj -c Release -p:Platform=x64
|
||||
|
||||
- name: Build UI
|
||||
run: dotnet build TimeMocker.UI\TimeMocker.UI.csproj -c Release -p:Platform=x64
|
||||
|
||||
- name: Verify Hook DLL sizes
|
||||
run: |
|
||||
$x64 = (Get-Item "TimeMocker.Hook\bin\x64\Release\net48\TimeMocker.Hook.dll").Length
|
||||
$x86 = (Get-Item "TimeMocker.Hook\bin\x86\Release\net48\TimeMocker.Hook.dll").Length
|
||||
Write-Host "x64 hook DLL: $x64 bytes"
|
||||
Write-Host "x86 hook DLL: $x86 bytes"
|
||||
if ($x64 -lt 20000) { throw "x64 hook DLL too small - build failed silently" }
|
||||
if ($x86 -lt 20000) { throw "x86 hook DLL too small - build failed silently" }
|
||||
- name: Build Solution
|
||||
run: dotnet build TimeMocker.sln -c Release -p:Platform=x64
|
||||
|
||||
- name: Prepare Release Artifacts
|
||||
run: |
|
||||
mkdir release
|
||||
copy TimeMocker.UI\bin\x64\Release\net48\*.dll release\
|
||||
copy TimeMocker.UI\bin\x64\Release\net48\*.exe release\
|
||||
copy TimeMocker.UI\bin\x64\Release\net48\*.config release\
|
||||
copy TimeMocker.UI\bin\x64\Release\net48\* release\
|
||||
|
||||
- name: Zip Release
|
||||
run: Compress-Archive -Path release\* -DestinationPath TimeMocker-x64.zip
|
||||
|
||||
@@ -2,7 +2,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using EasyHook;
|
||||
|
||||
namespace TimeMocker.UI.Core
|
||||
@@ -27,9 +26,6 @@ namespace TimeMocker.UI.Core
|
||||
private static readonly string HookDllPathX86 =
|
||||
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TimeMocker.Hook.x86.dll");
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
private static extern bool IsWow64Process(IntPtr hProcess, out bool wow64Process);
|
||||
|
||||
public event Action<string> LogMessage;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
@@ -53,19 +49,16 @@ namespace TimeMocker.UI.Core
|
||||
// Write initial delta (zero = real time) before hook starts reading
|
||||
entry.Shm.Write(new MockTimeInfo { DeltaTicks = 0 });
|
||||
|
||||
// Determine which DLL to use based on target process architecture
|
||||
string hookDllPath = GetHookDllPath(process);
|
||||
|
||||
RemoteHooking.Inject(
|
||||
process.Id,
|
||||
InjectionOptions.DoNotRequireStrongName,
|
||||
hookDllPath,
|
||||
hookDllPath,
|
||||
HookDllPathX86,
|
||||
HookDllPathX64,
|
||||
entry.Shm.MmfName);
|
||||
|
||||
entry.IsInjected = true;
|
||||
_injected[process.Id] = entry;
|
||||
Log($"Injected into [{process.Id}] {process.ProcessName} ({GetArchitectureName(process)})");
|
||||
Log($"Injected into [{process.Id}] {process.ProcessName}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -77,54 +70,6 @@ namespace TimeMocker.UI.Core
|
||||
return entry;
|
||||
}
|
||||
|
||||
private static string GetHookDllPath(Process process)
|
||||
{
|
||||
bool is64BitTarget = Is64BitProcess(process);
|
||||
|
||||
if (is64BitTarget)
|
||||
{
|
||||
if (!File.Exists(HookDllPathX64))
|
||||
throw new FileNotFoundException($"x64 hook DLL not found: {HookDllPathX64}");
|
||||
return HookDllPathX64;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!File.Exists(HookDllPathX86))
|
||||
throw new FileNotFoundException($"x86 hook DLL not found: {HookDllPathX86}");
|
||||
return HookDllPathX86;
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
private static extern bool IsWow64Process2(
|
||||
IntPtr hProcess,
|
||||
out ushort pProcessMachine,
|
||||
out ushort pNativeMachine);
|
||||
|
||||
private static bool Is64BitProcess(Process process)
|
||||
{
|
||||
if (!Environment.Is64BitOperatingSystem)
|
||||
return false;
|
||||
|
||||
ushort processMachine, nativeMachine;
|
||||
if (IsWow64Process2(process.Handle, out processMachine, out nativeMachine))
|
||||
{
|
||||
// IMAGE_FILE_MACHINE_UNKNOWN (0) means it's a native 64-bit process
|
||||
// IMAGE_FILE_MACHINE_I386 (0x014c) means it's 32-bit on 64-bit Windows
|
||||
return processMachine == 0x0000; // 0 = native, not emulated
|
||||
}
|
||||
|
||||
// Fallback
|
||||
bool isWow64;
|
||||
IsWow64Process(process.Handle, out isWow64);
|
||||
return !isWow64;
|
||||
}
|
||||
|
||||
private static string GetArchitectureName(Process process)
|
||||
{
|
||||
return Is64BitProcess(process) ? "x64" : "x86";
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Update fake time for a process
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"sdk": {
|
||||
"version": "10.0.0",
|
||||
"version": "10.0.100",
|
||||
"rollForward": "latestMajor",
|
||||
"allowPrerelease": true
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user