Vector35 / binaryninja-api

Public API, examples, documentation and issues for Binary Ninja
https://binary.ninja/
MIT License
928 stars 209 forks source link

More proper way for displaying function pointers in structures in linear view #4115

Open op2786 opened 1 year ago

op2786 commented 1 year ago

I've opened a general issue for this before as #3540 and I mentioned this problem in my second message in it. But I frequently get into trouble with this spesific example, so I want to open an seperate issue for it in order to make people find it more easy.

struct cc_handler_vft cc_handler_vftl = 
{
    void (* handle_cc_command)(struct cc_handler* this, int32_t a2, void (*** lpAddress)(void*, int32_t)) = handle_cc_command
    int32_t (* cc_handler_destroy)(struct cc_handler* this) = cc_handler_destroy
}

As you can see, it makes it very hard to see members of vft. Especially if there are a lot of them with longer prototypes and I open two BN side-by-side.

fuzyll commented 1 year ago

Just to make sure I'm following, the members here are handle_cc_command and cc_handler_destroy, which are both function pointers, right? And what you're looking for, from the other issue, is to just display:

struct cc_handler_vft cc_handler_vftl =
{
   handle_cc_command
   cc_handler_destroy
}

...because the names of the assignments match the members they're being assigned to, and you would prefer to have the types hidden?

Can you elaborate on this a little bit for me? I think I'm specifically having a hard time understanding wanting the assignment to go away. I can understanding wanting to hide the big function prototypes, since that pushes the assignment way out to the right, which is hard to read.

op2786 commented 1 year ago

Actually I don't mean to wanting the assignment to go away. I just say that if we would have option for doing so, it would be useful. I want to be able to get as much as possible C-like output in the decompiler because it makes copy-pasting from the decompiler more easier.

Imagine that we can customize the rendering of each structure in the decompiler with several flexibility options which could give us these outputs:

Hide assignments and type casts:

struct cc_handler_vft cc_handler_vftl =
{
   handle_cc_command
   cc_handler_destroy
}

Hide type casts:

struct cc_handler_vft cc_handler_vftl =
{
   handle_cc_command = handle_cc_command
   cc_handler_destroy = cc_handler_destroy
}

Hide type casts that matches member types:

struct cc_handler_vft cc_handler_vftl =
{
   handle_cc_command = handle_cc_command
   int32_t (* cc_handler_destroy)(struct cc_handler* this) = cc_handler_destroy
}

Show both assignments and type casts:

struct cc_handler_vft cc_handler_vftl = 
{
    void (* handle_cc_command)(struct cc_handler* this, int32_t a2, void (*** lpAddress)(void*, int32_t)) = handle_cc_command
    int32_t (* cc_handler_destroy)(struct cc_handler* this) = cc_handler_destroy
}