From 64f795ef4f84ff3a4ad9eb1892ab863062742b97 Mon Sep 17 00:00:00 2001 From: David Spickett Date: Fri, 1 Jul 2016 11:43:49 +0100 Subject: [PATCH] Get page size using 'mmap' module if 'resource' is not available. The resource module is Unix only, use mmap for Windows. --- elftools/elf/elffile.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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)) -- 2.30.2