Support invalid try handlers where start == end
This commit is contained in:
parent
edbd2c78a1
commit
5c61f7618f
|
@ -50,7 +50,7 @@ namespace de4dot.blocks {
|
||||||
public ExceptionInfo(int tryStart, int tryEnd, int filterStart,
|
public ExceptionInfo(int tryStart, int tryEnd, int filterStart,
|
||||||
int handlerStart, int handlerEnd, TypeReference catchType,
|
int handlerStart, int handlerEnd, TypeReference catchType,
|
||||||
ExceptionHandlerType handlerType) {
|
ExceptionHandlerType handlerType) {
|
||||||
if (tryStart > tryEnd || filterStart > handlerStart || handlerStart > handlerEnd ||
|
if (tryStart > tryEnd || filterStart > handlerStart ||
|
||||||
tryStart < 0 || tryEnd < 0 || filterStart < 0 || handlerStart < 0 || handlerEnd < 0)
|
tryStart < 0 || tryEnd < 0 || filterStart < 0 || handlerStart < 0 || handlerEnd < 0)
|
||||||
throw new ApplicationException("Invalid start/end/filter/handler indexes");
|
throw new ApplicationException("Invalid start/end/filter/handler indexes");
|
||||||
this.tryStart = tryStart;
|
this.tryStart = tryStart;
|
||||||
|
@ -196,11 +196,11 @@ namespace de4dot.blocks {
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var ex in exceptions) {
|
foreach (var ex in exceptions) {
|
||||||
var tryStart = blockInfos[ex.tryStart].start;
|
var tryStart = getBlockInfo(blockInfos, ex.tryStart).start;
|
||||||
var tryEnd = blockInfos[ex.tryEnd].end;
|
var tryEnd = getBlockInfo(blockInfos, ex.tryEnd).end;
|
||||||
var filterStart = ex.filterStart == -1 ? -1 : blockInfos[ex.filterStart].start;
|
var filterStart = ex.filterStart == -1 ? -1 : getBlockInfo(blockInfos, ex.filterStart).start;
|
||||||
var handlerStart = blockInfos[ex.handlerStart].start;
|
var handlerStart = getBlockInfo(blockInfos, ex.handlerStart).start;
|
||||||
var handlerEnd = blockInfos[ex.handlerEnd].end;
|
var handlerEnd = getBlockInfo(blockInfos, ex.handlerEnd).end;
|
||||||
|
|
||||||
var eh = new ExceptionHandler(ex.handlerType);
|
var eh = new ExceptionHandler(ex.handlerType);
|
||||||
eh.CatchType = ex.catchType;
|
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) {
|
static Instruction getInstruction(IList<Instruction> allInstructions, int i) {
|
||||||
if (i < allInstructions.Count)
|
if (i < allInstructions.Count)
|
||||||
return allInstructions[i];
|
return allInstructions[i];
|
||||||
|
|
|
@ -289,6 +289,9 @@ namespace de4dot.blocks {
|
||||||
|
|
||||||
// Replace the BaseBlocks with a new BaseBlock, returning the old ones.
|
// Replace the BaseBlocks with a new BaseBlock, returning the old ones.
|
||||||
public List<BaseBlock> replace(int startInstr, int endInstr, ScopeBlock bb) {
|
public List<BaseBlock> replace(int startInstr, int endInstr, ScopeBlock bb) {
|
||||||
|
if (endInstr < startInstr)
|
||||||
|
return new List<BaseBlock>();
|
||||||
|
|
||||||
int startIndex, endIndex;
|
int startIndex, endIndex;
|
||||||
var rv = getBlocks(startInstr, endInstr, out startIndex, out endIndex);
|
var rv = getBlocks(startInstr, endInstr, out startIndex, out endIndex);
|
||||||
updateParent(rv, bb);
|
updateParent(rv, bb);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user