Browse Source

Add EnumUnderlyingTypeResolveException and clean up exceptions in ReflectionDisassembler: use BadImageFormatException for any unexpected values.

pull/1030/head
Siegfried Pammer 7 years ago
parent
commit
01e374fd4f
  1. 12
      ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs
  2. 1
      ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj
  3. 44
      ICSharpCode.Decompiler/Metadata/EnumUnderlyingTypeResolveException.cs

12
ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs

@ -389,7 +389,7 @@ namespace ICSharpCode.Decompiler.Disassembler @@ -389,7 +389,7 @@ namespace ICSharpCode.Decompiler.Disassembler
try {
TryDecodeSecurityDeclaration(outputWithRollback, blob, module);
outputWithRollback.Commit();
} catch (Exception ex) when (ex is BadImageFormatException || ex is NotSupportedException || ex is ArgumentException) {
} catch (Exception ex) when (ex is BadImageFormatException || ex is EnumUnderlyingTypeResolveException) {
blob.Reset();
output.Write(" = ");
WriteBlob(blob);
@ -473,7 +473,7 @@ namespace ICSharpCode.Decompiler.Disassembler @@ -473,7 +473,7 @@ namespace ICSharpCode.Decompiler.Disassembler
case 0x55: // enum
return (0, TypeKind.Enum, false, blob.ReadSerializedString());
default:
throw new NotSupportedException($"Custom attribute type 0x{b:x} is not supported.");
throw new BadImageFormatException($"Unexpected custom attribute type 0x{b:x}.");
}
}
@ -565,7 +565,7 @@ namespace ICSharpCode.Decompiler.Disassembler @@ -565,7 +565,7 @@ namespace ICSharpCode.Decompiler.Disassembler
}
}
if (typeDefHandle.IsNil || !typeDefHandle.IsEnum(containingModule.Metadata, out var typeCode))
throw new NotSupportedException("Enum type cannot be resolved, cannot decode security declaration blob!");
throw new EnumUnderlyingTypeResolveException();
typeDefinition = (containingModule, typeDefHandle);
return (PrimitiveSerializationTypeCode)typeCode;
}
@ -1249,7 +1249,7 @@ namespace ICSharpCode.Decompiler.Disassembler @@ -1249,7 +1249,7 @@ namespace ICSharpCode.Decompiler.Disassembler
(TypeSpecificationHandle)eventDefinition.Type, 0);
break;
default:
throw new ArgumentOutOfRangeException("Expected a TypeDef, TypeRef or TypeSpec handle!");
throw new BadImageFormatException("Expected a TypeDef, TypeRef or TypeSpec handle!");
}
signature(ILNameSyntax.TypeName);
output.Write(' ');
@ -1922,7 +1922,7 @@ namespace ICSharpCode.Decompiler.Disassembler @@ -1922,7 +1922,7 @@ namespace ICSharpCode.Decompiler.Disassembler
output.Write("class ");
break;
default:
throw new NotSupportedException($"rawTypeKind: {rawTypeKind} (0x{rawTypeKind:x})");
throw new BadImageFormatException($"Unexpected rawTypeKind: {rawTypeKind} (0x{rawTypeKind:x})");
}
((EntityHandle)handle).WriteTo(module, output, GenericContext.Empty);
};
@ -1941,7 +1941,7 @@ namespace ICSharpCode.Decompiler.Disassembler @@ -1941,7 +1941,7 @@ namespace ICSharpCode.Decompiler.Disassembler
output.Write("class ");
break;
default:
throw new NotSupportedException($"rawTypeKind: {rawTypeKind} (0x{rawTypeKind:x})");
throw new BadImageFormatException($"Unexpected rawTypeKind: {rawTypeKind} (0x{rawTypeKind:x})");
}
((EntityHandle)handle).WriteTo(module, output, GenericContext.Empty);
};

1
ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj

@ -267,6 +267,7 @@ @@ -267,6 +267,7 @@
<Compile Include="CSharp\Transforms\AddXmlDocumentationTransform.cs" />
<Compile Include="DecompileRun.cs" />
<Compile Include="Metadata\AssemblyReferences.cs" />
<Compile Include="Metadata\EnumUnderlyingTypeResolveException.cs" />
<Compile Include="Metadata\MetadataTokenHelpers.cs" />
<Compile Include="Disassembler\OpCodeInfo.cs" />
<Compile Include="Documentation\GetPotentiallyNestedClassTypeReference.cs" />

44
ICSharpCode.Decompiler/Metadata/EnumUnderlyingTypeResolveException.cs

@ -0,0 +1,44 @@ @@ -0,0 +1,44 @@
// Copyright (c) 2018 Siegfried Pammer
//
// 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;
using System.Runtime.Serialization;
using System.Text;
namespace ICSharpCode.Decompiler.Metadata
{
public class EnumUnderlyingTypeResolveException : Exception
{
public EnumUnderlyingTypeResolveException()
{
}
public EnumUnderlyingTypeResolveException(string message) : base(message)
{
}
public EnumUnderlyingTypeResolveException(string message, Exception innerException) : base(message, innerException)
{
}
protected EnumUnderlyingTypeResolveException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}
}
Loading…
Cancel
Save