Update app.py
1. Format codes 2. GenerateLicense takes int rather than LicenseType typepull/15/head
parent
d1f202b785
commit
bcd98e8143
55
app.py
55
app.py
|
@ -1,16 +1,19 @@
|
||||||
#/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__)
|
||||||
|
|
||||||
VariantBase64Table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
|
VariantBase64Table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
|
||||||
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,7 +41,8 @@ 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,38 +69,44 @@ 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)):
|
||||||
result.append(bs[i] ^ ((key >> 8) & 0xff))
|
result.append(bs[i] ^ ((key >> 8) & 0xff))
|
||||||
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)):
|
||||||
result.append(bs[i] ^ ((key >> 8) & 0xff))
|
result.append(bs[i] ^ ((key >> 8) & 0xff))
|
||||||
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):
|
|
||||||
assert(Count >= 0)
|
def GenerateLicense(Type: int, Count: int, UserName: str, MajorVersion: int, MinorVersion):
|
||||||
LicenseString = '%d#%s|%d%d#%d#%d3%d6%d#%d#%d#%d#' % (Type,
|
assert (Count >= 0)
|
||||||
UserName, MajorVersion, MinorVersion,
|
LicenseString = '%d#%s|%d%d#%d#%d3%d6%d#%d#%d#%d#' % (
|
||||||
Count,
|
Type,
|
||||||
MajorVersion, MinorVersion, MinorVersion,
|
UserName, MajorVersion, MinorVersion,
|
||||||
0, # Unknown
|
Count,
|
||||||
0, # No Games flag. 0 means "NoGames = false". But it does not work.
|
MajorVersion, MinorVersion, MinorVersion,
|
||||||
0) # No Plugins flag. 0 means "NoPlugins = false". But it does not work.
|
0, # Unknown
|
||||||
|
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.
|
||||||
|
)
|
||||||
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:
|
||||||
f.writestr('Pro.key', data = EncodedLicenseString)
|
f.writestr('Pro.key', data=EncodedLicenseString)
|
||||||
return FileName
|
return FileName
|
||||||
|
|
||||||
|
|
||||||
|
@ -119,8 +129,8 @@ def get_lc():
|
||||||
def download_lc(lc):
|
def download_lc(lc):
|
||||||
if lc and len(lc) > 5 and os.path.exists('./' + lc):
|
if lc and len(lc) > 5 and os.path.exists('./' + lc):
|
||||||
return send_file(lc,
|
return send_file(lc,
|
||||||
as_attachment=True,
|
as_attachment=True,
|
||||||
attachment_filename='Custom.mxtpro')
|
attachment_filename='Custom.mxtpro')
|
||||||
else:
|
else:
|
||||||
return "请检查用户名版本号是否正确!"
|
return "请检查用户名版本号是否正确!"
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue