-
Dear community, I made a snippet to help me with static analysis of C++ structures and now want to convert it to a plugin. Idea is simple: I highlight a call to constructor function, it identifies the structure size, creates type, renames constructor and changes type of the pointer in the constructor arguments. On the screenshot below you can see the highlighted constructor call after renaming. This is the snippet itself: # C++ define type
bv.begin_undo_actions()
try:
size = results2[current_token.text]
name = current_token.text.replace('sub_', 'type_')
t = bv.parse_type_string(f'struct test{{__padding char _0[{size}];}}')[0]
bv.define_user_type(name, t)
fun = bv.get_functions_by_name(current_token.text)[0]
fun.name = f'{name}_Init'
fun.parameter_vars[0].type = bv.parse_type_string(f'{name}*')[0]
finally:
bv.commit_undo_actions() I was trying to replicate this functionality in an UI plugin, so that I could right click the constructor and select "Define type", however I am facing a problem that the current_token is not defined in the plugin action context. I tried to work around it with using I also tried to use Could you please give me an idea how could I achieve it with the UI plugin? Best regards, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I tried this before, but was getting a strange error that something is not available / does not exist anymore, but now it works. log_info(f"address: {hex(start)} - {hex(start+end)}")
context = UIContext.activeContext()
print(f'context = {context}')
action_handler = context.getCurrentActionHandler()
print(f'action_handler = {action_handler}')
view_frame = context.getCurrentViewFrame()
print(f'view_frame = {view_frame}')
view = context.getCurrentView()
print(f'view = {view}')
view_location = view_frame.getViewLocation()
print(f'view_location = {view_location}')
action_context = None
if view is not None:
action_context = view.actionContext()
elif action_handler is not None:
action_context = action_handler.actionContext()
token_state = action_context.token
print(f'token_state = {token_state}')
token = token_state.token if token_state.valid else None
print(f'token = {token}') This produces the log:
I guess that's it 😆 |
Beta Was this translation helpful? Give feedback.
I tried this before, but was getting a strange error that something is not available / does not exist anymore, but now it works.