Get page size using 'mmap' module if 'resource' is not available.
authorDavid Spickett <DavidSpickett@users.noreply.github.com>
Fri, 1 Jul 2016 10:43:49 +0000 (11:43 +0100)
committerDavid Spickett <DavidSpickett@users.noreply.github.com>
Mon, 4 Jul 2016 08:41:59 +0000 (09:41 +0100)
The resource module is Unix only, use mmap for Windows.

elftools/elf/elffile.py

index 0517b578023d7a75546b0588fcb8639b71596d84..2bc2651bb830d78fdb25702be9a165574ebb6ef1 100644 (file)
@@ -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))