Skip to content

Commit decf3d0

Browse files
Add files via upload
1 parent 3976fab commit decf3d0

File tree

2 files changed

+111
-34
lines changed

2 files changed

+111
-34
lines changed

pyneofile.py

Lines changed: 55 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4640,7 +4640,7 @@ def ReadFileHeaderDataWoSize(fp, delimiter=_default_delim(None)):
46404640
return first_two + headerdata
46414641

46424642

4643-
def ReadFileHeaderDataWithContent(fp, listonly=False, uncompress=True, skipchecksum=False, formatspecs=__file_format_dict__, saltkey=None):
4643+
def ReadFileHeaderDataWithContent(fp, listonly=False, contentasfile=False, uncompress=True, skipchecksum=False, formatspecs=__file_format_dict__, saltkey=None):
46444644
if(not hasattr(fp, "read")):
46454645
return False
46464646
delimiter = formatspecs['format_delimiter']
@@ -4657,15 +4657,41 @@ def ReadFileHeaderDataWithContent(fp, listonly=False, uncompress=True, skipcheck
46574657
fcs = HeaderOut[-2].lower()
46584658
fccs = HeaderOut[-1].lower()
46594659
fsize = int(HeaderOut[7], 16)
4660-
fcompression = HeaderOut[14]
4661-
fcsize = int(HeaderOut[15], 16)
4662-
fseeknextfile = HeaderOut[26]
4663-
fjsontype = HeaderOut[27]
4664-
fjsonlen = int(HeaderOut[28], 16)
4665-
fjsonsize = int(HeaderOut[29], 16)
4666-
fjsonchecksumtype = HeaderOut[30]
4667-
fjsonchecksum = HeaderOut[31]
4668-
fjsoncontent = {}
4660+
fcompression = HeaderOut[17]
4661+
fcsize = int(HeaderOut[18], 16)
4662+
fseeknextfile = HeaderOut[28]
4663+
fjsontype = HeaderOut[29]
4664+
fjsonlen = int(HeaderOut[30], 16)
4665+
fjsonsize = int(HeaderOut[31], 16)
4666+
fjsonchecksumtype = HeaderOut[32]
4667+
fjsonchecksum = HeaderOut[33]
4668+
fextrasize = int(HeaderOut[34], 16)
4669+
fextrafields = int(HeaderOut[35], 16)
4670+
fextrafieldslist = []
4671+
extrastart = 36
4672+
extraend = extrastart + fextrafields
4673+
while(extrastart < extraend):
4674+
fextrafieldslist.append(HeaderOut[extrastart])
4675+
extrastart = extrastart + 1
4676+
fvendorfieldslist = []
4677+
fvendorfields = 0;
4678+
if((len(HeaderOut) - 4)>extraend):
4679+
extrastart = extraend
4680+
extraend = len(HeaderOut) - 4
4681+
while(extrastart < extraend):
4682+
fvendorfieldslist.append(HeaderOut[extrastart])
4683+
extrastart = extrastart + 1
4684+
fvendorfields = fvendorfields + 1
4685+
if(fextrafields==1):
4686+
try:
4687+
fextrafieldslist = json.loads(base64.b64decode(fextrafieldslist[0]).decode("UTF-8"))
4688+
fextrafields = len(fextrafieldslist)
4689+
except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
4690+
try:
4691+
fextrafieldslist = json.loads(fextrafieldslist[0])
4692+
except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
4693+
pass
4694+
fjstart = fp.tell()
46694695
if(fjsontype=="json"):
46704696
fjsoncontent = {}
46714697
fprejsoncontent = fp.read(fjsonsize).decode("UTF-8")
@@ -4732,31 +4758,37 @@ def ReadFileHeaderDataWithContent(fp, listonly=False, uncompress=True, skipcheck
47324758
except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
47334759
pass
47344760
fp.seek(len(delimiter), 1)
4761+
fjend = fp.tell() - 1
47354762
jsonfcs = GetFileChecksum(fprejsoncontent, fjsonchecksumtype, True, formatspecs, saltkey)
47364763
if(not CheckChecksums(fjsonchecksum, jsonfcs) and not skipchecksum):
47374764
VerbosePrintOut("File JSON Data Checksum Error with file " +
47384765
fname + " at offset " + str(fheaderstart))
47394766
VerbosePrintOut("'" + fjsonchecksum + "' != " + "'" + jsonfcs + "'")
47404767
return False
4741-
fp.seek(len(delimiter), 1)
4768+
fcs = HeaderOut[-2].lower()
4769+
fccs = HeaderOut[-1].lower()
47424770
newfcs = GetHeaderChecksum(HeaderOut[:-2], HeaderOut[-4].lower(), True, formatspecs, saltkey)
4743-
HeaderOut.append(fjsoncontent)
47444771
if(fcs != newfcs and not skipchecksum):
47454772
VerbosePrintOut("File Header Checksum Error with file " +
47464773
fname + " at offset " + str(fheaderstart))
47474774
VerbosePrintOut("'" + fcs + "' != " + "'" + newfcs + "'")
47484775
return False
4776+
fhend = fp.tell() - 1
4777+
fcontentstart = fp.tell()
47494778
fcontents = MkTempFile()
4779+
pyhascontents = False
47504780
if(fsize > 0 and not listonly):
47514781
if(fcompression == "none" or fcompression == "" or fcompression == "auto"):
47524782
fcontents.write(fp.read(fsize))
47534783
else:
47544784
fcontents.write(fp.read(fcsize))
4785+
pyhascontents = True
47554786
elif(fsize > 0 and listonly):
47564787
if(fcompression == "none" or fcompression == "" or fcompression == "auto"):
47574788
fp.seek(fsize, 1)
47584789
else:
47594790
fp.seek(fcsize, 1)
4791+
pyhascontents = False
47604792
fcontents.seek(0, 0)
47614793
newfccs = GetFileChecksum(fcontents, HeaderOut[-3].lower(), False, formatspecs, saltkey)
47624794
fcontents.seek(0, 0)
@@ -4770,12 +4802,15 @@ def ReadFileHeaderDataWithContent(fp, listonly=False, uncompress=True, skipcheck
47704802
else:
47714803
fcontents.seek(0, 0)
47724804
if(uncompress):
4773-
cfcontents = UncompressFileAlt(fcontents, formatspecs)
4805+
cfcontents = UncompressFileAlt(
4806+
fcontents, formatspecs)
47744807
cfcontents.seek(0, 0)
47754808
fcontents = MkTempFile()
47764809
shutil.copyfileobj(cfcontents, fcontents, length=__filebuff_size__)
47774810
cfcontents.close()
47784811
fcontents.seek(0, 0)
4812+
fccs = GetFileChecksum(fcontents, HeaderOut[-3].lower(), False, formatspecs, saltkey)
4813+
fcontentend = fp.tell()
47794814
if(re.findall("^\\+([0-9]+)", fseeknextfile)):
47804815
fseeknextasnum = int(fseeknextfile.replace("+", ""))
47814816
if(abs(fseeknextasnum) == 0):
@@ -4793,6 +4828,9 @@ def ReadFileHeaderDataWithContent(fp, listonly=False, uncompress=True, skipcheck
47934828
fp.seek(fseeknextasnum, 0)
47944829
else:
47954830
return False
4831+
fcontents.seek(0, 0)
4832+
if(not contentasfile):
4833+
fcontents = fcontents.read()
47964834
HeaderOut.append(fcontents)
47974835
return HeaderOut
47984836

@@ -5241,7 +5279,7 @@ def ReadFileHeaderDataWithContentToList(fp, listonly=False, contentasfile=False,
52415279
return outlist
52425280

52435281

5244-
def ReadFileDataWithContent(fp, filestart=0, listonly=False, uncompress=True, skipchecksum=False, formatspecs=__file_format_dict__, saltkey=None):
5282+
def ReadFileDataWithContent(fp, filestart=0, listonly=False, contentasfile=False, uncompress=True, skipchecksum=False, formatspecs=__file_format_dict__, saltkey=None):
52455283
if(not hasattr(fp, "read")):
52465284
return False
52475285
delimiter = formatspecs['format_delimiter']
@@ -5279,8 +5317,8 @@ def ReadFileDataWithContent(fp, filestart=0, listonly=False, uncompress=True, sk
52795317
"'" + newfcs + "'")
52805318
return False
52815319
fnumfiles = int(inheader[8], 16)
5282-
outfseeknextfile = inheaderdata[9]
5283-
fjsonsize = int(inheaderdata[12], 16)
5320+
outfseeknextfile = inheader[9]
5321+
fjsonsize = int(inheader[12], 16)
52845322
fjsonchecksumtype = inheader[13]
52855323
fjsonchecksum = inheader[14]
52865324
fp.read(fjsonsize)
@@ -5305,7 +5343,7 @@ def ReadFileDataWithContent(fp, filestart=0, listonly=False, uncompress=True, sk
53055343
countnum = 0
53065344
flist = []
53075345
while(countnum < fnumfiles):
5308-
HeaderOut = ReadFileHeaderDataWithContent(fp, listonly, uncompress, skipchecksum, formatspecs, saltkey)
5346+
HeaderOut = ReadFileHeaderDataWithContent(fp, listonly, contentasfile, uncompress, skipchecksum, formatspecs, saltkey)
53095347
if(len(HeaderOut) == 0):
53105348
break
53115349
flist.append(HeaderOut)

pyneofile_py3.py

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3910,10 +3910,11 @@ def ReadFileHeaderDataWoSize(fp, delimiter=_default_delim(None)):
39103910
return first_two + headerdata
39113911

39123912

3913-
def ReadFileHeaderDataWithContent(fp, listonly=False, uncompress=True, skipchecksum=False, formatspecs=__file_format_dict__, saltkey=None):
3913+
def ReadFileHeaderDataWithContent(fp, listonly=False, contentasfile=False, uncompress=True, skipchecksum=False, formatspecs=__file_format_dict__, saltkey=None):
39143914
if(not hasattr(fp, "read")):
39153915
return False
39163916
delimiter = formatspecs['format_delimiter']
3917+
fheaderstart = fp.tell()
39173918
if(__use_new_style__):
39183919
HeaderOut = ReadFileHeaderDataBySize(fp, delimiter)
39193920
else:
@@ -3927,15 +3928,41 @@ def ReadFileHeaderDataWithContent(fp, listonly=False, uncompress=True, skipcheck
39273928
fcs = HeaderOut[-2].lower()
39283929
fccs = HeaderOut[-1].lower()
39293930
fsize = int(HeaderOut[7], 16)
3930-
fcompression = HeaderOut[14]
3931-
fcsize = int(HeaderOut[15], 16)
3932-
fseeknextfile = HeaderOut[26]
3933-
fjsontype = HeaderOut[27]
3934-
fjsonlen = int(HeaderOut[28], 16)
3935-
fjsonsize = int(HeaderOut[29], 16)
3936-
fjsonchecksumtype = HeaderOut[30]
3937-
fjsonchecksum = HeaderOut[31]
3938-
fjsoncontent = {}
3931+
fcompression = HeaderOut[17]
3932+
fcsize = int(HeaderOut[18], 16)
3933+
fseeknextfile = HeaderOut[28]
3934+
fjsontype = HeaderOut[29]
3935+
fjsonlen = int(HeaderOut[30], 16)
3936+
fjsonsize = int(HeaderOut[31], 16)
3937+
fjsonchecksumtype = HeaderOut[32]
3938+
fjsonchecksum = HeaderOut[33]
3939+
fextrasize = int(HeaderOut[34], 16)
3940+
fextrafields = int(HeaderOut[35], 16)
3941+
fextrafieldslist = []
3942+
extrastart = 36
3943+
extraend = extrastart + fextrafields
3944+
while(extrastart < extraend):
3945+
fextrafieldslist.append(HeaderOut[extrastart])
3946+
extrastart = extrastart + 1
3947+
fvendorfieldslist = []
3948+
fvendorfields = 0;
3949+
if((len(HeaderOut) - 4)>extraend):
3950+
extrastart = extraend
3951+
extraend = len(HeaderOut) - 4
3952+
while(extrastart < extraend):
3953+
fvendorfieldslist.append(HeaderOut[extrastart])
3954+
extrastart = extrastart + 1
3955+
fvendorfields = fvendorfields + 1
3956+
if(fextrafields==1):
3957+
try:
3958+
fextrafieldslist = json.loads(base64.b64decode(fextrafieldslist[0]).decode("UTF-8"))
3959+
fextrafields = len(fextrafieldslist)
3960+
except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
3961+
try:
3962+
fextrafieldslist = json.loads(fextrafieldslist[0])
3963+
except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
3964+
pass
3965+
fjstart = fp.tell()
39393966
if(fjsontype=="json"):
39403967
fjsoncontent = {}
39413968
fprejsoncontent = fp.read(fjsonsize).decode("UTF-8")
@@ -4002,31 +4029,37 @@ def ReadFileHeaderDataWithContent(fp, listonly=False, uncompress=True, skipcheck
40024029
except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
40034030
pass
40044031
fp.seek(len(delimiter), 1)
4032+
fjend = fp.tell() - 1
40054033
jsonfcs = GetFileChecksum(fprejsoncontent, fjsonchecksumtype, True, formatspecs, saltkey)
40064034
if(not CheckChecksums(fjsonchecksum, jsonfcs) and not skipchecksum):
40074035
VerbosePrintOut("File JSON Data Checksum Error with file " +
40084036
fname + " at offset " + str(fheaderstart))
40094037
VerbosePrintOut("'" + fjsonchecksum + "' != " + "'" + jsonfcs + "'")
40104038
return False
4011-
fp.seek(len(delimiter), 1)
4039+
fcs = HeaderOut[-2].lower()
4040+
fccs = HeaderOut[-1].lower()
40124041
newfcs = GetHeaderChecksum(HeaderOut[:-2], HeaderOut[-4].lower(), True, formatspecs, saltkey)
4013-
HeaderOut.append(fjsoncontent)
40144042
if(fcs != newfcs and not skipchecksum):
40154043
VerbosePrintOut("File Header Checksum Error with file " +
40164044
fname + " at offset " + str(fheaderstart))
40174045
VerbosePrintOut("'" + fcs + "' != " + "'" + newfcs + "'")
40184046
return False
4047+
fhend = fp.tell() - 1
4048+
fcontentstart = fp.tell()
40194049
fcontents = MkTempFile()
4050+
pyhascontents = False
40204051
if(fsize > 0 and not listonly):
40214052
if(fcompression == "none" or fcompression == "" or fcompression == "auto"):
40224053
fcontents.write(fp.read(fsize))
40234054
else:
40244055
fcontents.write(fp.read(fcsize))
4056+
pyhascontents = True
40254057
elif(fsize > 0 and listonly):
40264058
if(fcompression == "none" or fcompression == "" or fcompression == "auto"):
40274059
fp.seek(fsize, 1)
40284060
else:
40294061
fp.seek(fcsize, 1)
4062+
pyhascontents = False
40304063
fcontents.seek(0, 0)
40314064
newfccs = GetFileChecksum(fcontents, HeaderOut[-3].lower(), False, formatspecs, saltkey)
40324065
fcontents.seek(0, 0)
@@ -4040,12 +4073,15 @@ def ReadFileHeaderDataWithContent(fp, listonly=False, uncompress=True, skipcheck
40404073
else:
40414074
fcontents.seek(0, 0)
40424075
if(uncompress):
4043-
cfcontents = UncompressFileAlt(fcontents, formatspecs)
4076+
cfcontents = UncompressFileAlt(
4077+
fcontents, formatspecs)
40444078
cfcontents.seek(0, 0)
40454079
fcontents = MkTempFile()
40464080
shutil.copyfileobj(cfcontents, fcontents, length=__filebuff_size__)
40474081
cfcontents.close()
40484082
fcontents.seek(0, 0)
4083+
fccs = GetFileChecksum(fcontents, HeaderOut[-3].lower(), False, formatspecs, saltkey)
4084+
fcontentend = fp.tell()
40494085
if(re.findall("^\\+([0-9]+)", fseeknextfile)):
40504086
fseeknextasnum = int(fseeknextfile.replace("+", ""))
40514087
if(abs(fseeknextasnum) == 0):
@@ -4063,6 +4099,9 @@ def ReadFileHeaderDataWithContent(fp, listonly=False, uncompress=True, skipcheck
40634099
fp.seek(fseeknextasnum, 0)
40644100
else:
40654101
return False
4102+
fcontents.seek(0, 0)
4103+
if(not contentasfile):
4104+
fcontents = fcontents.read()
40664105
HeaderOut.append(fcontents)
40674106
return HeaderOut
40684107

@@ -4511,7 +4550,7 @@ def ReadFileHeaderDataWithContentToList(fp, listonly=False, contentasfile=False,
45114550
return outlist
45124551

45134552

4514-
def ReadFileDataWithContent(fp, filestart=0, listonly=False, uncompress=True, skipchecksum=False, formatspecs=__file_format_dict__, saltkey=None):
4553+
def ReadFileDataWithContent(fp, filestart=0, listonly=False, contentasfile=False, uncompress=True, skipchecksum=False, formatspecs=__file_format_dict__, saltkey=None):
45154554
if(not hasattr(fp, "read")):
45164555
return False
45174556
delimiter = formatspecs['format_delimiter']
@@ -4549,8 +4588,8 @@ def ReadFileDataWithContent(fp, filestart=0, listonly=False, uncompress=True, sk
45494588
"'" + newfcs + "'")
45504589
return False
45514590
fnumfiles = int(inheader[8], 16)
4552-
outfseeknextfile = inheaderdata[9]
4553-
fjsonsize = int(inheaderdata[12], 16)
4591+
outfseeknextfile = inheader[9]
4592+
fjsonsize = int(inheader[12], 16)
45544593
fjsonchecksumtype = inheader[13]
45554594
fjsonchecksum = inheader[14]
45564595
fp.read(fjsonsize)
@@ -4575,7 +4614,7 @@ def ReadFileDataWithContent(fp, filestart=0, listonly=False, uncompress=True, sk
45754614
countnum = 0
45764615
flist = []
45774616
while(countnum < fnumfiles):
4578-
HeaderOut = ReadFileHeaderDataWithContent(fp, listonly, uncompress, skipchecksum, formatspecs, saltkey)
4617+
HeaderOut = ReadFileHeaderDataWithContent(fp, listonly, contentasfile, uncompress, skipchecksum, formatspecs, saltkey)
45794618
if(len(HeaderOut) == 0):
45804619
break
45814620
flist.append(HeaderOut)

0 commit comments

Comments
 (0)