// Decompiled with JetBrains decompiler
// Type: Office_2010_Toolkit.Logic.Activation
// Assembly: AutoKMS, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: D1CED9E3-1FC7-49B8-B3AC-44976AB7F6E4
// Assembly location: C:\Users\Administrateur\Downloads\Virusshare-00000-msil\HackTool.Win32.KMSAuto.i-f317ba4d4051fad64a0aa45b587fa3dcea795bac30acec2872779abe31a07cbe.exe

using AutoKMS.Properties;
using HybridService;
using System;
using System.Diagnostics;
using System.Management;
using System.Threading;
using TaskScheduler;

namespace Office_2010_Toolkit.Logic
{
  internal class Activation
  {
    public static string Account = "";
    public static string Password = (string) null;
    public static bool AKInstallFailure = false;
    public static bool ARInstallFailure = false;
    public static bool AKUnInstallFailure = false;
    public static bool ARUnInstallFailure = false;
    public static int LicensedProducts = 0;
    public static int UnLicensedProducts = 0;
    public static string AutoKMSInstallPath = string.Empty;
    public static string AutoRearmInstallPath = string.Empty;
    public static string KMSEmulatorInstallPath = string.Empty;

    public static string CheckActivation(bool AppCall)
    {
      string str1 = string.Empty;
      string empty = string.Empty;
      try
      {
        Activation.LicensedProducts = 0;
        Activation.UnLicensedProducts = 0;
        foreach (ManagementObject managementObject in new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM OfficeSoftwareProtectionProduct").Get())
        {
          int int32 = Convert.ToInt32(managementObject["LicenseStatus"]);
          long int64 = Convert.ToInt64(managementObject["LicenseStatusReason"]);
          double num1 = Convert.ToDouble(managementObject["GracePeriodRemaining"]);
          string str2 = int64 != 0L ? "0x" + int64.ToString("X8") : "0 as licensed";
          if (int32 != 0)
          {
            ++Activation.LicensedProducts;
            string str3 = int32 != 1 ? (int32 != 2 ? (int32 != 3 ? (int32 != 4 ? (int32 != 5 ? (int32 != 6 ? "Unknown" : "Extended Grace Period") : "Notifications Mode") : "Non-Genuine Grace Period") : "Out-of-Tolerance Grace Period") : "Grace Period") : "Activated";
            double num2 = Math.Round(num1 / 1440.0);
            str1 = str1 + "---------------------------------------" + Environment.NewLine;
            str1 = str1 + "SKU ID: " + managementObject["ID"] + Environment.NewLine;
            string str4 = managementObject["OfflineInstallationId"].ToString();
            string str5 = str4.Substring(0, 6) + "-" + str4.Substring(6, 6) + "-" + str4.Substring(12, 6) + "-" + str4.Substring(18, 6) + "-" + str4.Substring(24, 6) + "-" + str4.Substring(30, 6) + "-" + str4.Substring(36, 6) + "-" + str4.Substring(42, 6) + "-" + str4.Substring(48, 6);
            str1 = str1 + "OID: " + str5 + Environment.NewLine;
            str1 = str1 + "LICENSE NAME: Office 14, " + managementObject["LicenseFamily"] + Environment.NewLine;
            str1 = str1 + "LICENSE DESCRIPTION: " + managementObject["Description"] + Environment.NewLine;
            str1 = str1 + "LICENSE STATUS: " + str3 + Environment.NewLine;
            str1 = str1 + "ERROR CODE: " + str2 + Environment.NewLine;
            str1 = str1 + "Last 5 characters of installed product key: " + managementObject["PartialProductKey"] + Environment.NewLine;
            if (str3 == "Activated" || str3 == "Grace Period" && num1 != 0.0)
              str1 = str1 + "REMAINING GRACE: " + (object) num2 + " days  (" + (object) num1 + " minute(s) before expiring)" + Environment.NewLine;
          }
          else
            ++Activation.UnLicensedProducts;
        }
      }
      catch (Exception ex)
      {
        return "<No installed product keys installed or possible license error>";
      }
      if (Activation.LicensedProducts == 0 && Activation.UnLicensedProducts > 0)
        return "<No installed product keys detected>";
      return Activation.LicensedProducts == 0 && Activation.UnLicensedProducts == 0 ? "<No installed product keys installed or possible license error>" : str1 + "---------------------------------------";
    }

    public static void RemoveKMSHost()
    {
      try
      {
        new ManagementObject("root\\CIMV2", "OfficeSoftwareProtectionService.Version='" + Common.OSPPSVCVersion + "'", (ObjectGetOptions) null).InvokeMethod("ClearKeyManagementServiceMachine", (ManagementBaseObject) null, (InvokeMethodOptions) null);
      }
      catch (Exception ex)
      {
        throw new Exception();
      }
    }

    public static void RemoveKMSHostWindows()
    {
      string empty = string.Empty;
      try
      {
        foreach (ManagementBaseObject managementBaseObject in new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM SoftwareLicensingService").Get())
          empty = Convert.ToString(managementBaseObject["Version"]);
        new ManagementObject("root\\CIMV2", "SoftwareLicensingService.Version='" + empty + "'", (ObjectGetOptions) null).InvokeMethod("ClearKeyManagementServiceMachine", (ManagementBaseObject) null, (InvokeMethodOptions) null);
      }
      catch (Exception ex)
      {
        throw new Exception();
      }
    }

    public static void SetKMSHost()
    {
      try
      {
        ManagementObject managementObject = new ManagementObject("root\\CIMV2", "OfficeSoftwareProtectionService.Version='" + Common.OSPPSVCVersion + "'", (ObjectGetOptions) null);
        ManagementBaseObject methodParameters = managementObject.GetMethodParameters("SetKeyManagementServiceMachine");
        methodParameters["MachineName"] = (object) Office_2010_Toolkit.Configuration.Settings.AutoKMSSettings.KMSServer;
        managementObject.InvokeMethod("SetKeyManagementServiceMachine", methodParameters, (InvokeMethodOptions) null);
      }
      catch (Exception ex)
      {
        throw new Exception();
      }
    }

    public static void SetKMSHostWindows()
    {
      string empty = string.Empty;
      try
      {
        foreach (ManagementBaseObject managementBaseObject in new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM SoftwareLicensingService").Get())
          empty = Convert.ToString(managementBaseObject["Version"]);
        ManagementObject managementObject = new ManagementObject("root\\CIMV2", "SoftwareLicensingService.Version='" + empty + "'", (ObjectGetOptions) null);
        ManagementBaseObject methodParameters = managementObject.GetMethodParameters("SetKeyManagementServiceMachine");
        methodParameters["MachineName"] = (object) Office_2010_Toolkit.Configuration.Settings.AutoKMSSettings.KMSServer;
        managementObject.InvokeMethod("SetKeyManagementServiceMachine", methodParameters, (InvokeMethodOptions) null);
      }
      catch (Exception ex)
      {
        throw new Exception();
      }
    }

    public static void StartKMSEmulator()
    {
      try
      {
        try
        {
          Activation.KMSEmulatorInstallPath = Office_2010_Toolkit.Configuration.Settings.PathsSettings.KMSEmulator;
          Common.FileCreate("KMSEmulator.exe", Resources.Keygen, Activation.KMSEmulatorInstallPath);
          new Process()
          {
            StartInfo = {
              FileName = (Activation.KMSEmulatorInstallPath + "\\KMSEmulator.exe"),
              CreateNoWindow = true,
              WindowStyle = ProcessWindowStyle.Hidden
            }
          }.Start();
        }
        catch (Exception ex)
        {
          Activation.KMSEmulatorInstallPath = Common.WINDIR;
          Console.WriteLine("Could not access KMSEmulator path set in Settings, using default installation path.");
          Common.FileCreate("KMSEmulator.exe", Resources.Keygen, Activation.KMSEmulatorInstallPath);
          new Process()
          {
            StartInfo = {
              FileName = (Activation.KMSEmulatorInstallPath + "\\KMSEmulator.exe"),
              CreateNoWindow = true,
              WindowStyle = ProcessWindowStyle.Hidden
            }
          }.Start();
        }
      }
      catch (Exception ex)
      {
        throw;
      }
      Thread.Sleep(5000);
    }

    public static void StopKMSEmulator()
    {
      foreach (Process process in Process.GetProcessesByName("KMSEmulator"))
        Common.KillProcess(process);
      if (!Office_2010_Toolkit.Configuration.Settings.AutoKMSSettings.AutoRemoveKMSEmulator)
        return;
      try
      {
        Common.FileDelete(Activation.KMSEmulatorInstallPath + "\\KMSEmulator.exe");
      }
      catch (Exception ex)
      {
        throw;
      }
    }

    public static void MakeAutoKMSService(string AutoKMSInstallPath)
    {
      try
      {
        ServiceInstaller.InstallService(AutoKMSInstallPath + "\\AutoKMS.exe", "AutoKMS", "AutoKMS", true, false);
      }
      catch (Exception ex)
      {
        throw new Exception();
      }
    }

    public static void MakeAutoKMSNormalTask(string AutoKMSInstallPath)
    {
      ScheduledTasks scheduledTasks = new ScheduledTasks();
      Task task = scheduledTasks.CreateTask("AutoKMS");
      task.ApplicationName = AutoKMSInstallPath + "\\AutoKMS.exe";
      task.Parameters = "/Application";
      task.SetAccountInformation(Activation.Account, Activation.Password);
      task.Priority = ProcessPriorityClass.Normal;
      Trigger trigger = (Trigger) new DailyTrigger(Convert.ToInt16(DateTime.Now.Hour), Convert.ToInt16(DateTime.Now.Minute));
      task.Triggers.Add(trigger);
      task.Triggers.Add((Trigger) new OnSystemStartTrigger());
      task.Save();
      task.Close();
      scheduledTasks.Dispose();
    }

    public static void DeleteAutoKMSNormalTask()
    {
      ScheduledTasks scheduledTasks = new ScheduledTasks();
      try
      {
        scheduledTasks.DeleteTask("AutoKMS");
        scheduledTasks.DeleteTask("AutoKMSDaily");
      }
      catch
      {
      }
    }
  }
}
