Exemple #1
0
def print_cmd(args):
    """Display an ELF file. args contains command line arguments passed
    from sys.argv. These are parsed using option parser."""

    parser = OptionParser("%prog print [options] file", add_help_option=0)
    parser.add_option("-H", "--help", action="help")
    parser.add_option("-a",
                      "--all",
                      action="store_true",
                      dest="all",
                      help="Print all information")
    parser.add_option("-h",
                      "--header",
                      action="store_true",
                      dest="header",
                      help="Print ELF header")
    parser.add_option("-l",
                      "--pheaders",
                      action="store_true",
                      dest="pheaders",
                      help="Print ELF sections headers")
    parser.add_option("-S",
                      "--sheaders",
                      action="store_true",
                      dest="sheaders",
                      help="Print ELF sections headers")
    parser.add_option("-k",
                      "--kconfig",
                      action="store_true",
                      dest="kconfig",
                      help="Print L4 kernel config data structure (Default)")
    parser.add_option("-B",
                      "--bootinfo",
                      action="store_true",
                      dest="bootinfo",
                      help="Print L4 Bootinfo")
    parser.add_option("-s",
                      "--segnames",
                      action="store_true",
                      dest="segnames",
                      help="Print segment names")

    (options, args) = parser.parse_args(args)

    if len(args) != 1:
        parser.error("incorrect number of arguments")

    if options.all:
        options.header = options.pheaders = options.sheaders = \
                             options.kconfig = options.bootinfo = True

    elf = PreparedElfFile(filename=args[0])

    if options.header:
        elf.get_elf_header().output(sys.stdout)

    if options.sheaders:
        print_sheaders(elf, not options.header, sys.stdout)

    if options.pheaders:
        print_pheaders(elf, not options.header, sys.stdout)

    if options.kconfig:
        print
        kconfig = find_kernel_config(elf)
        if kconfig:
            kconfig.output(sys.stdout)
        else:
            print "There is no kernel configuration in this file."

    if options.bootinfo:
        print
        bootinfo = find_bootinfo(elf)
        if bootinfo:
            bootinfo.output(sys.stdout)
        else:
            print "There is no Bootinfo section in this file."

    if options.segnames:
        print
        segnames = get_segnames(elf)
        if segnames:
            for segname in segnames.strings:
                idx = segname.index('\x00')
                segname = segname[:idx]
                segname = segname.strip()
                if segname == "":
                    continue
                print segname
        else:
            # TODO - use the first section in each segment
            # as the segment name and print that.
            print "There is no .segnames section in this file"

    return 0
Exemple #2
0
def print_cmd(args):
    """Display an ELF file. args contains command line arguments passed
    from sys.argv. These are parsed using option parser."""

    parser = OptionParser("%prog print [options] file", add_help_option=0)
    parser.add_option("-H", "--help", action="help")
    parser.add_option("-a", "--all", action="store_true", dest="all",
                      help="Print all information")
    parser.add_option("-h", "--header", action="store_true", dest="header",
                      help="Print ELF header")
    parser.add_option("-l", "--pheaders", action="store_true", dest="pheaders",
                      help="Print ELF sections headers")
    parser.add_option("-S", "--sheaders", action="store_true", dest="sheaders",
                      help="Print ELF sections headers")
    parser.add_option("-k", "--kconfig", action="store_true", dest="kconfig", 
                      help="Print L4 kernel config data structure (Default)")
    parser.add_option("-B", "--bootinfo", action="store_true", dest="bootinfo",
                      help="Print L4 Bootinfo")
    parser.add_option("-s", "--segnames", action="store_true", dest="segnames",
                      help="Print segment names")

    (options, args) = parser.parse_args(args)
    
    if len(args) != 1:
        parser.error("incorrect number of arguments")

    if options.all:
        options.header = options.pheaders = options.sheaders = \
                             options.kconfig = options.bootinfo = True

    elf = PreparedElfFile(filename=args[0])

    if options.header:
        elf.get_elf_header().output(sys.stdout)

    if options.sheaders:
        print_sheaders(elf, not options.header, sys.stdout)

    if options.pheaders:
        print_pheaders(elf, not options.header, sys.stdout)

    if options.kconfig:
        print
        kconfig = find_kernel_config(elf)
        if kconfig:
            kconfig.output(sys.stdout)
        else:
            print "There is no kernel configuration in this file."

    if options.bootinfo:
        print
        bootinfo = find_bootinfo(elf)
        if bootinfo:
            bootinfo.output(sys.stdout)
        else:
            print "There is no Bootinfo section in this file."

    if options.segnames:
        print
        segnames = get_segnames(elf)
        if segnames:
            for segname in segnames.strings:
                idx = segname.index('\x00')
                segname = segname[:idx]
                segname = segname.strip()
                if segname == "":
                    continue
                print segname
        else:
            # TODO - use the first section in each segment
            # as the segment name and print that.
            print "There is no .segnames section in this file"

    return 0
Exemple #3
0
def print_cmd(args):
    """Display an ELF file. args contains command line arguments passed
    from sys.argv. These are parsed using option parser."""

    parser = OptionParser("%prog print [options] file", add_help_option=0)
    parser.add_option("-H", "--help", action="help")
    parser.add_option("-a", "--all", action="store_true", dest="all",
                      help="Print all information")
    parser.add_option("-h", "--header", action="store_true", dest="header",
                      help="Print ELF header")
    parser.add_option("-l", "--pheaders", action="store_true", dest="pheaders",
                      help="Print ELF sections headers")
    parser.add_option("-S", "--sheaders", action="store_true", dest="sheaders",
                      help="Print ELF sections headers")
    parser.add_option("-k", "--kconfig", action="store_true", dest="kconfig",
                      help="Print L4 kernel config data structure (Default)")
    parser.add_option("-B", "--bootinfo", action="store_true", dest="bootinfo",
                      help="Print L4 Bootinfo")
    parser.add_option("-m", "--segnames", action="store_true", dest="segnames",
                      help="Print segment names")
    parser.add_option("-s", "--syms", action="store_true", dest="symbols",
                      help="Print the symbol table")
    parser.add_option("-r", "--relocs", action="store_true", dest="relocs",
                      help="Display the relocations (if present)")
    parser.add_option("-W", "--wide", action="store_true",
                      dest="wide", default=False,
                      help="Allow output width to exceed 80 characters")
    parser.add_option("-e", "--elfweaver-info", action="store_true",
                      dest="elfweaverinfo", help="Print elfweaver info section")

    (options, args) = parser.parse_args(args)

    if len(args) != 1:
        parser.error("incorrect number of arguments")

    if options.all:
        options.header = options.pheaders = options.sheaders = \
                             options.kconfig = options.bootinfo = \
                             options.elfweaverinfo = options.segnames = True

    elf = PreparedElfFile(filename=args[0])

    if options.header:
        elf.get_elf_header().output(sys.stdout)

    if options.sheaders:
        print_sheaders(elf, not options.header, sys.stdout)

    if options.pheaders:
        print_pheaders(elf, not options.header, sys.stdout)

    if options.symbols:
        print_symbol_table(elf, sys.stdout, options.wide)

    if options.relocs:
        print_relocations(elf, sys.stdout, options.wide)

    if options.kconfig:
        kern_ver = check_api_versions(elf)
        if kern_ver == NANO_KERNEL_API_VERSION:
            kconfig = find_nano_heap(elf)
        else: # kern_ver == MICRO_KERNEL_API_VERSION:
            kconfig = find_kernel_config(elf)

        print
        if kconfig:
            kconfig.output(sys.stdout)
        else:
            print "There is no kernel configuration in this file."

        if kern_ver != NANO_KERNEL_API_VERSION:
            print
            initscript = find_init_script(elf)
            if initscript:
                initscript.output(sys.stdout)
            else:
                print "There is no initialisation script in this file."

    if options.elfweaverinfo:
        print
        elfweaverinfo = find_elfweaver_info(elf)
        if elfweaverinfo:
            elfweaverinfo.output(sys.stdout)
        else:
            print "There is no elfweaver info section in this file."

    if options.bootinfo:
        print
        bootinfo = find_bootinfo(elf)
        if bootinfo:
            bootinfo.output(sys.stdout)
        else:
            print "There is no Bootinfo section in this file."

    if options.segnames:
        segcount = 0
        print
        segnames = get_segnames(elf)

        if segnames:
            print "Segment    Name"

            for segname in segnames.strings[1:]:
                idx = segname.index('\x00')
                segname = segname[:idx]
                segname = segname.strip()

                if segname != "":
                    print "  %02d       %s" % (segcount, segname)

                segcount += 1
        else:
            # TODO - use the first section in each segment
            # as the segment name and print that.
            print "There is no .segnames section in this file"

    return 0
Exemple #4
0
def print_cmd(args):
    """Display an ELF file. args contains command line arguments passed
    from sys.argv. These are parsed using option parser."""

    parser = OptionParser("%prog print [options] file", add_help_option=0)
    parser.add_option("-H", "--help", action="help")
    parser.add_option("-a",
                      "--all",
                      action="store_true",
                      dest="all",
                      help="Print all information")
    parser.add_option("-h",
                      "--header",
                      action="store_true",
                      dest="header",
                      help="Print ELF header")
    parser.add_option("-l",
                      "--pheaders",
                      action="store_true",
                      dest="pheaders",
                      help="Print ELF sections headers")
    parser.add_option("-S",
                      "--sheaders",
                      action="store_true",
                      dest="sheaders",
                      help="Print ELF sections headers")
    parser.add_option("-k",
                      "--kconfig",
                      action="store_true",
                      dest="kconfig",
                      help="Print L4 kernel config data structure (Default)")
    parser.add_option("-B",
                      "--bootinfo",
                      action="store_true",
                      dest="bootinfo",
                      help="Print L4 Bootinfo")
    parser.add_option("-m",
                      "--segnames",
                      action="store_true",
                      dest="segnames",
                      help="Print segment names")
    parser.add_option("-s",
                      "--syms",
                      action="store_true",
                      dest="symbols",
                      help="Print the symbol table")
    parser.add_option("-r",
                      "--relocs",
                      action="store_true",
                      dest="relocs",
                      help="Display the relocations (if present)")
    parser.add_option("-W",
                      "--wide",
                      action="store_true",
                      dest="wide",
                      default=False,
                      help="Allow output width to exceed 80 characters")
    parser.add_option("-e",
                      "--elfweaver-info",
                      action="store_true",
                      dest="elfweaverinfo",
                      help="Print elfweaver info section")

    (options, args) = parser.parse_args(args)

    if len(args) != 1:
        parser.error("incorrect number of arguments")

    if options.all:
        options.header = options.pheaders = options.sheaders = \
                             options.kconfig = options.bootinfo = \
                             options.elfweaverinfo = options.segnames = True

    elf = PreparedElfFile(filename=args[0])

    if options.header:
        elf.get_elf_header().output(sys.stdout)

    if options.sheaders:
        print_sheaders(elf, not options.header, sys.stdout)

    if options.pheaders:
        print_pheaders(elf, not options.header, sys.stdout)

    if options.symbols:
        print_symbol_table(elf, sys.stdout, options.wide)

    if options.relocs:
        print_relocations(elf, sys.stdout, options.wide)

    if options.kconfig:
        kern_ver = check_api_versions(elf)
        if kern_ver == NANO_KERNEL_API_VERSION:
            kconfig = find_nano_heap(elf)
        else:  # kern_ver == MICRO_KERNEL_API_VERSION:
            kconfig = find_kernel_config(elf)

        print
        if kconfig:
            kconfig.output(sys.stdout)
        else:
            print "There is no kernel configuration in this file."

        if kern_ver != NANO_KERNEL_API_VERSION:
            print
            initscript = find_init_script(elf)
            if initscript:
                initscript.output(sys.stdout)
            else:
                print "There is no initialisation script in this file."

    if options.elfweaverinfo:
        print
        elfweaverinfo = find_elfweaver_info(elf)
        if elfweaverinfo:
            elfweaverinfo.output(sys.stdout)
        else:
            print "There is no elfweaver info section in this file."

    if options.bootinfo:
        print
        bootinfo = find_bootinfo(elf)
        if bootinfo:
            bootinfo.output(sys.stdout)
        else:
            print "There is no Bootinfo section in this file."

    if options.segnames:
        segcount = 0
        print
        segnames = get_segnames(elf)

        if segnames:
            print "Segment    Name"

            for segname in segnames.strings[1:]:
                idx = segname.index('\x00')
                segname = segname[:idx]
                segname = segname.strip()

                if segname != "":
                    print "  %02d       %s" % (segcount, segname)

                segcount += 1
        else:
            # TODO - use the first section in each segment
            # as the segment name and print that.
            print "There is no .segnames section in this file"

    return 0