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. diff --git a/pybfd/objdump.py b/pybfd/objdump.py index dfd9631..60f0b44 100755 --- a/pybfd/objdump.py +++ b/pybfd/objdump.py @@ -48,11 +48,26 @@ 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): + 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): @@ -64,7 +79,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 +289,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="+",