Git Product home page Git Product logo

Comments (8)

justfoxing avatar justfoxing commented on August 20, 2024

Hey, thanks for linking to your code - it looks like maybe there's another file "refine.py" mentioned in the stacktrace that's not in your repo though, so I'm not sure exactly what you're doing.

Timeouts typically have two causes. Either a) the request running over on the ghidra side takes too long (default timeout is 2 seconds), or b) something has broken on the ghidra side in the bridge code, and it's not catching the exception correctly.

a) seems less likely, because this is failing on just getting the __str__ function (not even calling it). You can try using the response_timeout argument to increase the timeout when creating the GhidraBridge: do something like with ghidra_bridge.GhidraBridge(namespace=globals(), response_timeout=10):. If you share your refine.py code, it might help me work out why that might be going slow.

As for b) - are there any indications of uncaught exceptions on the ghidra end of things (e.g., perhaps in output from the analyzeHeadless command you're running, or in the Console window if you're running ghidra in GUI mode)? If there are, add them to this request and I'll try to track it down.

from ghidra_bridge.

EmpRamses avatar EmpRamses commented on August 20, 2024

Sorry, I just forget to update my repo. You can see it now.
Actually, this error have occurred many times at different steps during running my code. So I failed to locate where it is exactly occurred.

from ghidra_bridge.

EmpRamses avatar EmpRamses commented on August 20, 2024

Additionally, no matter where the timeout error occur, following error infos are always same, except for the part of refine.py and the id of response.

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/ghidra_bridge/bridge.py", line 414, in get_response
data = response.get(timeout)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/ghidra_bridge/bridge.py", line 378, in get
raise Exception()
Exception

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "refine.py", line 19, in
if line.getLabel():
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/ghidra_bridge/bridge.py", line 1190, in call
return self._bridge_conn.remote_call(self._bridge_handle, *args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/ghidra_bridge/bridge.py", line 665, in remote_call
return self.deserialize_from_dict(self.send_cmd(command_dict))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/ghidra_bridge/bridge.py", line 604, in send_cmd
cmd_id, timeout=timeout_override if timeout_override else self.response_timeout)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/ghidra_bridge/bridge.py", line 417, in get_response
"Didn't receive response {} before timeout".format(response_id))
Exception: Didn't receive response 89c2230d-7c9a-4abf-8e5f-13c65cf28615 before timeout

from ghidra_bridge.

justfoxing avatar justfoxing commented on August 20, 2024

Oh, right, I think I see the problem. The hidden third cause of timeouts is "the bridge is no longer open".

You've opened the ghidra_bridge in asm_exporter.py:asm_exporter(). However, because you've opened it using the with/context manager method, it is being told to close as soon as you exit that block, at the return statement on line 38. You're getting the resulting objects back in refine.py, but they belong to a bridge that's closing - you might get one or two requests through, but it's a race condition, that's why you're seeing it timeout in a few different places.

You'll need to refactor your code so that you hang on to the bridge until you've stopped using the objects from it. Suggestions:

  1. You could do something like move the with ghidra_bridge.GhidraBridge out of asm_exporter.py to the top of refine.py (so that all of the operations happen within that with block).
  2. You could change opening the bridge from the with/context manager block to something like bridge_to_keep_alive = ghidra_bridge.GhidraBridge(namespace=globals()) and return bridge_to_keep_alive from asm_exporter. Note that you need to hang onto this bridge object - once it leaves scope, the bridge will be shut down.

from ghidra_bridge.

EmpRamses avatar EmpRamses commented on August 20, 2024

Ahh, get it! Thank you! I used to think that ghidra_bridge contain a python3 version ghidra api.

from ghidra_bridge.

EmpRamses avatar EmpRamses commented on August 20, 2024

The problem re-occurred.
I've changed my code using a customized class to avoid replying on ghidra api. Making the whole process using ghidra api below the with. However, the timeout error occurred when transferring ghidra type inst to my Inst. You can see my new code in the same repo. And error infos are following:
error

from ghidra_bridge.

EmpRamses avatar EmpRamses commented on August 20, 2024

There are some other error infos in nohup.out. I just forget them.
And I have run my new code several times. Some errors are following.

Traceback (most recent call last):
File "/Users/empramsesii/Code/ghidra_export/ghidra_py_Instr/asm_exporter.py", line 49, in asm_exporter
str(line.getLabel()),
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/ghidra_bridge/bridge.py", line 1070, in getattribute
result = self._bridged_get(attr)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/ghidra_bridge/bridge.py", line 1091, in _bridged_get
return self._bridge_conn.remote_get(self._bridge_handle, name)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/ghidra_bridge/bridge.py", line 616, in remote_get
return self.deserialize_from_dict(self.send_cmd(command_dict))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/ghidra_bridge/bridge.py", line 604, in send_cmd
cmd_id, timeout=timeout_override if timeout_override else self.response_timeout)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/ghidra_bridge/bridge.py", line 417, in get_response
"Didn't receive response {} before timeout".format(response_id))
Exception: Didn't receive response 6440846e-6613-4569-8a06-d565f5192929 before timeout
Exception ignored in: <bound method BridgedObject.del of <BridgedIterableIterator('ghidra.program.database.code.CodeUnitRecordIterator@42ee7e44', type=CodeUnitRecordIterator, handle=26c47af2-cd94-457c-bdf7-05ddaa985bfc)>>
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/ghidra_bridge/bridge.py", line 1142, in del
self._bridge_conn.remote_del(self._bridge_handle)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/ghidra_bridge/bridge.py", line 696, in remote_del
self.send_cmd(command_dict, get_response=False)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/ghidra_bridge/bridge.py", line 598, in send_cmd
Exception in thread Thread-2:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/ghidra_bridge/bridge.py", line 300, in run
self.bridge_conn.get_socket())
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/ghidra_bridge/bridge.py", line 155, in read_size_and_data_from_socket
size_bytes = read_exactly(sock, struct.calcsize(SIZE_FORMAT))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/ghidra_bridge/bridge.py", line 142, in read_exactly
new_data = sock.recv(num_bytes)
ConnectionResetError: [Errno 54] Connection reset by peer

write_size_and_data_to_socket(sock, data)

File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/ghidra_bridge/bridge.py", line 134, in write_size_and_data_to_socket
bytes_sent = sock.send(package[sent:])
BrokenPipeError: [Errno 32] Broken pipe

nohup.out

Traceback (most recent call last):
File "/Users/empramsesii/Code/ghidra_bridge/ghidra_bridge/bridge.py", line 335, in handle
BridgeReceiverThread(BridgeConn(
File "/Users/empramsesii/Code/ghidra_bridge/ghidra_bridge/bridge.py", line 299, in run
data = read_size_and_data_from_socket(
File "/Users/empramsesii/Code/ghidra_bridge/ghidra_bridge/bridge.py", line 299, in run
data = read_size_and_data_from_socket(
File "/Users/empramsesii/Code/ghidra_bridge/ghidra_bridge/bridge.py", line 155, in read_size_and_data_from_socket
size_bytes = read_exactly(sock, struct.calcsize(SIZE_FORMAT))
File "/Users/empramsesii/Code/ghidra_bridge/ghidra_bridge/bridge.py", line 142, in read_exactly
new_data = sock.recv(num_bytes)
File "/Users/empramsesii/Code/ghidra_9.2_DEV/Ghidra/Features/Python/data/jython-2.7.1/Lib/_socket.py", line 1490, in recv
return super(ChildSocket, self).recv(bufsize, flags)
File "/Users/empramsesii/Code/ghidra_9.2_DEV/Ghidra/Features/Python/data/jython-2.7.1/Lib/_socket.py", line 1270, in recv
data, _ = self._get_message(bufsize, "recv")
File "/Users/empramsesii/Code/ghidra_9.2_DEV/Ghidra/Features/Python/data/jython-2.7.1/Lib/_socket.py", line 384, in handle_exception
raise _map_exception(jlx)
error: [Errno -1] Unmapped exception: java.lang.NullPointerException
WARNING:ghidra_bridge.bridge:Closing connection from ('127.0.0.1', 59138)

from ghidra_bridge.

justfoxing avatar justfoxing commented on August 20, 2024

Sorry for the delay, it took me a while to get enough time to try to replicate your setup. I note you've moved away from using ghidra_bridge, so I was using commit 8e2abbfb972f91b2f18f49ce5cd54352f518bc88 from about when you last commented on this issue.

Unfortunately, I can't reproduce the problem - your test.py code runs fine for me until it hits an error much further on in your code, in code not using any ghidra_bridge objects as far as I can tell. The errors in your log seem to suggest networking failures - maybe processes weren't being cleaned up correctly, or were dying too early - but apart from that, there's nothing else I can suggest.

I'm going to close this as unreproducable. If you have further information, feel free to add it.

from ghidra_bridge.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.