question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Different results in bridge and in Jython Shell

See original GitHub issue

Running hex(getState().getCurrentAddress().getOffset()) in the Jython shell gives a different result than running

import ghidra_bridge
b = ghidra_bridge.GhidraBridge()
b.get_flat_api(namespace=globals())
print(hex(getState().getCurrentAddress().getOffset()))

in the bridge.

I have no idea why, if you cant reproduce this on windows I can investigate this further.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:17 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
justfoxingcommented, Apr 10, 2019

Okay, finally had time to take a proper look. Good news is I can replicate it now. Bad news is, I’m pretty sure this is a Ghidra issue, so outside the scope of this project.

What appears to be happening is that when called inside a Python script (but not the python interpreter), getState() is not syncing/updating but is instead returning the same state each time (I assume the initial state variable). See this by running str(getState()) multiple times. In the interpreter, I get a different state object each time:

>>> str(getState())
'ghidra.app.script.GhidraState@4a448520'
>>> str(getState())
'ghidra.app.script.GhidraState@1f9f6539'
>>> str(getState())
'ghidra.app.script.GhidraState@58e50e17'

but in both a script run directly from the script manager, and running across the ghidra_bridge, I get the same state object:

>>> str(getState())
'ghidra.app.script.GhidraState@75c0f6cf'
>>> str(getState())
'ghidra.app.script.GhidraState@75c0f6cf'
>>> str(getState())
'ghidra.app.script.GhidraState@75c0f6cf'

Further, modifications to the state work and are reflected in the GUI - but the moment you call getState() again, it goes back to the original values (and the GUI updates to jump back to them).

>>> s = getState()
>>> str(s.getCurrentAddress())
'00007154'
>>> s.setCurrentAddress(s.getCurrentProgram().getAddressFactory().getAddress("0x31337"))
>>> str(s.getCurrentAddress())
'00031337'
>>> # confirmed in GUI - addr is 31337
>>> str(getState().getCurrentAddress())
'00007154'
>>> # confirmed in GUI - addr back to 7154

Given that this is occurring in a script run directly from the script manager, without the bridge, I’ve got to go with this being a bug in Ghidra. I’ll leave this issue open a little longer in case you’ve got another thought - otherwise, feel free to report the issue to them if you want (I feel like you found the original bug here, so you should get the cred - feel free to use any of my notes). If not, I’ll look into reporting it when I get ghidra_bridge stable.

0reactions
justfoxingcommented, May 29, 2019

Uploaded. Grab the latest version and hopefully that’ll do the trick.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jython User Guide
Jython and CPython are two different implementations of the same language. There are naturally some differences between the two implementations, ...
Read more >
Results Generation by the Jython Script - ITOM Practitioner Portal
Each Jython script runs on a specific Trigger CI, and ends with results that are returned by the return value of the DiscoveryMain...
Read more >
Object Relational Mapping and Using JDBC — Definitive ...
In this chapter we'll focus on using SQLAlchemy with Jython, as well as using Java technologies such as Hibernate. In the end you...
Read more >
Jython - Quick Guide - Tutorialspoint
Jython - Quick Guide, Jython is the JVM implementation of the Python programming language. It is designed to run on the Java platform....
Read more >
ghidra-bridge - Python Package Health Analysis - Snyk
Learn more about ghidra-bridge: package health score, popularity, security, ... For a better interactive shell like IPython or if you need Python 3 ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found