// Decompiled with JetBrains decompiler
// Type: A.c
// Assembly: RansomGuard, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 37652FF6-4FF5-4E76-944D-E6CA5073036F
// Assembly location: RansomGuard.dll inside C:\Users\WDAGUtilityAccount\Desktop\RansomGuard.exe)

using \u003CPrivateImplementationDetails\u003E\u007B29195D03\u002D3E0A\u002D468D\u002DA5D2\u002D1BA9D027086D\u007D;
using RansomGuard;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using System.Threading.Tasks;

#nullable enable
namespace A;

public static class c
{
  private const int aP = 10000;
  private const int ap = 5000;
  private static readonly ConcurrentDictionary<string, string> aQ = new ConcurrentDictionary<string, string>((IEqualityComparer<string>) StringComparer.OrdinalIgnoreCase);
  private static readonly ConcurrentQueue<string> aq = new ConcurrentQueue<string>();
  private static readonly object aR = new object();
  private static readonly ConcurrentDictionary<string, (SignerStatus Status, string? Signer, string? Issuer, DateTime? ValidFrom, DateTime? ValidTo, string? TrustReason)> ar = new ConcurrentDictionary<string, (SignerStatus, string, string, DateTime?, DateTime?, string)>((IEqualityComparer<string>) StringComparer.OrdinalIgnoreCase);
  private static readonly ConcurrentQueue<string> aS = new ConcurrentQueue<string>();
  private static readonly object @as = new object();

  public static async Task A([In] f obj0, F? identity, CancellationToken _param2 = default (CancellationToken))
  {
    string str1;
    if (identity != null)
    {
      obj0.fc = identity.B() ?? obj0.fc;
      obj0.fC = identity.a() ?? obj0.fC;
      f f = obj0;
      if (f.c() == null)
        f.C(str1 = identity.C());
      obj0.A(identity.c());
      obj0.c(identity.D());
      obj0.d(identity.d());
      obj0.D(identity.E());
    }
    string fc = obj0.fc;
    int num1 = string.IsNullOrWhiteSpace(fc) ? 0 : (!fc.Equals(F5D1BF18\u002D5FBA\u002D43C1\u002DA4E0\u002D6D909C027158.DO(), (StringComparison) 5) ? 1 : 0);
    if (num1 != 0)
    {
      f f = obj0;
      if (f.b() == null)
        f.B(str1 = F5D1BF18\u002D5FBA\u002D43C1\u002DA4E0\u002D6D909C027158.gw());
    }
    else
    {
      obj0.B(F5D1BF18\u002D5FBA\u002D43C1\u002DA4E0\u002D6D909C027158.gG());
      obj0.fc = F5D1BF18\u002D5FBA\u002D43C1\u002DA4E0\u002D6D909C027158.DO();
    }
    if (!string.IsNullOrWhiteSpace(obj0.fc) && obj0.fc.Contains('\\'))
      obj0.fC = Path.GetFileNameWithoutExtension(obj0.fc);
    else if (string.IsNullOrWhiteSpace(obj0.fC))
      obj0.fC = F5D1BF18\u002D5FBA\u002D43C1\u002DA4E0\u002D6D909C027158.DO();
    if (num1 != 0 && string.IsNullOrWhiteSpace(obj0.c()))
    {
      try
      {
        f f = obj0;
        f.C(await c.A(obj0.fc));
        f = (f) null;
      }
      catch (Exception ex) when (
      {
        // ISSUE: unable to correctly present filter
        bool flag;
        switch (ex)
        {
          case IOException _:
          case UnauthorizedAccessException _:
            flag = true;
            break;
          default:
            flag = false;
            break;
        }
        if (flag)
        {
          SuccessfulFiltering;
        }
        else
          throw;
      }
      )
      {
        f f = obj0;
        if (f.E() == null)
          f.D(str1 = F5D1BF18\u002D5FBA\u002D43C1\u002DA4E0\u002D6D909C027158.gX() + ex.Message);
      }
    }
    if (obj0.D() == SignerStatus.Unavailable || string.IsNullOrWhiteSpace(obj0.d()))
      c.a(obj0);
    f f1 = obj0;
    int num2 = obj0.M();
    string str2 = num2 < 40 ? (num2 >= 20 ? F5D1BF18\u002D5FBA\u002D43C1\u002DA4E0\u002D6D909C027158.gy() : F5D1BF18\u002D5FBA\u002D43C1\u002DA4E0\u002D6D909C027158.gZ()) : (num2 >= 80 /*0x50*/ ? F5D1BF18\u002D5FBA\u002D43C1\u002DA4E0\u002D6D909C027158.gx() : (num2 >= 60 ? F5D1BF18\u002D5FBA\u002D43C1\u002DA4E0\u002D6D909C027158.gt() : F5D1BF18\u002D5FBA\u002D43C1\u002DA4E0\u002D6D909C027158.gY()));
    f1.ff = str2;
  }

  public static Task A([In] f obj0) => c.A(obj0, (F) null, CancellationToken.None);

  public static Task a([In] f obj0, F? identity, CancellationToken _param2 = default (CancellationToken))
  {
    return c.A(obj0, identity, _param2);
  }

  private static async Task<string> A([In] string obj0)
  {
    int num;
    string str;
    if (num != 0 && c.aQ.TryGetValue(obj0, ref str) && str != null)
      return str;
    try
    {
      using (FileStream Ej = File.OpenRead(obj0))
      {
        using (SHA256 EK = SHA256.Create())
        {
          string upperInvariant = BitConverter.ToString(await EK.ComputeHashAsync((Stream) Ej)).Replace(F5D1BF18\u002D5FBA\u002D43C1\u002DA4E0\u002D6D909C027158.DP(), F5D1BF18\u002D5FBA\u002D43C1\u002DA4E0\u002D6D909C027158.Dp()).ToUpperInvariant();
          c.A(obj0, upperInvariant);
          return upperInvariant;
        }
      }
    }
    catch
    {
      c.A(obj0, F5D1BF18\u002D5FBA\u002D43C1\u002DA4E0\u002D6D909C027158.gW());
      return F5D1BF18\u002D5FBA\u002D43C1\u002DA4E0\u002D6D909C027158.gW();
    }
  }

  private static void A([In] string obj0, [In] string obj1)
  {
    if (c.aQ.ContainsKey(obj0))
      return;
    lock (c.aR)
    {
      if (c.aQ.ContainsKey(obj0))
        return;
      c.aQ[obj0] = obj1;
      c.aq.Enqueue(obj0);
      while (c.aq.Count > 10000)
      {
        string str1;
        if (c.aq.TryDequeue(ref str1))
        {
          string str2;
          c.aQ.TryRemove(str1, ref str2);
        }
      }
    }
  }

  internal static (SignerStatus Status, string? Signer, string? Issuer, DateTime? ValidFrom, DateTime? ValidTo, string? TrustReason) a(
    [In] string obj0)
  {
    if (string.IsNullOrWhiteSpace(obj0) || !File.Exists(obj0))
      return (SignerStatus.Unavailable, (string) null, (string) null, new DateTime?(), new DateTime?(), F5D1BF18\u002D5FBA\u002D43C1\u002DA4E0\u002D6D909C027158.cx());
    (SignerStatus, string, string, DateTime?, DateTime?, string) valueTuple1;
    if (c.ar.TryGetValue(obj0, ref valueTuple1))
      return valueTuple1;
    try
    {
      string str = k.A(obj0);
      if (str.Equals(F5D1BF18\u002D5FBA\u002D43C1\u002DA4E0\u002D6D909C027158.cY(), (StringComparison) 5))
      {
        X509Certificate2 x509Certificate2 = new X509Certificate2(obj0);
        (SignerStatus, string, string, DateTime?, DateTime?, string) valueTuple2 = (SignerStatus.Trusted, x509Certificate2.GetNameInfo(X509NameType.SimpleName, false), x509Certificate2.Issuer, new DateTime?(x509Certificate2.NotBefore), new DateTime?(x509Certificate2.NotAfter), (string) null);
        c.A(obj0, valueTuple2);
        return valueTuple2;
      }
      if (str.StartsWith(F5D1BF18\u002D5FBA\u002D43C1\u002DA4E0\u002D6D909C027158.cy(), (StringComparison) 5) || str.Contains(F5D1BF18\u002D5FBA\u002D43C1\u002DA4E0\u002D6D909C027158.cZ(), (StringComparison) 5))
      {
        X509Certificate2 x509Certificate2 = new X509Certificate2(obj0);
        (SignerStatus, string, string, DateTime?, DateTime?, string) valueTuple3 = (SignerStatus.UnknownPublisher, x509Certificate2.GetNameInfo(X509NameType.SimpleName, false), x509Certificate2.Issuer, new DateTime?(x509Certificate2.NotBefore), new DateTime?(x509Certificate2.NotAfter), F5D1BF18\u002D5FBA\u002D43C1\u002DA4E0\u002D6D909C027158.cz());
        c.A(obj0, valueTuple3);
        return valueTuple3;
      }
      if (B.A(obj0))
      {
        (SignerStatus, string, string, DateTime?, DateTime?, string) valueTuple4 = (SignerStatus.MicrosoftCatalog, (string) null, (string) null, new DateTime?(), new DateTime?(), F5D1BF18\u002D5FBA\u002D43C1\u002DA4E0\u002D6D909C027158.DA());
        c.A(obj0, valueTuple4);
        return valueTuple4;
      }
      if (str.Contains(F5D1BF18\u002D5FBA\u002D43C1\u002DA4E0\u002D6D909C027158.Da(), (StringComparison) 5) || str.Contains(F5D1BF18\u002D5FBA\u002D43C1\u002DA4E0\u002D6D909C027158.DB(), (StringComparison) 5) || str.Contains(F5D1BF18\u002D5FBA\u002D43C1\u002DA4E0\u002D6D909C027158.Db(), (StringComparison) 5))
      {
        (SignerStatus, string, string, DateTime?, DateTime?, string) valueTuple5 = (SignerStatus.Unsigned, (string) null, (string) null, new DateTime?(), new DateTime?(), F5D1BF18\u002D5FBA\u002D43C1\u002DA4E0\u002D6D909C027158.DC());
        c.A(obj0, valueTuple5);
        return valueTuple5;
      }
      if (str.Contains(F5D1BF18\u002D5FBA\u002D43C1\u002DA4E0\u002D6D909C027158.Dc(), (StringComparison) 5) || str.Contains(F5D1BF18\u002D5FBA\u002D43C1\u002DA4E0\u002D6D909C027158.DD(), (StringComparison) 5))
      {
        (SignerStatus, string, string, DateTime?, DateTime?, string) valueTuple6 = (SignerStatus.MalformedSignature, (string) null, (string) null, new DateTime?(), new DateTime?(), F5D1BF18\u002D5FBA\u002D43C1\u002DA4E0\u002D6D909C027158.Dd());
        c.A(obj0, valueTuple6);
        return valueTuple6;
      }
      (SignerStatus, string, string, DateTime?, DateTime?, string) valueTuple7 = (SignerStatus.Unverified, (string) null, (string) null, new DateTime?(), new DateTime?(), str);
      c.A(obj0, valueTuple7);
      return valueTuple7;
    }
    catch (Exception ex)
    {
      (SignerStatus, string, string, DateTime?, DateTime?, string) valueTuple8 = (SignerStatus.Unverified, (string) null, (string) null, new DateTime?(), new DateTime?(), ex.Message);
      c.A(obj0, valueTuple8);
      return valueTuple8;
    }
  }

  private static void A(
    [In] string obj0,
    (SignerStatus Status, string? Signer, string? Issuer, DateTime? ValidFrom, DateTime? ValidTo, string? TrustReason) value)
  {
    if (c.ar.ContainsKey(obj0))
      return;
    lock (c.@as)
    {
      if (c.ar.ContainsKey(obj0))
        return;
      c.ar[obj0] = value;
      c.aS.Enqueue(obj0);
      while (c.aS.Count > 5000)
      {
        string str;
        if (c.aS.TryDequeue(ref str))
        {
          (SignerStatus, string, string, DateTime?, DateTime?, string) valueTuple;
          c.ar.TryRemove(str, ref valueTuple);
        }
      }
    }
  }

  private static void a([In] f obj0)
  {
    if (string.IsNullOrWhiteSpace(obj0.fc) || !File.Exists(obj0.fc))
    {
      obj0.A(SignerStatus.Unavailable);
      obj0.D(F5D1BF18\u002D5FBA\u002D43C1\u002DA4E0\u002D6D909C027158.cx());
    }
    else
    {
      (SignerStatus Status, string Signer, string Issuer, DateTime? ValidFrom, DateTime? ValidTo, string TrustReason) tuple = c.a(obj0.fc);
      obj0.A(tuple.Status);
      obj0.c(tuple.Signer);
      obj0.d(tuple.Issuer);
      obj0.A(tuple.ValidFrom);
      obj0.a(tuple.ValidTo);
      obj0.D(tuple.TrustReason);
    }
  }
}
