Ignore invalid metadata tokens in code
This commit is contained in:
parent
9c253e7864
commit
61b1f7a06a
|
@ -183,8 +183,16 @@ namespace de4dot.blocks {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void repartitionBlocks() {
|
public void repartitionBlocks() {
|
||||||
foreach (var scopeBlock in getAllScopeBlocks(methodBlocks))
|
foreach (var scopeBlock in getAllScopeBlocks(methodBlocks)) {
|
||||||
scopeBlock.repartitionBlocks();
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,9 +38,15 @@ namespace de4dot.blocks.cflow {
|
||||||
var instructions = block.Instructions;
|
var instructions = block.Instructions;
|
||||||
if (instructions.Count == 0)
|
if (instructions.Count == 0)
|
||||||
return false;
|
return false;
|
||||||
for (int i = 0; i < instructions.Count - 1; i++) {
|
try {
|
||||||
var instr = instructions[i].Instruction;
|
for (int i = 0; i < instructions.Count - 1; i++) {
|
||||||
instructionEmulator.emulate(instr);
|
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) {
|
switch (block.LastInstr.OpCode.Code) {
|
||||||
|
|
|
@ -35,8 +35,14 @@ namespace de4dot.blocks.cflow {
|
||||||
public bool remove() {
|
public bool remove() {
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
|
|
||||||
foreach (var block in allBlocks)
|
foreach (var block in allBlocks) {
|
||||||
changed |= remove(block);
|
try {
|
||||||
|
changed |= remove(block);
|
||||||
|
}
|
||||||
|
catch (System.NullReferenceException) {
|
||||||
|
// Here if eg. invalid metadata token in a call instruction (operand is null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user