Skip to content

Instantly share code, notes, and snippets.

@mtnmts
Created December 7, 2014 00:22
Show Gist options
  • Save mtnmts/a107dbc1e4788d00f809 to your computer and use it in GitHub Desktop.
Save mtnmts/a107dbc1e4788d00f809 to your computer and use it in GitHub Desktop.
Basic reading of updates, todo validate checksum and read everything for real and put everything in normal types
# Author : Matan M. Mates
# Purpose: Parse an inc file and print some info about it
import sys
import struct
ARGC = 2
unpack_struct = ">IIBBBBIIIIII12s"
def clean_date(day,month,year1,year2):
return hex(day)[2:] + '.' + hex(month)[2:] + '.' + hex(year1)[2:] + hex(year2)[2:]
def parse_datafile(file_data):
data = {}
header_version, update_revision, \
month, day, year1,year2, cpuid, checksum, proc_flags, reserved, \
data_size, total_size, reserved2 = struct.unpack(unpack_struct, file_data[:48])
data.update({"Update Date": clean_date(day,month,year1,year2)})
data.update({"Header Version": str(header_version)})
data.update({"Update Revision": str(update_revision)})
data.update({"Data Size": str(data_size)})
data.update({"Total Size": str(total_size)})
data.update({"CPUID": hex(cpuid)})
data.update({"Checksum": hex(checksum)})
return data
def main():
script_name, target_file = sys.argv
file_data = open(target_file,'rb').read()
fields = parse_datafile(file_data)
print '\n\n' + '-' * 60 + '\n'
for k in fields:
print k + " - " + fields[k]
print '\n' + '-' * 60
if __name__ == '__main__':
if len(sys.argv) != ARGC:
print "Usage: {script} <Target File>".format(script=sys.argv[0])
sys.exit(1)
main()
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment