Posts Tagged ‘Decompiler’

Creating plugins for dotPeek

Wednesday, May 15th, 2013

In a previous post, we’ve seen that dotPeek supports creating and loading plugins. The NuGet plugin for dotPeek is a good example to demonstrate how to get started creating plugins for dotPeek. Sources for this plugin are available on GitHub. But let’s create a plugin of our own!

Before we start: dotPeek does not have a formal SDK yet. However it shares a lot of commonalities with ReSharper. In fact: dotPeek is built on the same platform as ReSharper reusing the project model, PSI, navigation and so on. Which is good news: we can use the ReSharper SDK (see the downloads page) to create plugins for dotPeek. Another option is to start from a class library project and work with a small NuGet package I’ve created to help you get started.

Creating a new plugin

To create a plugin for dotPeek, we can make use of the instructions provided with the ReSharper SDK. This involves a lot of project modifications so we’ll take the easy way out: we can create a dotPeek plugin by installing a NuGet package.

Install-Package JetBrains.DotPeek.PluginDevelopment

In Visual Studio, we can start out with a new Class Library project, making use of .NET 3.5 or up. Next, we can install the JetBrains.DotPeek.PluginDevelopment NuGet package into the project. This NuGet package will convert the class library we have into a dotPeek plugin by adding assembly references and several attributes. Note that the NuGet package will target the latest version of dotPeek that is installed on your system (which also means we have to have a copy of dotPeek installed).

That’s everything we have to do: by running our project, dotPeek will launch with our fresh plugin loaded:

New plugin for dotPeek

Now let’s see where those menu items are coming from…

Menus, toolbars and handlers

Menu items, like the About menu we saw when loading our plugin in dotPeek, are triggered using handlers. The AboutActionHandler.cs file in our project is a sample handler implementation.

About action handler

There are some things to note here:

  • The ActionHandler attribute denotes the fact that this class is a handler with a specific name, “MyFirstDotPeekPlugin.AboutAction” in this case.
  • Handlers are added to menus and toolbars in the Actions.xml file, referencing the action name. More information on actions.xml can be found in the ReSharper plugin documentation. To make working with Actions.xml easier, the NuGet package also added an Actions.xsd containing the full XML schema we can use.
  • Handlers implement two methods of the IActionHandler interface:

    • Update – specifying whether the action is enabled or disabled.
    • Execute – the code which is executed once an action is being invoked.

    The following handler will be always available and can open a new command dialog when invoked:

    Command line tool window in dotPeek

    We can add it to a menu or toolbar by updating the actions.xml file:

    Actions.xml for plugins

    Distributing a plugin

    There comes a time when we want to make our plugin available to the public. Distributing a plugin is a simple process:

    • Distribute the assembly compiled from your project
    • Users can copy this assembly into %LOCALAPPDATA%\JetBrains\dotPeek\v<your target dotPeek version>\plugins

    Another option is to generate a simple installation batch file, check my NuPeek plugin’s GitHub repository for more information.

    Further reading

    In this blog post, we’ve only scratched the top of the surface. With plugins, a lot of things are possible: we can add menu items, toolbar buttons, tool windows, options panes and so on. In fact, many of the features shipped with dotPeek are in fact built as plugins. It is advised to consult the ReSharper Plugin Development Guide for additional information on developing dotPeek plugins.

    Peeking into NuGet packages with dotPeek

    Tuesday, May 7th, 2013

    Using dotPeek, we can peek into assemblies by downloading symbols or by decompiling them. Out of the box, we can also open NuGet packages stored locally. But what about NuGet packages that we haven’t downloaded yet? Well… there’s a plugin for that!

    The plugin is available for download. Extract the ZIP file contents and run the appropriate batch file for your version of dotPeek, e.g. Install-NuPeek.1.0.bat for dotPeek 1.0, or Install-NuPeek.1.1.bat for dotPeek 1.1. The plugin is compatible with dotPeek 1.0 and the dotPeek 1.1 EAP. Source code for this plugin is available on GitHub.

    After downloading and installing the plugin, dotPeek features a new toolbar icon as well as two new menu items under the File menu. The File | Open from NuGet… menu entry allows us to download and open a NuGet package from any NuGet repository out there. The File | Open NuGet packages.config… menu entry allows us to open all NuGet packages defined in a packages.config file.

    dotPeek open from NuGet

    Using the toolbar button, we can search for a NuGet package we want to load and decompile using dotPeek. We can download packages from the official NuGet gallery as well as any other NuGet repository out there such as your TeamCity server.

    Select package from NuGet gallery

    We can search for packages and open them. Using the Load dependencies checkbox, we can automatically download dependencies for the selected package as well. Once downloaded, dotPeek will display the NuGet package and download symbols or decompile contained assemblies.

    dotPeek open NuGet package

    In a future blog post, we’ll dive into how we can create plugins for dotPeek. If you can’t wait, the sources for this plugin are available on GitHub. In the meanwhile, download the dotPeek EAP and give it a go!

    Introducing the dotPeek 1.1 EAP

    Tuesday, April 2nd, 2013

    In our recent blog post on the ReSharper 8 EAP, we have mentioned certain improvements to the decompilation support. Today, we are happy to announce that the next version of dotPeek, our free decompiler, has also reached the EAP stage. Here are some of the features that you can try out today.

    Export Assembly to Project

    Many of you have asked us to add functionality for saving a decompiled assembly as a ready-to-build Visual Studio project. We have listened to your requests: now, if you right-click a decompiled assembly, you get the option to export it as a project:

    All you need to do is provide the destination path and name of the project. You can also generate a solution (.sln) file if you need one.

    The above generates a project (.csproj) file containing all the decompiled files. dotPeek is smart about creating projects – here are some of the optimizations it performs:

    • If PDB files are available, dotPeek restores the file and folder structure of the original project.

    • If the project has unsafe code, the project is configured to allow it.

    • The type of assembly is detected and the project is configured accordingly.

    Incidentally, dotPeek also keeps track of your export history. If you try to export the project again, it will offer the following dialog:

    Project File Support in Assembly Explorer

    To make it easy to orient oneself in situations where parts of a solution exist only in compiled form and other parts exist as source code, dotPeek’s Assembly Explorer now supports Visual Studio projects (.csproj). You can automatically add the project to the Assembly Explorer after generating it from decompiled sources (see the Add project to Assembly Explorer checkbox in the above window):

    Go to Everything

    Just like ReSharper, dotPeek now uses Ctrl+T as the Go to Everything command, letting you navigate to either file, symbol or type within one menu:

    Odds and Ends

    Finally, here are a few more features that are available:

    • dotPeek now preserves window layout settings. It also keeps track of recently opened files.

    • Just like Visual Studio, dotPeek now lets you set bookmarks and navigate between them.

    • In addition to the MSI installer, dotPeek is now also available as a single executable file.

    If you’re interested in seeing these features right now, download the dotPeek EAP and give it a go!

    dotPeek 1.0 is Released

    Thursday, May 10th, 2012

    Free .NET decompiler and assembly browser from JetBrains is now officially live! Please download dotPeek 1.0 and enjoy high-standard decompilation with ReSharper-inspired navigation and search!

    Just as a reminder, here’s the list of key dotPeek features:

    • Decompiling .NET Framework 1.0-4.5 assemblies to C#. Libraries (.dll), executables (.exe), and Windows 8 metadata files (.winmd) are all supported.
    • Connecting to symbol and source servers to fetch original source code, if available. If you let dotPeek sniff around for PDB files or a source server, it can get source code matching your assemblies, and show it to you.
    • Quick overview of code structure and hierarchy. ReSharper’s File Structure and Type Hierarchy are all included. There’s also References Hierarchy to explore dependencies between references.
    • Powerful ReSharper-inspired navigation and search, including Go to Type, Go to Symbol, Go to File Member, and the whole set of context-sensitive navigation like jumping to symbol declarations, implementations, derived and base symbols.
    • Accurate search for symbol usages — again, this is by virtue of ReSharper search features like Find Usages, Find Usages Advanced, and Highlight Usages.
    • Familiar keyboard shortcuts for most actions: Visual Studio and IntelliJ IDEA keymaps are included to ensure a familiar experience for users of (you guessed it) ReSharper and other JetBrains developer tools.

    To learn more about dotPeek 1.0, read dotPeek Features, or watch this introductory video by James Kovacs that is also available on JetBrains TV:

    Haven’t you downloaded dotPeek yet? Please do. Decompile with pleasure!

    dotPeek 1.0 Beta Available

    Thursday, April 19th, 2012

    If by now you can’t recall what dotPeek is, it’s our free .NET decompiler, and it goes Beta today. Please go ahead and download dotPeek 1.0 Beta for your daily dose of awesomeness.

    Since the emergence of the previous dotPeek build that added base types and inheritors to Assembly Explorer, the dotPeek crew has introduced a whole bunch of great stuff that’s exposed in this Beta. Here’s the list:

    • Installer. dotPeek EAP used to be distributed as a simple zip archive, making managing versions a bit of a mess. It’s refreshing that on the verge of final release, there’s finally an installer.

      This has an additional implication: whether you choose to integrate dotPeek with Windows Explorer is now set from the installer, not from dotPeek Options.
    • Assembly management. Here’s another piece of must-have functionality that was previously unavailable: You can now work with different assembly lists depending on your context. You can save and reopen assembly lists, and clear the current list if you no longer need it. Assembly lists are actually not limited to .dll and .exe files: they can contain archives and folders (see below.)
    • Open archives and folders. In addition to traditional assemblies and executables, you can have dotPeek open archives (including .zip, .vsix, and .nupkg formats), and also folders. When you ask dotPeek to explore a folder, it processes all its subfolders in hunt for files that it is able to decompile.

      Since you can also open files from the web by passing an URL to the Open dialog, support for archives opens up some nifty scenarios like opening NuGet packages from GitHub or .zip files attached to a bug report in one go.
    • Support for .winmd files. If you’re playing with VS11 Beta and WinRT, you’re going to appreciate that dotPeek can now show contents of .winmd files
    • An option to show compiler-generated code. This switch turns off certain compiler transformations, making code structure very similar to what the compiler turns it to. This helps see how compiler deals with lambdas, closures, and auto-properties, among other things.
    • Add to this several important fixes and optimizations such as caching the contents of Open from GAC dialog box, and sorting out issues with key accelerators.

    Feels like it’s entirely worth it to download dotPeek 1.0 Beta, doesn’t it? If the build is any worse than a smooth ride, please let us know and we’ll be fixing critical issues ahead of the upcoming release.

    dotTrace 5.0 Performance is Live

    Monday, March 19th, 2012

    It’s official: the powerful .NET performance profiler from JetBrains gets a long-awaited update.

    Please welcome dotTrace 5.0 Performance that you’re invited to download and try.

    Key features of dotTrace 5.0 Performance include:

    • Attaching to and detaching from an already running process. You can now involve a profiler on demand, when an application starts displaying performance issues, and detach it from the application as soon as a performance snapshot is captured. This is especially useful with production applications that you no longer need to restart to profile, and the performance impact of running them under the profiler is minimized.
    • Streamlined remote profiling. Profiling .NET applications running on remote computers becomes easier, even in restricted environments. Combined with attaching to process, improvements in remote profiling make dotTrace Performance a great tool to detect performance issues in apps run in production environments.
    • Bundled decompiler. Even if source code is not immediately available, the code of any function featured in a profiling snapshot can now be decompiled using the decompiler engine that is also used in two more JetBrains .NET tools: dotPeek and ReSharper.
    • Support for IIS Express. All major servers used to develop and run .NET web applications are now supported: ASP.NET Development Server, IIS Express, and the complete edition of IIS.

    To learn more about the new release, read What’s New in dotTrace 5.0 Performance, or watch this video:

    Feels good enough? Please download dotTrace 5.0 Performance and let us know how it works for you.

    New dotPeek Build: Base Types and Inheritors in Assembly Explorer

    Thursday, December 29th, 2011

    We have today released a new early build of dotPeek, our lovely .NET decompiler and assembly browser.

    One thing about this new build that’s worth a mention is that from now on, the Assembly Explorer contains nodes representing base types and inheritors of the current type — in addition to the actual list of members:

    We hope that would be a handy addition for people with Reflector background. Of course, you can still use ReSharper-based navigation features such as Go to Base, Go to Inheritor, and Type Hierarchy to explore inheritance chains from symbol occurrences in the source code view area.

    Other than that, the new build is mostly filled with bug fixes in decompiler core, and a couple of niceties such as support for non-standard DPI settings in the UI, and support for Math.E and Math.Pi, which for example enables the decompiler to output 2.0*Math.PI/3.0 instead of 2.0943951023931966.

    The list of all fixes in the build is available here, and as usual, you can get the new dotPeek build from the Early Access Program home page.

    dotPeek is Back with New Early Build

    Thursday, December 8th, 2011

    After several months of no-show, we’re relieved to provide a new early build of dotPeek — our free .NET decompiler and assembly browser.

    We apologize for the considerable delay updating the tool, and we expect that as ReSharper 6.1 development is mostly coming to an end, we can now focus more on pre-release polishing of dotPeek.

    Here’s the list of prominent changes in the new dotPeek early build (No. 7603)

    • Opening .dll files by double-clicking in Windows Explorer. dotPeek can now automatically register as an application that handles files with the .dll extension. (DOTP-151) To switch Windows Explorer integration on, select Tools > Options, and click Integrate with Windows Explorer under Environment | General.
    • Resource decompilation. dotPeek can now open assembly resources, including images and XML-based resources (for example, .resx or .dtd files), internally or by passing them to an external application.
    • Opening libraries in a single dotPeek instance. (DOTP-2615) If you’re used to browsing assemblies in a file manager and opening them in a decompiler from there, there’s no more annoyance caused by initializing multiple copies of dotPeek.
    • XML doc comments can be shown in decompiled code if the corresponding XML documentation file is available. (DOTP-1208) For instance, that means additional convenience when exploring .NET Framework libraries.
    • Properties window that provides basic information about assemblies and references selected in the Assembly Explorer. (DOTP-481)
    • Reference Hierarchy tool window. Based on ReSharper’s Type Hierarchy feature that is now extensible, this new tool window shows which references the current assembly has, allowing you to track down all its dependencies, and additionally showing recursive dependencies with a glyph to the right of a reference entry. If you click Referencing projects in the tool window’s toolbar, you can see which of the assemblies in your current assembly list reference the current selected assembly.
    • Drag-n-drop assemblies: You can now drag assemblies (or selections of assemblies) from Windows Explorer, and drop them into dotPeek, which adds them to dotPeek’s Assembly Explorer.
    • New command-line options including keys to switch Windows Explorer integration on/off, hide splash screen, and always open every new assembly in a new instance.
    • Other improvements including a toolbar with basic commands, configurable font in the source code view area, and a new ReSharper-like Options dialog box (work in progress). Also, dotPeek window position and state is now preserved between application launches.

    For die-hard fans, here’s a selection of issues resolved for this build.

    Please download the new build and try it out. As usual, you’re encouraged to report any issues you’re facing to dotPeek bug tracker.

    dotTrace: Profiling decompiled code

    Wednesday, August 17th, 2011

    As you might know, dotPeek is our Free Decompiler which is currently available under the EAP program. The core engine for dotPeek is also included in ReSharper 6, allowing us to navigate and analyze assemblies for which we do not have the source code.

    As could be expected, we will be including the same feature in dotTrace Performance. This potentially allows us to decompile any code we are profiling and examine if a potential issue could lie in this actual decompiled code.

    Take the following sample application (in this case Nerddinner) :

    image

    When examining the list of functions, we might encounter a call that is part of a library. When trying to display the source, dotTrace would prompt us for the PDB files.

    image

    If, for whatever reason we do not have the PDB files, we can now click on the “Decompiled source” tab and have the dotPeek engine decompile the source code for us:

    image

    This makes it even easier to dig into third-party code to determine if there are any potential bottlenecks. This functionality will be available in the next major version of dotTrace and available soon when the EAP program opens.

    New dotPeek Early Build + Pioneering dotPeek Plug-ins

    Monday, June 20th, 2011

    Quick news on dotPeek that hasn’t been updated since last month. There’s a fresh EAP build (1.0.0.2545) out today that we invite you to download and try.

    The build provides quite a bit of miscellaneous bug fixes and some noticeable improvements, including:

    • Redundant else statements now occur much less frequently as an artifact of decompiling.
    • Ctrl+Click in the text editor now works as you’d expect it to, navigating you to symbol declaration.
    • Go to Type supports navigation to namespaces.
    • You can switch between Go To actions on-the-fly: you don’t have to enter a search string after you’ve switched from, say, Go to File that you accidentally invoked to Go to Type that you really need.
    • Browser-like navigation: Alt+Left and Alt+Right that are commonly used in browsers for “Back” and “Forward”, are now used as shortcuts for Go to Previous Location and Go to Next Location.

    In other exciting news, we already have a couple of plug-ins to dotPeek from the community:

    Hats off to these courageous people, and we hope to see more community plug-ins even before we release the first version of dotPeek.

    It’s time for a little break now as we’re all busy finalizing ReSharper 6 but we expect to get back to active dotPeek development right after we’ve released the new ReSharper.