summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorkat <katherine@vector35.com>2022-07-16 17:17:56 -0400
committercynder <KritantaDevelopment@gmail.com>2022-08-03 16:19:53 -0700
commit83ba14cbb835bed1fc04eb9b50cdd18ab2bb2176 (patch)
treef9f31067eb824c08f4f42b460e36b16c177aee5c /python
parent810c0f858e3734077d3df8acd4458d03e09c82ce (diff)
Fix bninspect on documented properties
Diffstat (limited to 'python')
-rw-r--r--python/binaryview.py2
-rw-r--r--python/scriptingprovider.py34
2 files changed, 31 insertions, 5 deletions
diff --git a/python/binaryview.py b/python/binaryview.py
index c527b09f..44a918bb 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -6228,7 +6228,7 @@ class BinaryView:
``get_linear_disassembly`` gets an iterator for all lines in the linear disassembly of the view for the given
disassembly settings.
- .. note:: linear_disassembly doesn't just return disassembly it will return a single line from the linear view,\
+ .. note:: linear_disassembly doesn't just return disassembly; it will return a single line from the linear view,\
and thus will contain both data views, and disassembly.
:param DisassemblySettings settings: instance specifying the desired output formatting. Defaults to None which will use default settings.
diff --git a/python/scriptingprovider.py b/python/scriptingprovider.py
index ed886f1d..fe6b1467 100644
--- a/python/scriptingprovider.py
+++ b/python/scriptingprovider.py
@@ -563,27 +563,53 @@ class BlacklistedDict(dict):
self._blacklist_enabled = value
-def bninspect(code, globals_, locals_):
+def bninspect(code_, globals_, locals_):
"""
``bninspect`` prints documentation about a command that is about to be run
The interpreter will invoke this function if you input a line ending in `?` e.g. `bv?`
- :param str code: Python code to be evaluated
+ :param str code_: Python code to be evaluated
:param dict globals_: globals() from callsite
:param dict locals_: locals() from callsite
"""
try:
import inspect
- value = eval(code, globals_, locals_)
+ value = eval(code_, globals_, locals_)
+
+ try:
+ if not hasattr(value, "__qualname__"):
+ # It was called on something that isn't a method type
+ if isinstance(code_, bytes):
+ code_ = code_.decode("utf-8")
+ class_type_str = code_.split(".")[:-1]
+ class_value = eval("type(" + ".".join(class_type_str) + ")." + code_.split(".")[-1], globals_, locals_)
+ doc = inspect.getdoc(class_value)
+ if doc is None:
+ comments = inspect.getcomments(class_value)
+ if comments is None:
+ pass
+ else:
+ print(comments)
+ return
+ else:
+ print(doc)
+ return
+ except:
+ pass
+
doc = inspect.getdoc(value)
if doc is None:
comments = inspect.getcomments(value)
if comments is None:
- print(f"No documentation found for {code}")
+ pass
else:
print(comments)
+ return
else:
print(doc)
+ return
+
+ print(f"No documentation found for {code_}")
except:
# Hide exceptions so the normal execution can report them
pass