gwcheck

Check .gnu.warning.* sections in ELF object files
Log | Files | Refs | README | LICENSE

commit b8f6817c9d813c4a51ad84ec43f6933d7b8e723c
parent a70955744ab4407f1ff01665464820f3f3ece90b
Author: Frederic Cambus <fred@statdns.com>
Date:   Thu,  4 Nov 2021 16:55:41 +0100

Add getopt support, and allow displaying usage and version.

Diffstat:
Mgwcheck | 28++++++++++++++++++++++++++++
1 file changed, 28 insertions(+), 0 deletions(-)

diff --git a/gwcheck b/gwcheck @@ -14,12 +14,40 @@ # SPDX-License-Identifier: BSD-2-Clause # +import getopt +import textwrap import sys from elftools.elf.elffile import ELFFile from elftools.common.exceptions import ELFError +def usage(): + usage = """\ + gwcheck [-hv] input + + The options are as follows: + + -h Display usage. + -v Display version.""" + + print(textwrap.dedent(usage)) + + def main(): + try: + options, args = getopt.getopt(sys.argv[1:], "hv") + except getopt.GetoptError as err: + print(err) + sys.exit(1) + + for option, arg in options: + if option == "-h": + usage() + sys.exit(0) + if option == "-v": + print("gwcheck 1.0.0") + sys.exit(0) + with open(sys.argv[1], "rb") as input: try: for section in ELFFile(input).iter_sections():