AllenExplorer v6.8 離線註冊分析

DirWangK發表於2024-12-07

AllenExplorer v6.8 離線註冊分析

目錄
  • AllenExplorer v6.8 離線註冊分析
  • 檔案資訊
  • 脫殼
  • 離線註冊分析
    • ConfirmButton_Click按鈕事件
    • FinishRegistration
    • SetGqm
  • py
  • ps
  • 解密的程式碼
  • null

檔案資訊

PE64
    作業系統: Windows(Server 2003)[AMD64, 64 位, GUI]
    連結程式: Microsoft Linker
    編譯器: VB.NET
    編譯器: VB.NET
    語言: BASIC
    庫: .NET(v4.0.30319)
    庫: CodeDom Compiler[C#]
    庫: .NET(v4.0.30319)
    簽名工具: Windows Authenticode(2.0)[PKCS #7]
    保護器: .NET Reactor(6.5)[Anti-Tamper + Anti-ILDASM]
    附加: Binary
        證書: WinAuth(2.0)[PKCS #7]
        證書: WinAuth(2.0)[PKCS #7]

脫殼

image-20241205191152000

image-20241205191332208

dnspy 啟動

image-20241207212155827

很快發現RegistrationWindow

離線註冊分析

ConfirmButton_Click按鈕事件

離線註冊只需關注Controller.Instance.FinishRegistration

		private void ConfirmButton_Click(object sender, RoutedEventArgs e)
		{
			RegistrationWindow.<>c__DisplayClass12_0 CS$<>8__locals1 = new RegistrationWindow.<>c__DisplayClass12_0();
			CS$<>8__locals1.registrationWindow_0 = this;
			CS$<>8__locals1.string_0 = "";
			CS$<>8__locals1.string_1 = "";
			if (this.ModeComboBox.SelectedIndex == -1)
			{
				MessageWindow.Show(this, App.GetText("註冊方式 未選擇"), "錯誤", "", null, "", null);
				return;
			}
			if (this.ModeComboBox.SelectedIndex != 0)
			{
				if (this.ModeComboBox.SelectedIndex == 1)
				{
					string text = this.ZcmTextBox.Text;
					if (text == "")
					{
						return;
					}
					Controller.Instance.FinishRegistration(this, text);
				}
				return;
			}
			RegistrationWindow.<>c__DisplayClass12_1 CS$<>8__locals2 = new RegistrationWindow.<>c__DisplayClass12_1();
			CS$<>8__locals2.<>c__DisplayClass12_0_0 = CS$<>8__locals1;
			if (this.MailAddressTextBox.Text == "" || this.MailAddressTextBox.Text == App.GetText("請填寫購買會員時預留的郵箱"))
			{
				MessageWindow.Show(this, App.GetText("郵箱地址 未填寫"), "錯誤", "", null, "", null);
				return;
			}
			if (!new Regex(".+@.+").IsMatch(this.MailAddressTextBox.Text))
			{
				MessageWindow.Show(this, App.GetText("郵箱地址 填寫錯誤"), "錯誤", "", null, "", null);
				return;
			}
			if (this.CodeTextBox.Text == "")
			{
				MessageWindow.Show(this, App.GetText("驗證碼 未填寫"), "錯誤", "", null, "", null);
				return;
			}
			if (!(this.CodeTextBox.Text != this.string_0))
			{
				if (this.OldPCDockPanel.Visibility == Visibility.Visible)
				{
					if (this.OldPCComboBox.SelectedIndex == -1)
					{
						MessageWindow.Show(this, App.GetText("要更換的舊電腦 未選擇"), "錯誤", "", null, "", null);
						return;
					}
					string[] array = this.list_0[this.OldPCComboBox.SelectedIndex];
					CS$<>8__locals2.<>c__DisplayClass12_0_0.string_0 = array[0];
					CS$<>8__locals2.<>c__DisplayClass12_0_0.string_1 = array[1];
				}
				if (DateTime.Now - Class2.keyValuePair_0.Key <= new TimeSpan(1, 0, 0))
				{
					Class2.keyValuePair_0 = new KeyValuePair<DateTime, int>(DateTime.Now, Class2.keyValuePair_0.Value + 1);
					if (Class2.keyValuePair_0.Value >= 6)
					{
						MessageWindow.Show(this, App.GetText("操作過於頻繁,請1小時後再試。"), "錯誤", "", null, "", null);
						return;
					}
				}
				else
				{
					Class2.keyValuePair_0 = new KeyValuePair<DateTime, int>(DateTime.Now, 0);
				}
				CS$<>8__locals2.string_0 = this.MailAddressTextBox.Text;
				Task.Run(new Action(CS$<>8__locals2.method_0));
				return;
			}
			MessageWindow.Show(this, App.GetText("驗證碼 錯誤"), "錯誤", "", null, "", null);
		}

FinishRegistration

public bool FinishRegistration(Window window, string zhuCeMa)
		{
			bool result;
			try
			{
				string text = App.SetGqm(zhuCeMa);
				if (text != "失敗")
				{
					string[] array = text.Split(new char[]
					{
						'-'
					});
					App.Days = (new DateTime(int.Parse(array[0]), int.Parse(array[1]), int.Parse(array[2]), 23, 59, 59) - DateTime.Now).Days;
					if (App.Days < 29200)
					{
						MessageWindow.Show(window, App.GetText("註冊成功!授權至:{{Result}}。").Replace("{{Result}}", text.ToString()), "成功", "", null, "", null);
					}
					else
					{
						MessageWindow.Show(window, App.GetText("永久授權,註冊成功!"), "成功", "", null, "", null);
					}
					if (window != null)
					{
						window.Close();
					}
					Class2.string_19 = "";
					Class2.int_6 = -1;
					Class2.smethod_31();
					result = true;
				}
				else
				{
					MessageWindow.Show(window, App.GetText("註冊失敗!請聯絡管理員。"), "錯誤", "", null, "", null);
					result = false;
				}
			}
			catch
			{
				MessageWindow.Show(window, App.GetText("註冊失敗!請聯絡管理員。"), "錯誤", "", null, "", null);
				result = false;
			}
			return result;
		}

關鍵函式

		public static string SetGqm(string zcm)
		{
			MethodBase setGqmMethod = App.SetGqmMethod;
			object obj = null;
			object[] parameters = new string[]
			{
				zcm
			};
			return (string)setGqmMethod.Invoke(obj, parameters);
		}

SetGqm

AllenExplorer.App.SetGqmMethod : MethodInfo @04000FBA
	讀取於
	賦值於
		AllenExplorer.Controller.method_0(object, RoutedEventArgs) : void @06000EEC

SetGqm透過Assembly.Load 載入後設定,相關邏輯在Controller.method_0 中

image-20241207213126965

解密array,得到SetGqm

string gqm = year-month-day + "\t" + jqm+"\t" + youjian

zcm='\t'+jqm+'\t'+year-month-day+'\t'+youjian

        public static string SetGqm(string zcm)
        {
            zcm = Yd(Jqm, zcm);//aes Decryptor,Jqm as key,iv
            string[] arr = zcm.Split('\t');
            if (arr[1] == Jqm)
            {
                string gqm = arr[2] + "\t" + arr[1] + "\t" + arr[3];
                gqm = Ye(Jqm, gqm);//aes Encryptor,jqm as k,iv 
                SetR(Jqm, gqm);//save to register
                return arr[2];//date==>授權至:  year-month-day
            }
            else
            {
                return "失敗";
            }
        }

py

from Crypto.Cipher import AES
from Crypto.Util import Padding
import base64

def aes_enc(key,iv,data):
    cipher=AES.new(key=key,iv=iv,mode=AES.MODE_CBC)
    out=cipher.encrypt(data)
    return out
def aes_dec(key,iv,data):
    cipher=AES.new(key=key,iv=iv,mode=AES.MODE_CBC)
    out=cipher.decrypt(data)
    return out

def kg(jqm:str,date='-'.join(['2999','1','1']),youjian='ikun@ikun.com',xx_id='ikun'):
    #xx_id ?? unknow
    tjqm=jqm.replace('-','')
       
    key=tjqm[:16].encode()
    iv=tjqm[16:].encode()
    lic=[xx_id,jqm,date,youjian]
    data='\t'.join(lic).encode()
    data=Padding.pad(data,16)
    enc=aes_enc(key,iv,data)
    b64enc=base64.b64encode(enc)
    return b64enc
    

def SetGqm(jqm:str,zcm_b64):
    '''
            public static string SetGqm(string zcm)
        {
            zcm = Yd(Jqm, zcm);//aes Decryptor,Jqm ==>key,iv
            string[] arr = zcm.Split('\t');
            if (arr[1] == Jqm)
            {
                string gqm = arr[2] + "\t" + arr[1] + "\t" + arr[3];
                gqm = Ye(Jqm, gqm);//aes Encryptor,jqm==>k,v 
                SetR(Jqm, gqm);
                return arr[2];//name==>授權至:  
            }
            else
            {
                return "失敗";
            }
        }
            private static string Yd(string jqm, string t)
        {
            jqm = jqm.Replace("-", "");
            string key = jqm.Substring(0, 16);
            string iv = jqm.Substring(16, 16);
            return Yd(t, key, iv);// aes dec
        }
    '''
    xjqm=jqm.replace('-','')
    key=xjqm[:16].encode()
    iv=xjqm[16:].encode()
    dec=base64.b64decode(zcm_b64)
    zcm=aes_dec(key,iv,dec)
    zcm=Padding.unpad(zcm,16).decode()
    arr = zcm.split('\t')
    if arr[1]==jqm:
        print(arr[2])
    else:
        print('error!')
    '''
            private static string Yd(string t, string k, string i)
        {
            ICryptoTransform transform = Ed(k, i).CreateDecryptor();
            byte[] ba1 = Convert.FromBase64String(t);
            byte[] ba2 = transform.TransformFinalBlock(ba1, 0, ba1.Length);
            string result = Encoding.UTF8.GetString(ba2);
            return result;
        }
                private static RijndaelManaged Ed(string k, string i)
        {
            RijndaelManaged rm = new RijndaelManaged();
            rm.Key = Encoding.UTF8.GetBytes(k);
            rm.IV = Encoding.UTF8.GetBytes(i);
            rm.Mode = CipherMode.CBC;
            rm.Padding = PaddingMode.PKCS7;
            return rm;
        }
    '''
    
def test():
    jqm='xxxxxxxxxxxxxxxxxxxxxxxx'
    x=kg(jqm)
    print(x.decode())
    #SetGqm(jqm,x)

ps

      App.Days = (new DateTime(int.Parse(array[0]), int.Parse(array[1]), int.Parse(array[2]), 23, 59, 59) - DateTime.Now).Days;
      if (App.Days < 29200)//顯示到期時間

image-20241207211222144

到期時間不小於29200天時顯示永久

image-20241207211342815

image-20241207211947970

解密的程式碼

using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Management;
using System.Net.NetworkInformation;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
namespace XXX
{
    static class XXX
    {
        static DateTime DateTimeNow = DateTime.Now;
        public static void SetDateTimeNow(long ticks)
        {
            DateTimeNow = new DateTime(ticks);
        }
        static string Jqm = "";
        public static string GetJqm(string language)
        {
            if (Jqm == "")
            {
                Jqm = GetUUID(language);
            }
            return Jqm;
        }
        private static string GetUUID(string language)
        {
            if (language == "zh")
            {
                language = "";
            }
            else
            {
                language = "-" + language.ToUpper();
            }
            try
            {
                return GetHash(GetSerialNumber() + "-Allen" + "-" + "Explorer-" + GetProcessorID() + language) + language;
            }
            catch
            {
                return "";
            }
        }
        private static string GetSerialNumber()
        {
            string serialNumber = "";
            try
            {
                using (ManagementClass managementClass = new ManagementClass("Win32_BaseBoard"))
                {
                    using (ManagementObjectCollection collection = managementClass.GetInstances())
                    {
                        ManagementObject obj = collection.OfType<ManagementObject>().FirstOrDefault();
                        if (obj != null)
                        {
                            serialNumber = obj["SerialNumber"].ToString();
                        }
                    }
                }
            }
            catch { }
            return serialNumber;
        }
        private static string GetProcessorID()
        {
            string processorId = "";
            try
            {
                using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT ProcessorID FROM Win32_Processor"))
                {
                    using (ManagementObjectCollection collection = searcher.Get())
                    {
                        foreach (ManagementObject obj in collection)
                        {
                            processorId = obj["ProcessorID"].ToString();
                        }
                    }
                }
            }
            catch { }
            return processorId;
        }
        private static string GetMacAddress()
        {
            string macAddress = "";
            NetworkInterface[] networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
            if (networkInterfaces.Length > 0)
            {
                NetworkInterface networkInterface = networkInterfaces[0];
                macAddress = networkInterface.GetPhysicalAddress().ToString();
            }
            return macAddress;
        }
        private static string GetHash(string str)
        {
            MD5 sec = new MD5CryptoServiceProvider();
            ASCIIEncoding enc = new ASCIIEncoding();
            byte[] bt = enc.GetBytes(str);
            return GetHexString(sec.ComputeHash(bt));
        }
        private static string GetHexString(byte[] bt)
        {
            string s = string.Empty;
            for (int i = 0; i < bt.Length; i++)
            {
                byte b = bt[i];
                int n, n1, n2;
                n = (int)b;
                n1 = n & 15;
                n2 = (n >> 4) & 15;
                if (n2 > 9)
                    s += ((char)(n2 - 10 + (int)'A')).ToString();
                else
                    s += n2.ToString();
                if (n1 > 9)
                    s += ((char)(n1 - 10 + (int)'A')).ToString();
                else
                    s += n1.ToString();
                if ((i + 1) != bt.Length && (i + 1) % 2 == 0) s += "-";
            }
            return s;
        }
        static string TianShu = "";
        public static string GetTianShu()
        {
            try
            {
                string gqm = GetR(Jqm);
                if (gqm == "")
                {
                    TianShu = "新裝";
                }
                else if (gqm == "失敗")
                {
                    TianShu = "失敗";
                }
                else
                {
                    gqm = Yd(Jqm, gqm);
                    string[] arr = gqm.Split('\t');
                    if (arr[1] == Jqm)
                    {
                        if (arr[0] != "Invalid")
                        {
                            string[] _arr = arr[0].Split('-');
                            DateTime dateTime = new DateTime(int.Parse(_arr[0]), int.Parse(_arr[1]), int.Parse(_arr[2]), 23, 59, 59);
                            TimeSpan timeSpan = dateTime - DateTimeNow;
                            if (timeSpan >= new TimeSpan(0))
                            {
                                TianShu = timeSpan.Days.ToString();
                            }
                            else
                            {
                                TianShu = "過期";
                            }
                        }
                        else
                        {
                            TianShu = "失效";
                        }
                    }
                    else
                    {
                        TianShu = "失敗";
                    }
                }
            }
            catch
            {
                TianShu = "失敗";
            }
            return TianShu;
        }
        public static void Set30()
        {
            string date = (DateTimeNow + new TimeSpan(30, 0, 0, 0)).ToString("yyyy-MM-dd");
            string gqm = date + "\t" + Jqm;
            gqm = Ye(Jqm, gqm);
            SetR(Jqm, gqm);
            TianShu = "30";
        }
        public static string SetGqm(string zcm)
        {
            zcm = Yd(Jqm, zcm);//aes Decryptor,Jqm as key,iv
            string[] arr = zcm.Split('\t');
            if (arr[1] == Jqm)
            {
                string gqm = arr[2] + "\t" + arr[1] + "\t" + arr[3];
                gqm = Ye(Jqm, gqm);//aes Encryptor,jqm as k,iv 
                SetR(Jqm, gqm);//save to register
                return arr[2];//date==>授權至:  year-month-day
            }
            else
            {
                return "失敗";
            }
        }
        public static string GetYouJian()
        {
            string youJian = "";
            try
            {
                string gqm = GetR(Jqm);
                gqm = Yd(Jqm, gqm);
                string[] arr = gqm.Split('\t');
                if (arr.Length >= 3)
                {
                    youJian = arr[2];
                }
            }
            catch { }
            return youJian;
        }
        public static void CheckTianShu2(string currentLanguage, string targetLanguage)
        {
            string tianShu2 = GetTianShu2(targetLanguage);
            if (tianShu2 != "新裝")
            {
                return;
            }
            tianShu2 = GetTianShu2(currentLanguage);
            if (tianShu2 == "新裝")
            {
                return;
            }
            if (tianShu2 == "過期" || tianShu2 == "失效" || tianShu2 == "失敗")
            {
                SetGqm2(tianShu2, targetLanguage);
            }
            else
            {
                int days = int.Parse(tianShu2);
                if (days <= 30)
                {
                    SetGqm2(tianShu2, targetLanguage);
                }
            }
        }
        private static string GetTianShu2(string language)
        {
            string tianShu;
            try
            {
                string jqm = GetUUID(language);
                string gqm = GetR(jqm);
                if (gqm == "")
                {
                    tianShu = "新裝";
                }
                else if (gqm == "失敗")
                {
                    tianShu = "失敗";
                }
                else
                {
                    gqm = Yd(jqm, gqm);
                    string[] arr = gqm.Split('\t');
                    if (arr[1] == jqm)
                    {
                        if (arr[0] != "Invalid")
                        {
                            string[] _arr = arr[0].Split('-');
                            DateTime dateTime = new DateTime(int.Parse(_arr[0]), int.Parse(_arr[1]), int.Parse(_arr[2]), 23, 59, 59);
                            TimeSpan timeSpan = dateTime - DateTimeNow;
                            if (timeSpan >= new TimeSpan(0))
                            {
                                tianShu = timeSpan.Days.ToString();
                            }
                            else
                            {
                                tianShu = "過期";
                            }
                        }
                        else
                        {
                            tianShu = "失效";
                        }
                    }
                    else
                    {
                        tianShu = "失敗";
                    }
                }
            }
            catch
            {
                tianShu = "失敗";
            }
            return tianShu;
        }
        private static void SetGqm2(string tianShu, string language)
        {
            string gqm;
            string jqm = GetUUID(language);
            if (tianShu == "過期" || tianShu == "失效" || tianShu == "失敗")
            {
                gqm = "Invalid" + "\t" + jqm;
            }
            else
            {
                int days = int.Parse(tianShu);
                string gqr = (DateTimeNow + new TimeSpan(days, 0, 0, 0)).ToString("yyyy-MM-dd");
                gqm = gqr + "\t" + jqm;
            }
            gqm = Ye(jqm, gqm);
            SetR(jqm, gqm);
        }
        private static string GetR(string jqm)
        {
            RegistryKey key = Registry.CurrentUser;
            string name = GetName(jqm);
            RegistryKey software = key.OpenSubKey("SOFTWARE\\Microsoft\\" + name);
            if (software == null)
            {
                return "";
            }
            object value = software.GetValue("Configuration");
            if (value == null)
            {
                return "";
            }
            string a = value.ToString();
            string b = GetP(jqm);
            if (a == b)
            {
                return a;
            }
            else
            {
                return "失敗";
            }
        }
        private static void SetR(string jqm, string gqm)
        {
            RegistryKey key = Registry.CurrentUser;
            string name = GetName(jqm);
            RegistryKey software = key.OpenSubKey("SOFTWARE\\Microsoft\\" + name, true);
            if (software == null)
            {
                software = key.CreateSubKey("SOFTWARE\\Microsoft\\" + name);
            }
            software.SetValue("Configuration", gqm);
            SetP(jqm, gqm);
        }
        public static string GetName(string jqm)
        {
            string str = jqm.Replace("-", "");
            str = Regex.Replace(str, "\\d", "");
            if (str.Length >= 3)
            {
                str = str.Substring(0, 3);
            }
            else
            {
                str = jqm.EndsWith("-EN") ? "LEN" : "LLA";
            }
            return str;
        }
        private static string GetP(string jqm)
        {
            try
            {
                string appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                string dir = appData + "\\Microsoft\\Crypto\\Keys";
                if (!Directory.Exists(dir))
                {
                    return "失敗";
                }
                string file = dir + "\\" + jqm.Replace("-", "").ToLower();
                if (!File.Exists(file))
                {
                    return "失敗";
                }
                else
                {
                    string text = File.ReadAllText(file);
                    DateTime creationDate = Directory.GetCreationTime(appData);
                    File.SetLastAccessTime(file, creationDate);
                    return text;
                }
            }
            catch
            {
                return "失敗";
            }
        }
        private static void SetP(string jqm, string gqm)
        {
            try
            {
                string appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                string dir = appData + "\\Microsoft\\Crypto\\Keys";
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                string file = dir + "\\" + jqm.Replace("-", "").ToLower();
                if (File.Exists(file))
                {
                    File.Delete(file);
                }
                File.WriteAllText(file, gqm);
                DateTime creationDate = Directory.GetCreationTime(appData);
                File.SetAttributes(file, FileAttributes.Hidden);
                File.SetCreationTime(file, creationDate);
                File.SetLastWriteTime(file, creationDate);
                File.SetLastAccessTime(file, creationDate);
            }
            catch { }
        }
        private static string Ye(string jqm, string t)
        {
            jqm = jqm.Replace("-", "");
            string key = jqm.Substring(0, 16);
            string iv = jqm.Substring(16, 16);
            return Ye(t, key, iv);
        }
        private static string Yd(string jqm, string t)
        {
            jqm = jqm.Replace("-", "");
            string key = jqm.Substring(0, 16);
            string iv = jqm.Substring(16, 16);
            return Yd(t, key, iv);
        }
        private static string Ye(string t, string k, string i)
        {
            ICryptoTransform transform = Ed(k, i).CreateEncryptor();
            byte[] ba1 = Encoding.UTF8.GetBytes(t);
            byte[] ba2 = transform.TransformFinalBlock(ba1, 0, ba1.Length);
            string result = Convert.ToBase64String(ba2, 0, ba2.Length);
            return result;
        }
        private static string Yd(string t, string k, string i)
        {
            ICryptoTransform transform = Ed(k, i).CreateDecryptor();
            byte[] ba1 = Convert.FromBase64String(t);
            byte[] ba2 = transform.TransformFinalBlock(ba1, 0, ba1.Length);
            string result = Encoding.UTF8.GetString(ba2);
            return result;
        }
        private static RijndaelManaged Ed(string k, string i)
        {
            RijndaelManaged rm = new RijndaelManaged();
            rm.Key = Encoding.UTF8.GetBytes(k);
            rm.IV = Encoding.UTF8.GetBytes(i);
            rm.Mode = CipherMode.CBC;
            rm.Padding = PaddingMode.PKCS7;
            return rm;
        }
        public static string A(string path)
        {
            CheckInvalid();
            path = path.Trim();
            if (path == "")
            {
                return "";
            }
            bool ok = false;
            if (path.Length > 2 && path[0] == '\\' && path[1] == '\\')
            {
                path = path.Substring(2);
                ok = true;
            }
            else if (path.Length > 1 && path[0] == '%')
            {
                Regex reg = new Regex("^%(.+)%");
                if (reg.IsMatch(path))
                {
                    string str = reg.Match(path).Groups[1].Value;
                    var environmentVariable = Environment.GetEnvironmentVariable(str);
                    if (environmentVariable != null)
                    {
                        path = reg.Replace(path, environmentVariable);
                    }
                }
            }
            path = Regex.Replace(path, "\\\\{2,}", "\\");
            if (path[path.Length - 1] == '\\')
            {
                path = path.Substring(0, path.Length - 1);
            }
            if (ok)
            {
                path = "\\\\" + path;
            }
            if (!path.Contains("\\"))
            {
                path += "\\";
            }
            return path;
        }
        public static string B(string path)
        {
            CheckInvalid();
            path = A(path);
            if (path == "")
            {
                return "";
            }
            bool ok = false;
            if (path.Length > 2 && path[0] == '\\' && path[1] == '\\')
            {
                path = path.Substring(2);
                ok = true;
            }
            string[] arr = path.Split('\\');
            if (!ok)
            {
                return arr[0] + "\\";
            }
            else
            {
                if (arr.Length > 1)
                {
                    return "\\\\" + arr[0] + "\\" + arr[1];
                }
                else
                {
                    return "";
                }
            }
        }
        public static string C(string path)
        {
            CheckInvalid();
            path = A(path);
            if (path == "")
            {
                return "";
            }
            bool ok = false;
            if (path.Length > 2 && path[0] == '\\' && path[1] == '\\')
            {
                path = path.Substring(2);
                ok = true;
            }
            if (ok)
            {
                int index = path.IndexOf("\\");
                if (index == -1)
                {
                    return "";
                }
                path = path.Substring(0, index) + "|" + path.Substring(index + 1);
            }
            if (path[path.Length - 1] == '\\')
            {
                path = path.Substring(0, path.Length - 1);
            }
            string[] arr = path.Split('\\');
            if (arr.Length <= 1)
            {
                return "";
            }
            List<string> list = new List<string>(arr);
            list.RemoveAt(list.Count - 1);
            string pdir = string.Join("\\", list);
            if (ok)
            {
                pdir = "\\\\" + pdir.Replace("|", "\\");
            }
            if (!pdir.Contains("\\"))
            {
                pdir += "\\";
            }
            return pdir;
        }
        public static bool D(string _dir, string dir)
        {
            CheckInvalid();
            if (_dir == "" || dir == "")
            {
                return false;
            }
            if (_dir == dir)
            {
                return false;
            }
            if (dir[dir.Length - 1] == '\\')
            {
                return _dir.Contains(dir);
            }
            else
            {
                return _dir.Contains(dir + "\\");
            }
        }
        public static List<string> E(string dir)
        {
            CheckInvalid();
            List<string> list = new List<string>();
            string _dir = "";
            string[] arr = dir.Split('\\');
            foreach (string str in arr)
            {
                if (str == "")
                {
                    continue;
                }
                if (_dir == "")
                {
                    _dir = str + "\\";
                }
                else
                {
                    if (_dir[_dir.Length - 1] == '\\')
                    {
                        _dir += str;
                    }
                    else
                    {
                        _dir += "\\" + str;
                    }
                }
                list.Add(_dir);
            }
            if (dir.Length > 2 && dir[0] == '\\' && dir[1] == '\\')
            {
                for (int i = 0; i <= list.Count - 1; i++)
                {
                    list[i] = "\\\\" + list[i];
                }
                list.RemoveAt(0);
            }
            return list;
        }
        public static string F(string dir, string title, string extension)
        {
            CheckInvalid();
            if (dir[dir.Length - 1] == '\\')
            {
                dir = dir.Substring(0, dir.Length - 1);
            }
            string uniquePath = dir + "\\" + title + extension;
            if (Directory.Exists(uniquePath) || File.Exists(uniquePath))
            {
                for (int i = 2; true; i++)
                {
                    uniquePath = dir + "\\" + title + " (" + i + ")" + extension;
                    if (!Directory.Exists(uniquePath) && !File.Exists(uniquePath))
                    {
                        break;
                    }
                }
            }
            return uniquePath;
        }
        public static string G(string name)
        {
            CheckInvalid();
            List<string> list = new List<string>();
            string num = "";
            string nonum = "";
            foreach (char c in name)
            {
                if ("0123456789".Contains(c))
                {
                    num += c;
                    if (nonum != "")
                    {
                        list.Add(nonum);
                        nonum = "";
                    }
                }
                else
                {
                    nonum += c;
                    if (num != "")
                    {
                        int length = num.Length;
                        if (length < 10)
                        {
                            for (int i = 0; i <= 10 - length - 1; i++)
                            {
                                num = "0" + num;
                            }
                        }
                        list.Add(num);
                        num = "";
                    }
                }
            }
            if (nonum != "")
            {
                list.Add(nonum);
            }
            if (num != "")
            {
                int length = num.Length;
                if (length < 10)
                {
                    for (int i = 0; i <= 10 - length - 1; i++)
                    {
                        num = "0" + num;
                    }
                }
                list.Add(num);
            }
            string orderName = string.Join("", list);
            return orderName;
        }
        public static string H(object obj)
        {
            CheckInvalid();
            double length = (double)obj;
            string size = "";
            length = length * 1024d;
            string[] dws = { "B", "K", "M", "G", "T" };
            for (int i = 0; i <= 4; i++)
            {
                length = length / 1024d;
                size = length.ToString();
                if (size.Replace(".", "").Length > 3)
                {
                    if (size.Contains("."))
                    {
                        if (length >= 100)
                        {
                            size = size.Substring(0, 3);
                        }
                        else
                        {
                            size = size.Substring(0, 4);
                        }
                    }
                    else
                    {
                        size = size.Substring(0, 3);
                    }
                }
                if (length < 1000)
                {
                    size = size + " " + dws[i];
                    break;
                }
            }
            return size;
        }
        private static void CheckInvalid()
        {
            if (TianShu == "過期" || TianShu == "失效" || TianShu == "失敗")
            {
                string gqm = "Invalid" + "\t" + Jqm;
                gqm = Ye(Jqm, gqm);
                SetR(Jqm, gqm);
                Environment.Exit(0);
            }
        }
    }
}

相關文章