new file: pixi.toml
[GalaxyCodeBases.git] / etc / Windows / py-kms / kmsPidGenerator.py
blob4fe6cfea7384f62a758e032c248313202921b7ca
1 import datetime
2 import random
3 import time
4 import uuid
6 APP_ID_WINDOWS = uuid.UUID("55C92734-D682-4D71-983E-D6EC3F16059F")
7 APP_ID_OFFICE14 = uuid.UUID("59A52881-A989-479D-AF46-F275C6370663")
8 APP_ID_OFFICE15 = uuid.UUID("0FF1CE15-A989-479D-AF46-F275C6370663")
11 # KMS Host OS Type
12 hostOsList = {}
13 # Windows Server 2008 R2 SP1
14 hostOsList["HOST_SERVER2008R2"] = {
15 "type" : 55041,
16 "osBuild" : 7601
18 # Windows Server 2012 RTM
19 hostOsList["HOST_SERVER2012"] = {
20 "type" : 5426,
21 "osBuild" : 9200
23 # Windows Server 2012 R2 RTM
24 hostOsList["HOST_SERVER2012R2"] = {
25 "type" : 6401,
26 "osBuild" : 9600
30 # Product Specific KeyConfig
31 pkeyConfigList = {}
32 # Windows Server KMS Host PID, actual PIDRangeMax = 191999999
33 pkeyConfigList["windows"] = {
34 "GroupID" : 206,
35 "PIDRangeMin" : 152000000,
36 "PIDRangeMax" : 152999999
38 # Windows Server 2012 R2 KMS Host PID, actual PIDRangeMax = 310999999
39 pkeyConfigList["windows2012r2"] = {
40 "GroupID" : 206,
41 "PIDRangeMin" : 271000000,
42 "PIDRangeMax" : 271999999
44 # Office 2010 KMSHost Class PID, actual PIDRangeMax = 217999999
45 pkeyConfigList["office14"] = {
46 "GroupID" : 96,
47 "PIDRangeMin" : 199000000,
48 "PIDRangeMax" : 201999999
50 # Office 2013 KMSHost Class PID, actual PIDRangeMax = 255999999
51 pkeyConfigList["office15"] = {
52 "GroupID" : 206,
53 "PIDRangeMin" : 234000000,
54 "PIDRangeMax" : 234999999
58 def epidGenerator(appId, version, lcid):
59 # Generate Part 1 & 7: Host Type and KMS Server OS Build
60 hostOsType = random.choice(hostOsList.keys())
61 hostOsDict = hostOsList[hostOsType]
63 # Generate Part 2: Group ID and Product Key ID Range
64 if appId == APP_ID_OFFICE14:
65 keyConfig = pkeyConfigList["office14"]
66 elif appId == APP_ID_OFFICE15:
67 keyConfig = pkeyConfigList["office15"]
68 else:
69 # Default to Windows
70 if hostOsDict['osBuild'] == 9600:
71 keyConfig = pkeyConfigList["windows2012r2"]
72 else:
73 keyConfig = pkeyConfigList["windows"]
75 # Generate Part 3 and Part 4: Product Key ID
76 productKeyID = random.randint(keyConfig["PIDRangeMin"], keyConfig["PIDRangeMax"])
78 # Generate Part 5: License Channel (00=Retail, 01=Retail, 02=OEM,
79 # 03=Volume(GVLK,MAK)) - always 03
80 licenseChannel = 3
82 # Generate Part 6: Language - use system default language
83 # 1033 is en-us
84 languageCode = lcid # C# CultureInfo.InstalledUICulture.LCID
86 # Generate Part 8: KMS Host Activation Date
87 # Get Minimum Possible Date: Newer Products first
88 if hostOsType == "HOST_SERVER2012R2" or version == 6:
89 # Microsoft Windows Server 2012 R2 RTM (October 17, 2013)
90 minTime = datetime.date(2013, 10, 17)
91 elif appId == APP_ID_OFFICE15:
92 # Microsoft Office 2013 RTM (October 24, 2012)
93 minTime = datetime.date(2012, 10, 24)
94 elif hostOsType == "HOST_SERVER2012" or version == 5:
95 # Microsoft Windows Server 2012 RTM (September 4, 2012)
96 minTime = datetime.date(2012, 9, 4)
97 else:
98 # Windows Server 2008 R2 SP1 (February 16, 2011)
99 minTime = datetime.date(2011, 2, 16)
101 # Generate Year and Day Number
102 randomDate = datetime.date.fromtimestamp(random.randint(time.mktime(minTime.timetuple()), time.mktime(datetime.datetime.now().timetuple())))
103 firstOfYear = datetime.date(randomDate.year, 1, 1)
104 randomDayNumber = int((time.mktime(randomDate.timetuple()) - time.mktime(firstOfYear.timetuple())) / 86400 + 0.5)
106 # generate the epid string
107 result = []
108 result.append(str(hostOsDict["type"]).rjust(5, "0"))
109 result.append("-")
110 result.append(str(keyConfig["GroupID"]).rjust(5, "0"))
111 result.append("-")
112 result.append(str(productKeyID / 1000000).rjust(3, "0"))
113 result.append("-")
114 result.append(str(productKeyID % 1000000).rjust(6, "0"))
115 result.append("-")
116 result.append(str(licenseChannel).rjust(2, "0"))
117 result.append("-")
118 result.append(str(languageCode))
119 result.append("-")
120 result.append(str(hostOsDict["osBuild"]).rjust(4, "0"))
121 result.append(".0000-")
122 result.append(str(randomDayNumber).rjust(3, "0"))
123 result.append(str(randomDate.year).rjust(4, "0"))
124 return "".join(result)