Skip to content

Commit 2a02c9b

Browse files
authored
Add files via upload
1 parent 5e59ced commit 2a02c9b

2 files changed

Lines changed: 111 additions & 34 deletions

File tree

pycatfile.py

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

46484648

4649-
def ReadFileHeaderDataWithContent(fp, listonly=False, uncompress=True, skipchecksum=False, formatspecs=__file_format_dict__, saltkey=None):
4649+
def ReadFileHeaderDataWithContent(fp, listonly=False, contentasfile=False, uncompress=True, skipchecksum=False, formatspecs=__file_format_dict__, saltkey=None):
46504650
if(not hasattr(fp, "read")):
46514651
return False
46524652
delimiter = formatspecs['format_delimiter']
@@ -4663,15 +4663,41 @@ def ReadFileHeaderDataWithContent(fp, listonly=False, uncompress=True, skipcheck
46634663
fcs = HeaderOut[-2].lower()
46644664
fccs = HeaderOut[-1].lower()
46654665
fsize = int(HeaderOut[7], 16)
4666-
fcompression = HeaderOut[14]
4667-
fcsize = int(HeaderOut[15], 16)
4668-
fseeknextfile = HeaderOut[26]
4669-
fjsontype = HeaderOut[27]
4670-
fjsonlen = int(HeaderOut[28], 16)
4671-
fjsonsize = int(HeaderOut[29], 16)
4672-
fjsonchecksumtype = HeaderOut[30]
4673-
fjsonchecksum = HeaderOut[31]
4674-
fjsoncontent = {}
4666+
fcompression = HeaderOut[17]
4667+
fcsize = int(HeaderOut[18], 16)
4668+
fseeknextfile = HeaderOut[28]
4669+
fjsontype = HeaderOut[29]
4670+
fjsonlen = int(HeaderOut[30], 16)
4671+
fjsonsize = int(HeaderOut[31], 16)
4672+
fjsonchecksumtype = HeaderOut[32]
4673+
fjsonchecksum = HeaderOut[33]
4674+
fextrasize = int(HeaderOut[34], 16)
4675+
fextrafields = int(HeaderOut[35], 16)
4676+
fextrafieldslist = []
4677+
extrastart = 36
4678+
extraend = extrastart + fextrafields
4679+
while(extrastart < extraend):
4680+
fextrafieldslist.append(HeaderOut[extrastart])
4681+
extrastart = extrastart + 1
4682+
fvendorfieldslist = []
4683+
fvendorfields = 0;
4684+
if((len(HeaderOut) - 4)>extraend):
4685+
extrastart = extraend
4686+
extraend = len(HeaderOut) - 4
4687+
while(extrastart < extraend):
4688+
fvendorfieldslist.append(HeaderOut[extrastart])
4689+
extrastart = extrastart + 1
4690+
fvendorfields = fvendorfields + 1
4691+
if(fextrafields==1):
4692+
try:
4693+
fextrafieldslist = json.loads(base64.b64decode(fextrafieldslist[0]).decode("UTF-8"))
4694+
fextrafields = len(fextrafieldslist)
4695+
except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
4696+
try:
4697+
fextrafieldslist = json.loads(fextrafieldslist[0])
4698+
except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
4699+
pass
4700+
fjstart = fp.tell()
46754701
if(fjsontype=="json"):
46764702
fjsoncontent = {}
46774703
fprejsoncontent = fp.read(fjsonsize).decode("UTF-8")
@@ -4738,31 +4764,37 @@ def ReadFileHeaderDataWithContent(fp, listonly=False, uncompress=True, skipcheck
47384764
except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
47394765
pass
47404766
fp.seek(len(delimiter), 1)
4767+
fjend = fp.tell() - 1
47414768
jsonfcs = GetFileChecksum(fprejsoncontent, fjsonchecksumtype, True, formatspecs, saltkey)
47424769
if(not CheckChecksums(fjsonchecksum, jsonfcs) and not skipchecksum):
47434770
VerbosePrintOut("File JSON Data Checksum Error with file " +
47444771
fname + " at offset " + str(fheaderstart))
47454772
VerbosePrintOut("'" + fjsonchecksum + "' != " + "'" + jsonfcs + "'")
47464773
return False
4747-
fp.seek(len(delimiter), 1)
4774+
fcs = HeaderOut[-2].lower()
4775+
fccs = HeaderOut[-1].lower()
47484776
newfcs = GetHeaderChecksum(HeaderOut[:-2], HeaderOut[-4].lower(), True, formatspecs, saltkey)
4749-
HeaderOut.append(fjsoncontent)
47504777
if(fcs != newfcs and not skipchecksum):
47514778
VerbosePrintOut("File Header Checksum Error with file " +
47524779
fname + " at offset " + str(fheaderstart))
47534780
VerbosePrintOut("'" + fcs + "' != " + "'" + newfcs + "'")
47544781
return False
4782+
fhend = fp.tell() - 1
4783+
fcontentstart = fp.tell()
47554784
fcontents = MkTempFile()
4785+
pyhascontents = False
47564786
if(fsize > 0 and not listonly):
47574787
if(fcompression == "none" or fcompression == "" or fcompression == "auto"):
47584788
fcontents.write(fp.read(fsize))
47594789
else:
47604790
fcontents.write(fp.read(fcsize))
4791+
pyhascontents = True
47614792
elif(fsize > 0 and listonly):
47624793
if(fcompression == "none" or fcompression == "" or fcompression == "auto"):
47634794
fp.seek(fsize, 1)
47644795
else:
47654796
fp.seek(fcsize, 1)
4797+
pyhascontents = False
47664798
fcontents.seek(0, 0)
47674799
newfccs = GetFileChecksum(fcontents, HeaderOut[-3].lower(), False, formatspecs, saltkey)
47684800
fcontents.seek(0, 0)
@@ -4776,12 +4808,15 @@ def ReadFileHeaderDataWithContent(fp, listonly=False, uncompress=True, skipcheck
47764808
else:
47774809
fcontents.seek(0, 0)
47784810
if(uncompress):
4779-
cfcontents = UncompressFileAlt(fcontents, formatspecs)
4811+
cfcontents = UncompressFileAlt(
4812+
fcontents, formatspecs)
47804813
cfcontents.seek(0, 0)
47814814
fcontents = MkTempFile()
47824815
shutil.copyfileobj(cfcontents, fcontents, length=__filebuff_size__)
47834816
cfcontents.close()
47844817
fcontents.seek(0, 0)
4818+
fccs = GetFileChecksum(fcontents, HeaderOut[-3].lower(), False, formatspecs, saltkey)
4819+
fcontentend = fp.tell()
47854820
if(re.findall("^\\+([0-9]+)", fseeknextfile)):
47864821
fseeknextasnum = int(fseeknextfile.replace("+", ""))
47874822
if(abs(fseeknextasnum) == 0):
@@ -4799,6 +4834,9 @@ def ReadFileHeaderDataWithContent(fp, listonly=False, uncompress=True, skipcheck
47994834
fp.seek(fseeknextasnum, 0)
48004835
else:
48014836
return False
4837+
fcontents.seek(0, 0)
4838+
if(not contentasfile):
4839+
fcontents = fcontents.read()
48024840
HeaderOut.append(fcontents)
48034841
return HeaderOut
48044842

@@ -5247,7 +5285,7 @@ def ReadFileHeaderDataWithContentToList(fp, listonly=False, contentasfile=False,
52475285
return outlist
52485286

52495287

5250-
def ReadFileDataWithContent(fp, filestart=0, listonly=False, uncompress=True, skipchecksum=False, formatspecs=__file_format_dict__, saltkey=None):
5288+
def ReadFileDataWithContent(fp, filestart=0, listonly=False, contentasfile=False, uncompress=True, skipchecksum=False, formatspecs=__file_format_dict__, saltkey=None):
52515289
if(not hasattr(fp, "read")):
52525290
return False
52535291
delimiter = formatspecs['format_delimiter']
@@ -5285,8 +5323,8 @@ def ReadFileDataWithContent(fp, filestart=0, listonly=False, uncompress=True, sk
52855323
"'" + newfcs + "'")
52865324
return False
52875325
fnumfiles = int(inheader[8], 16)
5288-
outfseeknextfile = inheaderdata[9]
5289-
fjsonsize = int(inheaderdata[12], 16)
5326+
outfseeknextfile = inheader[9]
5327+
fjsonsize = int(inheader[12], 16)
52905328
fjsonchecksumtype = inheader[13]
52915329
fjsonchecksum = inheader[14]
52925330
fp.read(fjsonsize)
@@ -5311,7 +5349,7 @@ def ReadFileDataWithContent(fp, filestart=0, listonly=False, uncompress=True, sk
53115349
countnum = 0
53125350
flist = []
53135351
while(countnum < fnumfiles):
5314-
HeaderOut = ReadFileHeaderDataWithContent(fp, listonly, uncompress, skipchecksum, formatspecs, saltkey)
5352+
HeaderOut = ReadFileHeaderDataWithContent(fp, listonly, contentasfile, uncompress, skipchecksum, formatspecs, saltkey)
53155353
if(len(HeaderOut) == 0):
53165354
break
53175355
flist.append(HeaderOut)

pycatfile_py3.py

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)