Skip to content

Commit

Permalink
Merge tag 'v6.5.0' into feature/new-ilspy
Browse files Browse the repository at this point in the history
  • Loading branch information
ElektroKill committed Feb 14, 2024
2 parents a5d4e65 + 2eef396 commit bc7afd0
Show file tree
Hide file tree
Showing 193 changed files with 3,278 additions and 1,099 deletions.
15 changes: 8 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ jobs:
build-dir: net48
- platform: net-x86
package-name: net-win32
build-dir: net6.0-windows\win-x86\publish
build-dir: net8.0-windows\win-x86\publish
- platform: net-x64
package-name: net-win64
build-dir: net6.0-windows\win-x64\publish
build-dir: net8.0-windows\win-x64\publish

steps:
- uses: actions/checkout@v3.5.3
- uses: actions/checkout@v4.1.1
with:
submodules: true

- uses: actions/setup-dotnet@v3.2.0
- uses: actions/setup-dotnet@v4.0.0
with:
dotnet-version: 6.0.x
dotnet-version: 8.0.x
dotnet-quality: ga

- uses: microsoft/[email protected].1
- uses: microsoft/[email protected].2

- name: Build dnSpy (${{matrix.platform}})
run: .\build.ps1 ${{matrix.platform}}
Expand All @@ -56,9 +56,10 @@ jobs:
- name: Copy release files for upload
run: Copy-Item -Path dnSpy\dnSpy\bin\Release\${{matrix.build-dir}}\* -Destination C:\builtfiles\dnSpy-${{matrix.platform}} -Recurse

- uses: actions/upload-artifact@v3.1.2
- uses: actions/upload-artifact@v4.3.0
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
with:
name: dnSpy-${{matrix.package-name}}
path: C:\builtfiles\dnSpy-${{matrix.platform}}
if-no-files-found: error
compression-level: 9
Binary file modified Build/compiled/ConvertToNetstandardReferences.dll
Binary file not shown.
Binary file modified Build/compiled/MakeEverythingPublic.dll
Binary file not shown.
Binary file modified Build/compiled/dnlib.dll
Binary file not shown.
31 changes: 21 additions & 10 deletions DnSpyCommon.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
<!--
- build.ps1
- .github/workflows/build.yml
- DnSpyRoslyn.props
NOTE: Update the ABOVE files when TargetFrameworks is updated -->
<TargetFrameworks>net48;net6.0-windows</TargetFrameworks>
<TargetFrameworks>net48;net8.0-windows</TargetFrameworks>
<IsDotNetFramework>false</IsDotNetFramework>
<IsDotNet>false</IsDotNet>
<IsSelfContainedDotNet>false</IsSelfContainedDotNet>
Expand All @@ -23,31 +24,41 @@
<DnSpyRuntimeIdentifiers>win-x86;win-x64</DnSpyRuntimeIdentifiers>
<SatelliteResourceLanguages>cs;de;es;es-ES;fa;fr;hu;it;pt-BR;pt-PT;ru;tr;uk;zh-CN;vi</SatelliteResourceLanguages>

<!-- Allow compiling for windows on non-windows platforms -->
<EnableWindowsTargeting>true</EnableWindowsTargeting>

<!-- Enable Visual Studio Build Acceleration -->
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>

<!-- Update app.config whenever this value changes -->
<DnSpyAssemblyVersion>6.4.0.0</DnSpyAssemblyVersion>
<DnSpyAssemblyVersion>6.5.0.0</DnSpyAssemblyVersion>
<!-- This is shown in the title bar -->
<DnSpyAssemblyInformationalVersion>v6.4.0</DnSpyAssemblyInformationalVersion>
<DnSpyAssemblyInformationalVersion>v6.5.0</DnSpyAssemblyInformationalVersion>
<!-- Prevent .NET SDK from appening the git commit hash to the information version -->
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<DnSpyAssemblyCopyright>Copyright (C) 2014-2020 [email protected]</DnSpyAssemblyCopyright>

<!-- AD0001: buggy Roslyn analyzer(s) crash, disable that warning -->
<!-- WFAC010: Prevent warning about app.manifest properties -->
<NoWarn>NU1701;AD0001;WFAC010</NoWarn>
<NoWarn>NU1701;AD0001;WFAC010;NETSDK1189</NoWarn>
<NoWarn Condition=" '$(IsDotNetFramework)' == 'true' ">$(NoWarn);CS8767</NoWarn>

<!-- Update app.config whenever some of these versions change (eg. dnlib version) -->
<DiaSymReaderVersion>1.7.0</DiaSymReaderVersion>
<DnlibVersion>3.6.0</DnlibVersion>
<IcedVersion>1.19.0</IcedVersion>
<DnlibVersion>4.4.0</DnlibVersion>
<IcedVersion>1.21.0</IcedVersion>
<MSBuildNuGetVersion>17.1.0</MSBuildNuGetVersion>
<MSDiagRuntimeVersion>1.1.142101</MSDiagRuntimeVersion>
<MSVSCompositionVersion>17.6.17</MSVSCompositionVersion>
<MSVSCompositionVersion>17.7.26</MSVSCompositionVersion>
<MSVSIntellisenseVersion>15.5.27130</MSVSIntellisenseVersion>
<MSVSTextVersion>15.5.27130</MSVSTextVersion>
<NewtonsoftJsonVersion>13.0.3</NewtonsoftJsonVersion>
<OokiiDialogsWpfVersion>5.0.1</OokiiDialogsWpfVersion>
<RoslynVersion>4.6.0</RoslynVersion>
<SCCompositionVersion>7.0.0</SCCompositionVersion>
<NuGetVersion>6.6.0</NuGetVersion>
<RoslynVersion>4.8.0</RoslynVersion>
<SCCompositionVersion>8.0.0</SCCompositionVersion>
<NuGetVersion>6.8.0</NuGetVersion>
<DbgShimVersion>8.0.505301</DbgShimVersion>
</PropertyGroup>

<Import Project="$(MSBuildThisFileDirectory)Build\ConvertToNetstandardReferences\ConvertToNetstandardReferences.tasks" Condition=" '$(IsDotNet)' == 'true' " />
Expand Down
2 changes: 1 addition & 1 deletion DnSpyRoslyn.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Import Project="DnSpyCommon.props" />

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0-windows</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net8.0-windows</TargetFrameworks>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,8 @@ void TypeToString(IDecompilerOutput output, ConvertTypeOptions options, ITypeDef
AstType astType = ICSharpCode.Decompiler.CSharp.CSharpDecompiler.ConvertType(type, new StringBuilder(), typeAttributes, options);

if (WriteRefIfByRef(output, type.TryGetByRefSig(), typeAttributes as ParamDef)) {
if (astType is ComposedType && ((ComposedType)astType).PointerRank > 0)
((ComposedType)astType).PointerRank--;
if (astType is ComposedType composedType && composedType.HasRefSpecifier)
composedType.HasRefSpecifier = false;
}

var ctx = new DecompilerContext(langSettings.Settings.SettingsVersion, type.Module, MetadataTextColorProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@
<data name="DecompilerSettings_HexadecimalNumbers" xml:space="preserve">
<value>以十六进制显示数字</value>
</data>
<data name="DecompilerSettings_EmitCalliAsInvocationExpression" xml:space="preserve">
<value>反编译 calli 指令为调用表达式</value>
</data>
<data name="DecompilerSettings_InsertParenthesesForReadability" xml:space="preserve">
<value>插入括号以增强可读性</value>
</data>
<data name="DecompilerSettings_IntroduceIncrementAndDecrement" xml:space="preserve">
<value>使用增量和减量运算符</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ void TypeToString(IDecompilerOutput output, ConvertTypeOptions options, ITypeDef
if (type.TryGetByRefSig() is not null) {
output.Write("ByRef", BoxedTextColor.Keyword);
output.Write(" ", BoxedTextColor.Text);
if (astType is ICSharpCode.NRefactory.CSharp.ComposedType && ((ICSharpCode.NRefactory.CSharp.ComposedType)astType).PointerRank > 0)
((ICSharpCode.NRefactory.CSharp.ComposedType)astType).PointerRank--;
if (astType is ComposedType composedType && composedType.HasRefSpecifier)
composedType.HasRefSpecifier = false;
}
var vbAstType = astType.AcceptVisitor(converter, null);
Expand Down
26 changes: 13 additions & 13 deletions Extensions/dnSpy.Analyzer/TreeNodes/EventOverriddenNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,23 @@ protected override void Write(ITextColorWriter output, IDecompiler decompiler) =
output.Write(BoxedTextColor.Text, dnSpy_Analyzer_Resources.OverridesTreeNode);

protected override IEnumerable<AnalyzerTreeNodeData> FetchChildren(CancellationToken ct) {
AddTypeEquivalentTypes(Context.DocumentService, analyzedTypes[0], analyzedTypes);
foreach (var declType in analyzedTypes) {
var analyzedAccessor = GetVirtualAccessor(analyzedEvent.AddMethod) ?? GetVirtualAccessor(analyzedEvent.RemoveMethod) ?? GetVirtualAccessor(analyzedEvent.InvokeMethod);
if (analyzedAccessor?.Overrides is IList<MethodOverride> overrides && overrides.Count > 0) {
bool matched = false;
foreach (var o in overrides) {
if (o.MethodDeclaration.ResolveMethodDef() is MethodDef method && (method.IsVirtual || method.IsAbstract)) {
if (method.DeclaringType.Events.FirstOrDefault(a => (object?)a.AddMethod == method || (object?)a.RemoveMethod == method || (object?)a.InvokeMethod == method) is EventDef eventDef) {
matched = true;
yield return new EventNode(eventDef) { Context = Context };
}
var analyzedAccessor = GetVirtualAccessor(analyzedEvent.AddMethod) ?? GetVirtualAccessor(analyzedEvent.RemoveMethod) ?? GetVirtualAccessor(analyzedEvent.InvokeMethod);
if (analyzedAccessor?.Overrides is IList<MethodOverride> overrides && overrides.Count > 0) {
bool matched = false;
foreach (var o in overrides) {
if (o.MethodDeclaration.ResolveMethodDef() is MethodDef method && (method.IsVirtual || method.IsAbstract)) {
if (method.DeclaringType.Events.FirstOrDefault(a => (object?)a.AddMethod == method || (object?)a.RemoveMethod == method || (object?)a.InvokeMethod == method) is EventDef eventDef) {
matched = true;
yield return new EventNode(eventDef) { Context = Context };
}
}
if (matched)
yield break;
}
if (matched)
yield break;
}

AddTypeEquivalentTypes(Context.DocumentService, analyzedTypes[0], analyzedTypes);
foreach (var declType in analyzedTypes) {
foreach (var eventDef in TypesHierarchyHelpers.FindBaseEvents(analyzedEvent, declType)) {
var anyAccessor = GetVirtualAccessor(eventDef.AddMethod) ?? GetVirtualAccessor(eventDef.RemoveMethod) ?? GetVirtualAccessor(eventDef.InvokeMethod);
if (anyAccessor is null || !(anyAccessor.IsVirtual || anyAccessor.IsAbstract))
Expand Down
26 changes: 16 additions & 10 deletions Extensions/dnSpy.Analyzer/TreeNodes/Helpers.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// 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
Expand All @@ -26,8 +26,8 @@ static class Helpers {
public static bool IsReferencedBy(TypeDef? type, ITypeDefOrRef? typeRef) => new SigComparer().Equals(type, typeRef.GetScopeType());

public static IMemberRef GetOriginalCodeLocation(IMemberRef member) {
if (member is MethodDef)
return GetOriginalCodeLocation((MethodDef)member);
if (member is MethodDef methodDef)
return GetOriginalCodeLocation(methodDef);
return member;
}

Expand All @@ -45,7 +45,7 @@ static MethodDef GetOriginalCodeLocation(MethodDef method) {
/// Given a compiler-generated type, returns the method where that type is used.
/// Used to detect the 'parent method' for a lambda/iterator/async state machine.
/// </summary>
static MethodDef? GetOriginalCodeLocation(TypeDef type) {
static MethodDef? GetOriginalCodeLocation(TypeDef? type) {
if (type is not null && type.DeclaringType is not null && IsCompilerGenerated(type)) {
if (type.IsValueType) {
// Value types might not have any constructor; but they must be stored in a local var
Expand Down Expand Up @@ -86,7 +86,8 @@ static MethodDef GetOriginalCodeLocation(MethodDef method) {
}

internal static bool CheckEquals(IMemberRef? mr1, IMemberRef? mr2) =>
new SigComparer(SigComparerOptions.CompareDeclaringTypes | SigComparerOptions.PrivateScopeIsComparable).Equals(mr1, mr2);
new SigComparer(SigComparerOptions.CompareDeclaringTypes | SigComparerOptions.PrivateScopeIsComparable |
SigComparerOptions.ReferenceCompareForMemberDefsInSameModule).Equals(mr1, mr2);

static MethodDef? FindVariableOfTypeUsageInType(TypeDef type, TypeDef variableType) {
foreach (MethodDef method in type.Methods) {
Expand All @@ -106,13 +107,18 @@ internal static bool CheckEquals(IMemberRef? mr1, IMemberRef? mr2) =>
return null;
}

static TypeDef? ResolveWithinSameModule(ITypeDefOrRef type) {
if (type is not null && type.Scope == type.Module)
static TypeDef? ResolveWithinSameModule(ITypeDefOrRef? type) {
if (type is null)
return null;
if (type is TypeDef typeDef)
return typeDef;
var scope = type.Scope;
if (scope is null || scope == type.Module)
return type.ResolveTypeDef();
return null;
}

static bool IsCompilerGenerated(this IHasCustomAttribute hca) =>
static bool IsCompilerGenerated(this IHasCustomAttribute? hca) =>
hca is not null && hca.CustomAttributes.IsDefined("System.Runtime.CompilerServices.CompilerGeneratedAttribute");
}
}
23 changes: 12 additions & 11 deletions Extensions/dnSpy.Analyzer/TreeNodes/MethodOverriddenNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,21 @@ protected override void Write(ITextColorWriter output, IDecompiler decompiler) =
output.Write(BoxedTextColor.Text, dnSpy_Analyzer_Resources.OverridesTreeNode);

protected override IEnumerable<AnalyzerTreeNodeData> FetchChildren(CancellationToken ct) {
AddTypeEquivalentTypes(Context.DocumentService, analyzedTypes[0], analyzedTypes);
var overrides = analyzedMethod.Overrides;
foreach (var declType in analyzedTypes) {
if (overrides.Count > 0) {
bool matched = false;
foreach (var o in overrides) {
if (o.MethodDeclaration.ResolveMethodDef() is MethodDef method && (method.IsVirtual || method.IsAbstract)) {
matched = true;
yield return new MethodNode(method) { Context = Context };
}
if (overrides.Count > 0) {
bool matched = false;
foreach (var o in overrides) {
if (o.MethodDeclaration.ResolveMethodDef() is MethodDef method && (method.IsVirtual || method.IsAbstract)) {
matched = true;
yield return new MethodNode(method) { Context = Context };
}
if (matched)
yield break;
}
if (matched)
yield break;
}

AddTypeEquivalentTypes(Context.DocumentService, analyzedTypes[0], analyzedTypes);
foreach (var declType in analyzedTypes) {
foreach (var method in TypesHierarchyHelpers.FindBaseMethods(analyzedMethod, declType)) {
if (!(method.IsVirtual || method.IsAbstract))
continue;
Expand Down
13 changes: 10 additions & 3 deletions Extensions/dnSpy.Analyzer/TreeNodes/MethodOverridesNode.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// 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
Expand Down Expand Up @@ -50,6 +50,13 @@ IEnumerable<AnalyzerTreeNodeData> FindReferencesInType(TypeDef type) {
yield return new MethodNode(method, hidesParent) { Context = Context };
yield break;
}

foreach (var o in method.Overrides) {
if (o.MethodDeclaration.ResolveMethodDef() is MethodDef methodDecl && CheckEquals(methodDecl, analyzedMethod)) {
yield return new MethodNode(method) { Context = Context };
yield break;
}
}
}
}

Expand Down
28 changes: 14 additions & 14 deletions Extensions/dnSpy.Analyzer/TreeNodes/PropertyOverriddenNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,28 @@ protected override void Write(ITextColorWriter output, IDecompiler decompiler) =
output.Write(BoxedTextColor.Text, dnSpy_Analyzer_Resources.OverridesTreeNode);

protected override IEnumerable<AnalyzerTreeNodeData> FetchChildren(CancellationToken ct) {
AddTypeEquivalentTypes(Context.DocumentService, analyzedTypes[0], analyzedTypes);
foreach (var declType in analyzedTypes) {
var analyzedAccessor = GetVirtualAccessor(analyzedProperty.GetMethod) ?? GetVirtualAccessor(analyzedProperty.SetMethod);
if (analyzedAccessor?.Overrides is IList<MethodOverride> overrides && overrides.Count > 0) {
bool matched = false;
foreach (var o in overrides) {
if (o.MethodDeclaration.ResolveMethodDef() is MethodDef method && (method.IsVirtual || method.IsAbstract)) {
if (method.DeclaringType.Properties.FirstOrDefault(a => (object?)a.GetMethod == method || (object?)a.SetMethod == method) is PropertyDef property) {
matched = true;
yield return new PropertyNode(property) { Context = Context };
}
var analyzedAccessor = GetVirtualAccessor(analyzedProperty.GetMethod) ?? GetVirtualAccessor(analyzedProperty.SetMethod);
if (analyzedAccessor?.Overrides is IList<MethodOverride> overrides && overrides.Count > 0) {
bool matched = false;
foreach (var o in overrides) {
if (o.MethodDeclaration.ResolveMethodDef() is MethodDef method && (method.IsVirtual || method.IsAbstract)) {
if (method.DeclaringType.Properties.FirstOrDefault(a => (object?)a.GetMethod == method || (object?)a.SetMethod == method) is PropertyDef property) {
matched = true;
yield return new PropertyNode(property) { Context = Context };
}
}
if (matched)
yield break;
}
if (matched)
yield break;
}

AddTypeEquivalentTypes(Context.DocumentService, analyzedTypes[0], analyzedTypes);
foreach (var declType in analyzedTypes) {
foreach (var property in TypesHierarchyHelpers.FindBaseProperties(analyzedProperty, declType)) {
var anyAccessor = GetVirtualAccessor(property.GetMethod) ?? GetVirtualAccessor(property.SetMethod);
if (anyAccessor is null || !(anyAccessor.IsVirtual || anyAccessor.IsAbstract))
continue;
yield return new PropertyNode(property) { Context = Context };
yield return new PropertyNode(property) { Context = Context };
yield break;
}
}
Expand Down
5 changes: 5 additions & 0 deletions Extensions/dnSpy.AsmEditor/Compiler/MDEditorPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ void PatchTypeRefsToEditedType(TypeDef nonNestedEditedType) {
bool CheckResolutionScopeIsSameModule(MDToken resolutionScope, ModuleDef module) {
switch (resolutionScope.Table) {
case Table.Module:
// ECMA II.22.38 states that in this case we should check ExportedTypes of the current module.
// The CLR however checks both TypeDefs and ExportedTypes.
if (resolutionScope.IsNull)
return true;

return resolutionScope.Rid == 1;

case Table.ModuleRef:
Expand Down
2 changes: 1 addition & 1 deletion Extensions/dnSpy.AsmEditor/Hex/Nodes/MetadataTableNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public override void OnBufferChanged(NormalizedHexChangeCollection changes) {
}

public MetadataTableRecordNode? FindTokenNode(uint token) {
uint rid = token & 0x00FFFFFF;
uint rid = MDToken.ToRID(token);
if (rid - 1 >= MetadataTableVM.Rows)
return null;
TreeNode.EnsureChildrenLoaded();
Expand Down
2 changes: 1 addition & 1 deletion Extensions/dnSpy.AsmEditor/Hex/Nodes/PENode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public bool Decompile(IDecompileNodeContext context) {
}

public MetadataTableRecordNode? FindTokenNode(uint token) {
if ((token & 0x00FFFFFF) == 0)
if (MDToken.ToRID(token) == 0)
return null;
TreeNode.EnsureChildrenLoaded();
var stgStreamNode = (StorageStreamNode?)TreeNode.DataChildren.FirstOrDefault(a => a is StorageStreamNode && ((StorageStreamNode)a).HeapKind == DotNetHeapKind.Tables);
Expand Down
Loading

0 comments on commit bc7afd0

Please sign in to comment.