mirror of
https://github.com/BeyondDimension/SteamTools.git
synced 2026-10-29 07:27:36 +08:00
完成 Steam 一键快速登录
This commit is contained in:
@@ -153,7 +153,7 @@ namespace System.Application.UI.Views.Windows
|
||||
static Task? mGetLoginUsingSteamClientCookiesAsync;
|
||||
static async Task GetLoginUsingSteamClientCookiesAsync()
|
||||
{
|
||||
var cookies = await Instance.GetLoginUsingSteamClientCookiesAsync(runasInvoker: DI.Platform == Platform.Windows);
|
||||
var cookies = await Instance.GetLoginUsingSteamClientCookieCollectionAsync(runasInvoker: DI.Platform == Platform.Windows);
|
||||
if (cookies != default)
|
||||
{
|
||||
var manager = CefRequestContext.GetGlobalContext().GetCookieManager(null);
|
||||
|
||||
@@ -5,9 +5,11 @@ using System.Application.Services;
|
||||
using System.Application.UI;
|
||||
using System.CommandLine;
|
||||
using System.CommandLine.Invocation;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Pipes;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using static System.Application.Program;
|
||||
using Process = System.Diagnostics.Process;
|
||||
|
||||
@@ -25,7 +27,11 @@ if (!args.Any())
|
||||
if (DI.Platform == Platform.Windows) mainFilePath += ".exe";
|
||||
if (File.Exists(mainFilePath))
|
||||
{
|
||||
Process.Start(mainFilePath);
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = mainFilePath,
|
||||
UseShellExecute = true,
|
||||
});
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -39,8 +45,10 @@ getstmauth.Handler = CommandHandler.Create(async (string key) =>
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(key))
|
||||
{
|
||||
var connStr = Serializable.DMPB64U<string>(key)!;
|
||||
var key2 = Serializable.DMPB64U<(string connStr, string rsaPK)>(key)!;
|
||||
var s = DISafeGet.GetLoginUsingSteamClientAuth();
|
||||
using var rsa = RSAUtils.CreateFromJsonString(key2.rsaPK);
|
||||
using var aes = AESUtils.Create();
|
||||
#if DEBUG
|
||||
if (DI.Platform == Platform.Windows)
|
||||
{
|
||||
@@ -48,9 +56,13 @@ getstmauth.Handler = CommandHandler.Create(async (string key) =>
|
||||
Console.WriteLine($"IsAdministrator: {dps.IsAdministrator}");
|
||||
}
|
||||
#endif
|
||||
var r = await s.GetLoginUsingSteamClientCookiesAsync(false);
|
||||
var r2 = Serializable.SMPB64U(r);
|
||||
File.WriteAllText(connStr, r2);
|
||||
var cookies = await s.GetLoginUsingSteamClientCookiesAsync();
|
||||
var cookiesBytes = Serializable.SMP(cookies);
|
||||
cookiesBytes = aes.Encrypt(cookiesBytes);
|
||||
var aesKey = aes.ToParamsByteArray();
|
||||
aesKey = rsa.Encrypt(aesKey);
|
||||
var fileBytes = Serializable.SMP((cookiesBytes, aesKey));
|
||||
File.WriteAllBytes(key2.connStr, fileBytes);
|
||||
}
|
||||
});
|
||||
rootCommand.AddCommand(getstmauth);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<RootNamespace>System.Application</RootNamespace>
|
||||
<AssemblyName>Steam++.Console</AssemblyName>
|
||||
@@ -58,21 +58,21 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ST.Client.Desktop.Avalonia\ST.Client.Desktop.Avalonia.csproj"/>
|
||||
<ProjectReference Include="..\ST.Client.Desktop\ST.Client.Desktop.csproj"/>
|
||||
<ProjectReference Include="..\Common.CoreLib\Common.CoreLib.csproj"/>
|
||||
<ProjectReference Include="..\ST.Client.Desktop.Avalonia\ST.Client.Desktop.Avalonia.csproj" />
|
||||
<ProjectReference Include="..\ST.Client.Desktop\ST.Client.Desktop.csproj" />
|
||||
<ProjectReference Include="..\Common.CoreLib\Common.CoreLib.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition=" $(RuntimeIdentifier.Contains(`win`)) Or ('$(OS)' == 'Windows_NT' And !$(DefineConstants.Contains(`PUBLISH`))) ">
|
||||
<ProjectReference Include="..\ST.Client.Desktop.Windows\ST.Client.Desktop.Windows.csproj"/>
|
||||
<ProjectReference Include="..\ST.Client.Desktop.Windows\ST.Client.Desktop.Windows.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition=" $(RuntimeIdentifier.Contains(`osx`)) Or ('$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true' And !$(DefineConstants.Contains(`PUBLISH`))) ">
|
||||
<ProjectReference Include="..\ST.Client.Desktop.Mac\ST.Client.Desktop.Mac.csproj"/>
|
||||
<ProjectReference Include="..\ST.Client.Desktop.Mac\ST.Client.Desktop.Mac.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition=" $(RuntimeIdentifier.Contains(`linux`)) Or ('$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true' And !$(DefineConstants.Contains(`PUBLISH`))) ">
|
||||
<ProjectReference Include="..\ST.Client.Desktop.Linux\ST.Client.Desktop.Linux.csproj"/>
|
||||
<ProjectReference Include="..\ST.Client.Desktop.Linux\ST.Client.Desktop.Linux.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition=" $(RuntimeIdentifier.Contains(`win`)) Or ('$(OS)' == 'Windows_NT' And !$(DefineConstants.Contains(`PUBLISH`))) ">
|
||||
|
||||
@@ -95,7 +95,7 @@ namespace System.Application.Services
|
||||
/// </summary>
|
||||
/// <param name="runasInvoker"></param>
|
||||
/// <returns></returns>
|
||||
Task<CookieCollection?> GetLoginUsingSteamClientCookiesAsync(bool runasInvoker = false);
|
||||
Task<CookieCollection?> GetLoginUsingSteamClientCookieCollectionAsync(bool runasInvoker = false);
|
||||
|
||||
/// <summary>
|
||||
/// 获取 Steam 客户端自动登录 Cookie(用于写入到 WebView3 中免登录)
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace System.Application.Services.Implementation
|
||||
/// <param name="checkMaxLength"></param>
|
||||
/// <returns></returns>
|
||||
bool TryOperation([NotNullWhen(false)] out string? message,
|
||||
out FileInfo fileInfo,
|
||||
[NotNullWhen(true)] out FileInfo? fileInfo,
|
||||
out bool removeReadOnly,
|
||||
bool checkReadOnly = false,
|
||||
bool checkMaxLength = true)
|
||||
@@ -133,7 +133,7 @@ namespace System.Application.Services.Implementation
|
||||
catch (Exception ex)
|
||||
{
|
||||
removeReadOnly = false;
|
||||
fileInfo = new FileInfo(s.HostsFilePath);
|
||||
fileInfo = null;
|
||||
message = ex.Message;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Application.Services.ISteamService;
|
||||
@@ -380,7 +381,7 @@ namespace System.Application.Services.Implementation
|
||||
//}
|
||||
}
|
||||
|
||||
public async Task<CookieCollection?> GetLoginUsingSteamClientCookiesAsync(bool runasInvoker = false)
|
||||
public async Task<CookieCollection?> GetLoginUsingSteamClientCookieCollectionAsync(bool runasInvoker = false)
|
||||
{
|
||||
var cookies = (string[]?)null;
|
||||
if (runasInvoker && DI.Platform == Platform.Windows)
|
||||
@@ -411,7 +412,9 @@ namespace System.Application.Services.Implementation
|
||||
};
|
||||
|
||||
var connStr = tempFilePath;
|
||||
connStr = Serializable.SMPB64U(connStr);
|
||||
using var rsa = RSA.Create(2048);
|
||||
var rsaPK = rsa.ToJsonString(false);
|
||||
var key = Serializable.SMPB64U((connStr, rsaPK));
|
||||
//pipeClient.StartInfo.Arguments = $"/trustlevel:0x20000 \"\"{consoleProgramPath}\" getstmauth -key \"{connStr}\"\"";
|
||||
//pipeClient.StartInfo.UseShellExecute = false;
|
||||
try
|
||||
@@ -421,16 +424,21 @@ namespace System.Application.Services.Implementation
|
||||
//pipeClient.WaitForExit();
|
||||
//pipeClient.Close();
|
||||
|
||||
platformService.UnelevatedProcessStart($"runas.exe /trustlevel:0x20000 \"\"{consoleProgramPath}\" getstmauth -key \"{connStr}\"\"");
|
||||
var command = $"runas.exe /trustlevel:0x20000 \"\"{consoleProgramPath}\" getstmauth -key \"{key}\"\"";
|
||||
platformService.UnelevatedProcessStart(command);
|
||||
|
||||
watcher.WaitForChanged(WatcherChangeTypes.Created, IPC_Call_GetLoginUsingSteamClient_Timeout_MS);
|
||||
if (File.Exists(tempFilePath))
|
||||
{
|
||||
var value = File.ReadAllText(tempFilePath);
|
||||
var value = File.ReadAllBytes(tempFilePath);
|
||||
File.Delete(tempFilePath);
|
||||
try
|
||||
{
|
||||
cookies = Serializable.DMPB64U<string[]>(value);
|
||||
var fileBytes = Serializable.DMP<(byte[] cookiesBytes, byte[] aesKey)>(value);
|
||||
var aesKey = rsa.Decrypt(fileBytes.aesKey);
|
||||
using var aes = AESUtils.Create(aesKey);
|
||||
var cookiesBytes = aes.Decrypt(fileBytes.cookiesBytes);
|
||||
cookies = Serializable.DMP<string[]>(cookiesBytes);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -463,8 +471,8 @@ namespace System.Application.Services.Implementation
|
||||
request.Headers.UserAgent.ParseAdd(http.PlatformHelper.UserAgent);
|
||||
var response = await client.SendAsync(request);
|
||||
#if DEBUG
|
||||
Console.WriteLine("GetLoginUsingSteamClientAuthAsync");
|
||||
Console.WriteLine($"StatusCode: {response.StatusCode}");
|
||||
//Console.WriteLine("GetLoginUsingSteamClientAuthAsync");
|
||||
//Console.WriteLine($"StatusCode: {response.StatusCode}");
|
||||
#endif
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
@@ -474,11 +482,20 @@ namespace System.Application.Services.Implementation
|
||||
var jsonObj = JObject.Load(json);
|
||||
var steamid = jsonObj["steamid"]!.ToString();
|
||||
#if DEBUG
|
||||
Console.WriteLine($"steamid: {steamid}");
|
||||
//Console.WriteLine($"steamid: {steamid}");
|
||||
#endif
|
||||
var encrypted_loginkey = jsonObj["encrypted_loginkey"]!.ToString();
|
||||
#if DEBUG
|
||||
//Console.WriteLine($"encrypted_loginkey: {encrypted_loginkey}");
|
||||
#endif
|
||||
var sessionkey = jsonObj["sessionkey"]!.ToString();
|
||||
#if DEBUG
|
||||
//Console.WriteLine($"sessionkey: {sessionkey}");
|
||||
#endif
|
||||
var digest = jsonObj["digest"]!.ToString();
|
||||
#if DEBUG
|
||||
//Console.WriteLine($"digest: {digest}");
|
||||
#endif
|
||||
return (steamid, encrypted_loginkey, sessionkey, digest);
|
||||
}
|
||||
}
|
||||
@@ -495,20 +512,30 @@ namespace System.Application.Services.Implementation
|
||||
{
|
||||
#pragma warning disable CS8620 // 由于引用类型的可为 null 性差异,实参不能用于形参。
|
||||
Content = new FormUrlEncodedContent(new Dictionary<string, string?>
|
||||
{
|
||||
{ "steamid", auth_data.steamid },
|
||||
{ "encrypted_loginkey", auth_data.encrypted_loginkey },
|
||||
{ "sessionkey", auth_data.sessionkey },
|
||||
{ "digest", auth_data.digest },
|
||||
}),
|
||||
{
|
||||
{ "steamid", auth_data.steamid },
|
||||
{ "sessionkey", auth_data.sessionkey },
|
||||
{ "encrypted_loginkey", auth_data.encrypted_loginkey },
|
||||
{ "digest", auth_data.digest },
|
||||
}),
|
||||
#pragma warning restore CS8620 // 由于引用类型的可为 null 性差异,实参不能用于形参。
|
||||
};
|
||||
request.Headers.Add("Accept", MediaTypeNames.JSON);
|
||||
request.Headers.UserAgent.ParseAdd(http.PlatformHelper.UserAgent);
|
||||
var client = http.Factory.CreateClient();
|
||||
client.Timeout = TimeSpan.FromSeconds(9.75);
|
||||
var response = await client.SendAsync(request/*, HttpCompletionOption.ResponseHeadersRead*/);
|
||||
if (response.IsSuccessStatusCode && response.Headers.TryGetValues("Set-Cookie", out var cookies))
|
||||
{
|
||||
return cookies.ToArray();
|
||||
var r = cookies.ToArray();
|
||||
#if DEBUG
|
||||
//foreach (var item in r)
|
||||
//{
|
||||
// Console.WriteLine($"Set-Cookie: {item}");
|
||||
//}
|
||||
//Console.WriteLine("OK");
|
||||
#endif
|
||||
return r;
|
||||
}
|
||||
|
||||
return default;
|
||||
|
||||
Reference in New Issue
Block a user