|
|
|
@ -1,5 +1,20 @@
@@ -1,5 +1,20 @@
|
|
|
|
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
|
|
|
|
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
|
|
|
|
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
|
|
|
|
|
//
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
|
|
|
// software and associated documentation files (the "Software"), to deal in the Software
|
|
|
|
|
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
|
|
|
|
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
|
|
|
|
// to whom the Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
//
|
|
|
|
|
// The above copyright notice and this permission notice shall be included in all copies or
|
|
|
|
|
// substantial portions of the Software.
|
|
|
|
|
//
|
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
|
|
|
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
|
|
|
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
|
|
|
|
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
|
// DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
|
|
using System; |
|
|
|
|
using System.Collections.Generic; |
|
|
|
@ -73,6 +88,8 @@ namespace ICSharpCode.ILSpy.Disassembler
@@ -73,6 +88,8 @@ namespace ICSharpCode.ILSpy.Disassembler
|
|
|
|
|
|
|
|
|
|
EnumNameCollection<MethodImplAttributes> methodImpl = new EnumNameCollection<MethodImplAttributes>() { |
|
|
|
|
{ MethodImplAttributes.Synchronized, "synchronized" }, |
|
|
|
|
{ MethodImplAttributes.NoInlining, "noinlining" }, |
|
|
|
|
{ MethodImplAttributes.NoOptimization, "nooptimization" }, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
public void DisassembleMethod(MethodDefinition method) |
|
|
|
@ -131,7 +148,7 @@ namespace ICSharpCode.ILSpy.Disassembler
@@ -131,7 +148,7 @@ namespace ICSharpCode.ILSpy.Disassembler
|
|
|
|
|
if (method.HasBody) |
|
|
|
|
methodBodyDisassembler.Disassemble(method.Body); |
|
|
|
|
|
|
|
|
|
CloseBlock(); |
|
|
|
|
CloseBlock("End of method " + method.DeclaringType.Name + "." + method.Name); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void WriteParameters(Collection<ParameterDefinition> parameters) |
|
|
|
@ -248,7 +265,7 @@ namespace ICSharpCode.ILSpy.Disassembler
@@ -248,7 +265,7 @@ namespace ICSharpCode.ILSpy.Disassembler
|
|
|
|
|
} |
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Disassembly Type
|
|
|
|
|
#region Disassemble Type
|
|
|
|
|
EnumNameCollection<TypeAttributes> typeVisibility = new EnumNameCollection<TypeAttributes>() { |
|
|
|
|
{ TypeAttributes.Public, "public" }, |
|
|
|
|
{ TypeAttributes.NotPublic, "private" }, |
|
|
|
@ -299,7 +316,7 @@ namespace ICSharpCode.ILSpy.Disassembler
@@ -299,7 +316,7 @@ namespace ICSharpCode.ILSpy.Disassembler
|
|
|
|
|
output.WriteLine(); |
|
|
|
|
output.Indent(); |
|
|
|
|
output.Write("extends "); |
|
|
|
|
type.BaseType.WriteTo(output); |
|
|
|
|
type.BaseType.WriteTo(output, true); |
|
|
|
|
output.Unindent(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -317,6 +334,7 @@ namespace ICSharpCode.ILSpy.Disassembler
@@ -317,6 +334,7 @@ namespace ICSharpCode.ILSpy.Disassembler
|
|
|
|
|
foreach (var nestedType in type.NestedTypes) { |
|
|
|
|
cancellationToken.ThrowIfCancellationRequested(); |
|
|
|
|
DisassembleType(nestedType); |
|
|
|
|
output.WriteLine(); |
|
|
|
|
} |
|
|
|
|
output.WriteLine(); |
|
|
|
|
} |
|
|
|
@ -358,7 +376,7 @@ namespace ICSharpCode.ILSpy.Disassembler
@@ -358,7 +376,7 @@ namespace ICSharpCode.ILSpy.Disassembler
|
|
|
|
|
} |
|
|
|
|
output.WriteLine(); |
|
|
|
|
} |
|
|
|
|
CloseBlock(); |
|
|
|
|
CloseBlock("// End of class " + type.FullName); |
|
|
|
|
isInType = oldIsInType; |
|
|
|
|
} |
|
|
|
|
#endregion
|
|
|
|
@ -405,10 +423,12 @@ namespace ICSharpCode.ILSpy.Disassembler
@@ -405,10 +423,12 @@ namespace ICSharpCode.ILSpy.Disassembler
|
|
|
|
|
output.Indent(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void CloseBlock() |
|
|
|
|
void CloseBlock(string comment = null) |
|
|
|
|
{ |
|
|
|
|
output.Unindent(); |
|
|
|
|
output.Write("}"); |
|
|
|
|
if (comment != null) |
|
|
|
|
output.Write("// " + comment); |
|
|
|
|
output.MarkFoldEnd(); |
|
|
|
|
output.WriteLine(); |
|
|
|
|
} |
|
|
|
@ -425,7 +445,7 @@ namespace ICSharpCode.ILSpy.Disassembler
@@ -425,7 +445,7 @@ namespace ICSharpCode.ILSpy.Disassembler
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if ((val & ~tested) != 0) |
|
|
|
|
output.Write("flag({0}) ", val & ~tested); |
|
|
|
|
output.Write("flag({0:x4}) ", val & ~tested); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void WriteEnum<T>(T enumValue, EnumNameCollection<T> enumNames) where T : struct |
|
|
|
@ -439,7 +459,7 @@ namespace ICSharpCode.ILSpy.Disassembler
@@ -439,7 +459,7 @@ namespace ICSharpCode.ILSpy.Disassembler
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (val != 0) { |
|
|
|
|
output.Write("flag({0})", val); |
|
|
|
|
output.Write("flag({0:x4})", val); |
|
|
|
|
output.Write(' '); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -465,5 +485,47 @@ namespace ICSharpCode.ILSpy.Disassembler
@@ -465,5 +485,47 @@ namespace ICSharpCode.ILSpy.Disassembler
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
public void DisassembleNamespace(string nameSpace, IEnumerable<TypeDefinition> types) |
|
|
|
|
{ |
|
|
|
|
if (!string.IsNullOrEmpty(nameSpace)) { |
|
|
|
|
output.Write(".namespace " + DisassemblerHelpers.Escape(nameSpace)); |
|
|
|
|
OpenBlock(false); |
|
|
|
|
} |
|
|
|
|
bool oldIsInType = isInType; |
|
|
|
|
isInType = true; |
|
|
|
|
foreach (TypeDefinition td in types) { |
|
|
|
|
cancellationToken.ThrowIfCancellationRequested(); |
|
|
|
|
DisassembleType(td); |
|
|
|
|
output.WriteLine(); |
|
|
|
|
} |
|
|
|
|
if (!string.IsNullOrEmpty(nameSpace)) { |
|
|
|
|
CloseBlock(); |
|
|
|
|
isInType = oldIsInType; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void WriteAssemblyHeader(AssemblyDefinition asm) |
|
|
|
|
{ |
|
|
|
|
output.Write(".assembly " + DisassemblerHelpers.Escape(asm.Name.Name)); |
|
|
|
|
OpenBlock(false); |
|
|
|
|
Version v = asm.Name.Version; |
|
|
|
|
if (v != null) { |
|
|
|
|
output.WriteLine(".ver {0}:{1}:{2}:{3}", v.Major, v.Minor, v.Build, v.Revision); |
|
|
|
|
} |
|
|
|
|
if (asm.Name.HashAlgorithm != AssemblyHashAlgorithm.None) { |
|
|
|
|
output.Write(".hash algorithm 0x{0:x8}", (int)asm.Name.HashAlgorithm); |
|
|
|
|
if (asm.Name.HashAlgorithm == AssemblyHashAlgorithm.SHA1) |
|
|
|
|
output.Write(" // SHA1"); |
|
|
|
|
output.WriteLine(); |
|
|
|
|
} |
|
|
|
|
if (asm.Name.PublicKey != null && asm.Name.PublicKey.Length > 0) { |
|
|
|
|
output.Write(".publickey = "); |
|
|
|
|
WriteBlob(asm.Name.PublicKey); |
|
|
|
|
output.WriteLine(); |
|
|
|
|
} |
|
|
|
|
WriteAttributes(asm.CustomAttributes); |
|
|
|
|
CloseBlock(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|