fix warnings in injector

This commit is contained in:
goat 2023-06-09 23:37:42 +02:00
parent 166301f56f
commit aa2cd47ef3
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
4 changed files with 45 additions and 25 deletions

View file

@ -54,6 +54,7 @@ namespace Dalamud.CorePlugin
/// Initializes a new instance of the <see cref="PluginImpl"/> class. /// Initializes a new instance of the <see cref="PluginImpl"/> class.
/// </summary> /// </summary>
/// <param name="pluginInterface">Dalamud plugin interface.</param> /// <param name="pluginInterface">Dalamud plugin interface.</param>
/// <param name="log">Logging service.</param>
public PluginImpl(DalamudPluginInterface pluginInterface, PluginLog log) public PluginImpl(DalamudPluginInterface pluginInterface, PluginLog log)
{ {
try try

View file

@ -739,10 +739,12 @@ namespace Dalamud.Injector
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{ {
[System.Runtime.InteropServices.DllImport("c")] [System.Runtime.InteropServices.DllImport("c")]
static extern ulong clock_gettime_nsec_np(int clock_id); #pragma warning disable SA1300
static extern ulong clock_gettime_nsec_np(int clockId);
#pragma warning restore SA1300
const int CLOCK_MONOTONIC_RAW = 4; const int CLOCK_MONOTONIC_RAW = 4;
var rawTickCountFixed = (clock_gettime_nsec_np(CLOCK_MONOTONIC_RAW) / 1000000); var rawTickCountFixed = clock_gettime_nsec_np(CLOCK_MONOTONIC_RAW) / 1000000;
Log.Information("ArgumentBuilder::DeriveKey() fixing up rawTickCount from {0} to {1} on macOS", rawTickCount, rawTickCountFixed); Log.Information("ArgumentBuilder::DeriveKey() fixing up rawTickCount from {0} to {1} on macOS", rawTickCount, rawTickCountFixed);
rawTickCount = (uint)rawTickCountFixed; rawTickCount = (uint)rawTickCountFixed;
} }
@ -764,21 +766,27 @@ namespace Dalamud.Injector
gameArgumentString = string.Join(" ", gameArguments.Select(x => EncodeParameterArgument(x))); gameArgumentString = string.Join(" ", gameArguments.Select(x => EncodeParameterArgument(x)));
} }
var process = GameStart.LaunchGame(Path.GetDirectoryName(gamePath), gamePath, gameArgumentString, noFixAcl, (Process p) => var process = GameStart.LaunchGame(
{ Path.GetDirectoryName(gamePath),
if (!withoutDalamud && mode == "entrypoint") gamePath,
gameArgumentString,
noFixAcl,
p =>
{ {
var startInfo = AdjustStartInfo(dalamudStartInfo, gamePath); if (!withoutDalamud && mode == "entrypoint")
Log.Information("Using start info: {0}", JsonConvert.SerializeObject(startInfo));
if (RewriteRemoteEntryPointW(p.Handle, gamePath, JsonConvert.SerializeObject(startInfo)) != 0)
{ {
Log.Error("[HOOKS] RewriteRemoteEntryPointW failed"); var startInfo = AdjustStartInfo(dalamudStartInfo, gamePath);
throw new Exception("RewriteRemoteEntryPointW failed"); Log.Information("Using start info: {0}", JsonConvert.SerializeObject(startInfo));
} if (RewriteRemoteEntryPointW(p.Handle, gamePath, JsonConvert.SerializeObject(startInfo)) != 0)
{
Log.Error("[HOOKS] RewriteRemoteEntryPointW failed");
throw new Exception("RewriteRemoteEntryPointW failed");
}
Log.Verbose("RewriteRemoteEntryPointW called!"); Log.Verbose("RewriteRemoteEntryPointW called!");
} }
}, waitForGameWindow); },
waitForGameWindow);
Log.Verbose("Game process started with PID {0}", process.Id); Log.Verbose("Game process started with PID {0}", process.Id);

View file

@ -211,6 +211,9 @@ namespace Dalamud.Injector
} }
} }
/// <summary>
/// Claim a SE Debug Privilege.
/// </summary>
public static void ClaimSeDebug() public static void ClaimSeDebug()
{ {
var hToken = PInvoke.INVALID_HANDLE_VALUE; var hToken = PInvoke.INVALID_HANDLE_VALUE;
@ -345,8 +348,6 @@ namespace Dalamud.Injector
private static class PInvoke private static class PInvoke
{ {
#region Constants #region Constants
public static readonly IntPtr INVALID_HANDLE_VALUE = new(-1);
public const string SE_DEBUG_NAME = "SeDebugPrivilege"; public const string SE_DEBUG_NAME = "SeDebugPrivilege";
public const UInt32 STANDARD_RIGHTS_ALL = 0x001F0000; public const UInt32 STANDARD_RIGHTS_ALL = 0x001F0000;
@ -369,6 +370,8 @@ namespace Dalamud.Injector
public const UInt32 ERROR_NO_TOKEN = 0x000003F0; public const UInt32 ERROR_NO_TOKEN = 0x000003F0;
public static readonly IntPtr INVALID_HANDLE_VALUE = new(-1);
public enum MULTIPLE_TRUSTEE_OPERATION public enum MULTIPLE_TRUSTEE_OPERATION
{ {
NO_MULTIPLE_TRUSTEE, NO_MULTIPLE_TRUSTEE,
@ -431,7 +434,7 @@ namespace Dalamud.Injector
SecurityAnonymous, SecurityAnonymous,
SecurityIdentification, SecurityIdentification,
SecurityImpersonation, SecurityImpersonation,
SecurityDelegation SecurityDelegation,
} }
#endregion #endregion
@ -485,8 +488,7 @@ namespace Dalamud.Injector
[DllImport("advapi32.dll", SetLastError = true)] [DllImport("advapi32.dll", SetLastError = true)]
public static extern bool ImpersonateSelf( public static extern bool ImpersonateSelf(
SECURITY_IMPERSONATION_LEVEL impersonationLevel SECURITY_IMPERSONATION_LEVEL impersonationLevel);
);
[DllImport("advapi32.dll", SetLastError = true)] [DllImport("advapi32.dll", SetLastError = true)]
public static extern bool OpenProcessToken( public static extern bool OpenProcessToken(
@ -496,10 +498,10 @@ namespace Dalamud.Injector
[DllImport("advapi32.dll", SetLastError = true)] [DllImport("advapi32.dll", SetLastError = true)]
public static extern bool OpenThreadToken( public static extern bool OpenThreadToken(
IntPtr ThreadHandle, IntPtr threadHandle,
uint DesiredAccess, uint desiredAccess,
bool OpenAsSelf, bool openAsSelf,
out IntPtr TokenHandle); out IntPtr tokenHandle);
[DllImport("advapi32.dll", SetLastError = true)] [DllImport("advapi32.dll", SetLastError = true)]
public static extern bool LookupPrivilegeValue(string lpSystemName, string lpName, ref LUID lpLuid); public static extern bool LookupPrivilegeValue(string lpSystemName, string lpName, ref LUID lpLuid);

View file

@ -1,8 +1,16 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
namespace Dalamud.Injector namespace Dalamud.Injector
{ {
[SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1124:Do not use regions", Justification = "Legacy code")]
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1413:Use trailing comma in multi-line initializers", Justification = "Legacy code")]
[SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1519:Braces should not be omitted from multi-line child statement", Justification = "Legacy code")]
[SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1414:Tuple types in signatures should have element names", Justification = "Legacy code")]
[SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1101:Prefix local calls with this", Justification = "Legacy code")]
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:Elements should be documented", Justification = "Legacy code")]
[SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1204:Static elements should appear before instance elements", Justification = "Legacy code")]
internal class LegacyBlowfish internal class LegacyBlowfish
{ {
#region P-Array and S-Boxes #region P-Array and S-Boxes
@ -203,10 +211,9 @@ namespace Dalamud.Injector
private static readonly int Rounds = 16; private static readonly int Rounds = 16;
/// <summary> /// <summary>
/// Initialize a new blowfish. /// Initializes a new instance of the <see cref="LegacyBlowfish"/> class.
/// </summary> /// </summary>
/// <param name="key">The key to use.</param> /// <param name="key">The key to use.</param>
/// <param name="fucked">Whether or not a sign confusion should be introduced during key init. This is needed for SE's implementation of blowfish.</param>
public LegacyBlowfish(byte[] key) public LegacyBlowfish(byte[] key)
{ {
foreach (var (i, keyFragment) in WrappingUInt32(key, this.p.Length)) foreach (var (i, keyFragment) in WrappingUInt32(key, this.p.Length))
@ -306,7 +313,9 @@ namespace Dalamud.Injector
for (var j = 0; j < 4 && enumerator.MoveNext(); j++) for (var j = 0; j < 4 && enumerator.MoveNext(); j++)
{ {
#pragma warning disable CS0675
n = (uint)((n << 8) | (sbyte)enumerator.Current); // NOTE(goat): THIS IS A BUG! SE's implementation wrongly uses signed numbers for this, so we need to as well. n = (uint)((n << 8) | (sbyte)enumerator.Current); // NOTE(goat): THIS IS A BUG! SE's implementation wrongly uses signed numbers for this, so we need to as well.
#pragma warning restore CS0675
} }
yield return (i, n); yield return (i, n);