Skip to content

Commit

Permalink
fix warnings in injector
Browse files Browse the repository at this point in the history
  • Loading branch information
goaaats committed Jun 9, 2023
1 parent 166301f commit aa2cd47
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 25 deletions.
1 change: 1 addition & 0 deletions Dalamud.CorePlugin/PluginImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public void Dispose()
/// Initializes a new instance of the <see cref="PluginImpl"/> class.
/// </summary>
/// <param name="pluginInterface">Dalamud plugin interface.</param>
/// <param name="log">Logging service.</param>
public PluginImpl(DalamudPluginInterface pluginInterface, PluginLog log)
{
try
Expand Down
36 changes: 22 additions & 14 deletions Dalamud.Injector/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -739,10 +739,12 @@ private static int ProcessLaunchCommand(List<string> args, DalamudStartInfo dala
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
[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;
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);
rawTickCount = (uint)rawTickCountFixed;
}
Expand All @@ -764,21 +766,27 @@ private static int ProcessLaunchCommand(List<string> args, DalamudStartInfo dala
gameArgumentString = string.Join(" ", gameArguments.Select(x => EncodeParameterArgument(x)));
}

var process = GameStart.LaunchGame(Path.GetDirectoryName(gamePath), gamePath, gameArgumentString, noFixAcl, (Process p) =>
{
if (!withoutDalamud && mode == "entrypoint")
var process = GameStart.LaunchGame(
Path.GetDirectoryName(gamePath),
gamePath,
gameArgumentString,
noFixAcl,
p =>
{
var startInfo = AdjustStartInfo(dalamudStartInfo, gamePath);
Log.Information("Using start info: {0}", JsonConvert.SerializeObject(startInfo));
if (RewriteRemoteEntryPointW(p.Handle, gamePath, JsonConvert.SerializeObject(startInfo)) != 0)
if (!withoutDalamud && mode == "entrypoint")
{
Log.Error("[HOOKS] RewriteRemoteEntryPointW failed");
throw new Exception("RewriteRemoteEntryPointW failed");
var startInfo = AdjustStartInfo(dalamudStartInfo, gamePath);
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);

Expand Down
20 changes: 11 additions & 9 deletions Dalamud.Injector/GameStart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ public static void CopyAclFromSelfToTargetProcess(IntPtr hProcess)
}
}

/// <summary>
/// Claim a SE Debug Privilege.
/// </summary>
public static void ClaimSeDebug()
{
var hToken = PInvoke.INVALID_HANDLE_VALUE;
Expand Down Expand Up @@ -345,8 +348,6 @@ public GameStartException(string? message = null)
private static class PInvoke
{
#region Constants
public static readonly IntPtr INVALID_HANDLE_VALUE = new(-1);

public const string SE_DEBUG_NAME = "SeDebugPrivilege";

public const UInt32 STANDARD_RIGHTS_ALL = 0x001F0000;
Expand All @@ -369,6 +370,8 @@ private static class PInvoke

public const UInt32 ERROR_NO_TOKEN = 0x000003F0;

public static readonly IntPtr INVALID_HANDLE_VALUE = new(-1);

public enum MULTIPLE_TRUSTEE_OPERATION
{
NO_MULTIPLE_TRUSTEE,
Expand Down Expand Up @@ -431,7 +434,7 @@ public enum SECURITY_IMPERSONATION_LEVEL
SecurityAnonymous,
SecurityIdentification,
SecurityImpersonation,
SecurityDelegation
SecurityDelegation,
}
#endregion

Expand Down Expand Up @@ -485,8 +488,7 @@ public static extern bool CreateProcess(

[DllImport("advapi32.dll", SetLastError = true)]
public static extern bool ImpersonateSelf(
SECURITY_IMPERSONATION_LEVEL impersonationLevel
);
SECURITY_IMPERSONATION_LEVEL impersonationLevel);

[DllImport("advapi32.dll", SetLastError = true)]
public static extern bool OpenProcessToken(
Expand All @@ -496,10 +498,10 @@ public static extern bool OpenProcessToken(

[DllImport("advapi32.dll", SetLastError = true)]
public static extern bool OpenThreadToken(
IntPtr ThreadHandle,
uint DesiredAccess,
bool OpenAsSelf,
out IntPtr TokenHandle);
IntPtr threadHandle,
uint desiredAccess,
bool openAsSelf,
out IntPtr tokenHandle);

[DllImport("advapi32.dll", SetLastError = true)]
public static extern bool LookupPrivilegeValue(string lpSystemName, string lpName, ref LUID lpLuid);
Expand Down
13 changes: 11 additions & 2 deletions Dalamud.Injector/LegacyBlowfish.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

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
{
#region P-Array and S-Boxes
Expand Down Expand Up @@ -203,10 +211,9 @@ internal class LegacyBlowfish
private static readonly int Rounds = 16;

/// <summary>
/// Initialize a new blowfish.
/// Initializes a new instance of the <see cref="LegacyBlowfish"/> class.
/// </summary>
/// <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)
{
foreach (var (i, keyFragment) in WrappingUInt32(key, this.p.Length))
Expand Down Expand Up @@ -306,7 +313,9 @@ private static IEnumerable<TSource> Cycle<TSource>(IEnumerable<TSource> source)

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.
#pragma warning restore CS0675
}

yield return (i, n);
Expand Down

0 comments on commit aa2cd47

Please sign in to comment.