diff --git a/blocks/BaseBlock.cs b/blocks/BaseBlock.cs index 622c46bf..23a2f79b 100644 --- a/blocks/BaseBlock.cs +++ b/blocks/BaseBlock.cs @@ -19,9 +19,9 @@ namespace de4dot.blocks { public abstract class BaseBlock { - BaseBlock parent = null; + ScopeBlock parent = null; - public BaseBlock Parent { + public ScopeBlock Parent { get { return parent; } set { parent = value; } } diff --git a/blocks/Blocks.cs b/blocks/Blocks.cs index 9e00a6f2..681de1b0 100644 --- a/blocks/Blocks.cs +++ b/blocks/Blocks.cs @@ -235,16 +235,14 @@ namespace de4dot.blocks { break; } - foreach (var nopBlock in nopBlocks.Keys) { - var scopeBlock = (ScopeBlock)nopBlock.Parent; - scopeBlock.removeDeadBlock(nopBlock); - } + foreach (var nopBlock in nopBlocks.Keys) + nopBlock.Parent.removeDeadBlock(nopBlock); } static Block getNopBlockTarget(Dictionary nopBlocks, Block source, Block nopBlock) { if (nopBlock == null || !nopBlocks.ContainsKey(nopBlock) || source == nopBlock.FallThrough) return null; - if (((ScopeBlock)nopBlock.Parent).BaseBlocks[0] == nopBlock) + if (nopBlock.Parent.BaseBlocks[0] == nopBlock) return null; var target = nopBlock.FallThrough; if (nopBlock.Parent != target.Parent) diff --git a/blocks/DeadBlocksRemover.cs b/blocks/DeadBlocksRemover.cs index 1fc8e743..aaac1f4c 100644 --- a/blocks/DeadBlocksRemover.cs +++ b/blocks/DeadBlocksRemover.cs @@ -53,7 +53,7 @@ namespace de4dot.blocks { var deadBlocksDict = new Dictionary(); foreach (var baseBlock in findDeadBlocks()) { deadBlocksDict[baseBlock] = true; - ScopeBlock parent = (ScopeBlock)baseBlock.Parent; + ScopeBlock parent = baseBlock.Parent; ScopeBlockInfo info; if (!infos.TryGetValue(parent, out info)) infos[parent] = info = new ScopeBlockInfo(parent); diff --git a/blocks/InstructionListParser.cs b/blocks/InstructionListParser.cs index 6ba1f3ef..7ff72578 100644 --- a/blocks/InstructionListParser.cs +++ b/blocks/InstructionListParser.cs @@ -282,7 +282,7 @@ namespace de4dot.blocks { } // Replace the BaseBlocks with a new BaseBlock, returning the old ones. - public List replace(int startInstr, int endInstr, BaseBlock bb) { + public List replace(int startInstr, int endInstr, ScopeBlock bb) { int startIndex, endIndex; var rv = getBlocks(startInstr, endInstr, out startIndex, out endIndex); updateParent(rv, bb); @@ -294,7 +294,7 @@ namespace de4dot.blocks { return rv; } - public List getBlocks(BaseBlock parent) { + public List getBlocks(ScopeBlock parent) { if (blocksLeft.Count == 0) return new List(); int startIndex, endIndex; @@ -302,7 +302,7 @@ namespace de4dot.blocks { return updateParent(lb, parent); } - List updateParent(List lb, BaseBlock parent) { + List updateParent(List lb, ScopeBlock parent) { foreach (var bb in lb) bb.Parent = parent; return lb; diff --git a/blocks/ScopeBlock.cs b/blocks/ScopeBlock.cs index bb227e00..53996920 100644 --- a/blocks/ScopeBlock.cs +++ b/blocks/ScopeBlock.cs @@ -174,10 +174,7 @@ namespace de4dot.blocks { if (isOurBaseBlock(bb)) return bb; - for (bb = bb.Parent; bb != null; bb = bb.Parent) { - var sb = bb as ScopeBlock; - if (sb == null) - throw new ApplicationException("Parent is not a ScopeBlock"); + for (var sb = bb.Parent; sb != null; sb = sb.Parent) { if (isOurBaseBlock(sb)) return sb; } diff --git a/de4dot.code/deobfuscators/SmartAssembly/TamperProtectionRemover.cs b/de4dot.code/deobfuscators/SmartAssembly/TamperProtectionRemover.cs index e64ad353..b6588e38 100644 --- a/de4dot.code/deobfuscators/SmartAssembly/TamperProtectionRemover.cs +++ b/de4dot.code/deobfuscators/SmartAssembly/TamperProtectionRemover.cs @@ -348,7 +348,7 @@ namespace de4dot.code.deobfuscators.SmartAssembly { } void removeDeadBlock(Block block) { - var parent = (ScopeBlock)block.Parent; + var parent = block.Parent; if (parent != null) // null if already dead parent.removeDeadBlock(block); } diff --git a/de4dot.code/deobfuscators/dotNET_Reactor/AntiStrongname.cs b/de4dot.code/deobfuscators/dotNET_Reactor/AntiStrongname.cs index 4c2cd10b..5915c097 100644 --- a/de4dot.code/deobfuscators/dotNET_Reactor/AntiStrongname.cs +++ b/de4dot.code/deobfuscators/dotNET_Reactor/AntiStrongname.cs @@ -99,15 +99,15 @@ namespace de4dot.code.deobfuscators.dotNET_Reactor { antiSnBlock.replaceLastInstrsWithBranch(numInstructions, goodBlock); if (badBlock.FallThrough == badBlock && badBlock.Sources.Count == 1 && badBlock.Targets == null) { - ((ScopeBlock)badBlock.Parent).removeGuaranteedDeadBlock(badBlock); + badBlock.Parent.removeGuaranteedDeadBlock(badBlock); return true; } if (badBlock.Instructions.Count <= 1 && badBlock.LastInstr.OpCode.Code == Code.Nop) { if (badBlock.FallThrough != null && badBlock.Targets == null && badBlock.Sources.Count == 0) { var badBlock2 = badBlock.FallThrough; if (badBlock2.FallThrough == badBlock2 && badBlock2.Sources.Count == 2 && badBlock2.Targets == null) { - ((ScopeBlock)badBlock.Parent).removeGuaranteedDeadBlock(badBlock); - ((ScopeBlock)badBlock2.Parent).removeGuaranteedDeadBlock(badBlock2); + badBlock.Parent.removeGuaranteedDeadBlock(badBlock); + badBlock2.Parent.removeGuaranteedDeadBlock(badBlock2); return true; } }