Support invalid try handlers where start == end

This commit is contained in:
de4dot 2012-04-11 02:00:44 +02:00
parent edbd2c78a1
commit 5c61f7618f
2 changed files with 17 additions and 6 deletions

View File

@ -50,7 +50,7 @@ namespace de4dot.blocks {
public ExceptionInfo(int tryStart, int tryEnd, int filterStart,
int handlerStart, int handlerEnd, TypeReference catchType,
ExceptionHandlerType handlerType) {
if (tryStart > tryEnd || filterStart > handlerStart || handlerStart > handlerEnd ||
if (tryStart > tryEnd || filterStart > handlerStart ||
tryStart < 0 || tryEnd < 0 || filterStart < 0 || handlerStart < 0 || handlerEnd < 0)
throw new ApplicationException("Invalid start/end/filter/handler indexes");
this.tryStart = tryStart;
@ -196,11 +196,11 @@ namespace de4dot.blocks {
}
foreach (var ex in exceptions) {
var tryStart = blockInfos[ex.tryStart].start;
var tryEnd = blockInfos[ex.tryEnd].end;
var filterStart = ex.filterStart == -1 ? -1 : blockInfos[ex.filterStart].start;
var handlerStart = blockInfos[ex.handlerStart].start;
var handlerEnd = blockInfos[ex.handlerEnd].end;
var tryStart = getBlockInfo(blockInfos, ex.tryStart).start;
var tryEnd = getBlockInfo(blockInfos, ex.tryEnd).end;
var filterStart = ex.filterStart == -1 ? -1 : getBlockInfo(blockInfos, ex.filterStart).start;
var handlerStart = getBlockInfo(blockInfos, ex.handlerStart).start;
var handlerEnd = getBlockInfo(blockInfos, ex.handlerEnd).end;
var eh = new ExceptionHandler(ex.handlerType);
eh.CatchType = ex.catchType;
@ -214,6 +214,14 @@ namespace de4dot.blocks {
}
}
static BlockInfo getBlockInfo(List<BlockInfo> blockInfos, int index) {
if (index >= blockInfos.Count)
index = blockInfos.Count - 1;
if (index < 0)
index = 0;
return blockInfos[index];
}
static Instruction getInstruction(IList<Instruction> allInstructions, int i) {
if (i < allInstructions.Count)
return allInstructions[i];

View File

@ -289,6 +289,9 @@ namespace de4dot.blocks {
// Replace the BaseBlocks with a new BaseBlock, returning the old ones.
public List<BaseBlock> replace(int startInstr, int endInstr, ScopeBlock bb) {
if (endInstr < startInstr)
return new List<BaseBlock>();
int startIndex, endIndex;
var rv = getBlocks(startInstr, endInstr, out startIndex, out endIndex);
updateParent(rv, bb);