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.

To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.7% of users enabled 2FA.

Commit e4b223c6 authored by John Zhang's avatar John Zhang
Browse files

mar.py as a importable function

parent b2aac66b
......@@ -5,66 +5,70 @@ import zipfile
import tempfile
import shutil
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
'''
)
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
colon-separated list of libraries.''')
parser.add_argument('bootimg', help='path to the boot image')
def mu_meta_set(bootimg, entry_point_id=None, entry_point_name=None, 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
for info in il:
name = info.filename
if name == 'entrypoint':
entrypoint = zi.read(info)
elif name == 'extralibs':
extralibs = zi.read(info)
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")
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)
shutil.move(tmpfilename, bootimg)
args = parser.parse_args()
with tempfile.NamedTemporaryFile(delete=False) as tf:
tmpfilename = tf.name
with zipfile.ZipFile(tf, 'w', compression=zipfile.ZIP_DEFLATED) as zo:
with zipfile.ZipFile(args.bootimg, "a") as zi:
il = zi.infolist()
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
'''
)
entrypoint = None
extralibs = None
entry_point_group = parser.add_mutually_exclusive_group()
for info in il:
name = info.filename
if name == 'entrypoint':
entrypoint = zi.read(info)
elif name == 'extralibs':
extralibs = zi.read(info)
else:
oldcontent = zi.read(info)
zo.writestr(name, oldcontent)
entry_point_group.add_argument('-i', '--entry-point-id',
metavar="MuID",
type=int,
help='set the entry point by ID'
)
if args.entry_point_id is not None:
entrypoint = "id {}".format(args.entry_point_id).encode("utf8")
if args.entry_point_name is not None:
entrypoint = "name {}".format(args.entry_point_name).encode("utf8")
if args.extra_libraries is not None:
extralibs = args.extra_libraries.encode("utf8")
entry_point_group.add_argument('-n', '--entry-point-name',
metavar="MuName",
help='set the entry point by name'
)
if entrypoint is not None:
zo.writestr("entrypoint", entrypoint)
if extralibs is not None:
zo.writestr("extralibs", extralibs)
parser.add_argument('-l', '--extra-libraries',
metavar="colon-separated-libs",
help='''extra libraries to load at boot-image loading time. It is a
colon-separated list of libraries.''')
shutil.move(tmpfilename, args.bootimg)
parser.add_argument('bootimg', help='path to the boot image')
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
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