logo

overlay

My own overlay for experimentations, use with caution, no support is provided git clone https://hacktivis.me/git/overlay.git

0001-Added-check-for-backports.lzma-when-importing-lzma-m.patch (2295B)


  1. From 95bce4edcc6e92c9517b80ccb1fb956f591e0738 Mon Sep 17 00:00:00 2001
  2. From: Craig Heffner <heffnercj@gmail.com>
  3. Date: Tue, 5 Jan 2016 13:28:24 -0500
  4. Subject: [PATCH] Added check for backports.lzma when importing lzma module
  5. ---
  6. src/binwalk/modules/compression.py | 5 ++++-
  7. src/binwalk/plugins/lzmaextract.py | 6 +++++-
  8. src/binwalk/plugins/lzmavalid.py | 5 ++++-
  9. 3 files changed, 13 insertions(+), 3 deletions(-)
  10. diff --git a/src/binwalk/modules/compression.py b/src/binwalk/modules/compression.py
  11. index 97ca68d..e919f7e 100644
  12. --- a/src/binwalk/modules/compression.py
  13. +++ b/src/binwalk/modules/compression.py
  14. @@ -2,11 +2,14 @@
  15. import os
  16. import zlib
  17. -import lzma
  18. import struct
  19. import binwalk.core.compat
  20. import binwalk.core.common
  21. from binwalk.core.module import Option, Kwarg, Module
  22. +try:
  23. + import lzma
  24. +except ImportError:
  25. + from backports import lzma
  26. class LZMAHeader(object):
  27. def __init__(self, **kwargs):
  28. diff --git a/src/binwalk/plugins/lzmaextract.py b/src/binwalk/plugins/lzmaextract.py
  29. index 137b4cc..93f6240 100755
  30. --- a/src/binwalk/plugins/lzmaextract.py
  31. +++ b/src/binwalk/plugins/lzmaextract.py
  32. @@ -12,7 +12,11 @@ class LZMAExtractPlugin(binwalk.core.plugin.Plugin):
  33. # lzma package in Python 2.0 decompress() does not handle multiple
  34. # compressed streams, only first stream is extracted.
  35. # backports.lzma package could be used to keep consistent behaviour.
  36. - import lzma
  37. + try:
  38. + import lzma
  39. + except ImportError:
  40. + from backports import lzma
  41. +
  42. self.decompressor = lzma.decompress
  43. # If the extractor is enabled for the module we're currently loaded
  44. diff --git a/src/binwalk/plugins/lzmavalid.py b/src/binwalk/plugins/lzmavalid.py
  45. index a343656..62e15b9 100644
  46. --- a/src/binwalk/plugins/lzmavalid.py
  47. +++ b/src/binwalk/plugins/lzmavalid.py
  48. @@ -17,7 +17,10 @@ class LZMAPlugin(binwalk.core.plugin.Plugin):
  49. def init(self):
  50. try:
  51. - import lzma
  52. + try:
  53. + import lzma
  54. + except ImportError:
  55. + from backports import lzma
  56. self.decompressor = lzma.decompress
  57. except ImportError as e:
  58. self.decompressor = None
  59. --
  60. 2.12.2