Skip to content

Commit

Permalink
simg_dump: Support and dump extended file/chunk headers
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberShadow committed Feb 13, 2018
1 parent ede4a71 commit a804ceb
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions simg_dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# limitations under the License.

from __future__ import print_function
import binascii
import csv
import getopt
import hashlib
Expand Down Expand Up @@ -94,12 +95,12 @@ def main():
print("%s: %s: I only know about version 1.0, but this is version %u.%u"
% (me, path, major_version, minor_version))
continue
if file_hdr_sz != 28:
print("%s: %s: The file header size was expected to be 28, but is %u."
if file_hdr_sz < 28:
print("%s: %s: The file header size was expected to be at least 28, but is %u."
% (me, path, file_hdr_sz))
continue
if chunk_hdr_sz != 12:
print("%s: %s: The chunk header size was expected to be 12, but is %u."
if chunk_hdr_sz < 12:
print("%s: %s: The chunk header size was expected to be at least 12, but is %u."
% (me, path, chunk_hdr_sz))
continue

Expand All @@ -109,6 +110,11 @@ def main():
if image_checksum != 0:
print("checksum=0x%08X" % (image_checksum))

if file_hdr_sz > 28:
header_extra = FH.read(file_hdr_sz - 28)
print("%s: Header extra bytes: %s"
% (me, binascii.hexlify(header_extra)))

if not output:
continue

Expand All @@ -127,14 +133,18 @@ def main():
chunk_type = header[0]
chunk_sz = header[2]
total_sz = header[3]
data_sz = total_sz - 12
data_sz = total_sz - chunk_hdr_sz
curhash = ""
curtype = ""
curpos = FH.tell()

if verbose > 0:
print("%4u %10u %10u %7u %7u" % (i, curpos, data_sz, offset, chunk_sz),
end=" ")
if chunk_hdr_sz > 12:
header_extra = FH.read(chunk_hdr_sz - 12)
print("[Extra bytes: %s]"
% (binascii.hexlify(header_extra)), end=" ")

if chunk_type == 0xCAC1:
if data_sz != (chunk_sz * blk_sz):
Expand Down

0 comments on commit a804ceb

Please sign in to comment.