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)) {
|
||||||
|
try {
|
||||||
scopeBlock.repartitionBlocks();
|
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,10 +38,16 @@ namespace de4dot.blocks.cflow {
|
||||||
var instructions = block.Instructions;
|
var instructions = block.Instructions;
|
||||||
if (instructions.Count == 0)
|
if (instructions.Count == 0)
|
||||||
return false;
|
return false;
|
||||||
|
try {
|
||||||
for (int i = 0; i < instructions.Count - 1; i++) {
|
for (int i = 0; i < instructions.Count - 1; i++) {
|
||||||
var instr = instructions[i].Instruction;
|
var instr = instructions[i].Instruction;
|
||||||
instructionEmulator.emulate(instr);
|
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) {
|
||||||
case Code.Beq:
|
case Code.Beq:
|
||||||
|
|
|
@ -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) {
|
||||||
|
try {
|
||||||
changed |= remove(block);
|
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