-
Notifications
You must be signed in to change notification settings - Fork 308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial Cutter integration #65
base: develop
Are you sure you want to change the base?
Conversation
#@not_mainthread | ||
# TODO Reenable not_mainthread | ||
def get_function_name_at(self, address): | ||
# TODO User Cutter API |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use*
@@ -566,7 +567,10 @@ def _update_functions(self, fresh_metadata): | |||
# | |||
|
|||
if new_metadata.empty: | |||
del self.functions[function_address] | |||
try: | |||
del self.functions[function_address] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may have been to account for a bug I fixed in a55ede7, I will see if it is safe to remove this change from your code now.
plugin/lighthouse/metadata.py
Outdated
# Cutter already provides this information, so just fetch it | ||
if disassembler.NAME == "CUTTER": | ||
try: | ||
return int(cutter.cmd('afCc @ ' + str(self.address))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to avoid inline disassembler casing. We have the disassembler API abstraction explicitly so we don't have to have if/else trees everywhere. It makes the code both more maintainable, and readable.
The exception to that rule is mostly class monkey patching, which is done to ensure performance for hot paths.
I'll evaluate whether it is reasonable to add complexity calculations to the disassembler API, or if it is okay to simply use the existing lighthouse code. Complexity calculations are already pretty fast in lighthouse, but I understand that r2 might offer more 'accurate' scores.
Thanks for the PR! You have done great work, and this is an awesome contribution for the project to receive from the community. I went through the PR and made some initial notes. In particular, the code I question and scrutinize the most from any contribution is code that affects everyone -- eg, any changes that are executed on every platform and disassembler. With regard to some of the disassembler threading code, I don't expect anyone to fully grasp its purpose or implementation. It requires a lot of context with both the existing lighthouse codebase, and the disassembler platforms (ida/binja/r2). I will have to evaluate r2/cutter a bit more and work out the appropriate implementation myself. I don't expect any additional work from you or the r2 guys, but always welcome any additional commits. Thanks! |
I will try to fix the comments you addressed when I find some time before next week. Thanks! |
Hey, sorry for the delay I said "before next week", but I think it's passed by now :3 |
No rush, I haven't had much time to look at it but I will try to work on it some more over the next few days. I fixed up a bunch of styling issues that cutter exposed, these changes are on dev. The cutter integration should look 'better' once we merge it into dev. Most of the 'threading' TODOs are a non-issue, I think I removed / cleaned up most of them but haven't committed it yet. One of the last things I was working on before I stopped was fixing the functionRenamed signal stuff. Hopefully https://github.com/radareorg/cutter/issues/1482 means it should be usable in 1.8.3. IIRC, there are still a few quirks that I haven't had a chance to look at, such as the graph not automatically refreshing when using the 'hotshell' mode. |
50ca546
to
0359fc5
Compare
I pushed a few more things onto dev and rebased this PR ontop of it with a few more minor updates. Sorry for the force push / dirtying up the PR, hopefully the final squash & merge will clean up the history. I updated the 'known issues' section of the initial PR. I would like to resolve these before officially merging. Once these are done, we can test it a bit more for general stability. |
I think that this is fixed now, isn't it? The related PR is merged on Cutter edge |
Hey there, |
Are there any updates? |
I started to rebase my branch on |
I have time to work on closing out this PR this week (sept 16 - 20). I am hoping to spend some time on doing the binja overhaul soon (early october?) and so I will probably just merge this is whether or not support is complete. I re-sorted the TODO list at the top of this PR by what is most likely to get resolved this week / without requiring any additional cutter changes / features to land. I think we will have to forego disas highlighting and the xref features for the time being. |
Hi @gaasedelen :) |
0359fc5
to
22dc30d
Compare
I've been trying to catch up on lighthouse maintenance. I looked at this branch and was honestly kind of surprised it still worked (granted, I haven't worked on lighthouse much...) There's still a lot of issues.
To give some perspective, I tested loading the same I can accept shipping a 10-20x slowdown from IDA in an experimental release, but I will not ship Lighthouse at 150x slowdown. That's a shitty user experience. I think this highlights what I am asking of you guys. I don't my way around the Cutter API (is it even documented ...?) or r2's command schema, so I would appreciate if you could look at For example, Please test your work against a larger executable such as |
Hi, I'm trying to continue this pull request as I'd like to use this plugin with Cutter. I've been able to merge the current develop branch with the cutter integration in this pull request and I'm currently trying to adapt it to use the new API (LighthouseCoreAPI and LighthouseContextAPI). But when I try to load a file the following error shows:
As it shows the abstract method Could any of you guys point me in the right direction to fix this? Edit: Furthermore, similar issue happens with |
Cool! You're a brave one :-) Yes those abstractions are quite new and this branch needs to be ported onto them... They were introduced in the recent 'binja refactor' for v0.9. Their purpose is to support the notion of 'multiple databases' open in one process, where each lighthouse 'context' roughly equates to an open database.
You are correct -- I am not sure why Python did not actually throw an abstraction warning, but I guess the metaclassing doesn't actually check the full function signatures (TIL) ?!? I believe I refactored the rename hooking code in the v0.9 update, so that probably explains why the function and comment are stale.
Yes, this project is working fine on IDA/Binja. Do you have an example / callstack of the issue? Sorry, I know it can get a bit complicated due to the shimming/compat/abstraction. I'll do my best to answer any other questions you may have though. |
Hi, I've made some changes based on your last response
I changed the signature in
Sorry, this was an error on my side, so nothing to worry here
Currently I'm running into an issue with the method
This seems strange as I put some I suspect there may be an error in how I'm creating the
|
For example, it is dangerous (as in prone to crashes) to read from the IDA database or use some of the IDA API's from a background thread without taking the correct precautions. IDA provides some API's to synchronize access to the database (eg, When you see the Lucky for you, r2/cutter doesn't really have any sort of thread safety / synchronziaton mechanisms in place -- so it's all pretty YOLO. If I remember correctly, the Another point of confusion is that IDA must do basically everything in the mainthread, where Binja requires you to do most database interaction in a 'background threaded worker'. So yes, the implementations can be pretty unique per disassembler... I started trying to breakdown what could actually be failing with the Could you push your work/contributions so I can poke around a bit, and see if I can get your port up to a baseline on the new interfaces? |
Thanks for the help. The issue was that I put some methods in the wrong place while migrating to the new I've uploaded the code to my fork in the |
This PR aims at adding lighthouse support for Cutter. Feel free to tell me if anything is wrong, I won't have much time myself to improve the PR more, but hopefully some people will do :)
Screenshot
How to install
ligthouse
andlighthouse_plugin.py
into~/.local/share/RadareOrg/Cutter/plugins/python/
Known issues:
functionRenamed()
(hopefully with cutter 1.8.2? https://github.com/radareorg/cutter/issues/1482)get_disassembler_user_directory()
incutter_api.py
self._stream.write(buf)
crashes (at least on windows) cuz cutter doesn't have a STDOUT stream