mirror of
https://github.com/tiennm99/time-mocker.git
synced 2026-10-14 16:18:05 +00:00
refactor: reformat & apply code style
This commit is contained in:
1 parent
f63317dc64
commit
78b60c8cea
8 files changed
+329
-227
No files matched your search
@@ -14,8 +14,8 @@ namespace TimeMocker.Hook
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct MockTimeInfo
|
||||
{
|
||||
public long FakeUtcTicks; // DateTime ticks (UTC)
|
||||
public int Enabled; // 1 = mock active, 0 = passthrough
|
||||
public long FakeUtcTicks; // DateTime ticks (UTC)
|
||||
public int Enabled; // 1 = mock active, 0 = passthrough
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
@@ -31,13 +31,13 @@ namespace TimeMocker.Hook
|
||||
{
|
||||
return new SYSTEMTIME
|
||||
{
|
||||
wYear = (ushort)dt.Year,
|
||||
wMonth = (ushort)dt.Month,
|
||||
wDayOfWeek = (ushort)dt.DayOfWeek,
|
||||
wDay = (ushort)dt.Day,
|
||||
wHour = (ushort)dt.Hour,
|
||||
wMinute = (ushort)dt.Minute,
|
||||
wSecond = (ushort)dt.Second,
|
||||
wYear = (ushort)dt.Year,
|
||||
wMonth = (ushort)dt.Month,
|
||||
wDayOfWeek = (ushort)dt.DayOfWeek,
|
||||
wDay = (ushort)dt.Day,
|
||||
wHour = (ushort)dt.Hour,
|
||||
wMinute = (ushort)dt.Minute,
|
||||
wSecond = (ushort)dt.Second,
|
||||
wMilliseconds = (ushort)dt.Millisecond
|
||||
};
|
||||
}
|
||||
@@ -69,7 +69,7 @@ namespace TimeMocker.Hook
|
||||
try
|
||||
{
|
||||
// Open the shared memory created by the UI process
|
||||
_mmf = System.IO.MemoryMappedFiles.MemoryMappedFile.OpenExisting(mmfName);
|
||||
_mmf = System.IO.MemoryMappedFiles.MemoryMappedFile.OpenExisting(mmfName);
|
||||
_view = _mmf.CreateViewAccessor(0, Marshal.SizeOf<MockTimeInfo>());
|
||||
|
||||
InstallHooks();
|
||||
@@ -146,25 +146,25 @@ namespace TimeMocker.Hook
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
delegate void GetSystemTimeDelegate(out SYSTEMTIME lpSystemTime);
|
||||
private delegate void GetSystemTimeDelegate(out SYSTEMTIME lpSystemTime);
|
||||
|
||||
void GetSystemTime_Hook(out SYSTEMTIME lpSystemTime)
|
||||
private void GetSystemTime_Hook(out SYSTEMTIME lpSystemTime)
|
||||
{
|
||||
lpSystemTime = SYSTEMTIME.FromDateTime(GetFakeUtc());
|
||||
}
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
delegate void GetLocalTimeDelegate(out SYSTEMTIME lpLocalTime);
|
||||
private delegate void GetLocalTimeDelegate(out SYSTEMTIME lpLocalTime);
|
||||
|
||||
void GetLocalTime_Hook(out SYSTEMTIME lpLocalTime)
|
||||
private void GetLocalTime_Hook(out SYSTEMTIME lpLocalTime)
|
||||
{
|
||||
lpLocalTime = SYSTEMTIME.FromDateTime(GetFakeUtc().ToLocalTime());
|
||||
}
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
delegate int NtQuerySystemTimeDelegate(out long systemTime);
|
||||
private delegate int NtQuerySystemTimeDelegate(out long systemTime);
|
||||
|
||||
int NtQuerySystemTime_Hook(out long systemTime)
|
||||
private int NtQuerySystemTime_Hook(out long systemTime)
|
||||
{
|
||||
// FILETIME epoch: Jan 1, 1601
|
||||
var epoch = new DateTime(1601, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
@@ -173,18 +173,18 @@ namespace TimeMocker.Hook
|
||||
}
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
delegate void GetSystemTimeAsFileTimeDelegate(out long lpFileTime);
|
||||
private delegate void GetSystemTimeAsFileTimeDelegate(out long lpFileTime);
|
||||
|
||||
void GetSystemTimeAsFileTime_Hook(out long lpFileTime)
|
||||
private void GetSystemTimeAsFileTime_Hook(out long lpFileTime)
|
||||
{
|
||||
var epoch = new DateTime(1601, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
lpFileTime = (GetFakeUtc() - epoch).Ticks;
|
||||
}
|
||||
|
||||
void GetSystemTimePreciseAsFileTime_Hook(out long lpFileTime)
|
||||
private void GetSystemTimePreciseAsFileTime_Hook(out long lpFileTime)
|
||||
{
|
||||
var epoch = new DateTime(1601, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
lpFileTime = (GetFakeUtc() - epoch).Ticks;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net48</TargetFramework>
|
||||
<Platforms>x64</Platforms>
|
||||
<AssemblyName>TimeMocker.Hook</AssemblyName>
|
||||
<RootNamespace>TimeMocker.Hook</RootNamespace>
|
||||
<OutputType>Library</OutputType>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="EasyHook" Version="2.7.7097.0" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net48</TargetFramework>
|
||||
<Platforms>x64</Platforms>
|
||||
<AssemblyName>TimeMocker.Hook</AssemblyName>
|
||||
<RootNamespace>TimeMocker.Hook</RootNamespace>
|
||||
<OutputType>Library</OutputType>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="EasyHook" Version="2.7.7097.0"/>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in new issue
Block a user