@@ -3916,10 +3916,11 @@ def ReadFileHeaderDataWoSize(fp, delimiter=_default_delim(None)):
39163916 return first_two + headerdata
39173917
39183918
3919- def ReadFileHeaderDataWithContent(fp, listonly=False, uncompress=True, skipchecksum=False, formatspecs=__file_format_dict__, saltkey=None):
3919+ def ReadFileHeaderDataWithContent(fp, listonly=False, contentasfile=False, uncompress=True, skipchecksum=False, formatspecs=__file_format_dict__, saltkey=None):
39203920 if(not hasattr(fp, "read")):
39213921 return False
39223922 delimiter = formatspecs['format_delimiter']
3923+ fheaderstart = fp.tell()
39233924 if(__use_new_style__):
39243925 HeaderOut = ReadFileHeaderDataBySize(fp, delimiter)
39253926 else:
@@ -3933,15 +3934,41 @@ def ReadFileHeaderDataWithContent(fp, listonly=False, uncompress=True, skipcheck
39333934 fcs = HeaderOut[-2].lower()
39343935 fccs = HeaderOut[-1].lower()
39353936 fsize = int(HeaderOut[7], 16)
3936- fcompression = HeaderOut[14]
3937- fcsize = int(HeaderOut[15], 16)
3938- fseeknextfile = HeaderOut[26]
3939- fjsontype = HeaderOut[27]
3940- fjsonlen = int(HeaderOut[28], 16)
3941- fjsonsize = int(HeaderOut[29], 16)
3942- fjsonchecksumtype = HeaderOut[30]
3943- fjsonchecksum = HeaderOut[31]
3944- fjsoncontent = {}
3937+ fcompression = HeaderOut[17]
3938+ fcsize = int(HeaderOut[18], 16)
3939+ fseeknextfile = HeaderOut[28]
3940+ fjsontype = HeaderOut[29]
3941+ fjsonlen = int(HeaderOut[30], 16)
3942+ fjsonsize = int(HeaderOut[31], 16)
3943+ fjsonchecksumtype = HeaderOut[32]
3944+ fjsonchecksum = HeaderOut[33]
3945+ fextrasize = int(HeaderOut[34], 16)
3946+ fextrafields = int(HeaderOut[35], 16)
3947+ fextrafieldslist = []
3948+ extrastart = 36
3949+ extraend = extrastart + fextrafields
3950+ while(extrastart < extraend):
3951+ fextrafieldslist.append(HeaderOut[extrastart])
3952+ extrastart = extrastart + 1
3953+ fvendorfieldslist = []
3954+ fvendorfields = 0;
3955+ if((len(HeaderOut) - 4)>extraend):
3956+ extrastart = extraend
3957+ extraend = len(HeaderOut) - 4
3958+ while(extrastart < extraend):
3959+ fvendorfieldslist.append(HeaderOut[extrastart])
3960+ extrastart = extrastart + 1
3961+ fvendorfields = fvendorfields + 1
3962+ if(fextrafields==1):
3963+ try:
3964+ fextrafieldslist = json.loads(base64.b64decode(fextrafieldslist[0]).decode("UTF-8"))
3965+ fextrafields = len(fextrafieldslist)
3966+ except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
3967+ try:
3968+ fextrafieldslist = json.loads(fextrafieldslist[0])
3969+ except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
3970+ pass
3971+ fjstart = fp.tell()
39453972 if(fjsontype=="json"):
39463973 fjsoncontent = {}
39473974 fprejsoncontent = fp.read(fjsonsize).decode("UTF-8")
@@ -4008,31 +4035,37 @@ def ReadFileHeaderDataWithContent(fp, listonly=False, uncompress=True, skipcheck
40084035 except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
40094036 pass
40104037 fp.seek(len(delimiter), 1)
4038+ fjend = fp.tell() - 1
40114039 jsonfcs = GetFileChecksum(fprejsoncontent, fjsonchecksumtype, True, formatspecs, saltkey)
40124040 if(not CheckChecksums(fjsonchecksum, jsonfcs) and not skipchecksum):
40134041 VerbosePrintOut("File JSON Data Checksum Error with file " +
40144042 fname + " at offset " + str(fheaderstart))
40154043 VerbosePrintOut("'" + fjsonchecksum + "' != " + "'" + jsonfcs + "'")
40164044 return False
4017- fp.seek(len(delimiter), 1)
4045+ fcs = HeaderOut[-2].lower()
4046+ fccs = HeaderOut[-1].lower()
40184047 newfcs = GetHeaderChecksum(HeaderOut[:-2], HeaderOut[-4].lower(), True, formatspecs, saltkey)
4019- HeaderOut.append(fjsoncontent)
40204048 if(fcs != newfcs and not skipchecksum):
40214049 VerbosePrintOut("File Header Checksum Error with file " +
40224050 fname + " at offset " + str(fheaderstart))
40234051 VerbosePrintOut("'" + fcs + "' != " + "'" + newfcs + "'")
40244052 return False
4053+ fhend = fp.tell() - 1
4054+ fcontentstart = fp.tell()
40254055 fcontents = MkTempFile()
4056+ pyhascontents = False
40264057 if(fsize > 0 and not listonly):
40274058 if(fcompression == "none" or fcompression == "" or fcompression == "auto"):
40284059 fcontents.write(fp.read(fsize))
40294060 else:
40304061 fcontents.write(fp.read(fcsize))
4062+ pyhascontents = True
40314063 elif(fsize > 0 and listonly):
40324064 if(fcompression == "none" or fcompression == "" or fcompression == "auto"):
40334065 fp.seek(fsize, 1)
40344066 else:
40354067 fp.seek(fcsize, 1)
4068+ pyhascontents = False
40364069 fcontents.seek(0, 0)
40374070 newfccs = GetFileChecksum(fcontents, HeaderOut[-3].lower(), False, formatspecs, saltkey)
40384071 fcontents.seek(0, 0)
@@ -4046,12 +4079,15 @@ def ReadFileHeaderDataWithContent(fp, listonly=False, uncompress=True, skipcheck
40464079 else:
40474080 fcontents.seek(0, 0)
40484081 if(uncompress):
4049- cfcontents = UncompressFileAlt(fcontents, formatspecs)
4082+ cfcontents = UncompressFileAlt(
4083+ fcontents, formatspecs)
40504084 cfcontents.seek(0, 0)
40514085 fcontents = MkTempFile()
40524086 shutil.copyfileobj(cfcontents, fcontents, length=__filebuff_size__)
40534087 cfcontents.close()
40544088 fcontents.seek(0, 0)
4089+ fccs = GetFileChecksum(fcontents, HeaderOut[-3].lower(), False, formatspecs, saltkey)
4090+ fcontentend = fp.tell()
40554091 if(re.findall("^\\+([0-9]+)", fseeknextfile)):
40564092 fseeknextasnum = int(fseeknextfile.replace("+", ""))
40574093 if(abs(fseeknextasnum) == 0):
@@ -4069,6 +4105,9 @@ def ReadFileHeaderDataWithContent(fp, listonly=False, uncompress=True, skipcheck
40694105 fp.seek(fseeknextasnum, 0)
40704106 else:
40714107 return False
4108+ fcontents.seek(0, 0)
4109+ if(not contentasfile):
4110+ fcontents = fcontents.read()
40724111 HeaderOut.append(fcontents)
40734112 return HeaderOut
40744113
@@ -4517,7 +4556,7 @@ def ReadFileHeaderDataWithContentToList(fp, listonly=False, contentasfile=False,
45174556 return outlist
45184557
45194558
4520- def ReadFileDataWithContent(fp, filestart=0, listonly=False, uncompress=True, skipchecksum=False, formatspecs=__file_format_dict__, saltkey=None):
4559+ def ReadFileDataWithContent(fp, filestart=0, listonly=False, contentasfile=False, uncompress=True, skipchecksum=False, formatspecs=__file_format_dict__, saltkey=None):
45214560 if(not hasattr(fp, "read")):
45224561 return False
45234562 delimiter = formatspecs['format_delimiter']
@@ -4555,8 +4594,8 @@ def ReadFileDataWithContent(fp, filestart=0, listonly=False, uncompress=True, sk
45554594 "'" + newfcs + "'")
45564595 return False
45574596 fnumfiles = int(inheader[8], 16)
4558- outfseeknextfile = inheaderdata [9]
4559- fjsonsize = int(inheaderdata [12], 16)
4597+ outfseeknextfile = inheader [9]
4598+ fjsonsize = int(inheader [12], 16)
45604599 fjsonchecksumtype = inheader[13]
45614600 fjsonchecksum = inheader[14]
45624601 fp.read(fjsonsize)
@@ -4581,7 +4620,7 @@ def ReadFileDataWithContent(fp, filestart=0, listonly=False, uncompress=True, sk
45814620 countnum = 0
45824621 flist = []
45834622 while(countnum < fnumfiles):
4584- HeaderOut = ReadFileHeaderDataWithContent(fp, listonly, uncompress, skipchecksum, formatspecs, saltkey)
4623+ HeaderOut = ReadFileHeaderDataWithContent(fp, listonly, contentasfile, uncompress, skipchecksum, formatspecs, saltkey)
45854624 if(len(HeaderOut) == 0):
45864625 break
45874626 flist.append(HeaderOut)
0 commit comments