Update app.py

1. Format codes
2. GenerateLicense takes int rather than LicenseType type
pull/15/head
Laurence Luo 2024-05-30 17:26:02 +08:00
parent d1f202b785
commit bcd98e8143
No known key found for this signature in database
GPG Key ID: 76D108A29460F5F9
1 changed files with 31 additions and 24 deletions

23
app.py
View File

@ -1,8 +1,10 @@
#/usr/bin/env python3 #/usr/bin/env python3
import os, sys, zipfile import os
from flask import Flask, request, send_file
import os.path import os.path
import zipfile
from flask import Flask, request, send_file
app = Flask(__name__) app = Flask(__name__)
@ -10,6 +12,7 @@ VariantBase64Table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345
VariantBase64Dict = {i: VariantBase64Table[i] for i in range(len(VariantBase64Table))} VariantBase64Dict = {i: VariantBase64Table[i] for i in range(len(VariantBase64Table))}
VariantBase64ReverseDict = {VariantBase64Table[i]: i for i in range(len(VariantBase64Table))} VariantBase64ReverseDict = {VariantBase64Table[i]: i for i in range(len(VariantBase64Table))}
def VariantBase64Encode(bs: bytes): def VariantBase64Encode(bs: bytes):
result = b'' result = b''
blocks_count, left_bytes = divmod(len(bs), 3) blocks_count, left_bytes = divmod(len(bs), 3)
@ -38,6 +41,7 @@ def VariantBase64Encode(bs : bytes):
result += block.encode() result += block.encode()
return result return result
def VariantBase64Decode(s: str): def VariantBase64Decode(s: str):
result = b'' result = b''
blocks_count, left_bytes = divmod(len(s), 4) blocks_count, left_bytes = divmod(len(s), 4)
@ -65,6 +69,7 @@ def VariantBase64Decode(s : str):
else: else:
raise ValueError('Invalid encoding.') raise ValueError('Invalid encoding.')
def EncryptBytes(key: int, bs: bytes): def EncryptBytes(key: int, bs: bytes):
result = bytearray() result = bytearray()
for i in range(len(bs)): for i in range(len(bs)):
@ -72,6 +77,7 @@ def EncryptBytes(key : int, bs : bytes):
key = result[-1] & key | 0x482D key = result[-1] & key | 0x482D
return bytes(result) return bytes(result)
def DecryptBytes(key: int, bs: bytes): def DecryptBytes(key: int, bs: bytes):
result = bytearray() result = bytearray()
for i in range(len(bs)): for i in range(len(bs)):
@ -79,20 +85,24 @@ def DecryptBytes(key : int, bs : bytes):
key = bs[i] & key | 0x482D key = bs[i] & key | 0x482D
return bytes(result) return bytes(result)
class LicenseType: class LicenseType:
Professional = 1 Professional = 1
Educational = 3 Educational = 3
Personal = 4 Personal = 4
def GenerateLicense(Type : LicenseType, Count : int, UserName : str, MajorVersion : int, MinorVersion):
def GenerateLicense(Type: int, Count: int, UserName: str, MajorVersion: int, MinorVersion):
assert (Count >= 0) assert (Count >= 0)
LicenseString = '%d#%s|%d%d#%d#%d3%d6%d#%d#%d#%d#' % (Type, LicenseString = '%d#%s|%d%d#%d#%d3%d6%d#%d#%d#%d#' % (
Type,
UserName, MajorVersion, MinorVersion, UserName, MajorVersion, MinorVersion,
Count, Count,
MajorVersion, MinorVersion, MinorVersion, MajorVersion, MinorVersion, MinorVersion,
0, # Unknown 0, # Unknown
0, # No Games flag. 0 means "NoGames = false". But it does not work. 0, # No Games flag. 0 means "NoGames = false". But it does not work.
0) # No Plugins flag. 0 means "NoPlugins = false". But it does not work. 0 # No Plugins flag. 0 means "NoPlugins = false". But it does not work.
)
EncodedLicenseString = VariantBase64Encode(EncryptBytes(0x787, LicenseString.encode())).decode() EncodedLicenseString = VariantBase64Encode(EncryptBytes(0x787, LicenseString.encode())).decode()
FileName = EncodedLicenseString.replace('/', '').replace('\\', '') FileName = EncodedLicenseString.replace('/', '').replace('\\', '')
with zipfile.ZipFile(FileName, 'w') as f: with zipfile.ZipFile(FileName, 'w') as f:
@ -136,8 +146,5 @@ def index():
return send_file('index.html') return send_file('index.html')
if __name__ == '__main__': if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=False) app.run(host='0.0.0.0', port=5000, debug=False)