Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebase pyelftools and reapply S2E-specific commits as needed #3

Draft
wants to merge 155 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
155 commits
Select commit Hold shift + click to select a range
ab76d5c
Handle ARM relocations (#121)
frederiksdun Jul 16, 2018
07cac37
Update CHANGES, add 3.6 testing to Travis and fixup README
eliben Sep 1, 2018
ba743b2
Update version to 0.25 to prepare for release
eliben Sep 1, 2018
572d5e8
Add .o test files to manifest
eliben Sep 1, 2018
f52f666
Call relocation for ARM V3 (#194)
dimas3452 Sep 5, 2018
117bb68
Redo the new arm reloc test as a proper unit test, aligned with other…
eliben Sep 5, 2018
8e8e8b8
Rename input files for arm relocation test to be more consistent
eliben Sep 5, 2018
e762568
Simplify arm reloc test file
eliben Sep 5, 2018
494ce81
Move arm reloc test to proper location and simplify its code a bit
eliben Sep 5, 2018
f613689
Fix division in calculation function for 'R_ARM_CALL' (#196)
dimas3452 Sep 5, 2018
9f3bf5d
Provide enums for DT_FLAGS and DT_FLAGS_1 (#200)
rupran Oct 4, 2018
c2f6fe3
ARMAttribute: fix access to structs, stream and nul (#203)
rupran Oct 25, 2018
f9d3e90
Remove unnecessary 'preserve_stream_pos' (#204)
andersdellien Oct 27, 2018
d60d952
Implemented ELFFile.get_machine_arch for the remaining architectures.…
gahag Nov 25, 2018
4c547a2
Bugfix: Reset prevstate if line program sequence ends (#211)
rvijayc Dec 18, 2018
5f9416f
Simplify handling of null DIEs (#209)
andersdellien Dec 20, 2018
ac90d06
Added support for decoding .debug_pubtypes and .debug_pubnames sectio…
rvijayc Dec 24, 2018
ee37f4c
More efficient AbbrevDecl handling (#212)
andersdellien Dec 24, 2018
41c9c50
Support for DWARFv4 location lists in dwarf_location_lists.py (#214)
andersdellien Jan 30, 2019
eeba82a
Fixup error on empty .debug_pubtypes section (#215)
laerreal Jan 31, 2019
55af257
Small stylistic fixes
eliben Jan 31, 2019
551601b
Remove py34 testing target
eliben Jan 31, 2019
c382520
Also decode strings in _DynamicStringTable.get_string() (#217)
rupran Feb 16, 2019
9b601d3
Fix LookupError when testing with tox (#221)
nneonneo Mar 11, 2019
430e3a5
Enable parsing of relocations pointed to by DYNAMIC. (#135)
nneonneo Mar 16, 2019
27941c5
Improve symbol table handling in DynamicSegment (#219)
rupran Mar 19, 2019
b66d892
Add ability to parse the NT_FILE note found in core files (#220)
zephyrj Apr 22, 2019
923c498
Fix deprecation warning in Python 3.7 (#231)
scottj97 Jun 22, 2019
c6572cc
Bump minimal supported Python 3.x version to 3.4 and add testing with…
eliben Jun 22, 2019
7d017b9
dwarf_expr: Add DW_OP_{implicit,stack}_value (#233)
woodruffw Jul 18, 2019
94c9764
dwarf/descriptions: Remove DW_LANG_Upc (#234)
woodruffw Jul 18, 2019
678652d
Fix for `CFIEntry.get_decoded()` (#232)
dimas3452 Jul 30, 2019
19fafd6
Improved handling of location information (#225)
andersdellien Aug 2, 2019
0210034
Portable import of collections.Mapping
eliben Sep 11, 2019
12a0b9f
dwarf_expr: Add DWARFv5 OPs (#240)
woodruffw Sep 17, 2019
85a698d
dwarf_expr: Add DW_OP_{lo,hi}_user (#239)
woodruffw Sep 18, 2019
5d0d111
dwarf/enums Add GNU parameter tags (#242)
woodruffw Oct 3, 2019
232b628
dwarf/enums: More attributes, tags, and forms (#244)
woodruffw Oct 4, 2019
2a89e6f
Realign columns for some constants
eliben Oct 4, 2019
cb0b3e9
dwarf/constants: More DW_LANG, DW_ATE constants (#245)
woodruffw Oct 4, 2019
1d1a498
dwarf/die: Handle DW_FORM_flag_present in value translation (#246)
woodruffw Oct 18, 2019
1e43567
Include README.rst instead of README in manifest (#247)
olofj Oct 21, 2019
6f44f40
elf/constants: Add SHN_XINDEX (#248)
woodruffw Oct 27, 2019
670079a
Lazy DIE parsing (#249)
woodruffw Nov 8, 2019
8a40f29
Prepare for release 0.26
eliben Dec 5, 2019
15bdb4e
Update release notes in TODO
eliben Dec 5, 2019
465a2be
Tweak release instructions in TODO
eliben Dec 9, 2019
a347dbf
Fix simple typo: wether -> whether (#259)
timgates42 Dec 16, 2019
9f5a73b
Travis: drop Python 3.4, add 3.8
eliben Feb 4, 2020
765e7ea
segments.py: fix TLS checks in section_in_segment() (#275)
rupran Feb 4, 2020
1399ba2
Make sure ELFFile.has_dwarf_info() returns a boolean. (#266)
ltfish Feb 4, 2020
46dea16
Trim whitespace
eliben Feb 4, 2020
4000c05
DWARF 5 tags and attributes (#271)
sevaa Feb 4, 2020
9956e1c
Reformat whitespace in dwarf enums
eliben Feb 4, 2020
83ad8a2
Move test file name to be included in distribution
eliben Feb 4, 2020
e8b815d
construct_utils.py: add missing import (#291)
rupran Mar 6, 2020
934345e
examples: Add dwarf_lineprogram_filenames.py (#285)
woodruffw Mar 7, 2020
919dcda
Fix typo in comment
eliben Mar 7, 2020
4ff90bf
ref_addr size changed between v2 and v3 - take 2 (#273)
sevaa Mar 7, 2020
8ee8588
Merge branch 'master' of github.com:eliben/pyelftools
eliben Mar 7, 2020
85b30d2
Reflow comments and clean up whitespace
eliben Mar 7, 2020
a3f1b7c
Add resilience for degenerate cases present in files with only debug …
rhelmot Mar 7, 2020
92f4209
Reformat comments and a bit of test logic
eliben Mar 7, 2020
f057241
DW_AT_const_value is not a location, take 2 (#277)
sevaa Mar 7, 2020
c8ccce8
readelf.py: adapt section mapping output for .tbss sections (#289)
rupran Mar 7, 2020
25a0660
Fix up README
eliben Mar 7, 2020
6fff9b5
readelf: print addend for RELA relocations without symbol (#292)
rupran Mar 7, 2020
2060b82
Minor enhancements for readelf-based tests (#293)
pmderodat Mar 9, 2020
966438d
{GNU,}HashSection: Implement symbol lookup (#290)
rupran Mar 9, 2020
25a2375
Remove some unconditional printouts in unit tests
eliben Mar 9, 2020
ecc5a2d
readelf.py: minor enhancements for debugging (#294)
pmderodat Mar 10, 2020
a70ccd3
callframe.py: fix DW_EH_PE_absptr decoding (#295)
pmderodat Mar 10, 2020
cb5c2f6
Clean up whitespace
eliben Mar 13, 2020
fd84dd1
Clean up whitespace in dwarf/ranges.py
eliben Mar 13, 2020
7688f2a
Merge branch 'master' of github.com:eliben/pyelftools
eliben Mar 13, 2020
43adb41
Initial commit of new expr parsing function.
eliben Mar 13, 2020
3d97b6e
DWARF expr: tests passing with new parser
eliben Mar 13, 2020
4cf5cb0
DWARF expr: removing old GenericExprVisitor
eliben Mar 13, 2020
4a98d47
DWARF expr: clean up more old code and add some comments
eliben Mar 13, 2020
79dd5d5
Only byteswap the little endian version of mips64 r_raw_info (#297)
rhelmot Mar 14, 2020
2c8f7dc
Cache dispatch table between expr parses
eliben Mar 14, 2020
9377b55
Simplify ExprDumper now that the expression parser is simpler.
eliben Mar 14, 2020
6ac99ad
Remove unused field
eliben Mar 14, 2020
3156d6f
Enhance MIPS64 testing and simplify handling code for its peculiar re…
pmderodat Mar 17, 2020
742a7c7
Add support for DW_LNE_set_discriminator (#282)
woodruffw Mar 21, 2020
98f0cdb
GNU expressions (#303)
sevaa Mar 22, 2020
b9129ce
Fix --parallel readelf test after previous commit
eliben Mar 22, 2020
e9df2e5
Add full list of supported debug sections in readelf's help message
eliben Mar 22, 2020
641729c
Reformat whitespace
eliben Mar 23, 2020
2697329
Support for --debug-dump=loc in readelf.py and in the test (#304)
sevaa Mar 23, 2020
ea81c3e
Clean up whitespace
eliben Mar 28, 2020
519a234
Cached random access to CUs and DIEs (#264)
mdmillerii Apr 22, 2020
e987bd8
Fix a typo in adapters.py (#309)
Apr 27, 2020
478f61c
Fix determining PAGESIZE under Jython (#314)
mephi42 May 21, 2020
9f12da5
fix issue in aranges cu_offset_at_addr (#310)
avagordon01 May 23, 2020
1ed78f5
dwarf/dwarf_expr: Add support for DW_OP_GNU_push_tls_address (#315)
woodruffw Jun 1, 2020
a5ee9be
Add PT_GNU_PROPERTY enum (#319)
disconnect3d Jun 8, 2020
3d91dbe
initial support for aarch64 little endian (#318)
nickdesaulniers Jun 9, 2020
ff8331a
dwarf.CallFrameInfo: Support parsing LSDA pointers from FDEs. (#308)
ltfish Jul 7, 2020
63e9137
Fix Python 2 support of FDE. (#323)
ltfish Jul 8, 2020
a2880a7
Fix typo when referencing DW_FORM_ref_addr (#321)
gpollo Jul 8, 2020
5754253
for sibling of form ref_addr, only sibling value should be used (#268)
sagiben Jul 8, 2020
b87fbea
Revert "for sibling of form ref_addr, only sibling value should be us…
eliben Jul 8, 2020
d1fc159
Fix the non-determinism in test_dwarf_expr. (#324)
ltfish Jul 8, 2020
7ca1668
Fix formatting and add comment in test
eliben Jul 8, 2020
eeddaba
Return the correct number of program headers when e_phnum is 0xffff (…
pagabuc Jul 20, 2020
619ba26
Update code to work with pickling (#327)
valdegtyarev Jul 25, 2020
9d722d7
Fix python versions for tests that run
eliben Aug 18, 2020
ee0face
Add support for ARM exception handler ABI (#328)
LeadroyaL Aug 19, 2020
a570d48
Add GitHub actions workflow for CI
eliben Sep 23, 2020
9e503b5
Fix typo in ci.yml
eliben Sep 23, 2020
b9f0e40
Set to run only on ubuntu because of readelf binary
eliben Sep 23, 2020
9023023
Change badge image to point to github actions, not Travis
eliben Sep 23, 2020
ab84e68
Remove Travis config
eliben Sep 23, 2020
49ffaf4
elf: support for ELF files with a large number of sections (#333)
rupran Oct 1, 2020
9704150
DWARFv1 constants in enums, DW_FORM_ref parsing (#335)
sevaa Oct 10, 2020
d6b2913
hash.py: observe endianness when reading hashes (#338)
rupran Oct 26, 2020
e5ed0ee
DebugSectionDescriptor.size initialized with decompressed section siz…
sevaa Oct 27, 2020
b9548e6
Replace field access with property name access
eliben Oct 27, 2020
ee723a3
Make dwarf_pubnames_types example a bit more general
eliben Oct 27, 2020
2ec8d03
Add a bit more details to dwarf_pubnames_types example
eliben Oct 27, 2020
ba73057
Version 0.27 release
eliben Oct 27, 2020
dc26051
remove dir that shouldn't be in git
eliben Oct 27, 2020
28e7f6d
Update TODO to mention git tag
eliben Oct 27, 2020
9f851f7
Update .gitignore to ignore .egg-info dirs
eliben Oct 27, 2020
ad5375f
added a method for returning the index of a section by name (#331)
JonBruchim Dec 7, 2020
d71faeb
ELFFile: allow filtering of sections by type in iter_sections (#345)
rupran Jan 12, 2021
14bc163
dynamic.py: move logic around to allow symbol access more easily (#346)
rupran Jan 12, 2021
fd7df9d
fix wrong prpsinfo in 32bit coredump (#347)
Kyle-Kyle Jan 20, 2021
46187f4
Fix/extend aarch64 register names table (#351)
plafosse Jan 26, 2021
a643660
Support Android compressed rel/rela sections (#357)
LeadroyaL Apr 18, 2021
0664de0
initial support for PPC64LE (#360)
nickdesaulniers May 15, 2021
e128bab
dwarf/constants: add DW_LNCT_* constants (#362)
woodruffw May 21, 2021
4384ad8
dwarf: initial DWARFv5 support (#363)
woodruffw May 27, 2021
ab444d9
fixed parsing for structures containing uids or gids in core dumps fo…
Lukas-Dresel Aug 2, 2021
9db67b1
[example] bug fixes in dwarf_decode_address example (#361)
jeffy1009 Aug 31, 2021
cc47f5f
Keep raw note descriptors in ELF note sections as raw bytes (#372)
mebeim Sep 17, 2021
4e88880
Use assertEqual instead of assertEquals for Python 3.11 compatibility…
tirkarthi Oct 16, 2021
a74b8ab
ELFFile: allow filtering by segment type in iter_segments() (#375)
rupran Oct 25, 2021
fa46554
add latest 'e_machine' mappings: EM_BPF, EM_CSKY, EM_FRV (#376)
ulugbekna Oct 29, 2021
87c7eba
DW_AT_virtual (#380)
sevaa Nov 6, 2021
0a997c1
DW_AT_private=0x24 (#382)
sevaa Nov 17, 2021
5ee4158
Add support for .note.gnu.property notes section (#386)
mebeim Dec 7, 2021
662e4ab
Update readelf to v2.37, adapt readelf.py output and tests (#387)
mebeim Dec 10, 2021
18a82d8
Run readelf tests in parallel by default
eliben Dec 10, 2021
9689294
Rebuild readelf locally and add more instructions
eliben Dec 10, 2021
8f7a0be
Add support for note GNU_PROPERTY_X86_FEATURE_1_AND (#388)
mebeim Dec 15, 2021
dd6cd02
Add PS3/CellOS OSABI identifier (#389)
iMoD1998 Jan 11, 2022
dedef14
Update structs.py (#392)
brendanhaines Jan 13, 2022
7d69c1a
Prepare for releasing version 0.28
eliben Feb 3, 2022
c2cfef0
Add support for DT_RELR/SHT_RELR compressed relocation sections (#395)
rupran Feb 14, 2022
97bf779
Improve DWARF 5 compatibility. (#400)
rdunklau May 10, 2022
6a43578
elftools/* Reapply S2E-specific commits.
michaelbrownuc May 14, 2022
011f917
Merge pull request #1 from michaelbrownuc/rebase-upstream
michaelbrownuc May 14, 2022
4eed0ee
Merge branch 'master' into master
michaelbrownuc May 14, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: pyelftools-tests
on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
build:

runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [2.7, 3.6, 3.7, 3.8]
os: [ubuntu-latest]

steps:

- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Test
run: |
python test/all_tests.py

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ build
dist
MANIFEST
*.sublime-workspace
*.egg-info




8 changes: 0 additions & 8 deletions .travis.yml

This file was deleted.

65 changes: 57 additions & 8 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,19 +1,68 @@
Changelog
=========

+ Version 0.25 (??)
+ Version 0.28 (2022.02.03)

- Added a method for returning the index of a section by name (#331)
- Allow filtering by section types in iter_sections (#345)
- Support Android compressed rel/rela sections (#357)
- Initial support for PPC64LE (#360)
- Initial DWARF v5 support (#363 with several follow-ups)
- Fixed parsing for structures containing uids or gids in core
dumps (#354)
- Allow filtering by segment types in iter_segments (#375)
- Add support for .note.gnu.property (#386)
- Update readelf tests to work with more recent version of
readelf (#387)
- Add support for note GNU_PROPERTY_X86_FEATURE_1_AND (#388)

+ Version 0.27 (2020.10.27)

- Print addend wfor RELA relocations without symbol (#292)
- Implement symbol lookup for {GNU,}HashSection (#290)
- Major rewrite of expression parsing
- Cashed random access to CUs and DIEs (#264)
- GNU expressions (#303)
- Support parsing LSDA pointers from FDEs (#308)
- Add support for DWA_OP_GNU_push_tls_address in expressions (#315)
- Some initial support for AArch64 little-endian (#318)
- Support for ELF files with a large number of sections (#333)
- Some minimal support for DWARFv1 (#335)
- Many small bug fixes; see git log.

+ Version 0.26 (2019.12.05)

- Call relocation for ARM v3 (#194)
- More complete architecture coverage for ENUM_E_MACHINE (#206)
- Support for .debug_pubtypes and .debug_pubnames sections (#208)
- Support for DWARF v4 location lists (#214)
- Decode strings in dynamic string tables (#217)
- Improve symbol table handling in dynamic segments (#219)
- Improved handling of location information (#225)
- Avoid deprecation warnings in Python 3.7+
- Add DWARF v5 OPs (#240)
- Handle many new translation forms and constants
- Lazy DIE parsing to speed up partial parsing of DWARF info (#249)

+ Version 0.25 (2018.09.01)

- Make parsing of SH_TYPE and PT_TYPE fields dependent on the machine
(e_machine header field), making it possible to support conflicting type
enums between different machines (#71 and #121).
- Add parsing and readelf dumping for .eh_frame (#155)
- Support compressed sections (#152)
- Better support for parsing core dumps (#147)
- More comprehensive handling of ARM relocations (#121)
- Convert all ascii encoding to utf-8 encoding (#182)
- Don't attempt to hex/string dump SHT_NOBITS sections in readelf (#119).
- Add Python 3.5 testing to the tox file.
- Test with Python 3.6
- Minor bugfixes (#118)
- Cleanup: Use argparse instead of optparse
- Make readelf comparison tests run in parallel using multiprocessing; cuts
testing time 3-5x
- Improvements in MIPS flags handling (#165)

+ Version 0.24 (04.08.2016)
+ Version 0.24 (2016.08.04)

- Retrieve symbols by name - get_symbol_by_name (#58).
- Symbol/section names are strings internally now, not bytestrings (this may
Expand All @@ -29,15 +78,15 @@ Changelog
- Support for zlib-compressed debug sections (#102)
- Support for DWARF v4 line programs (#82)

+ Version 0.23 (08.11.2014)
+ Version 0.23 (2014.11.08)

- Minimal Python 2.x version raised to 2.7
- Basic support for MIPS (contributed by Karl Vogel).
- Support for PT_NOTE segment parsing (contributed by Alex Deymo).
- Support for parsing symbol table in dynamic segment
(contributed by Nam T. Nguyen).

+ Version 0.22 (30.03.2014)
+ Version 0.22 (2014.03.30)

- pyelftools repository moved to https://github.com/eliben/pyelftools
- Support for version sections - contributed by Yann Rouillard.
Expand All @@ -50,7 +99,7 @@ Changelog
file name / path (based on pull request #16 by Shaheed Haque).
- Set up Travis CI integration.

+ Version 0.21 (17.04.2013)
+ Version 0.21 (2013.04.17)

- Added new example: dwarf_decode_address - decode function name and
file & line information from an address.
Expand All @@ -63,11 +112,11 @@ Changelog
- Output of scripts/readelf.py now matches that of binutils 2.23.52.
- Added more machine EM_ values to ENUM_E_TYPE.

+ Version 0.20 (27.01.2012)
+ Version 0.20 (2012.01.27)

- Python 3 support
- Fixed some problems with running tests
- Issue #2: made all examples run (and test/run_examples_test.py pass)
on Windows.

+ Version 0.10 - Initial public release (06.01.2012)
+ Version 0.10 - Initial public release (2012.01.06)
4 changes: 2 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
recursive-include elftools *.py
recursive-include scripts *.py
recursive-include examples *.py *.elf *.out
recursive-include test *.py *.elf *.arm *.mips
include README
recursive-include test *.py *.elf *.arm *.mips *.o
include README.rst
include LICENSE
include CHANGES
include tox.ini
24 changes: 11 additions & 13 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Introduction: what is pyelftools?
---------------------------------
==========
pyelftools
==========

.. image:: https://github.com/eliben/pyelftools/workflows/pyelftools-tests/badge.svg
:align: center
:target: https://github.com/eliben/pyelftools/actions

**pyelftools** is a pure-Python library for parsing and analyzing ELF files
and DWARF debugging information. See the
Expand All @@ -10,7 +15,7 @@ Pre-requisites
--------------

As a user of **pyelftools**, one only needs Python to run. It works with
Python versions 2.7 and 3.x (x >= 2). For hacking on **pyelftools** the
Python versions 2.7 and 3.x (x >= 5). For hacking on **pyelftools** the
requirements are a bit more strict, please see the
`hacking guide <https://github.com/eliben/pyelftools/wiki/Hacking-guide>`_.

Expand All @@ -33,6 +38,9 @@ recent version of the code. This can be done by downloading the `master zip
file <https://github.com/eliben/pyelftools/archive/master.zip>`_ or just
cloning the Git repository.

Since **pyelftools** has no external dependencies, it's also easy to use it
without installing, by locally adjusting ``PYTHONPATH``.

How to use it?
--------------

Expand All @@ -45,13 +53,3 @@ License

**pyelftools** is open source software. Its code is in the public domain. See
the ``LICENSE`` file for more details.

CI Status
---------

**pyelftools** has automatic testing enabled through the convenient
`Travis CI project <https://travis-ci.org>`_. Here is the latest build status:

.. image:: https://travis-ci.org/eliben/pyelftools.png?branch=master
:align: center
:target: https://travis-ci.org/eliben/pyelftools
23 changes: 14 additions & 9 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,10 @@ New version
construct
---------

The construct seems to be maintained again - they also backported my Python 3
fixes. Theoretically, I can remove construct from pyelftools and use it as a
dependency instead. I don't really have time to play with this now, but may
do so in the future.

Distribution
------------

python setup.py build sdist bdist_wheel upload
construct seems to be maintained again - they also backported my Python 3 fixes.
Theoretically, I can remove construct from pyelftools and use it as a dependency
instead. I don't really have time to play with this now, but may do so in the
future.

Preparing a new release
-----------------------
Expand All @@ -28,4 +23,14 @@ Preparing a new release
* Untar the created ``dist/pyelftools-x.y.tar.gz`` and make sure
everything looks ok
* Now build with upload to send it to PyPi
* Tag new version in git
* Test with pip install from some new virtualenv

Distribution
------------

1. First install Twine (https://packaging.python.org/tutorials/packaging-projects/)
2. python3 -m twine upload dist/*, but make sure ``setup.py`` was already run
and the updated whl and tarbal are in dist/.

Credentials for PyPI are stored in ~/.pypirc
2 changes: 1 addition & 1 deletion elftools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# Eli Bendersky ([email protected])
# This code is in the public domain
#-------------------------------------------------------------------------------
__version__ = '0.24'
__version__ = '0.28'
2 changes: 1 addition & 1 deletion elftools/common/construct_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#-------------------------------------------------------------------------------
from ..construct import (
Subconstruct, ConstructError, ArrayError, Adapter, Field, RepeatUntil,
Rename
Rename, SizeofError
)


Expand Down
4 changes: 2 additions & 2 deletions elftools/common/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
# Eli Bendersky ([email protected])
# This code is in the public domain
#-------------------------------------------------------------------------------
class ELFError(Exception):
class ELFError(Exception):
pass

class ELFRelocationError(ELFError):
pass

class ELFParseError(ELFError):
pass

Expand Down
16 changes: 16 additions & 0 deletions elftools/common/py3compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
# and strings are different types and bytes hold numeric values when
# iterated over.

def bytes2hex(b, sep=''):
if not sep:
return b.hex()
return sep.join(map('{:02x}'.format, b))

def bytes2str(b): return b.decode('latin-1')
def str2bytes(s): return s.encode('latin-1')
def int2byte(i): return bytes((i,))
Expand All @@ -41,6 +46,12 @@ def iterbytes(b):
import cStringIO
StringIO = BytesIO = cStringIO.StringIO

def bytes2hex(b, sep=''):
res = b.encode('hex')
if not sep:
return res
return sep.join(res[i:i+2] for i in range(0, len(res), 2))

def bytes2str(b): return b
def str2bytes(s): return s
int2byte = chr
Expand All @@ -64,3 +75,8 @@ def itervalues(d):
def iteritems(d):
"""Return an iterator over the items of a dictionary."""
return getattr(d, 'items' if PY3 else 'iteritems')()

try:
from collections.abc import Mapping # python >= 3.3
except ImportError:
from collections import Mapping # python < 3.3
7 changes: 6 additions & 1 deletion elftools/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from contextlib import contextmanager
from .exceptions import ELFParseError, ELFError, DWARFError
from .py3compat import int2byte
from ..construct import ConstructError
from ..construct import ConstructError, ULInt8


def merge_dicts(*dicts):
Expand Down Expand Up @@ -102,6 +102,11 @@ def roundup(num, bits):
"""
return (num - 1 | (1 << bits) - 1) + 1

def read_blob(stream, length):
"""Read length bytes from stream, return a list of ints
"""
return [struct_parse(ULInt8(''), stream) for i in range(length)]

#------------------------- PRIVATE -------------------------

def _assert_with_exception(cond, msg, exception_type):
Expand Down
2 changes: 1 addition & 1 deletion elftools/construct/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class ExprAdapter(Adapter):
* subcon - the subcon to adapt
* encoder - a function that takes (obj, context) and returns an encoded
version of obj
* decoder - a function that takes (obj, context) and returns an decoded
* decoder - a function that takes (obj, context) and returns a decoded
version of obj

Example:
Expand Down
4 changes: 3 additions & 1 deletion elftools/construct/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def __getstate__(self):
return attrs
def __setstate__(self, attrs):
attrs["packer"] = Packer(attrs["packer"])
return StaticField.__setstate__(attrs)
return StaticField.__setstate__(self, attrs)
def _parse(self, stream, context):
try:
return self.packer.unpack(_read_stream(stream, self.length))[0]
Expand Down Expand Up @@ -1297,6 +1297,8 @@ def _build(self, obj, stream, context):
assert obj is None
def _sizeof(self, context):
return 0
def __reduce__(self):
return self.__class__.__name__
Pass = Pass(None)

class Terminator(Construct):
Expand Down
Loading