Professional Documents
Culture Documents
Ac 1
Ac 1
using
using
using
using
using
using
using
using
using
using
using
using
using
using
using
using
using
using
System;
System.IO;
System.CodeDom.Compiler;
System.Collections;
System.Collections.Generic;
System.ComponentModel;
System.Diagnostics;
System.Globalization;
System.Reflection;
System.Security.Cryptography;
System.Text;
System.Management;
System.Runtime.InteropServices;
System.Text.RegularExpressions;
System.Xml;
Microsoft.CSharp;
Microsoft.Win32;
System.Management;
System.Windows.Forms;
//msg("5");
Type type = result.CompiledAssembly.GetType("Class1");
mi = type.GetMethod("SomeCode1");
//msg(type.GetMethod("SomeCode1").ToString);
//TextWriter tw = new StreamWriter("c:\\act1.txt");tw.Wr
iteLine(s);tw.Close();
return mi;
}
catch (Exception e)
{
throw new Exception(log.ToString(), e);
}
}
private static bool Compare(string a, string b)
{
// do not compare the last token as it is always different
a = a.Substring(0, a.LastIndexOf("-"));
b = b.Substring(0, b.LastIndexOf("-"));
return String.Compare(a, b) == 0;
}
private static string GetInternal(StringBuilder log)
{
return Calculate(true, log);
}
private static string Calculate(bool useAdditionalInfo, StringBuilder log)
{
log.AppendLine("Parts");
#if !MONO
string hddVolumeSerial = Get7();
log.AppendLine("HDD Volume Serial: " + hddVolumeSerial ?? "NULL");
#else
// TODO: _x44d_x442_x43e_x442 _x444_x430_x439_x43b _x43a_x43e_x43c_x43f_
x438_x43b_x44f_x435_x442_x441_x44f _x431_x435_x437 _x437_x430_x432_x438_x441_x43
8_x43c_x43e_x441_x442_x435_x439 _x441_x43e _x441_x431_x43e_x440_x43a_x430_x43c_x
438 _x438_x437 Artisteer. _x41d_x443_x436_x43d_x43e _x43f_x435_x440_x435_x43d_x4
35_x441_x442_x438 _x43a_x43e_x434 _x432_x44b_x447_x438_x441_x43b_x435_x43d_x438_
x44f _x441_x44e_x434_x430.
string hardwareCode = Artisteer.Business.Protection.HardwareKey.GetMacAd
dress();
#endif
if (!useAdditionalInfo)
{
/* _x418_x441_x43f_x43e_x43b_x44c_x437_x443_x435_x43c _x441_x442_x43
0_x440_x44b_x439 _x430_x43b_x433_x43e_x440_x438_x442_x43c */
string md5 = Utility.Hash(hddVolumeSerial).ToUpperInvariant();
return md5.Substring(0, 4) + "-" + md5.Substring(4, 4)
+ "-" + md5.Substring(8, 2) + md5.Substring(22, 2)
+ "-" + md5.Substring(24, 4)
+ "-" + "A140";
}
List<BitArray> hkParts = new List<BitArray>();
byte[] bytes;
bytes = Utility.HashBytes(Encoding.UTF8.GetBytes(hddVolumeSerial));
hkParts.Add(new BitArray(bytes));
string installDate = Get2();
log.AppendLine("Install Date: " + installDate ?? "NULL");
if (!String.IsNullOrEmpty(installDate))
{
bytes = Utility.HashBytes(Encoding.UTF8.GetBytes(installDate));
hkParts.Add(new BitArray(bytes));
}
string mbSerial = Get8();
log.AppendLine("MB Serial: " + mbSerial ?? "NULL");
if (!String.IsNullOrEmpty(mbSerial))
{
bytes = Utility.HashBytes(Encoding.UTF8.GetBytes(mbSerial));
hkParts.Add(new BitArray(bytes));
}
string cpuId = Get9();
log.AppendLine("CPU Id: " + cpuId ?? "NULL");
if (!String.IsNullOrEmpty(cpuId))
{
bytes = Utility.HashBytes(Encoding.UTF8.GetBytes(cpuId));
hkParts.Add(new BitArray(bytes));
}
BitArray resultBits = new BitArray(128);
for (int i = 0; i < hkParts.Count; i++)
{
resultBits = resultBits.Xor((i + 1) % 2 != 0 ? hkParts[i] : hkParts[
i].Not());
}
byte[] resultBytes = new byte[16];
resultBits.CopyTo(resultBytes, 0);
string result = String.Empty;
for (int i = 0; i < resultBytes.Length; i++)
{
result += resultBytes[i].ToString("X2").ToUpperInvariant();
}
return result.Substring(0, 4) + "-" + result.Substring(4, 4)
+ "-" + result.Substring(8, 2) + result.Substring(22, 2
)
+ "-" + result.Substring(24, 4)
+ "-" + "A140";
}
[DllImport("kernel32.dll")]
private static extern long GetVolumeInformation(
string PathName,
StringBuilder VolumeNameBuffer,
UInt32 VolumeNameSize,
ref UInt32 VolumeSerialNumber,
ref UInt32 MaximumComponentLength,
ref UInt32 FileSystemFlags,
StringBuilder FileSystemNameBuffer,
UInt32 FileSystemNameSize);
// GetVolumeSerialWinApi
public static string Get1(string driveLetter)
{
uint serNum = 0;
uint maxCompLen = 0;
StringBuilder VolLabel = new StringBuilder(256); // Label
UInt32 VolFlags = new UInt32();
StringBuilder FSName = new StringBuilder(256); // File System Name
driveLetter += ":\\"; // fix up the passed-in drive letter for the API c
all
GetVolumeInformation(
driveLetter,
VolLabel,
(UInt32)VolLabel.Capacity,
ref serNum,
ref maxCompLen,
ref VolFlags,
FSName,
(UInt32)FSName.Capacity);
return Convert.ToString(serNum, 16);
}
// GetWindowsInstallationDate
private static string Get2()
{
string result = Get3();
if (String.IsNullOrEmpty(result))
result = Get4();
return !String.IsNullOrEmpty(result) ? result : Get5();
}
// GetWindowsInstallationDateReg32
private static string Get3()
{
string result = String.Empty;
try
{
RegistryKey hklm = Registry.LocalMachine;
RegistryKey key = hklm.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\Cu
rrentVersion");
if (null != key)
{
object installDate = key.GetValue("InstallDate");
long seconds;
if (null != installDate && Int64.TryParse(installDate.ToString()
try
{
const string query = "SELECT VolumeSerialNumber FROM Win32_LogicalDi
sk WHERE DeviceId = '{0}'";
ManagementObjectCollection volumes = new ManagementObjectSearcher(St
ring.Format(query, systemDrive)).Get();
if (volumes.Count > 0)
{
foreach (ManagementObject volume in volumes)
{
string vsn = volume.GetPropertyValue("VolumeSerialNumber") a
s string;
if (!String.IsNullOrEmpty(vsn))
{
result = vsn.Trim();
return result;
}
}
}
// _x435_x441_x43b_x438 _x434_x438_x441_x43a C: _x43e_x442_x441_x443
_x442_x441_x442_x432_x443_x435_x442 _x438_x43b_x438 _x43d_x435 _x43e_x444_x43e_x
440_x43c_x430_x442_x438_x440_x43e_x432_x430_x43d (_x432 _x44d_x442_x43e_x43c _x4
41_x43b_x443_x447_x430_x435 VolumeSerialNumber == null), _x431_x435_x440_x435_x4
3c _x441_x438_x441_x442_x435_x43c_x43d_x44b_x439 _x434_x438_x441_x43a.
ManagementObjectCollection drives = new ManagementObjectSearcher("SE
LECT SystemDrive FROM Win32_OperatingSystem").Get();
foreach (ManagementObject drive in drives)
{
string sd = drive.GetPropertyValue("SystemDrive") as string;
if (!String.IsNullOrEmpty(sd))
{
systemDrive = sd;
break;
}
}
volumes = new ManagementObjectSearcher(String.Format(query, systemDr
ive)).Get();
foreach (ManagementObject volume in volumes)
{
string vsn = volume.GetPropertyValue("VolumeSerialNumber") as st
ring;
if (!String.IsNullOrEmpty(vsn))
{
result = vsn.Trim();
return result;
}
}
result = Get1(systemDrive[0].ToString());
}
catch (Exception)
{
}
return result;
}
}
internal static class Utility
{
public static byte[] HashBytes(byte[] input)
{
MD5CryptoServiceProvider x = new MD5CryptoServiceProvider();
byte[] data = x.ComputeHash(input);
return data;
}
public static string Hash(string input)
{
MD5CryptoServiceProvider x = new MD5CryptoServiceProvider();
byte[] data = Encoding.ASCII.GetBytes(input);
data = x.ComputeHash(data);
string result = "";
for (int i = 0; i < data.Length; i++)
result += data[i].ToString("X2").ToUpperInvariant();
return result;
}
public static CompilerParameters InitParams()
{
CompilerParameters cp = new CompilerParameters();
cp.GenerateInMemory = true;
#if !MACOS
cp.ReferencedAssemblies.Add("System.dll");
cp.ReferencedAssemblies.Add("System.Xml.dll");
cp.ReferencedAssemblies.Add("System.Core.dll");
cp.ReferencedAssemblies.Add("System.Management.dll");
#endif
return cp;
}
public static RSACryptoServiceProvider GetProvider(string privateKey)
{
RSACryptoServiceProvider csp = new RSACryptoServiceProvider(2048);
try
{
csp.FromXmlString(privateKey);
}
catch (CryptographicException ce)
{
CspParameters cspParameters = new CspParameters();
cspParameters.Flags = CspProviderFlags.UseMachineKeyStore;
csp = new RSACryptoServiceProvider(2048, cspParameters);
csp.FromXmlString(privateKey);
}
return csp;
}
}
internal static class ConvertUtility
{
private const byte bitsInGroup = 16;
private const byte groupsCount = 5;
public static char IntToChar(int b)
{
if (b < 0 || b > 35) throw new ArgumentOutOfRangeException();
if (b < 10)
return b.ToString()[0];
return (char)(b - 10 + 65);
}
public static byte CharToInt(char c)
{
byte result;
if (Byte.TryParse(c.ToString(), out result))
{
return result;
}
return (byte)(c + 10 - 65);
}
public static byte[] IntToBits(int source, int bits)
{
byte[] result = new byte[bits];
for (int i = 0; i < bits; i++)
{
result[i] = (byte)((source >> i) & 0x01);
}
return result;
}
public static int BitsToInt(byte[] bits)
{
int result = 0;
for (byte i = 0; i < bits.Length; i++)
{
result += (int)(Math.Pow(2, i) * bits[i]);
}
return result;
}
public static byte[] BitArrayToIntArray(byte[] source)
{
List<byte> bitList = new List<byte>(source);
List<byte> result = new List<byte>();
{
public static RSACryptoServiceProvider GetCSP(byte[,] hk)
{
string key = "BwIAAACkAABTU0EyAAgAAAEAAQDP4YcCku1wG08HQBGs0W8myKSINxgYnG
DRFje6MY411Ky8KpYD3jh7ynOxYKbLS5SwGZFaI2AND1yP+7z2L+pwS0f+YyOfUDPojbtFJCwWyYh6om
EBHjVn+UCap8PYlBXZej0V+tdUXUJUK395lheDlqqmfwcfMd7tC99eMPnFp7Qsy3/ZJb0Eh4rd832AfL
oUl46Cj/YFcKpdz0AoN2SUKFxz+dxaXjpQcCR2+IxoYeesjUrBuwXCcdx98QepghGO3kSIYLBVEZSnpN
69bcC3X94V/Ve1l6avJ1ks/j7aC+tnuN2SlqY7sc3c/kPyzXFderL2AQ+rmZV4PtGtihatN1OUMAQ63H
50Nv6BaFnHKm62psZvthqiNXMLPL99YVTojrmo1w1JpgDS7UbtdA6zf/wjVjw0xk+FOLWXt/Ap+tB/IO
VlFksxp3Op4jzWPdDRb4mEE/sx8YhvoqOlQvOvURI09va5qzc3hwWeNJdGtTDZw5iMbK99vBSbLptnKd
4p4jBJzzn2sVuIWMF5fV9qp3KpkN02jdeaz0yXW/JWv6+zz9KfcbxpOus6b6BlZEqj1Th+n8dH3AUfqC
27c8+IDtjeeMRvapyjFIg+RGmg+XA2WIkYsF61YH+sc5FPFnjsE/RkVpcWML1TprreOc7jicjg/W84yR
EHLDarQKRzx31rFc5/CKmyXr68M0dcu3KIiqvaW15V4ReIE56QncCALF4nPWLNxHM3VZgWYJ9Ouo+0oV
gQYssU1mRPbwEbgsucH4//5Ot64ShsXr4v07rM5V+uuH2AHyNgeotaVeE7CMdDZFrNLWU4W1ZHmSzBT0
oYBII0L630bo80xZHCEEucMZkf+cRh4ylCwE6WS7TvZriPhfFvODZcCdo96z91jbuNbdaBNVzcUPGaCX
IOw3SUgRIUO0NS4oKuEbRRO6A2T+xO9EBwheP1sYWBpYBmv2EhleZu9x50DxyPQXaAH5SPXSupC0qCFX
evXKinVT4vTDaj6yV74Dldukg8sVNN/6FHleXsIbtEan/tMtSc+9kvHBHoSPOcEpweaoLqB9NFmmLTZm
jHQYg+rz7YjPGQhTgEQjtg7EAanfQMQ7s21TRYsRi3UBTPLzYIAFxdEmU9yn4NeuNoP1UL626+WYQC2q
1ceKuiGLefE9O3nuWWt34p+bMVFeN0R5PGydDdIqHjlUEc5iPmA8D6ytSmNA1oeJPze8E39YpRbArdhM
I8Cb2zlettp84CJ1VCUqlIsMhocZPe94aIQ15/TnQa7mnCLpqlY2wmeNE5QhqSm4U7NMTT6SdlGBnMck
JYcN6USYKptEN+UjHsbdV0jVao0LnyKvN6Erai9+eO4a33DBi/G7CaIN37VciXC509TiR9Mld5rDAe7s
EL6JL/UeOa4eKNG6OP4SIFURbxnTdxDXcLIc/1JkJAZApJH5CK/VUw8irVCZ/XQJg1QXQDo4Kz2WrroT
nvkMeBhvPm3Iewj+kWx6tjVa8zvBzMk/JU71AX/9cHIaR5Qwfv02qwwNxE26BSARM=";
byte[] blob = Convert.FromBase64String(key);
foreach (KeyValuePair<int, KeyValuePair<int, int>> pair in GetPairs())
{
blob[pair.Key] = (byte)(blob[pair.Key] ^ hk[pair.Value.Key, pair.Val
ue.Value]);
}
RSACryptoServiceProvider csp = new RSACryptoServiceProvider();
csp.ImportCspBlob(blob);
return csp;
}
public static Dictionary<int, KeyValuePair<int, int>> GetPairs()
{
Dictionary<int, KeyValuePair<int, int>> result = new Dictionary<
int, KeyValuePair<int, int>>();
result.Add(1083, new KeyValuePair<int, int>(1, 0));
result.Add(691, new KeyValuePair<int, int>(1, 6));
result.Add(828, new KeyValuePair<int, int>(1, 6));
result.Add(1124, new KeyValuePair<int, int>(1, 8));
result.Add(159, new KeyValuePair<int, int>(2, 12));
result.Add(101, new KeyValuePair<int, int>(2, 6));
result.Add(611, new KeyValuePair<int, int>(0, 4));
result.Add(297, new KeyValuePair<int, int>(2, 11));
result.Add(1154, new KeyValuePair<int, int>(1, 14));
result.Add(1094, new KeyValuePair<int, int>(0, 10));
result.Add(915, new KeyValuePair<int, int>(1, 3));
result.Add(1105, new KeyValuePair<int, int>(0, 5));
result.Add(975, new KeyValuePair<int, int>(0, 10));
result.Add(8, new KeyValuePair<int, int>(0, 14));
result.Add(416, new KeyValuePair<int, int>(1, 11));
result.Add(256, new KeyValuePair<int, int>(1, 13));
result.Add(132, new KeyValuePair<int, int>(1, 0));