Skip to content

Commit

Permalink
add translation checks for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
laolarou726 committed Oct 11, 2023
1 parent a9fc2e2 commit c712cbb
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
using System.Threading.Tasks.Dataflow;
using ProjBobcat.Class.Helper;
using ProjBobcat.Class.Model;
using ProjBobcat.DefaultComponent.ResourceInfoResolver;
using ProjBobcat.Event;
using ProjBobcat.Interface;

namespace ProjBobcat.DefaultComponent;
#nullable enable

/// <summary>
/// 默认的资源补全器
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion ProjBobcat/ProjBobcat/NativeMethods.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
SetWindowText
SetWindowText
IsWow64Process2
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Windows.Win32;
using Windows.Win32.Foundation;
using Windows.Win32.System.SystemInformation;
using Microsoft.Win32;
using ProjBobcat.Class.Model;

Expand Down Expand Up @@ -229,4 +232,38 @@ public static IEnumerable<string> GetLogicalDrives()
{
return Environment.GetLogicalDrives();
}

public static bool IsWindows7()
{
var os = Environment.OSVersion;

return os is { Platform: PlatformID.Win32NT, Version: { Major: 6, Minor: 1 } };
}

/// <summary>
/// 检查某个进程是否运行在 X86 模拟下
/// </summary>
/// <param name="proc"></param>
/// <returns>待检查的进程,如果不传则检测当前进程</returns>
public static unsafe bool IsRunningUnderTranslation(Process? proc = null)
{
if (IsWindows7()) return false;

proc ??= Process.GetCurrentProcess();

var handle = proc.Handle;

IMAGE_FILE_MACHINE processMachine;
IMAGE_FILE_MACHINE nativeMachine;

var result = PInvoke.IsWow64Process2(
new HANDLE(handle),
&processMachine,
&nativeMachine);

if (!result) return false;
if (processMachine == IMAGE_FILE_MACHINE.IMAGE_FILE_MACHINE_UNKNOWN) return false;

return processMachine != nativeMachine;
}
}
6 changes: 3 additions & 3 deletions ProjBobcat/ProjBobcat/ProjBobcat.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ resolved the issue that LaunchWrapper may not return the correct exit code
<!-- Dependencies -->
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.18-beta">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="SharpCompress">
<Version>0.34.1</Version>
</PackageReference>
Expand All @@ -106,6 +103,9 @@ resolved the issue that LaunchWrapper may not return the correct exit code
<PackageReference Include="System.Management" Version="7.0.2" />
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="7.0.0" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.18-beta">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<!-- Dependencies -->

Expand Down

0 comments on commit c712cbb

Please sign in to comment.