WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

Commit 12b2d179 authored by John Zhang's avatar John Zhang
Browse files

updated mar.py, using metainfo

parent 87632589
......@@ -6,37 +6,35 @@ import tempfile
import shutil
def mu_meta_set(bootimg, entry_point_id=None, entry_point_name=None, extra_libraries=None):
def mu_meta_set(bootimg, extra_libraries=None):
with tempfile.NamedTemporaryFile(delete=False) as tf:
tmpfilename = tf.name
with zipfile.ZipFile(tf, 'w', compression=zipfile.ZIP_DEFLATED) as zo:
with zipfile.ZipFile(bootimg, "a") as zi:
il = zi.infolist()
entrypoint = None
extralibs = None
metainfo = ""
for info in il:
name = info.filename
if name == 'entrypoint':
entrypoint = zi.read(info)
elif name == 'extralibs':
extralibs = zi.read(info)
if name == 'metainfo':
metainfo = zi.read(info).decode('utf-8')
else:
oldcontent = zi.read(info)
zo.writestr(name, oldcontent)
if entry_point_id is not None:
entrypoint = "id {}".format(entry_point_id).encode("utf8")
if entry_point_name is not None:
entrypoint = "name {}".format(entry_point_name).encode("utf8")
dic = {}
for line in metainfo.splitlines():
if '=' in line:
key, val = line.split('=', 1)
dic[key] = val
if extra_libraries is not None:
extralibs = extra_libraries.encode("utf8")
if entrypoint is not None:
zo.writestr("entrypoint", entrypoint)
if extralibs is not None:
zo.writestr("extralibs", extralibs)
dic['extralibs'] = extra_libraries
new_metainfo = '\n'.join("{}={}".format(k,v) for k,v in dic.items()).encode('utf8')
zo.writestr("metainfo", new_metainfo)
shutil.move(tmpfilename, bootimg)
......@@ -45,23 +43,12 @@ if __name__ == "__main__":
parser = argparse.ArgumentParser(
description='''Set additional boot-image metadata.''',
epilog='''Example:
./tools/mar.py -n @foo -l libm.so:/path/to/mylib.so my-boot-img.muref
./tools/mar.py -l libm.so:/path/to/mylib.so my-boot-img.muref
'''
)
entry_point_group = parser.add_mutually_exclusive_group()
entry_point_group.add_argument('-i', '--entry-point-id',
metavar="MuID",
type=int,
help='set the entry point by ID'
)
entry_point_group.add_argument('-n', '--entry-point-name',
metavar="MuName",
help='set the entry point by name'
)
parser.add_argument('-l', '--extra-libraries',
metavar="colon-separated-libs",
help='''extra libraries to load at boot-image loading time. It is a
......@@ -71,4 +58,4 @@ if __name__ == "__main__":
args = parser.parse_args()
mu_meta_set(args.bootimg, args.entry_point_id, args.entry_point_name, args.extra_libraries)
\ No newline at end of file
mu_meta_set(args.bootimg, args.extra_libraries)
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment