From: Eli Bendersky Date: Fri, 9 Sep 2011 07:23:16 +0000 (+0300) Subject: some cleanup X-Git-Tag: v0.10~128 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6a12cde058e1bc0da3617bfaf6e608d0772fddfe;p=pyelftools.git some cleanup --- diff --git a/scripts/readelf.py b/scripts/readelf.py index 44b7798..427ee8f 100644 --- a/scripts/readelf.py +++ b/scripts/readelf.py @@ -87,11 +87,24 @@ class ReadElf(object): self._emitline(' Section header string table index: %s' % header['e_shstrndx']) + def _format_addr(self, addr, fullhex=False, lead0x=True): + """ Format an address into a hexadecimal string. - def _format_addr(self, addr): - """ Format an address into a string + fullhex: + If True, include leading zeros in the address, adjusted for + the elfclass. + + lead0x: + If True, leading 0x is added """ - return '0x%x' % addr + s = '0x' if lead0x else '' + if fullhex: + if self.elffile.elfclass == 32: + return s + '%08x' % addr + else: + return s + '%016x' % addr + else: + return s + '%x' % addr def _emit(self, s): """ Emit an object to output