def main(): """ Main executable function. Its task is to parse command line options and call a function which performs requested command. """ parser = argparse.ArgumentParser(description=__doc__.split('.')[0]) parser.add_argument("-e", "--elffile", type=str, required=True, help="Input ELF firmware file name") parser.add_argument("-o", "--valfile", type=str, help="Values list JSON file name") parser.add_argument("--dry-run", action="store_true", help="Do not write any files or do permanent changes") parser.add_argument("-v", "--verbose", action="count", default=0, help="Increases verbosity level; max level is set by -vvv") subparser = parser.add_mutually_exclusive_group(required=True) subparser.add_argument("-l", "--list", action="store_true", help="list values stored in the firmware") subparser.add_argument("-x", "--extract", action="store_true", help="Extract values to infos json text file") subparser.add_argument("-u", "--update", action="store_true", help="Update values in binary fw from infos text file") subparser.add_argument("-d", "--objdump", action="store_true", help="display asm like slightly primitive objdump") subparser.add_argument("--version", action='version', version="%(prog)s {version} by {author}" .format(version=__version__,author=__author__), help="Display version information and exit") po = parser.parse_args() po.basename = os.path.splitext(os.path.basename(po.elffile))[0] if len(po.elffile) > 0 and (po.valfile is None or len(po.valfile) == 0): po.valfile = po.basename + ".json" if po.objdump: if (po.verbose > 0): print("{}: Opening for objdump".format(po.elffile)) elffh = open(po.elffile, "rb") armfw_elf_generic_objdump(po, elffh) elffh.close(); elif po.list: if (po.verbose > 0): print("{}: Opening for list".format(po.elffile)) elffh = open(po.elffile, "rb") armfw_elf_dm3xxvals_list(po, elffh) elffh.close(); elif po.extract: if (po.verbose > 0): print("{}: Opening for extract".format(po.elffile)) elffh = open(po.elffile, "rb") armfw_elf_dm3xxvals_extract(po, elffh) elffh.close(); elif po.update: if (po.verbose > 0): print("{}: Opening for update".format(po.elffile)) elffh = open(po.elffile, "r+b") armfw_elf_dm3xxvals_update(po, elffh) elffh.close(); else: raise NotImplementedError('Unsupported command.')
def main(): """ Main executable function. Its task is to parse command line options and call a function which performs requested command. """ parser = argparse.ArgumentParser(description=__doc__.split('.')[0]) parser.add_argument("-e", "--elffile", type=str, required=True, help="Input ELF firmware file name") parser.add_argument("-o", "--valfile", type=str, help="Values list JSON file name") parser.add_argument("--dry-run", action="store_true", help="Do not write any files or do permanent changes") parser.add_argument("-v", "--verbose", action="count", default=0, help="Increases verbosity level; max level is set by -vvv") subparser = parser.add_mutually_exclusive_group(required=True) subparser.add_argument("-l", "--list", action="store_true", help="list values stored in the firmware") subparser.add_argument("-x", "--extract", action="store_true", help="Extract values to infos json text file") subparser.add_argument("-u", "--update", action="store_true", help="Update values in binary fw from infos text file") subparser.add_argument("-d", "--objdump", action="store_true", help="display asm like slightly primitive objdump") subparser.add_argument("--mapfile", action="store_true", help="export known symbols to map file") subparser.add_argument("--version", action='version', version="%(prog)s {version} by {author}" .format(version=__version__,author=__author__), help="Display version information and exit") po = parser.parse_args() po.basename = os.path.splitext(os.path.basename(po.elffile))[0] if len(po.elffile) > 0 and (po.valfile is None or len(po.valfile) == 0): po.valfile = po.basename + ".json" if po.objdump: if (po.verbose > 0): print("{}: Opening for objdump".format(po.elffile)) elffh = open(po.elffile, "rb") armfw_elf_generic_objdump(po, elffh) elffh.close(); elif po.list: if (po.verbose > 0): print("{}: Opening for list".format(po.elffile)) elffh = open(po.elffile, "rb") armfw_elf_dm3xxvals_list(po, elffh) elffh.close(); elif po.mapfile: if (po.verbose > 0): print("{}: Opening for mapfile generation".format(po.elffile)) elffh = open(po.elffile, "rb") armfw_elf_dm3xxvals_mapfile(po, elffh) elffh.close(); elif po.extract: if (po.verbose > 0): print("{}: Opening for extract".format(po.elffile)) elffh = open(po.elffile, "rb") armfw_elf_dm3xxvals_extract(po, elffh) elffh.close(); elif po.update: if (po.verbose > 0): print("{}: Opening for update".format(po.elffile)) elffh = open(po.elffile, "r+b") armfw_elf_dm3xxvals_update(po, elffh) elffh.close(); else: raise NotImplementedError('Unsupported command.')