Update ldelema type, and add unbox.any and ldobj

This commit is contained in:
de4dot 2012-04-06 15:38:44 +02:00
parent 2949862614
commit 5511ab833b
2 changed files with 27 additions and 4 deletions

View File

@ -53,13 +53,13 @@ namespace de4dot.code.deobfuscators.CliSecure.vm {
break;
case Code.Ldobj:
operandType = MethodStack.getLoadedType(method, instrs, i, 0);
operandType = getPtrElementType(MethodStack.getLoadedType(method, instrs, i, 0));
break;
case Code.Stobj:
operandType = MethodStack.getLoadedType(method, instrs, i, 1);
if (operandType == null)
operandType = MethodStack.getLoadedType(method, instrs, i, 0);
operandType = MethodStack.getLoadedType(method, instrs, i, 0);
if (!isValidType(operandType))
operandType = getPtrElementType(MethodStack.getLoadedType(method, instrs, i, 1));
break;
default:
@ -76,6 +76,18 @@ namespace de4dot.code.deobfuscators.CliSecure.vm {
return atLeastOneFailed;
}
static TypeReference getPtrElementType(TypeReference type) {
if (type == null)
return null;
var pt = type as PointerType;
if (pt != null)
return pt.ElementType;
var bt = type as ByReferenceType;
if (bt != null)
return bt.ElementType;
return null;
}
bool isValidType(TypeReference type) {
if (type == null)
return false;

View File

@ -192,6 +192,7 @@ namespace de4dot.code.deobfuscators {
case Code.Castclass:
case Code.Isinst:
case Code.Unbox_Any:
fieldType = pushInstr.Operand as TypeReference;
break;
@ -225,6 +226,10 @@ namespace de4dot.code.deobfuscators {
break;
case Code.Ldelema:
fieldType = createByReferenceType(pushInstr.Operand as TypeReference);
break;
case Code.Ldobj:
fieldType = pushInstr.Operand as TypeReference;
break;
@ -235,6 +240,12 @@ namespace de4dot.code.deobfuscators {
return fieldType;
}
static ByReferenceType createByReferenceType(TypeReference elementType) {
if (elementType == null)
return null;
return new ByReferenceType(elementType);
}
static Instruction getPreviousInstruction(IList<Instruction> instructions, ref int instrIndex) {
while (true) {
instrIndex--;