From 4ff064cda4475b4496eb547c5c176d9ccba0d67c Mon Sep 17 00:00:00 2001 From: Stefan Oberhumer Date: Fri, 6 Jan 2017 21:45:46 +0100 Subject: [PATCH 1/3] FIX: Pass 'target' parameter to underlying bfd_openr() and bfd_fdopenr() functions. --- pybfd/bfd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pybfd/bfd.c b/pybfd/bfd.c index 11d8a0f..969adef 100755 --- a/pybfd/bfd.c +++ b/pybfd/bfd.c @@ -153,7 +153,7 @@ pybfd_openr(PyObject *self, PyObject *args) { const char* target; if (PyArg_ParseTuple(args, "ss", &filename, &target)) { - abfd = bfd_openr(filename, NULL); + abfd = bfd_openr(filename, target); if (!abfd) { // An error ocurred trying to open the file. @@ -191,7 +191,7 @@ pybfd_fdopenr(PyObject *self, PyObject *args) { int fd; if (PyArg_ParseTuple(args, "ssi", &filename, &target, &fd)) { - abfd = bfd_fdopenr(filename, NULL, fd); + abfd = bfd_fdopenr(filename, target, fd); if (!abfd) { // An error ocurred trying to open the file. From 5964826e3738c527af8af8139d3df3ab392d860b Mon Sep 17 00:00:00 2001 From: Stefan Oberhumer Date: Fri, 6 Jan 2017 22:06:21 +0100 Subject: [PATCH 2/3] Add -b --target option to objdump. --- pybfd/objdump.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pybfd/objdump.py b/pybfd/objdump.py index dfd9631..bd62ee0 100755 --- a/pybfd/objdump.py +++ b/pybfd/objdump.py @@ -55,6 +55,15 @@ def do_action(self, parser, namespace, values, option_string): print " %s" % target +class BfdActionTarget(Action): + def __call__(self, parser, namespace, values, option_string=None): + self.bfd = bfd.Bfd() + if values[0] not in self.bfd.targets: + raise Exception("Invalid bfd target '%s'" % values[0]) + namespace.target = values[0] + self.bfd.close() + + class BfdActionWithFileParam(Action): """Base class for BFD actions invoked by the argument parser.""" @@ -64,7 +73,7 @@ def __call__(self, parser, namespace, values, option_string=None): for fd in values: try: # Create a new BFD from the current file descriptor. - self.bfd = bfd.Bfd(fd) + self.bfd = bfd.Bfd(fd, namespace.target) # Display current filename and corresponding architecture. print "\n%s: file format %s\n" % \ @@ -274,6 +283,12 @@ def init_parser(): type=FileType("r"), nargs="+", help="Display archive header information") + group.add_argument("-b", "--target", # add "-b, --target" to support bfd targets + action=BfdActionTarget, + nargs="+", + default="default", + help="") + group.add_argument("-f", "--file-headers", action=DumpFileHeadersAction, type=FileType("r"), nargs="+", From 1f94cb31b334bb6cad262f10d05087a26ade5b2f Mon Sep 17 00:00:00 2001 From: Stefan Oberhumer Date: Fri, 6 Jan 2017 22:11:21 +0100 Subject: [PATCH 3/3] Nicer output for list of architectures and bfd targets. --- pybfd/objdump.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pybfd/objdump.py b/pybfd/objdump.py index bd62ee0..60f0b44 100755 --- a/pybfd/objdump.py +++ b/pybfd/objdump.py @@ -48,11 +48,17 @@ def do_action(self, parser, namespace, values, option_string): print "%s %s (%s)" % (parser.prog, __version__, __description__) + print "Architectures:", for arch in self.bfd.architectures: print " %s" % arch, + print + print + + print "Bfd Targets:", for target in self.bfd.targets: - print " %s" % target + print " %s" % target, + print class BfdActionTarget(Action):