Update field type

This commit is contained in:
de4dot 2011-12-15 16:17:04 +01:00
parent 929d943112
commit d35e92b53c
7 changed files with 14 additions and 19 deletions

View File

@ -19,9 +19,9 @@
namespace de4dot.blocks { namespace de4dot.blocks {
public abstract class BaseBlock { public abstract class BaseBlock {
BaseBlock parent = null; ScopeBlock parent = null;
public BaseBlock Parent { public ScopeBlock Parent {
get { return parent; } get { return parent; }
set { parent = value; } set { parent = value; }
} }

View File

@ -235,16 +235,14 @@ namespace de4dot.blocks {
break; break;
} }
foreach (var nopBlock in nopBlocks.Keys) { foreach (var nopBlock in nopBlocks.Keys)
var scopeBlock = (ScopeBlock)nopBlock.Parent; nopBlock.Parent.removeDeadBlock(nopBlock);
scopeBlock.removeDeadBlock(nopBlock);
}
} }
static Block getNopBlockTarget(Dictionary<Block, bool> nopBlocks, Block source, Block nopBlock) { static Block getNopBlockTarget(Dictionary<Block, bool> nopBlocks, Block source, Block nopBlock) {
if (nopBlock == null || !nopBlocks.ContainsKey(nopBlock) || source == nopBlock.FallThrough) if (nopBlock == null || !nopBlocks.ContainsKey(nopBlock) || source == nopBlock.FallThrough)
return null; return null;
if (((ScopeBlock)nopBlock.Parent).BaseBlocks[0] == nopBlock) if (nopBlock.Parent.BaseBlocks[0] == nopBlock)
return null; return null;
var target = nopBlock.FallThrough; var target = nopBlock.FallThrough;
if (nopBlock.Parent != target.Parent) if (nopBlock.Parent != target.Parent)

View File

@ -53,7 +53,7 @@ namespace de4dot.blocks {
var deadBlocksDict = new Dictionary<BaseBlock, bool>(); var deadBlocksDict = new Dictionary<BaseBlock, bool>();
foreach (var baseBlock in findDeadBlocks()) { foreach (var baseBlock in findDeadBlocks()) {
deadBlocksDict[baseBlock] = true; deadBlocksDict[baseBlock] = true;
ScopeBlock parent = (ScopeBlock)baseBlock.Parent; ScopeBlock parent = baseBlock.Parent;
ScopeBlockInfo info; ScopeBlockInfo info;
if (!infos.TryGetValue(parent, out info)) if (!infos.TryGetValue(parent, out info))
infos[parent] = info = new ScopeBlockInfo(parent); infos[parent] = info = new ScopeBlockInfo(parent);

View File

@ -282,7 +282,7 @@ 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, BaseBlock bb) { public List<BaseBlock> replace(int startInstr, int endInstr, ScopeBlock bb) {
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);
@ -294,7 +294,7 @@ namespace de4dot.blocks {
return rv; return rv;
} }
public List<BaseBlock> getBlocks(BaseBlock parent) { public List<BaseBlock> getBlocks(ScopeBlock parent) {
if (blocksLeft.Count == 0) if (blocksLeft.Count == 0)
return new List<BaseBlock>(); return new List<BaseBlock>();
int startIndex, endIndex; int startIndex, endIndex;
@ -302,7 +302,7 @@ namespace de4dot.blocks {
return updateParent(lb, parent); return updateParent(lb, parent);
} }
List<BaseBlock> updateParent(List<BaseBlock> lb, BaseBlock parent) { List<BaseBlock> updateParent(List<BaseBlock> lb, ScopeBlock parent) {
foreach (var bb in lb) foreach (var bb in lb)
bb.Parent = parent; bb.Parent = parent;
return lb; return lb;

View File

@ -174,10 +174,7 @@ namespace de4dot.blocks {
if (isOurBaseBlock(bb)) if (isOurBaseBlock(bb))
return bb; return bb;
for (bb = bb.Parent; bb != null; bb = bb.Parent) { for (var sb = bb.Parent; sb != null; sb = sb.Parent) {
var sb = bb as ScopeBlock;
if (sb == null)
throw new ApplicationException("Parent is not a ScopeBlock");
if (isOurBaseBlock(sb)) if (isOurBaseBlock(sb))
return sb; return sb;
} }

View File

@ -348,7 +348,7 @@ namespace de4dot.code.deobfuscators.SmartAssembly {
} }
void removeDeadBlock(Block block) { void removeDeadBlock(Block block) {
var parent = (ScopeBlock)block.Parent; var parent = block.Parent;
if (parent != null) // null if already dead if (parent != null) // null if already dead
parent.removeDeadBlock(block); parent.removeDeadBlock(block);
} }

View File

@ -99,15 +99,15 @@ namespace de4dot.code.deobfuscators.dotNET_Reactor {
antiSnBlock.replaceLastInstrsWithBranch(numInstructions, goodBlock); antiSnBlock.replaceLastInstrsWithBranch(numInstructions, goodBlock);
if (badBlock.FallThrough == badBlock && badBlock.Sources.Count == 1 && badBlock.Targets == null) { if (badBlock.FallThrough == badBlock && badBlock.Sources.Count == 1 && badBlock.Targets == null) {
((ScopeBlock)badBlock.Parent).removeGuaranteedDeadBlock(badBlock); badBlock.Parent.removeGuaranteedDeadBlock(badBlock);
return true; return true;
} }
if (badBlock.Instructions.Count <= 1 && badBlock.LastInstr.OpCode.Code == Code.Nop) { if (badBlock.Instructions.Count <= 1 && badBlock.LastInstr.OpCode.Code == Code.Nop) {
if (badBlock.FallThrough != null && badBlock.Targets == null && badBlock.Sources.Count == 0) { if (badBlock.FallThrough != null && badBlock.Targets == null && badBlock.Sources.Count == 0) {
var badBlock2 = badBlock.FallThrough; var badBlock2 = badBlock.FallThrough;
if (badBlock2.FallThrough == badBlock2 && badBlock2.Sources.Count == 2 && badBlock2.Targets == null) { if (badBlock2.FallThrough == badBlock2 && badBlock2.Sources.Count == 2 && badBlock2.Targets == null) {
((ScopeBlock)badBlock.Parent).removeGuaranteedDeadBlock(badBlock); badBlock.Parent.removeGuaranteedDeadBlock(badBlock);
((ScopeBlock)badBlock2.Parent).removeGuaranteedDeadBlock(badBlock2); badBlock2.Parent.removeGuaranteedDeadBlock(badBlock2);
return true; return true;
} }
} }