Skip to content

Commit 38f0902

Browse files
committed
Update pyfoxfile.py
1 parent 57c4f47 commit 38f0902

1 file changed

Lines changed: 43 additions & 17 deletions

File tree

pyfoxfile.py

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4240,19 +4240,44 @@ def ReadFileHeaderDataWithContent(fp, listonly=False, uncompress=True, skipcheck
42404240
fjsonchecksumtype = HeaderOut[30]
42414241
fjsonchecksum = HeaderOut[31]
42424242
fjsoncontent = {}
4243-
fprejsoncontent = fp.read(fjsonsize).decode("UTF-8")
4244-
if(fjsonsize > 0):
4245-
try:
4246-
fjsoncontent = json.loads(base64.b64decode(fprejsoncontent.encode("UTF-8")).decode("UTF-8"))
4247-
except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
4243+
if(fjsontype=="json"):
4244+
fjsoncontent = {}
4245+
fprejsoncontent = fp.read(fjsonsize).decode("UTF-8")
4246+
if(fjsonsize > 0):
42484247
try:
4249-
fjsoncontent = json.loads(fprejsoncontent)
4248+
fjsonrawcontent = base64.b64decode(fprejsoncontent.encode("UTF-8")).decode("UTF-8")
4249+
fjsoncontent = json.loads(base64.b64decode(fprejsoncontent.encode("UTF-8")).decode("UTF-8"))
42504250
except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
4251-
fprejsoncontent = ""
4252-
fjsoncontent = {}
4253-
else:
4254-
fprejsoncontent = ""
4255-
fjsoncontent = {}
4251+
try:
4252+
fjsonrawcontent = fprejsoncontent
4253+
fjsoncontent = json.loads(fprejsoncontent)
4254+
except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
4255+
fprejsoncontent = ""
4256+
fjsonrawcontent = fprejsoncontent
4257+
fjsoncontent = {}
4258+
else:
4259+
fprejsoncontent = ""
4260+
fjsonrawcontent = fprejsoncontent
4261+
fjsoncontent = {}
4262+
elif(fjsontype=="list"):
4263+
fprejsoncontent = fp.read(fjsonsize).decode("UTF-8")
4264+
flisttmp = MkTempFile()
4265+
flisttmp.write(fprejsoncontent.encode())
4266+
flisttmp.seek(0)
4267+
fjsoncontent = ReadFileHeaderData(flisttmp, fjsonlen, delimiter)
4268+
flisttmp.close()
4269+
fjsonrawcontent = fjsoncontent
4270+
if(fjsonlen==1):
4271+
try:
4272+
fjsonrawcontent = base64.b64decode(fjsoncontent[0]).decode("UTF-8")
4273+
fjsoncontent = json.loads(base64.b64decode(fjsoncontent[0]).decode("UTF-8"))
4274+
fjsonlen = len(fjsoncontent)
4275+
except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
4276+
try:
4277+
fjsonrawcontent = fjsoncontent[0]
4278+
fjsoncontent = json.loads(fjsoncontent[0])
4279+
except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
4280+
pass
42564281
fp.seek(len(delimiter), 1)
42574282
jsonfcs = GetFileChecksum(fprejsoncontent, fjsonchecksumtype, True, formatspecs)
42584283
if(jsonfcs != fjsonchecksum and not skipchecksum):
@@ -4773,7 +4798,7 @@ def ReadFileDataWithContentToArray(fp, filestart=0, seekstart=0, seekend=0, list
47734798
fnumextrafieldsize = int(inheader[6], 16)
47744799
fnumextrafields = int(inheader[7], 16)
47754800
fextrafieldslist = []
4776-
extrastart = 7
4801+
extrastart = 8
47774802
extraend = extrastart + fnumextrafields
47784803
while(extrastart < extraend):
47794804
fextrafieldslist.append(inheader[extrastart])
@@ -4926,10 +4951,10 @@ def ReadFileDataWithContentToList(fp, filestart=0, seekstart=0, seekend=0, listo
49264951
else:
49274952
inheader = ReadFileHeaderDataWoSize(
49284953
fp, formatspecs['format_delimiter'])
4929-
fnumextrafieldsize = int(inheader[5], 16)
4930-
fnumextrafields = int(inheader[6], 16)
4954+
fnumextrafieldsize = int(inheader[6], 16)
4955+
fnumextrafields = int(inheader[7], 16)
49314956
fextrafieldslist = []
4932-
extrastart = 7
4957+
extrastart = 8
49334958
extraend = extrastart + fnumextrafields
49344959
while(extrastart < extraend):
49354960
fextrafieldslist.append(inheader[extrastart])
@@ -4948,7 +4973,8 @@ def ReadFileDataWithContentToList(fp, filestart=0, seekstart=0, seekend=0, listo
49484973
fnumfields = int(inheader[1], 16)
49494974
fhencoding = inheader[2]
49504975
fostype = inheader[3]
4951-
fnumfiles = int(inheader[4], 16)
4976+
fpythontype = inheader[4]
4977+
fnumfiles = int(inheader[5], 16)
49524978
fprechecksumtype = inheader[-2]
49534979
fprechecksum = inheader[-1]
49544980
headercheck = ValidateHeaderChecksum([formstring] + inheader[:-1], fprechecksumtype, fprechecksum, formatspecs)
@@ -9419,7 +9445,7 @@ def FoxFileValidate(infile, fmttype="auto", filestart=0,
94199445

94209446
fnumextrafieldsize = int(inheader[6], 16)
94219447
fnumextrafields = int(inheader[7], 16)
9422-
extrastart = 7
9448+
extrastart = 8
94239449
extraend = extrastart + fnumextrafields
94249450
formversion = re.findall("([\\d]+)", formstring)
94259451
fheadsize = int(inheader[0], 16)

0 commit comments

Comments
 (0)