From d603c4c267d605ecb4767e18073a72728fafbc49 Mon Sep 17 00:00:00 2001 From: thurask Date: Sat, 5 Aug 2017 10:25:42 -0400 Subject: [PATCH] --- tclcheck.py | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 tclcheck.py diff --git a/tclcheck.py b/tclcheck.py new file mode 100644 index 0000000..73739fb --- /dev/null +++ b/tclcheck.py @@ -0,0 +1,76 @@ +import hashlib +import random +import time +try: + from defusedxml import ElementTree +except (ImportError, AttributeError): + from xml.etree import ElementTree +import requests + + +def prep_sess(): + sess = requests.Session() + sess.headers.update({"User-Agent": "com.tcl.fota/5.1.0.2.0029.0, Android"}) + return sess + + +def salt(): + millis = round(time.time() * 1000) + tail = "{0:06d}".format(random.randint(0, 999999)) + return "{0}{1}".format(str(millis), tail) + + +def check(sess, serid, curef, fv="AAM481", mode=4, ftype="Firmware", cltp=2010, cktp=2, rtd=1, chnl=2): + geturl = "http://g2master-us-east.tctmobile.com/check.php" + params = {"id": serid, "curef": curef, "fv": fv, "mode": mode, "type": ftype, "cltp": cltp, "cktp": cktp, "rtd": rtd, "chnl": chnl} + req = sess.get(geturl, params=params) + if req.status_code == 200: + return(req.text) + + +def update_request(sess, serid, curef, tv, fwid, salt, vkh, fv="AAM481", mode=4, ftype="Firmware", cltp=2010): + posturl = "http://g2master-us-east.tctmobile.com/download_request.php" + params = {"id": serid, "curef": curef, "fv": fv, "mode": mode, "type": ftype, "tv": tv, "fw_id": fwid, "salt": salt, "vk": vkh, "cltp": cltp} + req = sess.post(posturl, data=params) + if req.status_code == 200: + return req.text + + +def vkhash(serid, curef, tv, fwid, salt, fv="AAM481", ftype="Firmware", mode=4, cltp=2010): + vdkey = "1271941121281905392291845155542171963889169361242115412511417616616958244916823523421516924614377131161951402261451161002051042011757216713912611682532031591181861081836612643016596231212872211620511861302106446924625728571011411121471811641125920123641181975581511602312222261817375462445966911723844130106116313122624220514" + query = "id={0}&salt={1}&curef={2}&fv={3}&tv={4}&type={5}&fw_id={6}&mode={7}&cltp={8}{9}".format(serid, salt, curef, fv, tv, ftype, fwid, mode, cltp, vdkey) + engine = hashlib.sha1() + engine.update(bytes(query, "utf-8")) + return engine.hexdigest() + + +def parse_check(body): + root = ElementTree.fromstring(body) + tv = root.find("VERSION").find("TV").text + fwid = root.find("FIRMWARE").find("FW_ID").text + fileinfo = root.find("FIRMWARE").find("FILESET").find("FILE") + filename = fileinfo.find("FILENAME").text + filesize = fileinfo.find("SIZE").text + filehash = fileinfo.find("CHECKSUM").text + return tv, fwid, filename, filesize, filehash + + +def parse_request(body): + root = ElementTree.fromstring(body) + slave = root.find("SLAVE_LIST").find("SLAVE").text + dlurl = root.find("FILE_LIST").find("FILE").find("DOWNLOAD_URL").text + return "http://{0}{1}".format(slave, dlurl) + + +if __name__ == "__main__": + sess = prep_sess() + serid = "543212345000000" + curef = "PRD-63116-001" + checktext = check(sess, serid, curef) + tv, fwid, filename, filesize, filehash = parse_check(checktext) + salt = salt() + vkh = vkhash(serid, curef, tv, fwid, salt) + updatetext = update_request(sess, serid, curef, tv, fwid, salt, vkh) + downloadurl = parse_request(updatetext) + print(filename) + print(downloadurl)