From a1ec7bf5c219de602a70cec3945815f55e09d2c9 Mon Sep 17 00:00:00 2001 From: malaohu Date: Sat, 27 Mar 2021 11:31:35 +0800 Subject: [PATCH] Add files via upload --- Dockerfile | 13 +++++ app.py | 124 +++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 1 + 3 files changed, 138 insertions(+) create mode 100644 Dockerfile create mode 100644 app.py create mode 100644 requirements.txt diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..72d9e9d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM python:3.6 + +MAINTAINER malaohu + +WORKDIR /usr/src/app + +COPY requirements.txt ./ + +RUN pip install --no-cache-dir -r requirements.txt + +COPY . . + +CMD [ "python", "./app.py" ] diff --git a/app.py b/app.py new file mode 100644 index 0000000..efcde65 --- /dev/null +++ b/app.py @@ -0,0 +1,124 @@ +#/usr/bin/env python3 + +import os, sys, zipfile +from flask import Flask +from flask import request +from flask import send_file +import os.path + +app = Flask(__name__) + +VariantBase64Table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=' +VariantBase64Dict = { i : VariantBase64Table[i] for i in range(len(VariantBase64Table)) } +VariantBase64ReverseDict = { VariantBase64Table[i] : i for i in range(len(VariantBase64Table)) } + +def VariantBase64Encode(bs : bytes): + result = b'' + blocks_count, left_bytes = divmod(len(bs), 3) + + for i in range(blocks_count): + coding_int = int.from_bytes(bs[3 * i:3 * i + 3], 'little') + block = VariantBase64Dict[coding_int & 0x3f] + block += VariantBase64Dict[(coding_int >> 6) & 0x3f] + block += VariantBase64Dict[(coding_int >> 12) & 0x3f] + block += VariantBase64Dict[(coding_int >> 18) & 0x3f] + result += block.encode() + + if left_bytes == 0: + return result + elif left_bytes == 1: + coding_int = int.from_bytes(bs[3 * blocks_count:], 'little') + block = VariantBase64Dict[coding_int & 0x3f] + block += VariantBase64Dict[(coding_int >> 6) & 0x3f] + result += block.encode() + return result + else: + coding_int = int.from_bytes(bs[3 * blocks_count:], 'little') + block = VariantBase64Dict[coding_int & 0x3f] + block += VariantBase64Dict[(coding_int >> 6) & 0x3f] + block += VariantBase64Dict[(coding_int >> 12) & 0x3f] + result += block.encode() + return result + +def VariantBase64Decode(s : str): + result = b'' + blocks_count, left_bytes = divmod(len(s), 4) + + for i in range(blocks_count): + block = VariantBase64ReverseDict[s[4 * i]] + block += VariantBase64ReverseDict[s[4 * i + 1]] << 6 + block += VariantBase64ReverseDict[s[4 * i + 2]] << 12 + block += VariantBase64ReverseDict[s[4 * i + 3]] << 18 + result += block.to_bytes(3, 'little') + + if left_bytes == 0: + return result + elif left_bytes == 2: + block = VariantBase64ReverseDict[s[4 * blocks_count]] + block += VariantBase64ReverseDict[s[4 * blocks_count + 1]] << 6 + result += block.to_bytes(1, 'little') + return result + elif left_bytes == 3: + block = VariantBase64ReverseDict[s[4 * blocks_count]] + block += VariantBase64ReverseDict[s[4 * blocks_count + 1]] << 6 + block += VariantBase64ReverseDict[s[4 * blocks_count + 2]] << 12 + result += block.to_bytes(2, 'little') + return result + else: + raise ValueError('Invalid encoding.') + +def EncryptBytes(key : int, bs : bytes): + result = bytearray() + for i in range(len(bs)): + result.append(bs[i] ^ ((key >> 8) & 0xff)) + key = result[-1] & key | 0x482D + return bytes(result) + +def DecryptBytes(key : int, bs : bytes): + result = bytearray() + for i in range(len(bs)): + result.append(bs[i] ^ ((key >> 8) & 0xff)) + key = bs[i] & key | 0x482D + return bytes(result) + +class LicenseType: + Professional = 1 + Educational = 3 + Persional = 4 + +def GenerateLicense(Type : LicenseType, Count : int, UserName : str, MajorVersion : int, MinorVersion): + assert(Count >= 0) + LicenseString = '%d#%s|%d%d#%d#%d3%d6%d#%d#%d#%d#' % (Type, + UserName, MajorVersion, MinorVersion, + Count, + MajorVersion, MinorVersion, MinorVersion, + 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() + with zipfile.ZipFile(EncodedLicenseString, 'w') as f: + f.writestr('Pro.key', data = EncodedLicenseString) + return EncodedLicenseString + + +@app.route('/') +def get_lc(): + name = request.args.get('name', '') + version = request.args.get('ver', '') + MajorVersion, MinorVersion = version.split('.')[0:2] + MajorVersion = int(MajorVersion) + MinorVersion = int(MinorVersion) + lc = GenerateLicense(LicenseType.Professional, 1, name, MajorVersion, MinorVersion) + return lc + +@app.route('/download/') +def download_lc(lc): + if lc and len(lc) > 5 and os.path.exists('./' + lc): + return send_file('./' + lc, + as_attachment=True, + attachment_filename='Custom.mxtpro') + else: + return "请确保生成成功后再来下载!" + +if __name__ == '__main__': + app.run(host='0.0.0.0', port=5000, debug=False) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..46a48dd --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +Flask==1.1.2