@@ -2085,8 +2085,17 @@ def ReadFileHeaderDataWithContent(fp, listonly=False, uncompress=True, skipcheck
20852085 fcompression = HeaderOut [12 ]
20862086 fcsize = int (HeaderOut [13 ], 16 )
20872087 fseeknextfile = HeaderOut [25 ]
2088+ fjsonsize = int (HeaderOut [27 ], 16 )
2089+ fjsoncontent = {}
2090+ fprejsoncontent = fp .read (fjsonsize ).decode ("UTF-8" )
2091+ if (len (fjsoncontent ) > 0 ):
2092+ fjsoncontent = json .loads (fprejsoncontent .decode ("UTF-8" ))
2093+ else :
2094+ fprejsoncontent = ""
2095+ fp .seek (len (delimiter ), 1 )
2096+ HeaderOut .append (fjsoncontent )
20882097 newfcs = GetHeaderChecksum (
2089- HeaderOut [:- 2 ], HeaderOut [- 4 ].lower (), True , formatspecs )
2098+ HeaderOut [:- 2 ] + [ fprejsoncontent ] , HeaderOut [- 4 ].lower (), True , formatspecs )
20902099 if (fcs != newfcs and not skipchecksum ):
20912100 VerbosePrintOut ("File Header Checksum Error with file " +
20922101 fname + " at offset " + str (fheaderstart ))
@@ -2190,10 +2199,11 @@ def ReadFileHeaderDataWithContentToArray(fp, listonly=False, contentasfile=True,
21902199 fdev_minor = int (HeaderOut [24 ], 16 )
21912200 fdev_major = int (HeaderOut [25 ], 16 )
21922201 fseeknextfile = HeaderOut [26 ]
2193- fextrasize = int (HeaderOut [27 ], 16 )
2194- fextrafields = int (HeaderOut [28 ], 16 )
2202+ fjsonsize = int (HeaderOut [27 ], 16 )
2203+ fextrasize = int (HeaderOut [28 ], 16 )
2204+ fextrafields = int (HeaderOut [29 ], 16 )
21952205 fextrafieldslist = []
2196- extrastart = 29
2206+ extrastart = 30
21972207 extraend = extrastart + fextrafields
21982208 while (extrastart < extraend ):
21992209 fextrafieldslist .append (HeaderOut [extrastart ])
@@ -2204,10 +2214,17 @@ def ReadFileHeaderDataWithContentToArray(fp, listonly=False, contentasfile=True,
22042214 fextrafields = len (fextrafieldslist )
22052215 except (binascii .Error , json .decoder .JSONDecodeError , UnicodeDecodeError ):
22062216 pass
2217+ fjsoncontent = {}
2218+ fprejsoncontent = fp .read (fjsonsize ).decode ("UTF-8" )
2219+ if (len (fjsoncontent ) > 0 ):
2220+ fjsoncontent = json .loads (fprejsoncontent .decode ("UTF-8" ))
2221+ else :
2222+ fprejsoncontent = ""
2223+ fp .seek (len (delimiter ), 1 )
22072224 fcs = HeaderOut [- 2 ].lower ()
22082225 fccs = HeaderOut [- 1 ].lower ()
22092226 newfcs = GetHeaderChecksum (
2210- HeaderOut [:- 2 ], HeaderOut [- 4 ].lower (), True , formatspecs )
2227+ HeaderOut [:- 2 ] + [ fprejsoncontent ] , HeaderOut [- 4 ].lower (), True , formatspecs )
22112228 if (fcs != newfcs and not skipchecksum ):
22122229 VerbosePrintOut ("File Header Checksum Error with file " +
22132230 fname + " at offset " + str (fheaderstart ))
@@ -2242,7 +2259,7 @@ def ReadFileHeaderDataWithContentToArray(fp, listonly=False, contentasfile=True,
22422259 else :
22432260 fcontents .seek (0 , 0 )
22442261 if (uncompress ):
2245- cfcontents = UncompressArchiveFile (
2262+ cfcontents = UncompressCatFile (
22462263 fcontents , formatspecs )
22472264 cfcontents .seek (0 , 0 )
22482265 fcontents = BytesIO ()
@@ -2321,10 +2338,11 @@ def ReadFileHeaderDataWithContentToList(fp, listonly=False, contentasfile=False,
23212338 fdev_minor = int (HeaderOut [24 ], 16 )
23222339 fdev_major = int (HeaderOut [25 ], 16 )
23232340 fseeknextfile = HeaderOut [26 ]
2324- fextrasize = int (HeaderOut [27 ], 16 )
2325- fextrafields = int (HeaderOut [28 ], 16 )
2341+ fjsonsize = int (HeaderOut [27 ], 16 )
2342+ fextrasize = int (HeaderOut [28 ], 16 )
2343+ fextrafields = int (HeaderOut [29 ], 16 )
23262344 fextrafieldslist = []
2327- extrastart = 29
2345+ extrastart = 30
23282346 extraend = extrastart + fextrafields
23292347 while (extrastart < extraend ):
23302348 fextrafieldslist .append (HeaderOut [extrastart ])
@@ -2335,10 +2353,17 @@ def ReadFileHeaderDataWithContentToList(fp, listonly=False, contentasfile=False,
23352353 fextrafields = len (fextrafieldslist )
23362354 except (binascii .Error , json .decoder .JSONDecodeError , UnicodeDecodeError ):
23372355 pass
2356+ fjsoncontent = {}
2357+ fprejsoncontent = fp .read (fjsonsize ).decode ("UTF-8" )
2358+ if (len (fjsoncontent ) > 0 ):
2359+ fjsoncontent = json .loads (fprejsoncontent .decode ("UTF-8" ))
2360+ else :
2361+ fprejsoncontent = ""
2362+ fp .seek (len (delimiter ), 1 )
23382363 fcs = HeaderOut [- 2 ].lower ()
23392364 fccs = HeaderOut [- 1 ].lower ()
23402365 newfcs = GetHeaderChecksum (
2341- HeaderOut [:- 2 ], HeaderOut [- 4 ].lower (), True , formatspecs )
2366+ HeaderOut [:- 2 ] + [ fprejsoncontent ] , HeaderOut [- 4 ].lower (), True , formatspecs )
23422367 if (fcs != newfcs and not skipchecksum ):
23432368 VerbosePrintOut ("File Header Checksum Error with file " +
23442369 fname + " at offset " + str (fheaderstart ))
@@ -2373,7 +2398,7 @@ def ReadFileHeaderDataWithContentToList(fp, listonly=False, contentasfile=False,
23732398 else :
23742399 fcontents .seek (0 , 0 )
23752400 if (uncompress ):
2376- cfcontents = UncompressArchiveFile (
2401+ cfcontents = UncompressCatFile (
23772402 fcontents , formatspecs )
23782403 cfcontents .seek (0 , 0 )
23792404 fcontents = BytesIO ()
@@ -2404,7 +2429,7 @@ def ReadFileHeaderDataWithContentToList(fp, listonly=False, contentasfile=False,
24042429 if (not contentasfile ):
24052430 fcontents = fcontents .read ()
24062431 outlist = [ftype , fencoding , fcencoding , fname , flinkname , fsize , fatime , fmtime , fctime , fbtime , fmode , fwinattributes , fcompression , fcsize , fuid , funame , fgid , fgname , fid ,
2407- finode , flinkcount , fdev , fdev_minor , fdev_major , fseeknextfile , fextrafieldslist , HeaderOut [- 4 ], HeaderOut [- 3 ], fcontents ]
2432+ finode , flinkcount , fdev , fdev_minor , fdev_major , fseeknextfile , fjsoncontent , fextrafieldslist , HeaderOut [- 4 ], HeaderOut [- 3 ], fcontents ]
24082433 return outlist
24092434
24102435
@@ -3319,10 +3344,17 @@ def AppendFileHeaderWithContent(fp, filevalues=[], extradata=[], filecontent="",
33193344 extrasizestr = extrasizestr + \
33203345 AppendNullBytes (extradata , formatspecs ['format_delimiter' ])
33213346 extrasizelen = format (len (extrasizestr ), 'x' ).lower ()
3322- tmpoutlen = len (filevalues ) + len (extradata ) + 6
3347+ tmpoutlen = len (filevalues ) + len (extradata ) + 7
33233348 tmpoutlenhex = format (tmpoutlen , 'x' ).lower ()
33243349 tmpoutlist = filevalues
3350+ fprejsoncontent = {}
3351+ if (len (fprejsoncontent ) > 0 ):
3352+ fjsoncontent = json .dumps (fprejsoncontent , separators = (',' , ':' ))
3353+ else :
3354+ fjsoncontent = ""
3355+ fjsonsize = format (len (fjsoncontent ), 'x' ).lower ()
33253356 tmpoutlist .insert (0 , tmpoutlenhex )
3357+ tmpoutlist .append (fjsonsize )
33263358 tmpoutlist .append (extrasizelen )
33273359 tmpoutlist .append (extrafields )
33283360 outfileoutstr = AppendNullBytes (
@@ -3336,8 +3368,10 @@ def AppendFileHeaderWithContent(fp, filevalues=[], extradata=[], filecontent="",
33363368 checksumlist = checksumtype
33373369 outfileoutstr = outfileoutstr + \
33383370 AppendNullBytes (checksumlist , formatspecs ['format_delimiter' ])
3371+ nullstrecd = formatspecs ['format_delimiter' ].encode ('UTF-8' )
3372+ print (outfileoutstr )
33393373 outfileheadercshex = GetFileChecksum (
3340- outfileoutstr , checksumtype [0 ], True , formatspecs )
3374+ outfileoutstr + nullstrecd + fjsoncontent . encode ( 'UTF-8' ) , checksumtype [0 ], True , formatspecs )
33413375 if (len (filecontent ) == 0 ):
33423376 outfilecontentcshex = GetFileChecksum (
33433377 filecontent , "none" , False , formatspecs )
@@ -3356,8 +3390,7 @@ def AppendFileHeaderWithContent(fp, filevalues=[], extradata=[], filecontent="",
33563390 AppendNullBytes ([outfileheadercshex , outfilecontentcshex ],
33573391 formatspecs ['format_delimiter' ])
33583392 outfileoutstrecd = outfileoutstr
3359- nullstrecd = formatspecs ['format_delimiter' ].encode ('UTF-8' )
3360- outfileout = outfileoutstrecd + filecontent + nullstrecd
3393+ outfileout = outfileoutstrecd + fjsoncontent .encode ('UTF-8' ) + nullstrecd + filecontent + nullstrecd
33613394 try :
33623395 fp .write (outfileout )
33633396 except OSError :
0 commit comments