Git Product home page Git Product logo

Comments (5)

justfoxing avatar justfoxing commented on July 18, 2024

Replicated. Looks like it's looking for the __index__ special method - not sure why as yet.

While I dig in to that, I'll suggest changing your code to something like bytes(getBytes(address, length).tolist()). The tolist() function extracts the bytes into a list, so bytes() works cleanly - the end result in Python3 will be something like b'\x7fELF\x01\x01\x01\x00\x00\x00'

from jfx_bridge.

justfoxing avatar justfoxing commented on July 18, 2024

Further observation:

The issue only happens when bridging from Python 3. In Python 2, the following occurs:

>>> x = getBytes(currentAddress,10)
>>> x
<BridgedIterable('array('b', [127, 69, 76, 70, 1, 1, 1, 0, 0, 0])', type=array, handle=076c3e90-c52d-431d-9d71-e4a4d2d4ca66)>
>>> bytes(x)
"array('b', [127, 69, 76, 70, 1, 1, 1, 0, 0, 0])"

This is because bytes() in Python 2 is just an alias to str(). This is also the behaviour in the Ghidra python interpreter.

from jfx_bridge.

justfoxing avatar justfoxing commented on July 18, 2024

Confirmed that the issue is not specific to Ghidra - a bridged collections.deque object shows the same behaviour in pure Python. Moving this issue to jfx_bridge to solve there.

from jfx_bridge.

justfoxing avatar justfoxing commented on July 18, 2024

Ref the bytes_new function at https://github.com/python/cpython/blob/a81849b0315277bb3937271174aaaa5059c0b445/Objects/bytesobject.c#L2542

When bytes() is called, there's a _PyIndex_Check call at L2617 to see if __index__ is defined for this type, and if it is, it proceeds into PyNumber_AsSsize_t which calls __index__, thus triggering the failure. What we actually want to happen is for the _PyIndex_Check to return false, and the code to fall through to the final case PyBytes_FromObject.

__index__ is defined on BridgedObject by my code for automatically registering all operator methods as class methods, so that's the root cause of this bug - __index__ is being defined, but just straight up doesn't exist.

Best solution is probably dusting off the feature-dynamic-types branch and completing that work, so that the BridgedObjects will have the correct class methods for their remote type. I'll move that up my TODO list.

from jfx_bridge.

justfoxing avatar justfoxing commented on July 18, 2024

Fixed in version 0.3.0 of jfx_bridge (no version bump for ghidra_bridge).

Upgrade with pip install ghidra_bridge --upgrade --force-reinstall to get the latest jfx_bridge component, then re-install the server scripts with python -m ghidra_bridge.install_server <script location>.

Then your original bytes(getBytes(xxx)) should work as expected.

from jfx_bridge.

Related Issues (5)

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.