Linker.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:spartacus 作者: CommunicationsSecurityEstablishment 项目源码 文件源码
def parseCommandLineArgs():
    """
    As implied by the name, this will parse the command line arguments so we can use them.
    :return: A parsed object as provided by argparse.parse_args()
    """
    parser = argparse.ArgumentParser(prog="Linker.py",
                                     description="Capua Static Flat Linker Version {}".format(__version__,),
                                     epilog="This tool is provided as part of Spartacus learning environment under {} "
                                            "licence. Feel free to distribute, modify, "
                                            "contribute and learn!".format(__license__,))
    parser.add_argument("-i", "--input",
                        required=True,
                        nargs="+",  # Using "+" here allows for variable number or parameters associated with this option
                        type=str,
                        help="Define the input file(s) to be used by the linker.")

    parser.add_argument("-o", "--output",
                        required=False,
                        nargs=1,
                        type=str,
                        default=UNDEFINED,
                        help="Define the output file where the linker data will be written. If not specified, this "
                             "will default to the input file name.")

    parser.add_argument("-a", "--address",
                        required=False,
                        nargs=1,
                        type=int,
                        default=DEFAULT_LOAD_ADDRESS,
                        help="Define the address at which a binary should be loaded. Don't mess this up, "
                             "Capua does not currently have virtual addressing mode... This means that you"
                             "HAVE TO MAKE SURE that your binary is loaded in a free memory region otherwise"
                             "you will destroy other programs!")

    parser.add_argument("-s", "--software",
                        required=False,
                        nargs=1,
                        type=bool,
                        default=False,
                        help="This specifies if the load happens by hardware or software. If it happens by"
                             "software, the load address will be but in the first 4 bytes of the final file"
                             "so that software can know where to put the binary in memory. Otherwise, the address"
                             "will not be added and the load will happen at hardware specified address.")

    args = parser.parse_args()
    args.output = args.output[0] if type(args.output) is not str else args.input[0].split(".")[0]  # Using input as default

    return args
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号