ILSpy icon indicating copy to clipboard operation
ILSpy copied to clipboard

How to edit MethodTreeNode or AssemblyTreeNode in plugins

Open beaverden opened this issue 3 years ago • 5 comments

I'm a bit new to such levels of C# and, while I managed to develop most of the features using the example plugins, I'm struggling to find any hints on editing the display text or icons of tree nodes.

Do you have any guidance on that?

image

beaverden avatar May 20 '21 13:05 beaverden

What exactly would you want to change? Exposing tree nodes is a complex task, which is why we never started doing so, although it is a previously requested change.

siegfriedpammer avatar May 27 '21 07:05 siegfriedpammer

In my use-case, changing the text could be helpful. I tried digging through the code, but I found that most of the attributes are marked read only. I think that adding some suffix/prefix or changing the text during runtime could be helpful.

I'm not proficient in C#, but I could try submitting a pull request implementing this

beaverden avatar May 27 '21 07:05 beaverden

The text is controlled by the active language, e.g. with IL selected you'll see different text than with C# selected. You can add additional Language implementations via plugin.

The tree node is a graphical representation of the underlying SRM MethodDefinition. SRM is immutable; so I don't think the UI layer should introduce mutability.

Why are you trying to change the text?

dgrunwald avatar May 27 '21 15:05 dgrunwald

We're using an ILSpy plugin to create detections for malicious MSIL files. One of the features of the plugin is identifying whether a method has been seen in clean executables, thus it would be pretty cool to be able to somehow show that a particular method was used in legitimate files. This can be done in multiple ways, but one of the most intuitive ways is somehow inserting the info about that in the nodes dynamically, as the information is loaded from internal APIs.

I have read how C# node text is constructed, but I didn't see a way to extend that using a plugin (without breaking future compatibility or introducing UB) . Would you happen to have an example plugin doing that lying around? Any hints would be appreciated

beaverden avatar May 27 '21 15:05 beaverden

As Daniel already mentioned, the currently selected language implementation dictates the text of a node. You could try extending CSharpLanguage and providing your custom "C# with malicious code detection" language in the dropdown.

siegfriedpammer avatar Dec 03 '21 23:12 siegfriedpammer