AttributeError: 'instancemethod' object has no attribute '__len__' (bridge.py", line 974)
I get a whole lot of the following in the Ghidra console when first connecting initiating a connection to ghidra_bridge. I'm on Windows, running Ghidra in interactive mode. It appears to be working (I'm just getting started), but I get enough of this to overflow the Ghidra console when starting to run a script.
Traceback (most recent call last):
File "C:\Users\eddyw\ghidra_scripts\jfx_bridge\bridge.py", line 974, in local_get
result = getattr(target, name)
AttributeError: 'instancemethod' object has no attribute '__len__'
Hi, @mechgt - can you post the script you're running, including how you're starting the bridge? That'll help me see if I can reproduce the problem.
See below. When I 'run' the code from PyCharm it behaves normally. When I debug and it hits a breakpoint (e.g. at name = func.getName() ) it spits out the errors at the end of this post.
I made a simple demo script and can now see the first errors mentioning django missing. Is this maybe at the root of the issue?
# Ghidra Bridge Issue 53 Test
# @author mechgt
# @category _NEW_
# @keybinding
# @menupath
# @toolbar
try:
import ghidra_bridge
b = ghidra_bridge.GhidraBridge(namespace=globals(), hook_import=True) # creates the bridge and loads the flat API into the global namespace
except:
pass
try:
# import pydevd
# pydevd.settrace("127.0.0.1", port=5678, stdoutToServer=True, stderrToServer=True)
from ghidra_builtins import *
except:
pass
def someFun(func):
name = func.getName()
return name
# Iterate through functions, parsing and printing each
function = getFirstFunction()
while function is not None:
name = someFun(function)
println(name)
function = getFunctionAfter(function)
Ghidra Console output:
ghidra_bridge_server_background.py> Running...
INFO:jfx_bridge.bridge:Server launching in background - will continue to run after launch script finishes...
INFO:jfx_bridge.bridge:serving! (jfx_bridge v0.8.0, Python 2.7.1)
ghidra_bridge_server_background.py> Finished!
WARNING:jfx_bridge.bridge:Handling connection from ('127.0.0.1', 3960)
Traceback (most recent call last):
File "C:\Users\user\ghidra_scripts\jfx_bridge\bridge.py", line 1129, in local_import
result = importlib.import_module(name)
File "C:\Ghidra\ghidra_9.1.2_PUBLIC\Ghidra\Features\Python\data\jython-2.7.1\Lib\importlib\__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named django
Traceback (most recent call last):
File "C:\Users\user\ghidra_scripts\jfx_bridge\bridge.py", line 1129, in local_import
result = importlib.import_module(name)
File "C:\Ghidra\ghidra_9.1.2_PUBLIC\Ghidra\Features\Python\data\jython-2.7.1\Lib\importlib\__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named django
Traceback (most recent call last):
File "C:\Users\user\ghidra_scripts\jfx_bridge\bridge.py", line 974, in local_get
result = getattr(target, name)
AttributeError: 'ghidra.program.database.function.FunctionDB' object has no attribute '__len__'
Traceback (most recent call last):
File "C:\Users\user\ghidra_scripts\jfx_bridge\bridge.py", line 974, in local_get
result = getattr(target, name)
AttributeError: 'ghidra.program.database.function.FunctionDB' object has no attribute '__len__'
WARNING:jfx_bridge.bridge:Closing connection from ('127.0.0.1', 3960)
WARNING:jfx_bridge.bridge:Handling connection from ('127.0.0.1', 3966)
Traceback (most recent call last):
File "C:\Users\user\ghidra_scripts\jfx_bridge\bridge.py", line 1129, in local_import
result = importlib.import_module(name)
File "C:\Ghidra\ghidra_9.1.2_PUBLIC\Ghidra\Features\Python\data\jython-2.7.1\Lib\importlib\__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named ghidra_builtins
Traceback (most recent call last):
File "C:\Users\user\ghidra_scripts\jfx_bridge\bridge.py", line 1129, in local_import
result = importlib.import_module(name)
File "C:\Ghidra\ghidra_9.1.2_PUBLIC\Ghidra\Features\Python\data\jython-2.7.1\Lib\importlib\__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named django
Traceback (most recent call last):
File "C:\Users\user\ghidra_scripts\jfx_bridge\bridge.py", line 1129, in local_import
result = importlib.import_module(name)
File "C:\Ghidra\ghidra_9.1.2_PUBLIC\Ghidra\Features\Python\data\jython-2.7.1\Lib\importlib\__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named django
Traceback (most recent call last):
File "C:\Users\user\ghidra_scripts\jfx_bridge\bridge.py", line 974, in local_get
result = getattr(target, name)
AttributeError: 'ghidra.program.database.function.FunctionDB' object has no attribute '__len__'
Traceback (most recent call last):
File "C:\Users\user\ghidra_scripts\jfx_bridge\bridge.py", line 974, in local_get
result = getattr(target, name)
AttributeError: 'ghidra.program.database.function.FunctionDB' object has no attribute '__len__'
ghidra_bridge_server_background.py> FUN_StatusObjConstructor
Traceback (most recent call last):
File "C:\Users\user\ghidra_scripts\jfx_bridge\bridge.py", line 974, in local_get
result = getattr(target, name)
AttributeError: 'ghidra.program.database.function.FunctionDB' object has no attribute '__len__'
Traceback (most recent call last):
File "C:\Users\user\ghidra_scripts\jfx_bridge\bridge.py", line 974, in local_get
result = getattr(target, name)
AttributeError: 'ghidra.program.database.function.FunctionDB' object has no attribute '__len__'
ghidra_bridge_server_background.py> FUN_ReleaseMemory
Traceback (most recent call last):
File "C:\Users\user\ghidra_scripts\jfx_bridge\bridge.py", line 974, in local_get
result = getattr(target, name)
AttributeError: 'ghidra.program.database.function.FunctionDB' object has no attribute '__len__'
Traceback (most recent call last):
File "C:\Users\user\ghidra_scripts\jfx_bridge\bridge.py", line 974, in local_get
result = getattr(target, name)
AttributeError: 'ghidra.program.database.function.FunctionDB' object has no attribute '__len__'
WARNING:jfx_bridge.bridge:Closing connection from ('127.0.0.1', 3966)
Ahh, okay. So this looks like it's something to do with the PyCharm debugger (I've managed to replicate it by debugging in PyCharm). It looks like it's querying every Python object to see if it's got a __len__, probably so it can fill out some info or represent it in a handy way for debugging.
GhidraBridge will just blindly proxy the attribute requests across - on the server side, the error is caught and handled, and the message that appears is just a warning; everything should still be operating just fine.
Since this is only going to occur while debugging, and even then it doesn't really break things, I'm not going to be super-motivated to change this behaviour. Let me know if it is actually breaking things for you, though, and I can re-evaluate.
Gotcha. For a single user datapoint, my primary motivator for checking out ghidra_bridge was exclusively for debugging. I'm having trouble getting other debug mechanisms working, so this is currently THE solution that's working for me. Point being that debugging can be a primary use case for ghidra_bridge.
Thx for taking the time to check it the error messages and providing feedback!
One workaround is to set PyCharm's variable loading policy to "On demand" (Gear Icon on the left edge of the debugger panel). At least with my quick test just now this gets rid of all the errors in the ghidra_bridge server log. But at the obvious price of having to request the value for a variable if you want to see it in the debugger.