Browse Source

Do not fall though the end of try-block. It should never happen in valid IL, but some obfuscators generate such code. Closes #164

pull/234/merge
David Srbecký 14 years ago
parent
commit
c31f9232c5
  1. 7
      ICSharpCode.Decompiler/ILAst/ILAstBuilder.cs

7
ICSharpCode.Decompiler/ILAst/ILAstBuilder.cs

@ -281,6 +281,8 @@ namespace ICSharpCode.Decompiler.ILAst
int varCount = methodDef.Body.Variables.Count; int varCount = methodDef.Body.Variables.Count;
var exceptionHandlerStarts = new HashSet<ByteCode>(methodDef.Body.ExceptionHandlers.Select(eh => instrToByteCode[eh.HandlerStart]));
// Add known states // Add known states
if(methodDef.Body.HasExceptionHandlers) { if(methodDef.Body.HasExceptionHandlers) {
foreach(ExceptionHandler ex in methodDef.Body.ExceptionHandlers) { foreach(ExceptionHandler ex in methodDef.Body.ExceptionHandlers) {
@ -347,8 +349,13 @@ namespace ICSharpCode.Decompiler.ILAst
// Find all successors // Find all successors
List<ByteCode> branchTargets = new List<ByteCode>(); List<ByteCode> branchTargets = new List<ByteCode>();
if (!byteCode.Code.IsUnconditionalControlFlow()) { if (!byteCode.Code.IsUnconditionalControlFlow()) {
if (exceptionHandlerStarts.Contains(byteCode.Next)) {
// Do not fall though down to exception handler
// It is invalid IL as per ECMA-335 §12.4.2.8.1, but some obfuscators produce it
} else {
branchTargets.Add(byteCode.Next); branchTargets.Add(byteCode.Next);
} }
}
if (byteCode.Operand is Instruction[]) { if (byteCode.Operand is Instruction[]) {
foreach(Instruction inst in (Instruction[])byteCode.Operand) { foreach(Instruction inst in (Instruction[])byteCode.Operand) {
ByteCode target = instrToByteCode[inst]; ByteCode target = instrToByteCode[inst];

Loading…
Cancel
Save