Git Product home page Git Product logo

Comments (3)

justfoxing avatar justfoxing commented on June 19, 2024

Hi, Tom.

Could you give me the actual code you're running across the GhidraBridge to get this issue? I'm unable to replicate it across the bridge as written (using ghidra_bridge 0.2.5, jfx_bridge 0.7.1, and Ghidra 9.1.2) - when I make some modifications to work around an unrelated issue (thanks for helping me find that! [but it's not your problem :P]), I get the expected behaviour (data populated in the buffer - I'm using an ELF file instead of a PE because that's what I had open, but that won't make a difference). Here's what works for me:

In [1]: import ghidra_bridge
In [2]: b = ghidra_bridge.GhidraBridge(namespace=globals())
In [3]: array = b.remote_import("array")
In [4]: start = 0x100000
In [5]: length = 16
In [6]: buffer = b.remote_eval("array.array('b', data)", array=array, data = b"\0"*length) # need to remote_eval this to work around "b" being set to unicode by the bridge
In [7]: print(buffer)
array('b', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
In [8]: currentProgram.getMemory().getBytes(currentProgram.getAddressFactory().getDefaultAddressSpace().getAddress(hex(start)), buffer)
Out[8]: 16
In [9]: print(buffer)
array('b', [127, 69, 76, 70, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0])

Similarly, when I run your code directly in the Ghidra python interpreter, I get the expected behaviour:

>>> import array
>>> length = 16
>>> start = 0x100000
>>> buffer = array.array ("b", b"\0" * length)
>>> print(buffer)
array('b', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
>>> currentProgram.getMemory().getBytes(currentProgram.getAddressFactory().getDefaultAddressSpace().getAddress(hex(start)), buffer)
16
>>> print(buffer)
array('b', [127, 69, 76, 70, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0])

from ghidra_bridge.

justfoxing avatar justfoxing commented on June 19, 2024

Added a fix to the unrelated issue in jfx_bridge 0.8.0. So with that, the bridged code now reads:

In [1]: import ghidra_bridge
In [2]: b = ghidra_bridge.GhidraBridge(namespace=globals())
In [3]: array = b.remote_import("array")
In [4]: start = 0x100000
In [5]: length = 16
In [6]: buffer = array.array("b", b"\0"*length)
In [7]: print(buffer)
array('b', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
In [8]: currentProgram.getMemory().getBytes(currentProgram.getAddressFactory().getDefaultAddressSpace().getAddress(hex(start)), buffer)
Out[8]: 16
In [9]: print(buffer)
array('b', [127, 69, 76, 70, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0])

It makes no difference to your problem, just slightly cleaner.

from ghidra_bridge.

tombonner avatar tombonner commented on June 19, 2024

Ahh, so I was doing something stupid!

This was key...

array = self.bridge.remote_import("array")
buffer = self.bridge.remote_eval("array.array('b', data)", array=array, data = b"\0"*length) 

With that in place everything works very much as expected, thanks for your assistance!

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.