From: David Spickett Date: Fri, 1 Jul 2016 10:43:49 +0000 (+0100) Subject: Get page size using 'mmap' module if 'resource' is not available. X-Git-Tag: v0.24~7^2 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=64f795ef4f84ff3a4ad9eb1892ab863062742b97;p=pyelftools.git Get page size using 'mmap' module if 'resource' is not available. The resource module is Unix only, use mmap for Windows. --- diff --git a/elftools/elf/elffile.py b/elftools/elf/elffile.py index 0517b57..2bc2651 100644 --- a/elftools/elf/elffile.py +++ b/elftools/elf/elffile.py @@ -7,9 +7,17 @@ # This code is in the public domain #------------------------------------------------------------------------------- import io -import resource import struct import zlib + +try: + import resource + PAGESIZE = resource.getpagesize() +except ImportError: + # Windows system + import mmap + PAGESIZE = mmap.PAGESIZE + from ..common.py3compat import BytesIO from ..common.exceptions import ELFError from ..common.utils import struct_parse, elf_assert @@ -416,7 +424,7 @@ class ELFFile(object): decompressor = zlib.decompressobj() uncompressed_stream = BytesIO() while True: - chunk = section.stream.read(resource.getpagesize()) + chunk = section.stream.read(PAGESIZE) if not chunk: break uncompressed_stream.write(decompressor.decompress(chunk))