import os, sys, re
|
|
def main():
|
|
if len(sys.argv) != 2:
|
print "USAGE: %s <TRUSTLET_DIR>" % sys.argv[0]
|
return
|
trustlet_dir = sys.argv[1]
|
|
image_version_map = {}
|
for root, dirs, files in os.walk(trustlet_dir):
|
for name in files:
|
|
#Making sure this is an mdt
|
if not name.endswith(".mdt"):
|
continue
|
|
#Searching for the SW_ID
|
fullpath = os.path.join(root, name)
|
mdt = ""
|
try:
|
mdt = open(fullpath, "rb").read()
|
except:
|
print "Failed to open %s, skipping" % fullpath
|
continue
|
|
m = re.search("01 ([0-9A-F]{16}) SW_ID", mdt)
|
if not m:
|
print "Couldn't find SW_ID in %s" % fullpath
|
continue
|
|
#Extracting the SW_ID
|
sw_id = m.group(1)
|
image_version = int(sw_id[:8], 16)
|
image_id = int(sw_id[8:], 16)
|
|
#Is this a TA image_id?
|
if image_id == 0xC:
|
if not name in image_version_map:
|
image_version_map[name] = []
|
image_version_map[name].append((fullpath, image_version))
|
|
for image_name in image_version_map:
|
print "------------------------------------"
|
print "IMAGE: %s" % image_name
|
for fullpath, image_version in image_version_map[image_name]:
|
print " version: %02d, path: %s" % (image_version, fullpath)
|
|
if __name__ == "__main__":
|
main()
|