Download directly the recovery_ramdisk image needed for Magisk, the system or any other image from the Huawei official website with proper CRC checking.
Scan and show details about latest firmwares for your device.
Usage examples :
-> To download only the recovery_ramdisk for magisk and the kernel images on the Mediapad M5 Pro's current firmware (update.hicloud.com/TDS/data/files/p3/s15/G3776/g1699/v252687/f1/full/filelist.xml) :
python3 script.py 3776 1699 252687 1 recovery_ramdisk kernel
-> To scan or check for latest Huawei Firmwares in the ranges /G3776/ ; /g1699/ ; /v260000/ to /v280000/ ; /f1/ :
replace first lines 1-10 with :
Install :
install python3
pip3 install requests crcmod
Script :
Scan and show details about latest firmwares for your device.
Usage examples :
-> To download only the recovery_ramdisk for magisk and the kernel images on the Mediapad M5 Pro's current firmware (update.hicloud.com/TDS/data/files/p3/s15/G3776/g1699/v252687/f1/full/filelist.xml) :
python3 script.py 3776 1699 252687 1 recovery_ramdisk kernel
-> To scan or check for latest Huawei Firmwares in the ranges /G3776/ ; /g1699/ ; /v260000/ to /v280000/ ; /f1/ :
replace first lines 1-10 with :
Code:
# mgg is the scan range for G : /G3776/
mgg = [3776, 3776]
# mg is the scan range for g : /g1699/
mg = [1699, 1699]
# mv is the scan range for v : /v252687/
mv = [260000, 280000]
# mf is the scan range for f : /f1/
mf = [1, 1]
Install :
install python3
pip3 install requests crcmod
Script :
Code:
# e.g. : http://update.hicloud.com:8180/TDS/data/files/p3/s15/G3776/g1699/v252687/f1/full/filelist.xml
# mgg is the scan range for G : /G3776/
mgg = [3776, 3776]
# mg is the scan range for g : /g1699/
mg = [1699, 1699]
# mv is the scan range for v : /v252687/
mv = [200000, 300000]
# mf is the scan range for f : /f1/
mf = [1, 1]
# the more threads the heavier the upload
NumberOfThreads=20
# dig +short update.hicloud.com
updatehost="update.hicloud.com"
updateServerAddressList=[
"211.152.136.73",
"211.152.136.75",
"211.152.136.30",
"211.152.137.18",
"211.152.137.14",
"211.152.137.16",
"211.152.136.11",
"211.152.136.74",
"211.152.137.15",
"211.152.136.76",
"211.152.136.29",
"211.152.136.41",
"211.152.137.17",
]
#updatehost="update.dbankcdn.com"
# dig +short update.dbankcdn.com
#updateServerAddressList=[
#"152.195.132.192",
#]
directDownloadHost = "update.dbankcdn.com"
# dig +short query.hicloud.com
queryServerAddress="80.158.19.121"
# RSA : IMEI
myIMEI=""
# look for the image inside following *.APP (UPDATE.APP, USERDATA.APP, PTABLE.APP)
LookForFirmwareInsideAPP = "UPDATE.APP"
'''
sort -r scanfound.html > result.tmp ; echo "<html><head><style>table { font-family: Sans-Serif; white-space: nowrap; font-size:9px; border-collapse: separate; border-spacing: 10px 0px;}</style></head><body><table>`cat result.tmp`</table></body></html>" > result.html ; rm result.tmp ; firefox result.html
'''
import time
import requests
import sys
import threading
import queue
import random
import json
import re
import os
import base64
import io
import struct
import datetime
import zlib
import crcmod
'''
latest valid version for device http://query.hicloud.com:80/sp_ard_common/v1/onestopCheck.action?verType=true
QueryServerURL http://query.hicloud.com:80/sp_ard_common/v2/Check.action?latest=true
RetrieveAuthInfoURL http://query.hicloud.com:80/sp_ard_common/v1/authorize.action
ReportStatusURL http://query.hicloud.com:80/sp_ard_common/v2/UpdateReport.action
'''
def getauthorizeaction(s, versionId):
headers1 = {
'User-Agent': useragent,
'Host' : "query.hicloud.com",
'Accept': 'application/json; charset=UTF-8',
'X-Requested-With': 'XMLHttpRequest',
'Connection': 'keep-alive'
}
url1="http://"+queryServerAddress+"/sp_ard_common/v1/authorize.action"
data1={
"deviceId" : "null",
"imei" : myIMEI,
"updateToken" : "null",
"vendor" : "null",
"ver" : "1",
"version" : [
{
"versionId" : versionId,
}
]
}
payload = json.dumps(data1)
while True :
try:
r = s.post(url=url1, data=payload, headers=headers1, allow_redirects=False, timeout=6)
if r.status_code == 200 :
reponse=str(r.content, encoding="utf-8")
rep=re.fullmatch(r'data=(.*?)&sign=(.*?)&cert=(.*?)', reponse)
if rep is not None :
dataout={
"data" : json.loads(base64.b64decode(rep.group(1))),
"sign" : base64.b64decode(rep.group(2)),
"cert" : base64.b64decode(rep.group(3))
}
return dataout
except Exception as e:
print("getauthorizeaction error : "+str(e))
time.sleep(1)
mystartbytes = 187
mymagicnum = "187"
myunknown = "187"
myunlockcode = "187"
def extractimg(source, outdir) :
global mymagicnum, myunknown, myunlockcode, downloadramdisk, mystartbytes
sourcel = source.tell()
source.seek(0)
i = 0
if sourcel < 20 :
return None, 0, 20
startbytes = source.read(4)
i += 4
hasstartbytes = False
while startbytes == b'\x00\x00\x00\x00' :
hasstartbytes = True
startbytes = source.read(4)
i += 4
if hasstartbytes and mystartbytes != int(i/4) :
mystartbytes = int(i/4)
print("Start Bytes : " + str(b'\x00\x00\x00\x00') + " * " + str(int(i/4)))
magicnum = startbytes
while True :
if not magicnum :
break
if magicnum != mymagicnum :
mymagicnum = magicnum
print("Magic Number : " + str(magicnum))
j = i-4
headersize = list(struct.unpack('<L', source.read(4)))[0]
if j + headersize > sourcel :
return None, j, j + headersize + 20
i += 4
unknown = source.read(4)
if unknown != myunknown :
myunknown = unknown
print("Unkown : " + str(unknown))
i += 4
unlockcode = source.read(8)
if unlockcode != myunlockcode :
myunlockcode = unlockcode
print("Unlockcode : " + str(unlockcode))
i += 8
moduleid = list(struct.unpack('<L', source.read(4)))[0]
i += 4
filesize = list(struct.unpack('<L', source.read(4)))[0]
if j + headersize + filesize > sourcel :
return None, j, j + headersize + filesize + 20
i += 4
date = str(source.read(16), encoding='utf-8').rstrip('\x00')
date = re.sub(r'(\d\d\d\d)\.(\d\d)\.(\d\d)', r'\3/\2/\1', date)
i += 16
time = str(source.read(16), encoding='utf-8').rstrip('\x00')
time = re.sub(r'(\d\d)\.(\d\d)\.(\d\d)', r'\1:\2:\3', time)
i += 16
filename = str(source.read(32), encoding='utf-8').rstrip('\x00').lower()
i += 32
headercsum = source.read(2)
i += 2
blocksize = list(struct.unpack('<H', source.read(2)))[0]
i += 2
blank2 = source.read(2)
if blank2 != b'\x00\x00' :
print("blank2 = " % (blank2))
i += 2
crcdatasize = headersize - (i-j)
crcdata = source.read(crcdatasize)
i+=crcdatasize
if len(downloadramdisk) == 0 :
if filename == "sha256rsa" :
return date, j, 0
else :
crcgood = "success : calculated CRC does match Huawei's"
with open(outdir+os.sep+filename+'.img', 'wb') as out :
s = 0
c = 0
readl = 4096
while s < filesize :
if s + readl > filesize :
readl = filesize - s
readdata = source.read(readl)
i += readl
crcv = crc(readdata)
if crcdata[c] != (crcv & 0xff) or crcdata[c+1] != ((crcv>>8) & 0xff) :
crcgood = "ERROR : calculated CRC does not match Huawei's"
out.write(readdata)
c += 2
s += 4096
print("%12d header %12d file %12d %32s %12s %8s %8x %4d %s" % (i-filesize-headersize, headersize, filesize, filename, date, time, moduleid, blocksize, crcgood))
if len(downloadramdisk) > 0 :
if filename in downloadramdisk :
downloadramdisk.remove(filename)
print(filename + " checked and saved as "+outdir+os.sep+filename+'.img')
if len(downloadramdisk) == 0 :
return date, j, 0
alignment_padding = (4 - i % 4) % 4
if alignment_padding :
source.seek(alignment_padding, 1)
i += alignment_padding
if i+4 > sourcel :
return date, i, 0
magicnum = source.read(4)
i += 4
return "2015", 0, 0
def downloadonlypartofzip(s, page, fich, debut, fin, appname) :
url1="http://"+directDownloadHost+"/TDS/data/files/p3/s15/G"+str(page[0])+"/g"+str(page[1])+"/v"+str(page[2])+"/f"+str(page[3])+"/full/"+fich
headers1 = {
'Host' : directDownloadHost,
'User-Agent': useragent,
'Connection': 'keep-alive',
'Range': 'bytes='+str(debut)+'-'+str(fin),
}
outdir = ""
if len(downloadramdisk) > 0 :
outdir = "G"+str(page[0])+"_g"+str(page[1])+"_v"+str(page[2])+"_f"+str(page[3])+os.sep+fich.replace("/", " ")+os.sep+appname
os.makedirs(outdir, exist_ok=True)
status = -1
while True :
status=0
filebytesl=0
r = None
try :
r = s.get(url=url1, headers=headers1, allow_redirects=False, stream=True, timeout=60)
status = r.status_code
except Exception as e :
print("\n downloadonlypartofzip erreur : "+str(e)+" : "+url1)
if status == 206 :
needminimum = 8192
r.raw.decode_content = True
z = zlib.decompressobj(wbits=-zlib.MAX_WBITS)
cherchencore = True
oltime = time.time()
fout = None
if len(downloadramdisk) > 0 :
fout = open("removethis.tmp", "w+b")
else :
fout = io.BytesIO(b'')
while cherchencore :
buf = z.unconsumed_tail
if buf == b'' :
buf = r.raw.read(8192)
if buf == b'' :
cherchencore = False
extr = z.decompress(buf)
if extr == b'':
cherchencore = False
fout.write(extr)
currentpos = fout.tell()
if time.time() - oltime > 1 :
oltime = time.time()
print("%10.1f MB < %.1f MB needed" % (currentpos/1000000.0, needminimum/1000000.0), end="\r")
if currentpos >= needminimum or not cherchencore :
foundit, stripuntil, needminimum = extractimg(fout, outdir)
if foundit is not None :
if len(downloadramdisk) == 0 :
fout.close()
return foundit
else :
fout.close()
return foundit
fout.seek(stripuntil)
if len(downloadramdisk) > 0 :
fout2 = open("removethis2.tmp", "w+b")
else :
fout2 = io.BytesIO(b'')
fout2.write(fout.read())
fout.close()
fout2.seek(0)
if len(downloadramdisk) > 0 :
fout = open("removethis.tmp", "w+b")
else :
fout = io.BytesIO(b'')
fout.write(fout2.read())
fout2.close()
fout.close()
time.sleep(1)
def getzipfilelist(s, page, fich, debut, fin):
updateServerAddress = updateServerAddressList[random.randint(0, len(updateServerAddressList)-1)]
url1="http://"+updateServerAddress+"/TDS/data/files/p3/s15/G"+str(page[0])+"/g"+str(page[1])+"/v"+str(page[2])+"/f"+str(page[3])+"/full/"+fich
headers1 = {
'Host' : updatehost,
'User-Agent': useragent,
'Connection': 'keep-alive',
'Range': 'bytes='+str(debut)+'-'+str(fin),
}
status = -1
while True :
status=0
filebytes=b''
filebytesl=0
try :
r = s.get(url=url1, headers=headers1, allow_redirects=False, stream=True, timeout=6)
status = r.status_code
if status == 206 :
for chunk in r.iter_content(chunk_size=8192) :
if chunk : # filter out keep-alive new chunks
filebytes += chunk
except Exception as e :
print("\n getzipfilelist erreur : "+str(e)+" : "+url1)
if status == 206 :
filezipdata={
"realdate" : "",
"version" : "",
"tag" : ""
}
i = 0
filebytesl = len(filebytes) - 1
while i < filebytesl :
compressionmethod = list(struct.unpack('<H', filebytes[i+10:i+10+2]))[0]
lastmodifdate = list(struct.unpack('<H', filebytes[i+14:i+14+2]))[0]
lastmodifdate = "%02d/%02d/%04d" % ((lastmodifdate>>11), (lastmodifdate>>7)&0b1111, 6+1980+(lastmodifdate&0b1111111))
compressedsize = list(struct.unpack('<L', filebytes[i+20:i+20+4]))[0]
uncompressedsize = list(struct.unpack('<L', filebytes[i+24:i+24+4]))[0]
filenamelength = list(struct.unpack('<H', filebytes[i+28:i+28+2]))[0]
extrafieldlength = list(struct.unpack('<H', filebytes[i+30:i+30+2]))[0]
filecommentlength = list(struct.unpack('<H', filebytes[i+32:i+32+2]))[0]
relativeoffset = list(struct.unpack('<L', filebytes[i+42:i+42+4]))[0]
filename = str(filebytes[i+46:i+46+filenamelength], encoding="utf-8").rstrip('\x00')
extrafield = filebytes[i+46+filenamelength:i+46+filenamelength+extrafieldlength]
filecomment = filebytes[i+46+filenamelength+extrafieldlength:i+46+filenamelength+extrafieldlength+filecommentlength]
#print("%s : %s ; uncompressed %d ; compressed %d ; offset %d" % (str(filename), lastmodifdate, uncompressedsize, compressedsize, relativeoffset))
if compressionmethod == 0 :
if uncompressedsize > 0 :
if filename == "VERSION.mbn" :
myversion = getfilecontent(s, page, fich, relativeoffset+30+filenamelength, relativeoffset+30+filenamelength+uncompressedsize-1)
myversion = str(myversion, encoding="utf-8").rstrip('\x00')
if len(myversion) > 0 :
if myversion[-1]=='\n' :
myversion = myversion[:-1]
filezipdata["version"] = myversion
elif filename == "UPT_VER.tag" :
prg=0
elif filename.endswith(".tag") :
mytag = getfilecontent(s, page, fich, relativeoffset+30+filenamelength, relativeoffset+30+filenamelength+uncompressedsize-1)
mytag = str(mytag, encoding="utf-8").rstrip('\x00')
if len(mytag) > 0 :
if mytag[-1]=='\n' :
mytag = mytag[:-1]
filezipdata["tag"] += mytag.lower() + " "
elif compressionmethod == 8 :
if filename == LookForFirmwareInsideAPP :
filezipdata["realdate"] = downloadonlypartofzip(s, page, fich, relativeoffset+30+filenamelength, relativeoffset+30+filenamelength+compressedsize-1, filename)
elif downloadeverything and filename.endswith(".APP") :
downloadonlypartofzip(s, page, fich, relativeoffset+30+filenamelength, relativeoffset+30+filenamelength+compressedsize-1, filename)
else :
print("new compression method : %d" % ())
i +=46+filenamelength+extrafieldlength+filecommentlength
return filezipdata
time.sleep(1)
def getfilecontent(s, page, fich, debut, fin):
updateServerAddress = updateServerAddressList[random.randint(0, len(updateServerAddressList)-1)]
url1="http://"+updateServerAddress+"/TDS/data/files/p3/s15/G"+str(page[0])+"/g"+str(page[1])+"/v"+str(page[2])+"/f"+str(page[3])+"/full/"+fich
headers1 = {
'Host' : updatehost,
'User-Agent': useragent,
'Connection': 'keep-alive',
'Range': 'bytes='+str(debut)+'-'+str(fin),
}
status = -1
while True :
status=0
filebytes=b''
filebytesl=0
try :
r = s.get(url=url1, headers=headers1, allow_redirects=False, stream=True, timeout=6)
status = r.status_code
if status == 206 :
for chunk in r.iter_content(chunk_size=8192) :
if chunk :
filebytes += chunk
except Exception as e :
print("\n getfilecontent erreur : "+str(e)+" : "+url1)
if status == 206 :
return filebytes
time.sleep(1)
def getzipinfo(s, page, fich, fichtaille):
updateServerAddress = updateServerAddressList[random.randint(0, len(updateServerAddressList)-1)]
url1="http://"+updateServerAddress+"/TDS/data/files/p3/s15/G"+str(page[0])+"/g"+str(page[1])+"/v"+str(page[2])+"/f"+str(page[3])+"/full/"+fich
fin = int(fichtaille)
debut = fin - 8192
headers1 = {
'Host' : updatehost,
'User-Agent': useragent,
'Connection': 'keep-alive',
'Range': 'bytes='+str(debut)+'-'+str(fin),
}
status = -1
while True :
status=0
filebytes=b''
filebytesl=0
texte=""
try :
r = s.get(url=url1, headers=headers1, allow_redirects=False, stream=True, timeout=6)
status = r.status_code
if status == 206 :
for chunk in r.iter_content(chunk_size=8192) :
if chunk :
filebytes += chunk
except Exception as e :
print("\n getzipinfo erreur : "+str(e)+" : "+url1)
if status == 206 :
filebytesl = len(filebytes) - 4
eocd = -1
i = 0
while i < filebytesl :
if filebytes[i:i+4] == b'PK\05\06' :
eocd = i
i += 4
i += 1
if eocd != -1 :
cdfh = list(struct.unpack('<L', filebytes[eocd+16:eocd+16+4]))[0]
cdfhl = list(struct.unpack('<L', filebytes[eocd+12:eocd+12+4]))[0]
return getzipfilelist(s, page, fich, cdfh, cdfh+cdfhl)
return []
time.sleep(1)
def getsechtml(s, page, fich):
updateServerAddress = updateServerAddressList[random.randint(0, len(updateServerAddressList)-1)]
url1="http://"+updateServerAddress+"/TDS/data/files/p3/s15/G"+str(page[0])+"/g"+str(page[1])+"/v"+str(page[2])+"/f"+str(page[3])+"/full/"+fich
headers1 = {
'Host' : updatehost,
'User-Agent': useragent,
'Connection': 'keep-alive'
}
status = -1
while True :
status=0
texte=""
try :
r = s.get(url=url1, headers=headers1, allow_redirects=False, timeout=6)
status = r.status_code
if status == 200 :
texte = str(r.content, encoding="utf-8")
except Exception as e :
print("\n getsechtml erreur : "+str(e)+" : "+url1)
if status == 200 :
version=re.search(r'<component .*?version=\"(.*?)\"/>', texte)
if version is not None :
version=version.group(1)
else :
version=""
language=re.search(r'<default-language name="(.*?)\"', texte)
if language is not None :
language=language.group(1)
else :
print(texte[:200])
language=""
return version, language
time.sleep(1)
def gethtml(s, page, fich):
updateServerAddress = updateServerAddressList[random.randint(0, len(updateServerAddressList)-1)]
url1="http://"+updateServerAddress+"/TDS/data/files/p3/s15/G"+str(page[0])+"/g"+str(page[1])+"/v"+str(page[2])+"/f"+str(page[3])+"/full/"+fich
headers1 = {
'Host' : updatehost,
'User-Agent': useragent,
'Connection': 'keep-alive'
}
status = -1
while True :
status=0
texte=""
try:
r = s.get(url=url1, headers=headers1, allow_redirects=False, timeout=6)
status = r.status_code
if status == 200 :
texte = str(r.content, encoding="utf-8")
except Exception as e :
print("\n gethtml erreur : "+str(e)+" : "+url1)
if status == 200 :
maxStashInfo=re.search(r'<maxStashInfo>(.*?)</maxStashInfo>', texte)
if maxStashInfo is not None :
maxStashInfo=maxStashInfo.group(1)
else :
maxStashInfo = ""
partitionName=re.search(r'<partitionName>(.*?)</partitionName>', texte)
if partitionName is not None :
partitionName=partitionName.group(1)
else :
partitionName = ""
value = re.search(r'<value>(.*?)</value>', texte)
if value is not None :
value = value.group(1)
else :
value = ""
packagetype=re.search(r'<packagetype>(.*?)</packagetype>', texte)
if packagetype is not None :
packagetype=packagetype.group(1)
else :
packagetype = ""
fileinfo=re.finditer(r'<file>.*?<spath>(.*?)</spath>.*?<md5>(.*?)</md5>.*?<size>(.*?)</size>.*?</file>', texte, re.S)
listefichier={}
for info in fileinfo :
zipname=info.group(1)
if zipname.endswith(".zip") :
listefichier[zipname]={"md5" : info.group(2) , "size" : info.group(3)}
vendorinfo=re.finditer(r'<vendorInfo (.*?)>', texte)
version=""
language=""
for info in vendorinfo :
info = info.group(1)
vendoritem=re.finditer(r'([^ =]+)=\"(.*?)\"', info)
listevendorinfodata={"logfile":"", "name":"", "newData":"", "package":""}
for vendordata in vendoritem :
listevendorinfodata[vendordata.group(1)]=vendordata.group(2)
logfilelen=len(listevendorinfodata["logfile"])
logfile=listevendorinfodata["logfile"]
subpath=listevendorinfodata["subpath"]
if len(subpath) > 0 :
logfile = subpath+"/"+logfile
listevendorinfodata["logfile"] = logfile
if listevendorinfodata["package"] in listefichier :
for vendordata in listevendorinfodata :
listefichier[listevendorinfodata["package"]][vendordata] = listevendorinfodata[vendordata]
if vendordata == "package" :
if len(subpath) > 0 :
listefichier[listevendorinfodata["package"]][vendordata] = subpath+"/"+listevendorinfodata[vendordata]
if logfilelen > 0 :
version, language = getsechtml(s, page, logfile)
authorized = getauthorizeaction(s, str(page[2]))
approvedstatus=""
versionNumber=""
if authorized["data"]["approvedVersionList"][0]["status"] == "0" :
versionNumber=authorized["data"]["approvedVersionList"][0]["versionNumber"]
approvedstatus="approved"
else :
versionNumber=""
approvedstatus=""
zipinfo = {}
for fichier in listefichier :
zipinfo[fichier] = getzipinfo(s, page, listefichier[fichier]["package"], listefichier[fichier]["size"])
with lock :
with open("scanfound.html", "a") as hout :
with open("scanfound.txt", "a") as fout :
mybaseaddress = "http://update.hicloud.com/TDS/data/files/p3/s15/G"+str(page[0])+"/g"+str(page[1])+"/v"+str(page[2])+"/f"+str(page[3])+"/full/"
strung = "%83s " % (mybaseaddress)
strong = "<tr><td><a href='"+mybaseaddress+"filelist.xml'>G"+str(page[0])+"/g"+str(page[1])+"/v"+str(page[2])+"/f"+str(page[3])+"/"+"</a></td>"
print(strung)
fout.write(strung)
hout.write(strong)
strung = "%65s %45s %15s %15s %15s %20s " % (
version,
versionNumber,
packagetype,
partitionName,
approvedstatus,
"size "+value
)
strong = "<td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td>" % (
version,
versionNumber,
packagetype,
partitionName,
approvedstatus,
"size "+value
)
print(strung)
fout.write(strung)
hout.write(strong)
premier=True
for fichier in listefichier :
if premier :
strung = "%16s %45s " % (zipinfo[fichier]["realdate"], zipinfo[fichier]["version"])
strong = "<td>%s</td><td>%s</td>" % (zipinfo[fichier]["realdate"], zipinfo[fichier]["version"])
print(strung)
fout.write(strung)
hout.write(strong)
strung = "( %30s %65s %20s %40s %55s %20s %62s ) " % (
listefichier[fichier]["name"],
listefichier[fichier]["package"],
"size "+listefichier[fichier]["size"],
"md5 "+listefichier[fichier]["md5"],
listefichier[fichier]["logfile"],
"newData "+listefichier[fichier]["newData"],
zipinfo[fichier]["tag"]
)
strong = "<td>(</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>)</td>" % (
listefichier[fichier]["name"],
"<a href='"+mybaseaddress+listefichier[fichier]["package"]+"'>"+listefichier[fichier]["package"]+"</a>",
"size "+listefichier[fichier]["size"],
"md5 "+listefichier[fichier]["md5"],
"<a href='"+mybaseaddress+listefichier[fichier]["logfile"]+"'>"+listefichier[fichier]["logfile"]+"</a>",
"newData "+listefichier[fichier]["newData"],
zipinfo[fichier]["tag"]
)
print(strung)
fout.write(strung)
hout.write(strong)
if premier :
strung = " %10s %35s " % (language, "maxStashInfo "+maxStashInfo)
strong = "<td>%10s</td><td>%s</td>" % (language, "maxStashInfo "+maxStashInfo)
print(strung)
fout.write(strung)
hout.write(strong)
if premier :
premier=False
fout.write("\n")
hout.write("</tr>\n")
return status
time.sleep(1)
def gethtmlcode(s, page, fich) :
updateServerAddress = updateServerAddressList[random.randint(0, len(updateServerAddressList)-1)]
url1="http://"+updateServerAddress+"/TDS/data/files/p3/s15/G"+str(page[0])+"/g"+str(page[1])+"/v"+str(page[2])+"/f"+str(page[3])+"/full/"+fich
headers1 = {
'Host' : updatehost,
'User-Agent': useragent,
'Connection': 'keep-alive'
}
while True :
status = 0
try :
r = s.get(url=url1, headers=headers1, allow_redirects=False, timeout=6)
status = r.status_code
except Exception as e :
with lock :
print(".", end="")
if status == 200 :
gethtml(s, page, fich)
return status
elif status == 404 :
return status
time.sleep(1)
def worker() :
global cpt, lastcheck
while True :
page=q.get()
cpt+=1
result = 0
s = requests.Session()
result = gethtmlcode(s, page, "filelist.xml")
s.close()
if result is None :
with lock :
print("\nerreur avec : "+url)
elif result == 200 :
with lock :
print("\nfound : %8d %8d %8d %8d " % (page[0], page[1], page[2], page[3]))
if time.time() - lastcheck > 2 :
lastcheck = time.time()
with lock :
print("%6d : %8d %8d %8d %8d " % (cpt, page[0], page[1], page[2], page[3]), end="\r")
q.task_done()
s.close()
downloadeverything = False
downloadramdisk = []
sysargvl = len(sys.argv)
if sysargvl >= 5 :
NumberOfThreads = 1
mgg[0] = int(sys.argv[1])
mgg[1] = mgg[0]
mg[0] = int(sys.argv[2])
mg[1] = mg[0]
mv[0] = int(sys.argv[3])
mv[1] = mv[0]
mf[0] = int(sys.argv[4])
mf[1] = mf[0]
if sysargvl > 5 :
for k in range(5, sysargvl, 1) :
downloadramdisk.append(sys.argv[k])
print("download image : "+str(downloadramdisk))
else :
downloadeverything = True
downloadramdisk = ["thisfirmwaredoesntexist"]
print("download and extract everything")
cpt = 0
lastcheck=time.time()
useragent="HwOUCDownloadManager"
lock = threading.Lock()
crc = crcmod.mkCrcFun(0x11021, initCrc=0x0000, xorOut=0xFFFF)
q = queue.Queue()
for i in range(NumberOfThreads) :
t = threading.Thread(target=worker)
t.daemon = True
t.start()
moncpt=0
for ngg in range(mgg[0], 1+mgg[1], 1) :
for ng in range(mg[0], 1+mg[1], 1) :
for nv in range(mv[0], 1+mv[1], 1) :
for nf in range(mf[0], 1+mf[1], 1) :
moncpt+=1
q.put([ngg, ng, nv, nf])
while moncpt > cpt+NumberOfThreads*2 :
# speed & ram limit
time.sleep(0.2)
q.join()
if os.path.exists('removethis.tmp') :
os.remove('removethis.tmp')
if os.path.exists('removethis2.tmp') :
os.remove('removethis2.tmp')
Last edited: