pyelftools.git
14 months agoFriendly error in get_location_list_at_offset (#492)
Seva Alekseyev [Wed, 23 Aug 2023 14:32:24 +0000 (10:32 -0400)]
Friendly error in get_location_list_at_offset (#492)

14 months agofix examples/dwarf_location_info.py (#490)
Nick Desaulniers [Wed, 23 Aug 2023 12:23:34 +0000 (05:23 -0700)]
fix examples/dwarf_location_info.py (#490)

Pass along the DIE otherwise the following error is observed:

    Traceback (most recent call last):
      File "/tmp/pyelftools/examples/dwarf_location_info.py", line 110, in <module>
        process_file(filename)
      File "/tmp/pyelftools/examples/dwarf_location_info.py", line 78, in process_file
        loc = loc_parser.parse_from_attribute(attr,
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/tmp/pyelftools/elftools/dwarf/locationlists.py", line 307, in parse_from_attribute
        return self.location_lists.get_location_list_at_offset(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/tmp/pyelftools/elftools/dwarf/locationlists.py", line 96, in get_location_list_at_offset
        return self._parse_location_list_from_stream_v5(die.cu) if self.version >= 5 else self._parse_location_list_from_stream()
                                                        ^^^^^^
    AttributeError: 'NoneType' object has no attribute 'cu'

14 months agoARM tag 46 (#491)
Seva Alekseyev [Wed, 23 Aug 2023 12:17:48 +0000 (08:17 -0400)]
ARM tag 46 (#491)

15 months agoreadelf 2.41 with Ranges test excluded on 2 files (#489)
Seva Alekseyev [Tue, 22 Aug 2023 12:26:05 +0000 (08:26 -0400)]
readelf 2.41 with Ranges test excluded on 2 files (#489)

* readelf 2.41 with Ranges test excluded

* Ranges test reinstated except two binaries

---------

Co-authored-by: Seva <seva@sandbox.home>
15 months agoMissing tags (#487)
Seva Alekseyev [Wed, 16 Aug 2023 00:31:26 +0000 (17:31 -0700)]
Missing tags (#487)

16 months agoReporting the real attribute form for DW_FORM_indirect (#475)
Seva Alekseyev [Thu, 29 Jun 2023 02:31:30 +0000 (22:31 -0400)]
Reporting the real attribute form for DW_FORM_indirect (#475)

* Reporting the real attribute form for DW_FORM_indirect

* Fixes

* Unit test

* Comments

* Typo

---------

Co-authored-by: Seva Alekseyev <sevaa@nih.gov>
19 months agoClean up some tabs and remove tox.ini which isn't used any more
Eli Bendersky [Fri, 21 Apr 2023 13:17:49 +0000 (06:17 -0700)]
Clean up some tabs and remove tox.ini which isn't used any more

19 months agoAdd support for LoongArch (#470)
Wu Xiaotian [Fri, 21 Apr 2023 13:13:14 +0000 (21:13 +0800)]
Add support for LoongArch (#470)

refer: https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html#_e_flags_identifies_abi_type_and_version

19 months agoadd reloc type and recipe for eBPF (#466)
Flier Lu [Mon, 17 Apr 2023 15:12:43 +0000 (23:12 +0800)]
add reloc type and recipe for eBPF (#466)

19 months agoCreate SECURITY.md
Eli Bendersky [Mon, 17 Apr 2023 13:38:25 +0000 (06:38 -0700)]
Create SECURITY.md

20 months agoFilename in lineprog index fix made DWARF5 aware (#463)
Seva Alekseyev [Tue, 21 Mar 2023 00:01:05 +0000 (20:01 -0400)]
Filename in lineprog index fix made DWARF5 aware (#463)

21 months agoAdd support for RISC-V attributes (#459)
Ricardo Barbedo [Sat, 4 Feb 2023 00:41:41 +0000 (01:41 +0100)]
Add support for RISC-V attributes (#459)

* Add support for RISC-V attributes

* Fix typos and formatting

21 months agoadd support for loongarch64 to dwarfdump (#458)
haomi123 [Mon, 30 Jan 2023 16:49:56 +0000 (00:49 +0800)]
add support for loongarch64 to dwarfdump (#458)

2 years agoadd support for arm to dwarfdump (#449)
laqieer [Thu, 27 Oct 2022 20:05:50 +0000 (04:05 +0800)]
add support for arm to dwarfdump (#449)

refer to: https://github.com/eliben/pyelftools/pull/445

2 years agoSome GNU extension attributes (#447)
Seva Alekseyev [Tue, 18 Oct 2022 15:53:57 +0000 (11:53 -0400)]
Some GNU extension attributes (#447)

2 years agoadd support for aarch64 to dwarfdump (#445)
Nick Desaulniers [Sat, 15 Oct 2022 17:42:10 +0000 (10:42 -0700)]
add support for aarch64 to dwarfdump (#445)

llvm-dwarfdump prints
elf64-littleaarch64

We probably need more logic to differentiate between big endian (less
common) vs little endian (more common), but at least this allows us to
use ./scripts/dwarfdump on aarch64 targets now.

I probably should have added this to #318 / #317.

2 years agoAdd pyproject.toml (#443)
Kevin Phoenix [Sat, 24 Sep 2022 13:29:15 +0000 (06:29 -0700)]
Add pyproject.toml (#443)

2 years agoAdded Dwarfv5 CU headers (#442)
Will Denissen [Thu, 22 Sep 2022 20:11:30 +0000 (22:11 +0200)]
Added Dwarfv5 CU headers (#442)

Extended readelf.py
Added test file compiled with
-gdebug_types-section to readelf tests

2 years agoFix for CU version check in LocationListsPair (#439)
Seva Alekseyev [Mon, 22 Aug 2022 12:41:49 +0000 (08:41 -0400)]
Fix for CU version check in LocationListsPair (#439)

2 years agoMinor stylistic fixes following up the previous commit
Eli Bendersky [Wed, 17 Aug 2022 12:46:40 +0000 (05:46 -0700)]
Minor stylistic fixes following up the previous commit

2 years agoCache instantiation of DWARF structs. (#435)
Ronan Dunklau [Wed, 17 Aug 2022 12:42:21 +0000 (14:42 +0200)]
Cache instantiation of DWARF structs. (#435)

This takes a huge amount of time when iterating over compile units.

2 years agoMerge branch 'master' of github.com:eliben/pyelftools
Eli Bendersky [Tue, 16 Aug 2022 13:41:28 +0000 (06:41 -0700)]
Merge branch 'master' of github.com:eliben/pyelftools

2 years agoRemove z.py
Eli Bendersky [Tue, 16 Aug 2022 13:41:16 +0000 (06:41 -0700)]
Remove z.py

2 years agoSupport for DW_FORM_data16, unit test (#437)
Seva Alekseyev [Tue, 16 Aug 2022 13:40:14 +0000 (09:40 -0400)]
Support for DW_FORM_data16, unit test (#437)

Fixes #436

2 years agoFinish refactoring out py3compat and delete the file
Eli Bendersky [Tue, 16 Aug 2022 13:38:15 +0000 (06:38 -0700)]
Finish refactoring out py3compat and delete the file

Fixes #415

2 years agoRemove int2byte and byte2int utilities from py3compat
Eli Bendersky [Tue, 16 Aug 2022 13:31:35 +0000 (06:31 -0700)]
Remove int2byte and byte2int utilities from py3compat

2 years agoRemove BytesIO and StringIO from py3compat
Eli Bendersky [Tue, 16 Aug 2022 13:26:19 +0000 (06:26 -0700)]
Remove BytesIO and StringIO from py3compat

2 years agoRemove path and maxint from py3compat
Eli Bendersky [Tue, 16 Aug 2022 13:21:11 +0000 (06:21 -0700)]
Remove path and maxint from py3compat

2 years agoMove utilities from py3compat to utils
Eli Bendersky [Tue, 16 Aug 2022 13:15:04 +0000 (06:15 -0700)]
Move utilities from py3compat to utils

2 years agoRemove iter* utilities from py3compat and refactor uses
Eli Bendersky [Tue, 16 Aug 2022 13:03:20 +0000 (06:03 -0700)]
Remove iter* utilities from py3compat and refactor uses

2 years agoRemove mention of supporting Python 2 from the README
Eli Bendersky [Mon, 15 Aug 2022 13:24:10 +0000 (06:24 -0700)]
Remove mention of supporting Python 2 from the README

Updates #415

2 years agoPython version 3.10 needs quotes in the yaml file
Eli Bendersky [Mon, 15 Aug 2022 13:18:32 +0000 (06:18 -0700)]
Python version 3.10 needs quotes in the yaml file

2 years agoOfficially remove Python 2 support from this point forward
Eli Bendersky [Mon, 15 Aug 2022 13:15:29 +0000 (06:15 -0700)]
Officially remove Python 2 support from this point forward

This change removes the support from setup.py and the testing files, and
adds an assertion to py3compat that will crash when pyelftools is run
w/ Python 2

Doesn't remove compatibility code, yet

Updates #415

2 years agoRejigger MANIFEST.in to properly include/exclude test stuff v0.29
Eli Bendersky [Wed, 10 Aug 2022 03:23:00 +0000 (20:23 -0700)]
Rejigger MANIFEST.in to properly include/exclude test stuff

2 years agoAdd back empty_pubtypes dir, and include *.common test files too
Eli Bendersky [Tue, 9 Aug 2022 23:23:37 +0000 (16:23 -0700)]
Add back empty_pubtypes dir, and include *.common test files too

2 years agoRename test files with .debug
Eli Bendersky [Tue, 9 Aug 2022 23:18:01 +0000 (16:18 -0700)]
Rename test files with .debug

This is also added to MANIFEST.in

... and make the subdirectory executable again

2 years agoRemove 'x' permissions from all test files in testfiles_for_unittests
Eli Bendersky [Tue, 9 Aug 2022 23:15:02 +0000 (16:15 -0700)]
Remove 'x' permissions from all test files in testfiles_for_unittests

2 years agoPrepare for 0.29 release
Eli Bendersky [Tue, 9 Aug 2022 23:11:07 +0000 (16:11 -0700)]
Prepare for 0.29 release

Not tagging in Git yet -- testing distribution

2 years agoUpdate tox to run all_tests
Eli Bendersky [Tue, 9 Aug 2022 23:01:19 +0000 (16:01 -0700)]
Update tox to run all_tests

2 years agoAdded out of bounds read detection for corrups section headers (#434)
Javier Rascón Mesa [Tue, 9 Aug 2022 22:53:02 +0000 (00:53 +0200)]
Added out of bounds read detection for corrups section headers (#434)

* Added test for files with corrupt e_shoff & e_shnum

* Added basic detection for reading out of the stream bounds due to corrupt header

* Added None check when accessing '_section_header_stringtable'

* Fix to work on python2

Co-authored-by: halos <halos@synth>
2 years agoInclude so, dat files in the test (#433)
Seva Alekseyev [Tue, 9 Aug 2022 22:51:27 +0000 (18:51 -0400)]
Include so, dat files in the test (#433)

Fixes #349

2 years agoSupplementary object files (#426)
Ronan Dunklau [Mon, 8 Aug 2022 14:50:55 +0000 (16:50 +0200)]
Supplementary object files (#426)

* Recognize DW_FORM_ref_udata as a reference type.

References to other DIEs can also be implemented with a form
DW_FORM_ref_udata, for using the ULEB128 encoding

* Add support for DWARF supplementary object files.

2 years agodocs: Fix a few typos (#431)
Tim Gates [Wed, 13 Jul 2022 21:01:06 +0000 (07:01 +1000)]
docs: Fix a few typos (#431)

There are small typos in:
- elftools/common/py3compat.py
- elftools/dwarf/die.py

Fixes:
- Should read `representations` rather than `pepresentations`.
- Should read `purposes` rather than `pusposes`.

2 years agoIndirect encoding support (#430)
Seva Alekseyev [Tue, 12 Jul 2022 02:27:32 +0000 (22:27 -0400)]
Indirect encoding support (#430)

* Indirect encoding support

* Readelf fix for ranges/rnglists mix

* Typo, comments

2 years agoMixing v4 and v5 loclists and rangelists sections (#429)
Seva Alekseyev [Fri, 8 Jul 2022 12:41:52 +0000 (08:41 -0400)]
Mixing v4 and v5 loclists and rangelists sections (#429)

* More GNU note dumping

* aranges fix for empty sections

* Mixed v4/v5 sections.

* Test for readelf

* Comments, typo

2 years agoAutotest against llvm-dwarfdump (#428)
Seva Alekseyev [Wed, 6 Jul 2022 17:06:37 +0000 (13:06 -0400)]
Autotest against llvm-dwarfdump (#428)

* Descriptive output dump file names on autotest

* Dwarfdump.py

* Test and test files for dwarfdump

* Loclist dump fix

* Permissions

* Fixes

2 years agoClean up whitespace
Eli Bendersky [Fri, 17 Jun 2022 14:10:12 +0000 (07:10 -0700)]
Clean up whitespace

2 years agoReadelf upgraded to 2.38, format fixes (#420)
Seva Alekseyev [Fri, 17 Jun 2022 14:04:44 +0000 (10:04 -0400)]
Readelf upgraded to 2.38, format fixes (#420)

2 years agoSupport for DWARFv5 debug_rnglists section (#419)
Seva Alekseyev [Fri, 17 Jun 2022 13:09:32 +0000 (09:09 -0400)]
Support for DWARFv5 debug_rnglists section (#419)

* Pre-DWARFv5 range section dumping, Ranges in readelf autotest

* DWARFv5 rnglists section support

* Autotest fixes

* Misleading comment

* Version, dwarfinfo now required in RangeLists constructor

2 years agoClarify instructions in test/external_tools
Eli Bendersky [Fri, 17 Jun 2022 12:28:05 +0000 (05:28 -0700)]
Clarify instructions in test/external_tools

2 years agoAdd previously untested output file to test set
Eli Bendersky [Thu, 16 Jun 2022 13:47:35 +0000 (06:47 -0700)]
Add previously untested output file to test set

* By renaming it to have a .elf suffix

This also fixes descriptions for DW_FORM_sdata to comply with the recent output
format of readelf

2 years agoSay which test file failed in readelf tests
Eli Bendersky [Thu, 16 Jun 2022 13:42:36 +0000 (06:42 -0700)]
Say which test file failed in readelf tests

[otherwise in parallel mode it's hard to know]

2 years agoDWARF 5 operations and DWARF5 location lists (#418)
Seva Alekseyev [Thu, 16 Jun 2022 12:19:30 +0000 (08:19 -0400)]
DWARF 5 operations and DWARF5 location lists (#418)

* Test binary for DWARFv5 operations

* DWARFv5 ops, part 1: entry_value, const_type, deref_type

* DWARFv5 ops, part 2: regval_type, implicit_pointer, convert

* DWARFv5 loclists section parsing, take 1

* Foamtting fix

* Test fixes

* Lineprogram header file_entries with DWARFv5 now are indexable by string

* Excising the View column, if present, from GNU readelf..decodedline output

* Readelf test fixes

* Typo

* Formatting and comments

* More style fixes

2 years agoChange supported Python versions in github actions (#416)
Eli Bendersky [Mon, 13 Jun 2022 13:59:35 +0000 (06:59 -0700)]
Change supported Python versions in github actions (#416)

2 years agoWhitespace cleanups
Eli Bendersky [Mon, 13 Jun 2022 12:49:02 +0000 (05:49 -0700)]
Whitespace cleanups

2 years agoVersion 5 lineprogram header (#411)
Seva Alekseyev [Mon, 13 Jun 2022 12:44:44 +0000 (08:44 -0400)]
Version 5 lineprogram header (#411)

* Version 5 lineprogram header, take 1

* Readelf/decodedline formatting fix

* DWARF 5 fields None, not missing

* Comment

* Sample binary

* Dump unit type in readelf info

* More languages described

* Describing form_line_strp

* Basic support for GNU_PROPERTY_X86_ISA_1

* Readelf decodedline format fixes to match with DWARF5

* Readelf test shorted out for the file/test where a bug in GNU readelf manifests, see PR #411.

* Newline :)

* Readelf' language names matched against binutils

* Comment about lineprogram files and directories

* GNU binutils bug worked around in a slightly less disturbing way - patched the binary, left a comment in the test script.

* Examples autotest no longer fails on Windows over expected path format

* Autotest fix

* Typo

* Windows compatibility, take 2

* No pathlib on Python 2

Co-authored-by: Seva Alekseyev <sevaa@nih.gov>
2 years agoReformat some docstrings
Eli Bendersky [Wed, 8 Jun 2022 12:57:46 +0000 (05:57 -0700)]
Reformat some docstrings

2 years agoMinor cosmetic changes
Eli Bendersky [Tue, 7 Jun 2022 23:20:05 +0000 (16:20 -0700)]
Minor cosmetic changes

2 years agoSupport for sibling in form DW_FORM_ref_addr (#408)
Seva Alekseyev [Tue, 7 Jun 2022 23:17:31 +0000 (19:17 -0400)]
Support for sibling in form DW_FORM_ref_addr (#408)

Co-authored-by: Seva Alekseyev <sevaa@nih.gov>
2 years agoStoring the offset of DWARF operations within the expression block (#404)
Seva Alekseyev [Mon, 16 May 2022 13:58:24 +0000 (09:58 -0400)]
Storing the offset of DWARF operations within the expression block (#404)

* Storing the offset of every DWARF operations within the expression block

* Trivial auto test

2 years agoImprove DWARF 5 compatibility. (#400)
Ronan Dunklau [Tue, 10 May 2022 13:56:32 +0000 (15:56 +0200)]
Improve DWARF 5 compatibility. (#400)

* Add support DW_FORM_implicit_const

* Add support for DW_FORM_line_strp

* Add new tests for DW_FORM_implicit_const and DW_FORM_linestrp.

2 years agoAdd support for DT_RELR/SHT_RELR compressed relocation sections (#395)
Andreas Ziegler [Mon, 14 Feb 2022 13:44:27 +0000 (14:44 +0100)]
Add support for DT_RELR/SHT_RELR compressed relocation sections (#395)

As more and more tools now support DT_RELR compressed relocations
(most notably, the just released GNU binutils 2.38 [0]), let's add
support for reading these relocations as well.

The original discussion about advantages of packe RELATIVE
relocations can be found at [1]. In a nutshell, the format
exploits the fact that RELATIVE relocations are often placed
next to each other and (for x86_64) stores up to 64 relocations
in two 8-byte words. In a regular .rela.dyn table, these would
take up 24 * 64 = 1536 bytes.

The compressed relocations work as follows:

The first word in the section describes a base address and
contains an offset for a relocation. This offset must always
lie at an even address. Following this entry can be one or
more bitmap(s) which have their least significant bit set to 1.
All other bits describe (in increasing order of significance) if
the following continuous offsets also contain a relocation. The
addends for existing relocations are stored at the corresponding
offsets in the file (that is, they work like REL relocations).
A good description of the history of this feature and its current
adoption is the following blog post [2].

[0]: https://lists.gnu.org/archive/html/info-gnu/2022-02/msg00009.html
[1]: https://groups.google.com/g/generic-abi/c/bX460iggiKg?pli=1
[2]: https://maskray.me/blog/2021-10-31-relative-relocations-and-relr

2 years agoPrepare for releasing version 0.28 v0.28
Eli Bendersky [Thu, 3 Feb 2022 14:45:41 +0000 (06:45 -0800)]
Prepare for releasing version 0.28

2 years agoUpdate structs.py (#392)
Brendan Haines [Thu, 13 Jan 2022 23:07:39 +0000 (16:07 -0700)]
Update structs.py (#392)

Remove unused imports

2 years agoAdd PS3/CellOS OSABI identifier (#389)
Adam [Tue, 11 Jan 2022 12:05:21 +0000 (12:05 +0000)]
Add PS3/CellOS OSABI identifier (#389)

* Add PS3/CellOS OSABI identifier.

* Remove "OS" from CELL OS ABI

* Remove "OS" from CELL OS ABI

* Add Missing comma for ELFOSABI_CELL_LV2.

2 years agoAdd support for note GNU_PROPERTY_X86_FEATURE_1_AND (#388)
Marco Bonelli [Wed, 15 Dec 2021 19:25:34 +0000 (20:25 +0100)]
Add support for note GNU_PROPERTY_X86_FEATURE_1_AND (#388)

- Implement support for GNU property note type
  GNU_PROPERTY_X86_FEATURE_1_AND (which is a feature bitmask) and its
  relative flags.
- Fix off-by-one in "Data size" column alignment for readelf.py note
  sections dump.

References:

- https://gitlab.com/x86-psABIs/x86-64-ABI

2 years agoRebuild readelf locally and add more instructions
Eli Bendersky [Fri, 10 Dec 2021 14:57:26 +0000 (06:57 -0800)]
Rebuild readelf locally and add more instructions

2 years agoRun readelf tests in parallel by default
Eli Bendersky [Fri, 10 Dec 2021 14:49:08 +0000 (06:49 -0800)]
Run readelf tests in parallel by default

2 years agoUpdate readelf to v2.37, adapt readelf.py output and tests (#387)
Marco Bonelli [Fri, 10 Dec 2021 14:36:18 +0000 (15:36 +0100)]
Update readelf to v2.37, adapt readelf.py output and tests (#387)

Changes to conform the output of readelf.py to binutils readelf v2.37:

- Use singular "entry" when needed instead of "entries".

- Output the last entry for the .debug_line output table when
  DW_LNE_end_sequence is encountered, as DWARF standard dictates. Looks
  looks like this was a readelf bug which was fixed in commit
  ba8826a82a29a19b78c18ce4f44fe313de279af7 of the GNU binutils-gdb repo.

- Add additional "Stmt" field in the .debug_line output table, and
  ignore the new "View" field. The "Stmt" field has been implemented in
  readelf.py. The "View" field is not something that the DWARF standard
  defines, it's an internal register added to the line number
  information state machine by binutils to perform assembler checks (see
  commit ba8826a82a29a19b78c18ce4f44fe313de279af7 of GNU binutils-gdb
  repo for more info, in particular gas/doc/as.texinfo). "View" is
  unimplemented in pyelftools for now and a special case has been added
  in the readelf test suite to ignore it.

- Add support for printing section names when dumping .symtab entries of
  st_type STT_SECTION as readelf v2.37 does (see commit
  23356397449a8aa65afead0a895a20be53b3c6b0 of GNU binutils-gdb repo).

- Add suport for recognizing SOs specifically tagged as PIE (DT_FLAGS_1
  dynamic tag with DF_1_PIE set). In such case, describe the file as
  "Position-Independent Executable file" instead of "Shared object
  file", as readelf v2.37 does.

- Add leading "0x" for version section addresses when dumping version
   information (-V) as readelf does.

- Ignore "D (mbind)" in section headers flags legend (pyelftools does
  not output this flag).

Special cases ADDED for run_readelf_tests.py:

- Ignore "View" column for --debug-dump=decodedline in readelf's output.
- Ignore ellipsis ("[...]") for long names/symbols/paths in readelf's
  output.

Special cases REMOVED for run_readelf_tests.py:

- Detection of additional '@' after symbol names (flag_after_symtable)
  seems to no longer be needed as all tests pass whitout this exception.
- Special case for DW_AT_apple_xxx seems to no longer be needed, readelf
  now recognizes those.
- Special case for PT_GNU_PROPERTY no longer needed, readelf now
  recognizes it.

Other changes:

- Add missing import in elftools/dwarf/lineprogram.py.

References:

- GNU binutils-gdb repo: https://sourceware.org/git/?p=binutils-gdb.git

2 years agoAdd support for .note.gnu.property notes section (#386)
Marco Bonelli [Tue, 7 Dec 2021 14:08:54 +0000 (15:08 +0100)]
Add support for .note.gnu.property notes section (#386)

* Add support for .note.gnu.properties notes section

References:

- Doc: https://github.com/hjl-tools/linux-abi/wiki/linux-abi-draft.pdf
- Linux: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=00e19ceec80b03a43f626f891fcc53e57919f1b3
- Glibc: https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/x86/dl-prop.h;h=385548fad3e4ad71dbdcdbfada58585c2f24ea5e;hb=HEAD
- Binutils: https://sourceware.org/git/?p=binutils-gdb.git&a=search&h=HEAD&st=commit&s=NT_GNU_PROPERTY_TYPE_0

* Add descriptions for .note.gnu.properties notes

* descriptions: add missing PT_GNU_PROPERTY description

* py3compat: add optional separator for bytes2hex

* readelf: align notes column headers

* elf/descriptions: conform to real readelf's output format

* test: special case some known readelf output quirks

* test: add test ELFs for .note.gnu.property notes

3 years agoDW_AT_private=0x24 (#382)
Seva Alekseyev [Wed, 17 Nov 2021 23:51:53 +0000 (18:51 -0500)]
DW_AT_private=0x24 (#382)

* DWARF 5 tags and attributes

* DW_AT_private

Co-authored-by: Seva Alekseyev <sevaa@nih.gov>
3 years agoDW_AT_virtual (#380)
Seva Alekseyev [Sat, 6 Nov 2021 20:58:46 +0000 (16:58 -0400)]
DW_AT_virtual (#380)

* DWARF 5 tags and attributes

* DW_AT_virtual

Co-authored-by: Seva Alekseyev <sevaa@nih.gov>
3 years agoadd latest 'e_machine' mappings: EM_BPF, EM_CSKY, EM_FRV (#376)
Ulugbek Abdullaev [Fri, 29 Oct 2021 16:03:24 +0000 (18:03 +0200)]
add latest 'e_machine' mappings: EM_BPF, EM_CSKY, EM_FRV (#376)

3 years agoELFFile: allow filtering by segment type in iter_segments() (#375)
Andreas Ziegler [Mon, 25 Oct 2021 14:31:14 +0000 (16:31 +0200)]
ELFFile: allow filtering by segment type in iter_segments() (#375)

This is very similar to the filtering implemented for
sections in commit d71faebcd58e.

3 years agoUse assertEqual instead of assertEquals for Python 3.11 compatibility. (#374)
Karthikeyan Singaravelan [Sat, 16 Oct 2021 13:18:32 +0000 (18:48 +0530)]
Use assertEqual instead of assertEquals for Python 3.11 compatibility. (#374)

3 years agoKeep raw note descriptors in ELF note sections as raw bytes (#372)
Marco Bonelli [Fri, 17 Sep 2021 20:37:03 +0000 (22:37 +0200)]
Keep raw note descriptors in ELF note sections as raw bytes (#372)

* ELF notes: keep raw note descriptors as bytes

* py3compat: add bytes2hex function

* elf/descriptions: use bytes2hex where needed

* ELF notes: convert to string only for known types

3 years ago[example] bug fixes in dwarf_decode_address example (#361)
Jangseop Shin [Tue, 31 Aug 2021 13:19:27 +0000 (22:19 +0900)]
[example] bug fixes in dwarf_decode_address example (#361)

* [example] Handle lpe with end_sequence correctly

* [example] exclude highpc in address comparison in decode_funcname

Co-authored-by: Jangseop Shin <j.s.shin@samsung.com>
3 years agofixed parsing for structures containing uids or gids in core dumps for most architect...
Lukas Dresel [Mon, 2 Aug 2021 15:30:19 +0000 (11:30 -0400)]
fixed parsing for structures containing uids or gids in core dumps for most architectures (#354)

* fixed parsing for structures containing uids or gids in core dumps for most architectures

* added testcase for mips corefile uid/gid parsing

* better description

* better email

3 years agodwarf: initial DWARFv5 support (#363)
William Woodruff [Thu, 27 May 2021 13:38:35 +0000 (09:38 -0400)]
dwarf: initial DWARFv5 support (#363)

* dwarf: initial DWARFv5 support

* dwarf/structs: use Embed to select header layout

* dwarf/structs: DW_FORM_strx family

Not sure how best to handle 24-bit values yet.

* dwarf/structs: use IfThenElse

`If` alone wraps the else in a `Value`.

* dwarf/structs: DW_FORM_addrx family handling

* dwarf_expr: support DW_OP_addrx

Not complete, but gets readelf.py to the end of a single
binary.

* dwarf/constants: DW_UT_* constants

* dwarf/structs: fix some DW_FORMs

* elftools, test: plumbing for DWARFv5 sections

* dwarf/constants: fix typo

* dwarf/structs: re-add a comment that got squashed

* dwarf/structs: DWARFv5 table header scaffolding

* dwarf/constants: typo

* test: add a basic DWARFv5 test

3 years agodwarf/constants: add DW_LNCT_* constants (#362)
William Woodruff [Fri, 21 May 2021 13:20:12 +0000 (07:20 -0600)]
dwarf/constants: add DW_LNCT_* constants (#362)

These were introduced with DWARFv5 and are documented in S. 6.2.4.1.

3 years agoinitial support for PPC64LE (#360)
Nick Desaulniers [Sat, 15 May 2021 03:34:21 +0000 (20:34 -0700)]
initial support for PPC64LE (#360)

* initial support for PPC64LE

See also:
https://openpowerfoundation.org/wp-content/uploads/2016/03/ABI64BitOpenPOWERv1.1_16July2015_pub4.pdf
3.4.1 Symbol Values
3.5.3 Relocation Types Table

Fixes #317
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
* remove references to LLVM_ADDR_SIG

3 years agoSupport Android compressed rel/rela sections (#357)
LeadroyaL [Sun, 18 Apr 2021 13:30:12 +0000 (21:30 +0800)]
Support Android compressed rel/rela sections (#357)

Ref: https://android.googlesource.com/platform/bionic/+/refs/tags/android-11.0.0_r35/libc/include/elf.h

3 years agoFix/extend aarch64 register names table (#351)
Peter LaFosse [Tue, 26 Jan 2021 00:11:51 +0000 (19:11 -0500)]
Fix/extend aarch64 register names table (#351)

3 years agofix wrong prpsinfo in 32bit coredump (#347)
Kyle Zeng [Wed, 20 Jan 2021 13:58:50 +0000 (06:58 -0700)]
fix wrong prpsinfo in 32bit coredump (#347)

* fix wrong prpsinfo in 32bit coredump

* add a sample coredump

* finish the testcase for 32bit core dump

3 years agodynamic.py: move logic around to allow symbol access more easily (#346)
Andreas Ziegler [Tue, 12 Jan 2021 15:03:47 +0000 (16:03 +0100)]
dynamic.py: move logic around to allow symbol access more easily (#346)

So far, the implementation of num_symbols() and get_symbol()
in the DynamicSegment class depended on iter_symbols().
However, most part of iter_symbols() is actually about
determining the number of symbols. Let's move that logic to
the correct method and use it in iter_symbols().

Additionally, in an ELF file without any exported symbols,
the hash table will be empty and will thus return a too low
number of symbols. However, a loader might still need to
access the imported symbols (which also have an entry in
the symbol table, with st_shndx set to SHN_UNDEF). To allow
this, make get_symbol() take any index and simply read the
symbol data from the corresponding index, and use
get_symbol() from iter_symbols(). This way, one can for
example use symbol index information from relocation entries
to directly access the symbol data.

These changes also make the logic in DynamicSegment resemble
the code in SymbolTableSection more closely.

Fixes: #342
3 years agoELFFile: allow filtering of sections by type in iter_sections (#345)
Andreas Ziegler [Tue, 12 Jan 2021 00:27:24 +0000 (01:27 +0100)]
ELFFile: allow filtering of sections by type in iter_sections (#345)

As stated in the corresponding issue, we can already filter
the output of Dynamic.iter_tags() by the type of the tag
we're looking for.

Let's adapt the iteration over the sections of the ELF file
so that it only yields sections of a certain type if the
optional type parameter is passed to iter_sections().

By doing this we can also simplify two call sites inside
the ELFFile class.

Fixes: #344
3 years agoadded a method for returning the index of a section by name (#331)
Jonathan Bruchim [Mon, 7 Dec 2020 16:36:47 +0000 (18:36 +0200)]
added a method for returning the index of a section by name (#331)

* added an method for returning the index of a section by name

Signed-off-by: Jonathan <yonbruchim@gmail.com>
* changed naming of init mapping function

Signed-off-by: Jonathan <yonbruchim@gmail.com>
* Fixed CR

Added a test file containing 3 tests
1. test index of existing section
2. test index of missing section
3. test index of existing section when section_map_name is None

Signed-off-by: Jonathan Bruchim <yonbruchim@gmail.com>
4 years agoUpdate .gitignore to ignore .egg-info dirs
Eli Bendersky [Tue, 27 Oct 2020 13:47:42 +0000 (06:47 -0700)]
Update .gitignore to ignore .egg-info dirs

4 years agoUpdate TODO to mention git tag
Eli Bendersky [Tue, 27 Oct 2020 13:47:07 +0000 (06:47 -0700)]
Update TODO to mention git tag

4 years agoremove dir that shouldn't be in git v0.27
Eli Bendersky [Tue, 27 Oct 2020 13:42:31 +0000 (06:42 -0700)]
remove dir that shouldn't be in git

4 years agoVersion 0.27 release
Eli Bendersky [Tue, 27 Oct 2020 13:42:12 +0000 (06:42 -0700)]
Version 0.27 release

4 years agoAdd a bit more details to dwarf_pubnames_types example
Eli Bendersky [Tue, 27 Oct 2020 13:29:22 +0000 (06:29 -0700)]
Add a bit more details to dwarf_pubnames_types example

Fix reference output and make test emit both outputs when they differ

4 years agoMake dwarf_pubnames_types example a bit more general
Eli Bendersky [Tue, 27 Oct 2020 12:59:56 +0000 (05:59 -0700)]
Make dwarf_pubnames_types example a bit more general

4 years agoReplace field access with property name access
Eli Bendersky [Tue, 27 Oct 2020 12:39:37 +0000 (05:39 -0700)]
Replace field access with property name access

4 years agoDebugSectionDescriptor.size initialized with decompressed section size (#339)
Seva Alekseyev [Tue, 27 Oct 2020 12:36:46 +0000 (08:36 -0400)]
DebugSectionDescriptor.size initialized with decompressed section size (#339)

4 years agohash.py: observe endianness when reading hashes (#338)
Andreas Ziegler [Mon, 26 Oct 2020 13:07:42 +0000 (14:07 +0100)]
hash.py: observe endianness when reading hashes (#338)

Reading the hashes from a GNUHashTable didn't properly use
the endianness of the underlying ELF file, so looking up
hashes would fail if the byte order of the analyzed file
did not match the native byte order of the current machine.

The test file consists of two functions:

int callee(){
    return 42;
}

int caller(){
    return callee();
}

and was compiled using `aarch64_be-linux-gcc` (version 8.3
on an x86_64 host) with the `-mbig-endian` and `-shared`
command line flags.

4 years agoDWARFv1 constants in enums, DW_FORM_ref parsing (#335)
Seva Alekseyev [Sat, 10 Oct 2020 12:38:13 +0000 (08:38 -0400)]
DWARFv1 constants in enums, DW_FORM_ref parsing (#335)

4 years agoelf: support for ELF files with a large number of sections (#333)
Andreas Ziegler [Thu, 1 Oct 2020 13:45:19 +0000 (15:45 +0200)]
elf: support for ELF files with a large number of sections (#333)

* elf: implement support for ELF files with a large number of sections

As documented in the ELF specification [0] and reported in #330,
the number of sections (`e_shnum` member of the ELF header)
as well as the section table index of the section name string
table (`e_shstrndx` member) could exceed the SHN_LORESERVE
(0xff00) value. In this case, the members of the ELF header
are set to 0 or SHN_XINDEX (0xffff), respectively, and the
actual values are found in the inital entry of the section
header table (which is otherwise set to zeroes).

So far, the implementation of `elffile.num_sections()`
didn't handle these situations and simply reported that the
file contained 0 sections, and `scripts/readelf.py` presented
invalid values.

Fix it by following the specification more closely and
showing the corresponding correct values in `readelf.py`.

[0]: https://refspecs.linuxfoundation.org/elf/gabi4+/ch4.eheader.html

Closes: #330
* test: add test file with a large number of sections

This file was generated with the following commands:

$ for i in {1..65280}; do
    echo "void __attribute__((section(\"s.$i\"), naked)) f$i(void) {}";
done > many_sections.c;
echo "int main(){}" >> many_sections.c

$ gcc-8 -fno-asynchronous-unwind-tables -c -o many_sections.o.elf many_sections.c

$ strip many_sections.o.elf

4 years agoRemove Travis config
Eli Bendersky [Wed, 23 Sep 2020 13:25:36 +0000 (06:25 -0700)]
Remove Travis config

4 years agoChange badge image to point to github actions, not Travis
Eli Bendersky [Wed, 23 Sep 2020 13:23:47 +0000 (06:23 -0700)]
Change badge image to point to github actions, not Travis