Skip to content

Commit

Permalink
Fixed format error with LIEF 0.14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dhondta committed Feb 5, 2024
1 parent d470025 commit 6416b03
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/bintropy/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5.6
1.5.7
15 changes: 13 additions & 2 deletions src/bintropy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

__btype = lambda b: str(type(b)).split(".")[2]
__log = lambda l, m, lvl="debug": getattr(l, lvl)(m) if l else None
__secname = lambda s: s.strip("\x00") or s or "<empty>"
__secname = lambda s: _ensure_str(s).strip("\x00") or _ensure_str(s) or "<empty>"

# https://matplotlib.org/2.0.2/examples/color/named_colors.html
COLORS = {
Expand Down Expand Up @@ -71,6 +71,17 @@
}


def _ensure_str(s, encoding='utf-8', errors='strict'):
if isinstance(s, bytes):
try:
return s.decode(encoding, errors)
except:
return s.decode("latin-1")
elif not isinstance(s, (str, bytes)):
raise TypeError("not expecting type '%s'" % type(s))
return s


def _get_ep_and_section(binary):
""" Helper for computing the entry point and finding its section for each supported format.
:param binary: LIEF-parsed binary object
Expand Down Expand Up @@ -384,7 +395,7 @@ def plot(*filenames, img_name=None, img_format="png", dpi=200, labels=None, subl
:param img: destination filename for the created figure
:param filenames: list of paths of the binaries to be included in the figure
:param img_format: format of the created figure
:param img_format: image format of the created figure
:param dpi: resolution of the created figure
:param labels: list of custom labels to be used for the binaries (can be lambda-based)
:param sublabel: static or lambda-based sublabel for display under the label
Expand Down

0 comments on commit 6416b03

Please sign in to comment.