diff --git a/src/bintropy/VERSION.txt b/src/bintropy/VERSION.txt index 5810be7..21539a6 100644 --- a/src/bintropy/VERSION.txt +++ b/src/bintropy/VERSION.txt @@ -1 +1 @@ -1.5.6 +1.5.7 diff --git a/src/bintropy/__init__.py b/src/bintropy/__init__.py index 7dfb416..e43cb6f 100644 --- a/src/bintropy/__init__.py +++ b/src/bintropy/__init__.py @@ -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 "" +__secname = lambda s: _ensure_str(s).strip("\x00") or _ensure_str(s) or "" # https://matplotlib.org/2.0.2/examples/color/named_colors.html COLORS = { @@ -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 @@ -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