binsync / libbs

A library for writing plugins in any decompiler: includes API lifting, common data formatting, and GUI abstraction!
BSD 2-Clause "Simplified" License
63 stars 4 forks source link

Add Artifact Watcher Support for Ghidra #37

Closed Flipout50 closed 5 months ago

Flipout50 commented 6 months ago

Wasn't really sure where we want the new classes to handle artifact watching to be, so I just put the TODO in interface.py. I was thinking hooks.py looked related but not 100% sure

Flipout50 commented 6 months ago

Im going to model the DataMonitor from binja's hooks.py for now

mahaloz commented 6 months ago

@Flipout50 ayy, nice. However, I'm worried about the approach you take in this commit https://github.com/binsync/libbs/pull/37/commits/a96a5cbb3d52561927c7cf2fef5c80f965ec3809. Take special note of the import you are doing from GhidraAPIWrapper. Imports in the public scope like this are done at file-import time. Remember, our Ghidra bridge is not connected at import time. Its connect later. How will you import this class Baseclass if Ghidra has not been connected yet? You cant.

As absolutely scuffed as it is, I think you need to take all the code you would've written in the outermost scope of this file and wrap in a function. Something like def initialize_hooks(ghidra_bridge), so that you know you have the bridge.

Flipout50 commented 6 months ago

Wait so I would need to define the class inside the function? I needed the import_module from the bridge to create the class as a child but in order to import the ghidra object I need the bridge

mahaloz commented 6 months ago

@Flipout50 yup you need to define the class inside the function, a conditionally defined class. Are you sure the code you have right now works? From how I've read it, I believe it should just crash on init. Unless you have observed something else.

Flipout50 commented 6 months ago

Yeah it definitely crashes rn. I'm not familiar with a class defined in a function. I'm guessing that means you can only use the class inside the function?

mahaloz commented 6 months ago

@Flipout50 indeed, so you need to return the class from the function, and now it's defined and usable as an instantiable thing.

mahaloz commented 5 months ago

In your current error on CI, I am seeing a lot of:

jfx_bridge.bridge.BridgeException: ("getDataType(): 1st arg can't be coerced to ghidra.program.model.data.DataTypePath, long, String", <_bridged_exceptions.TypeError('TypeError("getDataType(): 1st arg can't be coerced to ghidra.program.model.data.DataTypePath, long, String",)', type=exceptions.TypeError, handle=32d4479b-eee6-410d-98c5-8cef7614d5bb)>)

Might want to check what we are passing to that in the handler.

mahaloz commented 5 months ago

Wait @Flipout50 did you fix the struct bug?

Flipout50 commented 5 months ago

Yeah @mahaloz, I was using the newValue wrong. Its a structDB object so I had to get its name and add the slash to work with the artifact dict

mahaloz commented 5 months ago

@Flipout50 can we do the other way around? I.e., don't record the name with a / if it is only in the front of the name? So in the callback all you see is the struct name? Maybe we even just omit all the / and just get the name and store that.

Flipout50 commented 5 months ago

Yeah its just the struct name. I could do that, id have to rework some functions in interface.py a bit though. Should we put it in a different PR?

mahaloz commented 5 months ago

Eh, yeah just do it in another PR.