Ignore invalid metadata tokens in code

This commit is contained in:
de4dot 2011-10-27 15:57:33 +02:00
parent 9c253e7864
commit 61b1f7a06a
3 changed files with 27 additions and 7 deletions

View File

@ -183,8 +183,16 @@ namespace de4dot.blocks {
}
public void repartitionBlocks() {
foreach (var scopeBlock in getAllScopeBlocks(methodBlocks))
scopeBlock.repartitionBlocks();
foreach (var scopeBlock in getAllScopeBlocks(methodBlocks)) {
try {
scopeBlock.repartitionBlocks();
}
catch (NullReferenceException) {
//TODO: Send this message to the log
Console.WriteLine("Null ref exception! Invalid metadata token in code? Method: {0:X8}: {1}", method.MetadataToken.ToUInt32(), method.FullName);
return;
}
}
}
}
}

View File

@ -38,9 +38,15 @@ namespace de4dot.blocks.cflow {
var instructions = block.Instructions;
if (instructions.Count == 0)
return false;
for (int i = 0; i < instructions.Count - 1; i++) {
var instr = instructions[i].Instruction;
instructionEmulator.emulate(instr);
try {
for (int i = 0; i < instructions.Count - 1; i++) {
var instr = instructions[i].Instruction;
instructionEmulator.emulate(instr);
}
}
catch (System.NullReferenceException) {
// Here if eg. invalid metadata token in a call instruction (operand is null)
return false;
}
switch (block.LastInstr.OpCode.Code) {

View File

@ -35,8 +35,14 @@ namespace de4dot.blocks.cflow {
public bool remove() {
bool changed = false;
foreach (var block in allBlocks)
changed |= remove(block);
foreach (var block in allBlocks) {
try {
changed |= remove(block);
}
catch (System.NullReferenceException) {
// Here if eg. invalid metadata token in a call instruction (operand is null)
}
}
return changed;
}