LSW .NET Decompiler ( integrated into LSW-DNRB )

The Decompiler decompiles .NET Assemblies and generates a high quality readable source-code which  can be recompiled in most cases and produces the same behavior as the binary.

The Decompiler Backends renderes the final output. Version 1.3 of the decompiler comes with 5 Backends:

we are working to add new backends ( J#, Delphi etc ).

The Decompiler is integrated into the browser's GUI.  Decompiled code can be  saved to  Disk.

The decompilation engine produces  readable formatted code. A Name inference engine produces readable Names for local variables.

Here  is  a sample output:

  public virtual string  ToString ()
    {
        string str5 = this._Domain;
        string str4 = this._Path;
        string str3 = this._Port;
        string str = this._Version;
        string[ ] str1 = new String [7];
        str1  [0] = (str.Length  ==  null) ? String.Empty : String.Concat (str, "; ");
        str1  [1] = this.Name;
        str1  [2] = "=";
        str1  [3] = this.Value;
        str1  [4] = (str4.Length  ==  null) ? String.Empty : String.Concat ("; ", str4);
        str1  [5] = (str5.Length  ==  null) ? String.Empty : String.Concat ("; ", str5);
        str1  [6] = (str3.Length  ==  null) ? String.Empty : String.Concat ("; ", str3);
        string str2 = String.Concat (str1);
        if ( ((str2 == "=")))
        {
            return String.Empty;
        }
   
        return str2;
    }

Switch  statements

This method ( [1.0.3300.0]System.Design.ControlDesigner.WndProc( ... ) contains a "complex" switch statement which decompiles to:
 
void  WndProc (
    System.Windows.Forms.Message&  m)
{
    System.Guid guid;
    RECT rECT;
    PAINTSTRUCT pAINTSTRUCT;
    System.Windows.Forms.Design.IMouseHandler iMouseHandler = null;
    if ((m.Msg  ==  132) && (this.inHitTest  ==  null))
    {
        this.inHitTest = 1;
        System.Drawing.Point point = new System.Drawing.Point (Util.LOWORD (IntPtr.op_Explicit (m.LParam)), Util.HIWORD (IntPtr.op_Explicit (m.LParam)));
        
        try
        {
            this.liveRegion = this.GetHitTest (point);            
        }
        catch (Exception )
        {
            this.liveRegion = 0;            
        }
        this.inHitTest = 0;
    }

    bool f = m.Msg  ==  123;
    if ((this.liveRegion  !=  null) && ( (this.IsMouseMessage (m.Msg)) ||  (f)))
    {
        if (m.Msg  ==  123)
        {
            ControlDesigner.inContextMenu = 1;
        }
        try
        {
            this.DefWndProc (&m);          
        }
        finally {
            if (m.Msg  ==  123)
            {
                ControlDesigner.inContextMenu = 0;
            }
        }
        return;
    }
    int k = 0;
    int i = 0;
    if (((m.Msg  >=  512) && (m.Msg  <=  522)) || ((m.Msg  >=  160) && (m.Msg  <=  169)) || (m.Msg  ==  32))
    {
        if (this.eventSvc  ==  null)
        {
            this.eventSvc = (IEventHandlerService) base.GetService (Type.GetTypeFromHandle (IEventHandlerService));
        }

        if (this.eventSvc  !=  null)
        {
            iMouseHandler = (IMouseHandler) this.eventSvc.GetHandler (Type.GetTypeFromHandle (IMouseHandler));
        }
    }
    if ((m.Msg  >=  512) && (m.Msg  <=  522))
    {
        POINT pOINT = new NMHEADER ();
        pOINT.x = Util.SignedLOWORD (IntPtr.op_Explicit (m.LParam));
        pOINT.y = Util.SignedHIWORD (IntPtr.op_Explicit (m.LParam));
        NativeMethods.MapWindowPoints (m.HWnd, IntPtr.Zero, pOINT, 1);
        k = pOINT.x;
        i = pOINT.y;
    }
    else {
        if ((m.Msg  >=  160) && (m.Msg  <=  169))
        {
            k = Util.SignedLOWORD (IntPtr.op_Explicit (m.LParam));
            i = Util.SignedHIWORD (IntPtr.op_Explicit (m.LParam));
        }
    }
    System.Windows.Forms.MouseButtons mouseButtons = 0;
    int m = m.Msg;
    switch (m)
    {       
        case 1: 
            this.DefWndProc (&m);
            (IntPtr(m.HWnd == this.Control.Handle)  ==  null)
            
            this.OnCreateHandle ();
            return;        
        case 61:         
            if (-4  ==  IntPtr.op_Explicit (m.LParam))
            {
                guid = new System.Guid ("{618736E0-3C3D-11CF-810C-00AA00389B71}");             
                try
                {
                    Accessibility.IAccessible iAccessible = this.AccessibilityObject;
                    if (iAccessible  ==  null)
                    {
                        m.Result = IntPtr.op_Explicit (0);
                    }
                    else {
                         j = Marshal.GetIUnknownForObject (iAccessible);
                        try
                        {
                            m.Result = UnsafeNativeMethods.LresultFromObject (&guid, m.WParam, j); 
                        }
                        finally {
                            Marshal.Release (j);
                        }
                    }                    
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            this.DefWndProc (&m);
            return;
        
        case 673: 
            if (iMouseHandler  !=  null)
            {
                iMouseHandler.OnMouseHover (base.Component);
                return;
            }

            this.OnMouseHover ();
            return;
        
        case 675: 
            this.OnMouseLeave ();
            this.BaseWndProc (&m);
            return;
        
        case 163: 
        case 166: 
        case 515: 
        case 518: 
            if ((m.Msg  ==  166) || (m.Msg  ==  518))
            {
                mouseButtons = 2097152;
            }
            else {
                mouseButtons = 1048576;
            }

            (mouseButtons  !=  1048576)
            
            if (iMouseHandler  !=  null)
            {
                iMouseHandler.OnMouseDoubleClick (base.Component);
                return;
            }

            this.OnMouseDoubleClick ();
            return;
        
        case 161: 
        case 164: 
        case 513: 
        case 516: 
            
            if ((m.Msg  ==  164) || (m.Msg  ==  516))
            {
                mouseButtons = 2097152;
            }
            else {
                mouseButtons = 1048576;
            }

            NativeMethods.SendMessage (this.Control.Handle, 7, 0, 0);
            if ((mouseButtons  ==  1048576) &&  (this.IsDoubleClick (k, i)))
            {
                if (iMouseHandler  !=  null)
                {
                    iMouseHandler.OnMouseDoubleClick (base.Component);
                    return;
                }
                this.OnMouseDoubleClick ();
                return;
            }
            this.toolPassThrough = 0;
            if (! (this.EnableDragRect) && (mouseButtons  ==  1048576))
            {
                if (this.toolboxSvc  ==  null)
                {
                    this.toolboxSvc = (IToolboxService) base.GetService (Type.GetTypeFromHandle (IToolboxService));
                }

                if ((this.toolboxSvc  !=  null) && (this.toolboxSvc.GetSelectedToolboxItem ((IDesignerHost) base.GetService (Type.GetTypeFromHandle (IDesignerHost)))  !=  null))
                {
                    this.toolPassThrough = 1;
                    
                }

                this.toolPassThrough = 0;
            }            
IL_04e0:if (this.toolPassThrough  !=  null)
            {
                NativeMethods.SendMessage (this.Control.Parent.Handle, m.Msg, m.WParam, IntPtr.op_Explicit (this.GetParentPointFromLparam (m.LParam)));
                return;
            }
            if (iMouseHandler  !=  null)
            {
                iMouseHandler.OnMouseDown (base.Component, mouseButtons, k, i);
            }
            else {
                if (mouseButtons  ==  1048576)
                {
                    this.OnMouseDragBegin (k, i);                    
                }
                if (mouseButtons  ==  2097152)
                {
                    System.ComponentModel.Design.ISelectionService iSelectionService = (ISelectionService) base.GetService (Type.GetTypeFromHandle (ISelectionService));
                    if (iSelectionService  !=  null)
                    {
                        object[ ] obj = new System.Object [1];
                        obj  [0] = base.Component;
                        iSelectionService.SetSelectedComponents (obj, 16);
                    }
                }
            }            
IL_0587:this.lastMoveScreenX = k;
            this.lastMoveScreenY = i;
            return;
        
        case 160: 
        case 512: 
            if ((IntPtr.op_Explicit (m.WParam)  &  1)  !=  null)
            {
                mouseButtons = 1048576;
            }
            else {
                if ((IntPtr.op_Explicit (m.WParam)  &  2)  !=  null)
                {
                    mouseButtons = 2097152;
                    this.toolPassThrough = 0;                    
                }
                this.toolPassThrough = 0;
            }
            
IL_05d5:if ((this.lastMoveScreenX  !=  k) || (this.lastMoveScreenY  !=  i))
            {
                if (this.toolPassThrough  !=  null)
                {
                    NativeMethods.SendMessage (this.Control.Parent.Handle, m.Msg, m.WParam, IntPtr.op_Explicit (this.GetParentPointFromLparam (m.LParam)));
                    return;
                }
                if (iMouseHandler  !=  null)
                {
                    iMouseHandler.OnMouseMove (base.Component, k, i);
                    
                }
                if (mouseButtons  ==  1048576)
                {
                    this.OnMouseDragMove (k, i);
                }
            }
            
IL_064a:this.lastMoveScreenX = k;
            this.lastMoveScreenY = i;
            this.BaseWndProc (&m);
            return;
        
        case 162: 
        case 165: 
        case 514: 
        case 517: 
            if ((m.Msg  ==  164) || (m.Msg  ==  516))
            {
                mouseButtons = 2097152;
            }
            else {
                mouseButtons = 1048576;
            }
            if (iMouseHandler  !=  null)
            {
                iMouseHandler.OnMouseUp (base.Component, mouseButtons);
            }
            else {
                if (this.toolPassThrough  !=  null)
                {
                    NativeMethods.SendMessage (this.Control.Parent.Handle, m.Msg, m.WParam, IntPtr.op_Explicit (this.GetParentPointFromLparam (m.LParam)));
                    this.toolPassThrough = 0;
                    return;
                }
                if (mouseButtons  ==  1048576)
                {
                    this.OnMouseDragEnd (0);
                }
            }
            this.toolPassThrough = 0;
            this.BaseWndProc (&m);
            return;
        
        case 15: 
            if (OleDragDropHandler.FreezePainting)
            {
                NativeMethods.ValidateRect (m.HWnd, IntPtr.Zero);
                return;
            }
            rECT = (RECT) null;
            n = NativeMethods.CreateRectRgn (0, 0, 0, 0);
            NativeMethods.GetUpdateRgn (m.HWnd, n, 0);
            NativeMethods.GetUpdateRect (m.HWnd, &rECT, 0);
            System.Drawing.Region region = Region.FromHrgn (n);
            try
            {
                if (this.thrownException  ==  null)
                {
                    this.DefWndProc (&m);
                }
                System.Drawing.Graphics graphics = Graphics.FromHwnd (m.HWnd);
                if (IntPtr.op_Inequality (m.HWnd, this.Control.Handle))
                {
                    POINT pOINT1 = new NMHEADER ();
                    pOINT1.x = 0;
                    pOINT1.y = 0;
                    NativeMethods.MapWindowPoints (m.HWnd, this.Control.Handle, pOINT1, 1);
                    graphics.TranslateTransform (- (pOINT1.x), - (pOINT1.y));
                    NativeMethods.MapWindowPoints (m.HWnd, this.Control.Handle, &rECT, 2);
                }
                System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle (rECT.left, rECT.top, (rECT.right  -  rECT.left), (rECT.bottom  -  rECT.top));
                System.Windows.Forms.PaintEventArgs paintEventArgs = new System.Windows.Forms.PaintEventArgs (graphics, rectangle);               
                try
                {
                    graphics.Clip = region;
                    if (this.thrownException  ==  null)
                    {
                        this.OnPaintAdornments (paintEventArgs);
                    }
                    else {
                        pAINTSTRUCT = (PAINTSTRUCT) null;
                        UnsafeNativeMethods.BeginPaint (m.HWnd, &pAINTSTRUCT);
                        this.PaintException (paintEventArgs, this.thrownException);
                        UnsafeNativeMethods.EndPaint (m.HWnd, &pAINTSTRUCT);
                    }
                }
                finally {
                    if (paintEventArgs  !=  null)
                    {
                        paintEventArgs.Dispose ();
                    }
                    graphics.Dispose ();
                }
            }
            finally {
                region.Dispose ();
                NativeMethods.DeleteObject (n);
            }
        goto case 32;
        
        case 32: 
            if (this.liveRegion  !=  null)
            {
                this.DefWndProc (&m);
                return;
            }

            if (iMouseHandler  !=  null)
            {
                iMouseHandler.OnSetCursor (base.Component);
                return;
            }
            this.OnSetCursor ();
            return;
        
        case 5: 
            if (this.thrownException  !=  null)
            {
                this.Control.Invalidate ();
            }
            this.DefWndProc (&m);
            return;
        
        case 31: 
            this.OnMouseDragEnd (1);
            this.DefWndProc (&m);
            return;
        
        case 7: 
            if ((this.host  !=  null) && (this.host.RootComponent  !=  null))
            {
                System.ComponentModel.Design.IDesigner iDesigner = this.host.GetDesigner (this.host.RootComponent);
                if (iDesigner  is  IRootDesigner)
                {
                    System.ComponentModel.Design.IRootDesigner iRootDesigner = (IRootDesigner) iDesigner;
                    System.ComponentModel.Design.ViewTechnology[ ] viewTechnology = iRootDesigner.SupportedTechnologies;
                    System.ComponentModel.Design.ViewTechnology[ ] viewTechnology2 = viewTechnology;
                    for (m = 0; m  <  viewTechnology2.Length; m++)
                    {
                        System.ComponentModel.Design.ViewTechnology viewTechnology1 = viewTechnology2  [m];
                        if (viewTechnology1  ==  1)
                        {
                            (Control) iRootDesigner.GetView (viewTechnology1).Focus ();
                            return;
                        }
                    };
                    return;
                }
            }
        goto case 123;
        
        case 123: 
        case 6: 
            
    };
    return;
} 

Native Functions :

The Decompiler decompiles .NET code referring to Native Code:

private static void  Win32Native ()
    {

        Win32Native.INVALID_HANDLE_VALUE.ctor (-1);
        Win32Native.NULL = IntPtr.Zero;
        return;
    }

    public void  Win32Native ()
    {

        base  ();
        return;
    }

    [DllImport ("kernel32.dll", CharSet = None)]
    internal static bool  CloseHandle (
        int  handle)
    ;

    [DllImport ("kernel32.dll", CharSet = Auto)]
    internal static bool  CopyFile (
        string  src
        ,string  dst
        ,bool  failIfExists)
    ;